Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
script: script/test
language: node_js
node_js:
- '0.10'
- "lts/*"

install:
- wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
- tar -xvf ./phantomjs-1.9.8-linux-x86_64.tar.bz2
- export PATH=$PWD/phantomjs-1.9.8-linux-x86_64/bin:$PATH

script:
- npm test
12 changes: 5 additions & 7 deletions classList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if ("document" in self) {
// Full polyfill for browsers with no classList support
// Including IE < Edge missing SVGElement.classList
if (
!("classList" in document.createElement("_"))
!("classList" in document.createElement("_"))
|| document.createElementNS
&& !("classList" in document.createElementNS("http://www.w3.org/2000/svg","g"))
) {
Expand Down Expand Up @@ -104,14 +104,13 @@ classListProto.add = function () {
, token
, updated = false
;
do {
while (++i <= l) {
token = tokens[i] + "";
if (!~checkTokenAndGetIndex(this, token)) {
this.push(token);
updated = true;
}
}
while (++i < l);
};

if (updated) {
this._updateClassName();
Expand All @@ -126,7 +125,7 @@ classListProto.remove = function () {
, updated = false
, index
;
do {
while (++i <= l) {
token = tokens[i] + "";
index = checkTokenAndGetIndex(this, token);
while (~index) {
Expand All @@ -135,7 +134,6 @@ classListProto.remove = function () {
index = checkTokenAndGetIndex(this, token);
}
}
while (++i < l);

if (updated) {
this._updateClassName();
Expand Down Expand Up @@ -260,4 +258,4 @@ if (objCtr.defineProperty) {
testElement = null;
}());

}
}
2 changes: 1 addition & 1 deletion classList.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,18 @@ QUnit.test("Removes class with second argument", function(assert) {
"Returns false when class was not present"
);
});

QUnit.test("Adds no class with no argument", function(assert) {
var cList = document.createElement("p").classList;

cList.add();
assert.ok(!cList.contains("c1"), "Adds no class");
});

QUnit.test("Removes no class with no argument", function(assert) {
var cList = document.createElement("p").classList;

cList.add("c1");
cList.remove();
assert.ok(cList.contains("c1"), "Removes no class");
});