vendor: 3,852 bytes, lines 1-176
1/* 2 * classList.js: Cross-browser full element.classList implementation. 3 * 2014-01-07 4 * 5 * By Eli Grey, http://eligrey.com 6 * Public Domain. 7 * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. 8 */ 9 10/*global self, document, DOMException */ 11 12/*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js*/ 13 14if ("document" in self && !("classList" in document.createElement("_"))) { 15 16(function (view) { 17 18"use strict"; 19 20if (!('Element' in view)) return; 21 22var 23 classListProp = "classList" 24 , protoProp = "prototype" 25 , elemCtrProto = view.Element[protoProp] 26 , objCtr = Object 27 , strTrim = String[protoProp].trim || function () { 28 return this.replace(/^\s+|\s+$/g, ""); 29 } 30 , arrIndexOf = Array[protoProp].indexOf || function (item) { 31 var 32 i = 0 33 , len = this.length 34 ; 35 for (; i < len; i++) { 36 if (i in this && this[i] === item) { 37 return i; 38 } 39 } 40 return -1; 41 } 42 // Vendors: please allow content code to instantiate DOMExceptions 43 , DOMEx = function (type, message) { 44 this.name = type; 45 this.code = DOMException[type]; 46 this.message = message; 47 } 48 , checkTokenAndGetIndex = function (classList, token) { 49 if (token === "") { 50 throw new DOMEx( 51 "SYNTAX_ERR" 52 , "An invalid or illegal string was specified" 53 ); 54 } 55 if (/\s/.test(token)) { 56 throw new DOMEx( 57 "INVALID_CHARACTER_ERR" 58 , "String contains an invalid character" 59 ); 60 } 61 return arrIndexOf.call(classList, token); 62 } 63 , ClassList = function (elem) { 64 var 65 trimmedClasses = strTrim.call(elem.getAttribute("class") || "") 66 , classes = trimmedClasses ? trimmedClasses.split(/\s+/) : [] 67 , i = 0 68 , len = classes.length 69 ; 70 for (; i < len; i++) { 71 this.push(classes[i]); 72 } 73 this._updateClassName = function () { 74 elem.setAttribute("class", this.toString()); 75 }; 76 } 77 , classListProto = ClassList[protoProp] = [] 78 , classListGetter = function () { 79 return new ClassList(this); 80 } 81; 82// Most DOMException implementations don't allow calling DOMException's toString() 83// on non-DOMExceptions. Error's toString() is sufficient here. 84DOMEx[protoProp] = Error[protoProp]; 85classListProto.item = function (i) { 86 return this[i] || null; 87}; 88classListProto.contains = function (token) { 89 token += ""; 90 return checkTokenAndGetIndex(this, token) !== -1; 91}; 92classListProto.add = function () { 93 var 94 tokens = arguments 95 , i = 0 96 , l = tokens.length 97 , token 98 , updated = false 99 ; 100 do { 101 token = tokens[i] + ""; 102 if (checkTokenAndGetIndex(this, token) === -1) { 103 this.push(token); 104 updated = true; 105 } 106 } 107 while (++i < l); 108 109 if (updated) { 110 this._updateClassName(); 111 } 112}; 113classListProto.remove = function () { 114 var 115 tokens = arguments 116 , i = 0 117 , l = tokens.length 118 , token 119 , updated = false 120 ; 121 do { 122 token = tokens[i] + ""; 123 var index = checkTokenAndGetIndex(this, token); 124 if (index !== -1) { 125 this.splice(index, 1); 126 updated = true; 127 } 128 } 129 while (++i < l); 130 131 if (updated) { 132 this._updateClassName(); 133 } 134}; 135classListProto.toggle = function (token, forse) { 136 token += ""; 137 138 var 139 result = this.contains(token) 140 , method = result ? 141 forse !== true && "remove" 142 : 143 forse !== false && "add" 144 ; 145 146 if (method) { 147 this[method](token); 148 } 149 150 return !result; 151}; 152classListProto.toString = function () { 153 return this.join(" "); 154}; 155 156if (objCtr.defineProperty) { 157 var classListPropDesc = { 158 get: classListGetter 159 , enumerable: true 160 , configurable: true 161 }; 162 try { 163 objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc); 164 } catch (ex) { // IE 8 doesn't support enumerable:true 165 if (ex.number === -0x7FF5EC54) { 166 classListPropDesc.enumerable = false; 167 objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc); 168 } 169 } 170} else if (objCtr[protoProp].__defineGetter__) { 171 elemCtrProto.__defineGetter__(classListProp, classListGetter); 172} 173 174}(self)); 175 176}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.