polyfill.classlist.js
4.74 KB
(function(){"defineProperty"in Object&&function(){try{var t={};return Object.defineProperty(t,"test",{value:42}),!0}catch(e){return!1}}()||!function(t){var e=Object.prototype.hasOwnProperty("__defineGetter__"),n="Getters & setters cannot be defined on this javascript engine",o="A property cannot both have accessors and be writable or have a value";Object.defineProperty=function(r,i,c){if(t&&(r===window||r===document||r===Element.prototype||r instanceof Element))return t(r,i,c);if(null===r||!(r instanceof Object||"object"==typeof r))throw new TypeError("Object must be an object (Object.defineProperty polyfill)");if(!(c instanceof Object))throw new TypeError("Descriptor must be an object (Object.defineProperty polyfill)");var a=String(i),u="value"in c||"writable"in c,p="get"in c&&typeof c.get,l="set"in c&&typeof c.set;if(p){if("function"!==p)throw new TypeError("Getter expected a function (Object.defineProperty polyfill)");if(!e)throw new TypeError(n);if(u)throw new TypeError(o);r.__defineGetter__(a,c.get)}else r[a]=c.value;if(l){if("function"!==l)throw new TypeError("Setter expected a function (Object.defineProperty polyfill)");if(!e)throw new TypeError(n);if(u)throw new TypeError(o);r.__defineSetter__(a,c.set)}return"value"in c&&(r[a]=c.value),r}}(Object.defineProperty);var t=function(){function t(t){if(/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/.test(t))return String(t);throw new Error("InvalidCharacterError: DOM Exception 5")}function e(t){for(var e,n=-1,o={};e=t[++n];)o[e]=!0;return o}function n(t,e){var n,o=[];for(n in e)e[n]&&o.push(n);[].splice.apply(t,[0,t.length].concat(o))}var o=function(){};return o.prototype={constructor:o,item:function(t){return this[parseFloat(t)]||null},length:Array.prototype.length,toString:function(){return[].join.call(this," ")},add:function(){for(var o,r=e(this),i=0;i in arguments;++i)o=t(arguments[i]),r[o]=!0;n(this,r)},contains:function(t){return t in e(this)},remove:function(){for(var o,r=e(this),i=0;i in arguments;++i)o=t(arguments[i]),r[o]=!1;n(this,r)},toggle:function(o){var r=e(this),i=1 in arguments?!arguments[1]:t(o)in r;return r[o]=!i,n(this,r),!i}},o}();"Document"in this||(this.HTMLDocument?this.Document=this.HTMLDocument:(this.Document=this.HTMLDocument=document.constructor=new Function("return function Document() {}")(),this.Document.prototype=document)),"Element"in this&&"HTMLElement"in this||!function(){function t(){return l--||clearTimeout(e),document.body&&!document.body.prototype&&/(complete|interactive)/.test(document.readyState)?(a(document,!0),e&&document.body.prototype&&clearTimeout(e),!!document.body.prototype):!1}if(window.Element&&!window.HTMLElement)return void(window.HTMLElement=window.Element);window.Element=window.HTMLElement=new Function("return function Element() {}")();var e,n=document.appendChild(document.createElement("body")),o=n.appendChild(document.createElement("iframe")),r=o.contentWindow.document,i=Element.prototype=r.appendChild(r.createElement("*")),c={},a=function(t,e){var n,o,r,i=t.childNodes||[],u=-1;if(1===t.nodeType&&t.constructor!==Element){t.constructor=Element;for(n in c)o=c[n],t[n]=o}for(;r=e&&i[++u];)a(r,e);return t},u=document.getElementsByTagName("*"),p=document.createElement,l=100;i.attachEvent("onpropertychange",function(t){for(var e,n=t.propertyName,o=!c.hasOwnProperty(n),r=i[n],a=c[n],p=-1;e=u[++p];)1===e.nodeType&&(o||e[n]===a)&&(e[n]=r);c[n]=r}),i.constructor=Element,i.hasAttribute||(i.hasAttribute=function(t){return null!==this.getAttribute(t)}),t(!0)||(document.onreadystatechange=t,e=setInterval(t,25)),document.createElement=function(t){var e=p(String(t).toLowerCase());return a(e)},document.removeChild(n)}(),"document"in this&&"classList"in document.documentElement||Object.defineProperty(Element.prototype,"classList",{configurable:!0,get:function(){function e(){var t="object"==typeof r.className?r.className.baseVal:r.className;[].splice.apply(o,[0,o.length].concat((t||"").replace(/^\s+|\s+$/g,"").split(/\s+/)))}function n(){r.attachEvent&&r.detachEvent("onpropertychange",e),"object"==typeof r.className?r.className.baseVal=i.toString.call(o):r.className=i.toString.call(o),r.attachEvent&&r.attachEvent("onpropertychange",e)}var o,r=this,i=t.prototype,c=function(){};return c.prototype=new t,c.prototype.item=function(){return e(),i.item.apply(o,arguments)},c.prototype.toString=function(){return e(),i.toString.apply(o,arguments)},c.prototype.add=function(){return e(),i.add.apply(o,arguments),n()},c.prototype.contains=function(){return e(),i.contains.apply(o,arguments)},c.prototype.remove=function(){return e(),i.remove.apply(o,arguments),n()},c.prototype.toggle=function(t){return e(),t=i.toggle.apply(o,arguments),n(),t},o=new c,r.attachEvent&&r.attachEvent("onpropertychange",e),o}})}).call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{});