This repository has been archived by the owner on Sep 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
element.classlist.min.js
13 lines (13 loc) · 1.66 KB
/
element.classlist.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* Implementation of classList attribute (DOMTokenList interface)
* http://www.w3.org/TR/dom/#domtokenlist
*
* Depends on array generics
* https://github.com/plusdude/array-generics
*
* Copyright (c) 2013 Alex K @plusdude
* http://opensource.org/licenses/MIT
*/
(function(f,m){function d(a){var b;if(!(this instanceof d))return new d(this);b=a.className;b=b.match(/\S+/g)||[];c.forEach(b,n,this);this.length=b.length;this.element=a;return this}function n(a,b){this[b]=a}function h(a){a.element.className=c.join(a," ")}function g(a){a=String(a);if(""===a)throw Error("An invalid or illegal string was specified");if(/\s/.test(a))throw Error("String contains an invalid character");return a}function e(a,b){if(!a.length)throw Error("Not enough arguments to DOMTokenList."+
b);}function p(a){e(arguments,"item");return a in this?this[a]:null}function q(a){e(arguments,"contains");a=g(a);return-1<c.indexOf(this,a)}function r(){e(arguments,"add");c.forEach(arguments,s,this);h(this)}function s(a){a=g(a);0>c.indexOf(this,a)&&c.push(this,a)}function t(){e(arguments,"remove");c.forEach(arguments,u,this);h(this)}function u(a){a=g(a);a=c.indexOf(this,a);-1<a&&c.splice(this,a,1)}function v(a,b){var d;e(arguments,"toggle");a=g(a);m!==b&&(b=Boolean(b));d=c.indexOf(this,a);-1<d?!0!==
b&&(c.splice(this,d,1),b=!1):!1!==b&&(c.push(this,a),b=!0);h(this);return b}function w(){return c.join(this," ")}var c=f.Array,l=f.document,k=f.HTMLElement||f.Element;if(l&&!l.documentElement.classList&&k){d.prototype={constructor:d,item:p,contains:q,add:r,remove:t,toggle:v,toString:w};try{Object.defineProperty(k.prototype,"classList",{get:d})}catch(x){k.prototype.__defineGetter__("classList",d)}}})(this);