From fa49de3a2902aaaedb6e73625b6292e1c52ab300 Mon Sep 17 00:00:00 2001 From: Dominique Date: Thu, 18 Oct 2018 22:50:02 +0200 Subject: [PATCH 1/4] feat(add, remove): Make add & remove parameters optional --- classList.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/classList.js b/classList.js index 615456a..fa2b741 100644 --- a/classList.js +++ b/classList.js @@ -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")) ) { @@ -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(); @@ -126,7 +125,7 @@ classListProto.remove = function () { , updated = false , index ; - do { + while (++i <= l) { token = tokens[i] + ""; index = checkTokenAndGetIndex(this, token); while (~index) { @@ -135,7 +134,6 @@ classListProto.remove = function () { index = checkTokenAndGetIndex(this, token); } } - while (++i < l); if (updated) { this._updateClassName(); @@ -260,4 +258,4 @@ if (objCtr.defineProperty) { testElement = null; }()); -} \ No newline at end of file +} From 1ca90ee8ab12b116bb8bdb7dad6436a62e6abf65 Mon Sep 17 00:00:00 2001 From: Dominique Date: Thu, 18 Oct 2018 22:50:41 +0200 Subject: [PATCH 2/4] test(*): Extend unit tests to cover optional parameters --- tests/tests.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/tests.js b/tests/tests.js index b76a72a..5333be2 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -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"); +}); From 658c7cd6ca60a7a47c1db50a6ed5d93741b5e1fc Mon Sep 17 00:00:00 2001 From: Dominique Date: Thu, 18 Oct 2018 23:00:49 +0200 Subject: [PATCH 3/4] Update minified file --- classList.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classList.min.js b/classList.min.js index 93bb1bf..adf1658 100644 --- a/classList.min.js +++ b/classList.min.js @@ -1,2 +1,2 @@ /*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js */ -"document"in self&&("classList"in document.createElement("_")&&(!document.createElementNS||"classList"in document.createElementNS("http://www.w3.org/2000/svg","g"))||!function(t){"use strict";if("Element"in t){var e="classList",n="prototype",i=t.Element[n],s=Object,r=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,"")},o=Array[n].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1},c=function(t,e){this.name=t,this.code=DOMException[t],this.message=e},a=function(t,e){if(""===e)throw new c("SYNTAX_ERR","The token must not be empty.");if(/\s/.test(e))throw new c("INVALID_CHARACTER_ERR","The token must not contain space characters.");return o.call(t,e)},l=function(t){for(var e=r.call(t.getAttribute("class")||""),n=e?e.split(/\s+/):[],i=0,s=n.length;s>i;i++)this.push(n[i]);this._updateClassName=function(){t.setAttribute("class",this.toString())}},u=l[n]=[],h=function(){return new l(this)};if(c[n]=Error[n],u.item=function(t){return this[t]||null},u.contains=function(t){return~a(this,t+"")},u.add=function(){var t,e=arguments,n=0,i=e.length,s=!1;do t=e[n]+"",~a(this,t)||(this.push(t),s=!0);while(++nn;n++)t=arguments[n],e.call(this,t)}};e("add"),e("remove")}if(t.classList.toggle("c3",!1),t.classList.contains("c3")){var n=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(t,e){return 1 in arguments&&!this.contains(t)==!e?e:n.call(this,t)}}"replace"in document.createElement("_").classList||(DOMTokenList.prototype.replace=function(t,e){var n=this.toString().split(" "),i=n.indexOf(t+"");~i&&(n=n.slice(i),this.remove.apply(this,n),this.add(e),this.add.apply(this,n.slice(1)))}),t=null}()); \ No newline at end of file +"document"in self&&("classList"in document.createElement("_")&&(!document.createElementNS||"classList"in document.createElementNS("http://www.w3.org/2000/svg","g"))||function(t){"use strict";if("Element"in t){var e="classList",n="prototype",i=t.Element[n],s=Object,r=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,"")},o=Array[n].indexOf||function(t){for(var e=0,n=this.length;e Date: Thu, 18 Oct 2018 23:13:09 +0200 Subject: [PATCH 4/4] Fix travis CI configuration --- .travis.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3147878..3446cdb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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