This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from arv/class-list
Invalidate shadow renderer when classList is mutated
- Loading branch information
Showing
6 changed files
with
192 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2014 The Polymer Authors. All rights reserved. | ||
// Use of this source code is goverened by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
(function(scope) { | ||
'use strict'; | ||
|
||
function invalidateClass(el) { | ||
scope.invalidateRendererBasedOnAttribute(el, 'class'); | ||
} | ||
|
||
function DOMTokenList(impl, ownerElement) { | ||
this.impl = impl; | ||
this.ownerElement_ = ownerElement; | ||
} | ||
|
||
DOMTokenList.prototype = { | ||
get length() { | ||
return this.impl.length; | ||
}, | ||
item: function(index) { | ||
return this.impl.item(index); | ||
}, | ||
contains: function(token) { | ||
return this.impl.contains(token); | ||
}, | ||
add: function() { | ||
this.impl.add.apply(this.impl, arguments); | ||
invalidateClass(this.ownerElement_); | ||
}, | ||
remove: function() { | ||
this.impl.remove.apply(this.impl, arguments); | ||
invalidateClass(this.ownerElement_); | ||
}, | ||
toggle: function(token) { | ||
var rv = this.impl.toggle.apply(this.impl, arguments); | ||
invalidateClass(this.ownerElement_); | ||
return rv; | ||
}, | ||
toString: function() { | ||
return this.impl.toString(); | ||
} | ||
}; | ||
|
||
scope.wrappers.DOMTokenList = DOMTokenList; | ||
})(window.ShadowDOMPolyfill); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2014 The Polymer Authors. All rights reserved. | ||
* Use of this source code is goverened by a BSD-style | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
|
||
suite('DOMTokenList', function() { | ||
|
||
test('instanceof', function() { | ||
var div = document.createElement('div'); | ||
assert.instanceOf(div.classList, DOMTokenList); | ||
}); | ||
|
||
test('identity', function() { | ||
var div = document.createElement('div'); | ||
assert.equal(div.classList, div.classList); | ||
}); | ||
|
||
test('length', function() { | ||
var div = document.createElement('div'); | ||
var classList = div.classList; | ||
assert.equal(classList.length, 0); | ||
div.className = 'a'; | ||
assert.equal(classList.length, 1); | ||
div.className = 'a b'; | ||
assert.equal(classList.length, 2); | ||
div.className = 'a b a'; | ||
assert.equal(classList.length, 3); | ||
}); | ||
|
||
test('item', function() { | ||
var div = document.createElement('div'); | ||
var classList = div.classList; | ||
assert.isNull(classList.item(0)); | ||
div.className = 'a'; | ||
assert.equal(classList.item(0), 'a'); | ||
assert.isNull(classList.item(1)); | ||
div.className = 'a b'; | ||
assert.equal(classList.item(0), 'a'); | ||
assert.equal(classList.item(1), 'b'); | ||
assert.isNull(classList.item(2)); | ||
div.className = 'a b a'; | ||
assert.equal(classList.item(0), 'a'); | ||
assert.equal(classList.item(1), 'b'); | ||
assert.equal(classList.item(2), 'a'); | ||
assert.isNull(classList.item(3)); | ||
}); | ||
|
||
test('contains', function() { | ||
var div = document.createElement('div'); | ||
var classList = div.classList; | ||
assert.isFalse(classList.contains()); | ||
assert.isFalse(classList.contains('a')); | ||
div.className = 'a'; | ||
assert.isTrue(classList.contains('a')); | ||
div.className = 'a b'; | ||
assert.isTrue(classList.contains('a')); | ||
assert.isTrue(classList.contains('b')); | ||
}); | ||
|
||
test('add', function() { | ||
var div = document.createElement('div'); | ||
var classList = div.classList; | ||
classList.add('a'); | ||
assert.equal(div.className, 'a'); | ||
classList.add('b'); | ||
assert.equal(div.className, 'a b'); | ||
classList.add('a'); | ||
assert.equal(div.className, 'a b'); | ||
}); | ||
|
||
test('remove', function() { | ||
var div = document.createElement('div'); | ||
var classList = div.classList; | ||
div.className = 'a b'; | ||
classList.remove('a'); | ||
assert.equal(div.className, 'b'); | ||
classList.remove('a'); | ||
assert.equal(div.className, 'b'); | ||
classList.remove('b'); | ||
assert.equal(div.className, ''); | ||
}); | ||
|
||
test('toggle', function() { | ||
var div = document.createElement('div'); | ||
var classList = div.classList; | ||
div.className = 'a b'; | ||
classList.toggle('a'); | ||
assert.equal(div.className, 'b'); | ||
classList.toggle('a'); | ||
assert.equal(div.className, 'b a'); | ||
classList.toggle('b'); | ||
assert.equal(div.className, 'a'); | ||
}); | ||
|
||
test('toString', function() { | ||
var div = document.createElement('div'); | ||
var classList = div.classList; | ||
div.className = 'a'; | ||
assert.equal(classList.toString(), 'a'); | ||
div.className = 'b a'; | ||
assert.equal(classList.toString(), 'b a'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters