-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathdom4.js
2 lines (2 loc) · 10.7 KB
/
dom4.js
1
2
/*! (C) Andrea Giammarchi - @WebReflection - Mit Style License */
!function(e){"use strict";function t(){return h.createDocumentFragment()}function n(e){return h.createElement(e)}function r(e,t){if(!e)throw new Error("Failed to construct "+t+": 1 argument required, but only 0 present.")}function i(e){if(1===e.length)return o(e[0]);for(var n=t(),r=O.call(e),i=0;i<e.length;i++)n.appendChild(o(r[i]));return n}function o(e){return"object"==typeof e?e:h.createTextNode(e)}for(var a,c,l,s,u,h=e.document,p=Object.prototype.hasOwnProperty,f=Object.defineProperty||function(e,t,n){return p.call(n,"value")?e[t]=n.value:(p.call(n,"get")&&e.__defineGetter__(t,n.get),p.call(n,"set")&&e.__defineSetter__(t,n.set)),e},v=[].indexOf||function(e){for(var t=this.length;t--&&this[t]!==e;);return t},d=function(e){if(!e)throw"SyntaxError";if(b.test(e))throw"InvalidCharacterError";return e},y=function(e){var t="undefined"==typeof e.className,n=t?e.getAttribute("class")||"":e.className,r=t||"object"==typeof n,i=(r?t?n:n.baseVal:n).replace(E,"");i.length&&q.push.apply(this,i.split(b)),this._isSVG=r,this._=e},m={get:function(){return new y(this)},set:function(){}},E=/^\s+|\s+$/g,b=/\s+/,g=function(e,t){return this.contains(e)?t||this.remove(e):(t===undefined||t)&&(t=!0,this.add(e)),!!t},_=e.DocumentFragment&&DocumentFragment.prototype,w=e.Node,K=(w||Element).prototype,A=e.CharacterData||w,C=A&&A.prototype,S=e.DocumentType,M=S&&S.prototype,k=(e.Element||w||e.HTMLElement).prototype,L=e.HTMLSelectElement||n("select").constructor,T=L.prototype.remove,N=e.SVGElement,q=["matches",k.matchesSelector||k.webkitMatchesSelector||k.khtmlMatchesSelector||k.mozMatchesSelector||k.msMatchesSelector||k.oMatchesSelector||function(e){var t=this.parentNode;return!!t&&-1<v.call(t.querySelectorAll(e),this)},"closest",function(e){for(var t,n=this;(t=n&&n.matches)&&!n.matches(e);)n=n.parentNode;return t?n:null},"prepend",function(){var e=this.firstChild,t=i(arguments);e?this.insertBefore(t,e):this.appendChild(t)},"append",function(){this.appendChild(i(arguments))},"before",function(){var e=this.parentNode;e&&e.insertBefore(i(arguments),this)},"after",function(){var e=this.parentNode,t=this.nextSibling,n=i(arguments);e&&(t?e.insertBefore(n,t):e.appendChild(n))},"toggleAttribute",function(e,t){var n=this.hasAttribute(e);return 1<arguments.length?n&&!t?this.removeAttribute(e):t&&!n&&this.setAttribute(e,""):n?this.removeAttribute(e):this.setAttribute(e,""),this.hasAttribute(e)},"replace",function(){this.replaceWith.apply(this,arguments)},"replaceWith",function(){var e=this.parentNode;e&&e.replaceChild(i(arguments),this)},"remove",function(){var e=this.parentNode;e&&e.removeChild(this)}],O=q.slice,D=q.length;D;D-=2)if(c=q[D-2],c in k||(k[c]=q[D-1]),"remove"!==c||T._dom4||((L.prototype[c]=function(){return 0<arguments.length?T.apply(this,arguments):k.remove.call(this)})._dom4=!0),/^(?:before|after|replace|replaceWith|remove)$/.test(c)&&(!A||c in C||(C[c]=q[D-1]),!S||c in M||(M[c]=q[D-1])),/^(?:append|prepend)$/.test(c))if(_)c in _||(_[c]=q[D-1]);else try{t().constructor.prototype[c]=q[D-1]}catch(F){}n("a").matches("a")||(k[c]=function(e){return function(n){return e.call(this.parentNode?this:t().appendChild(this),n)}}(k[c])),y.prototype={length:0,add:function(){for(var e,t=0;t<arguments.length;t++)e=arguments[t],this.contains(e)||q.push.call(this,c);this._isSVG?this._.setAttribute("class",""+this):this._.className=""+this},contains:function(e){return function(t){return-1<(D=e.call(this,c=d(t)))}}([].indexOf||function(e){for(D=this.length;D--&&this[D]!==e;);return D}),item:function(e){return this[e]||null},remove:function(){for(var e,t=0;t<arguments.length;t++)e=arguments[t],this.contains(e)&&q.splice.call(this,D,1);this._isSVG?this._.setAttribute("class",""+this):this._.className=""+this},toggle:g,toString:function(){return q.join.call(this," ")}},!N||"classList"in N.prototype||f(N.prototype,"classList",m),"classList"in h.documentElement?(s=n("div").classList,s.add("a","b","a"),"a b"!=s&&(l=s.constructor.prototype,"add"in l||(l=e.TemporaryTokenList.prototype),u=function(e){return function(){for(var t=0;t<arguments.length;)e.call(this,arguments[t++])}},l.add=u(l.add),l.remove=u(l.remove),l.toggle=g)):f(k,"classList",m),"contains"in K||f(K,"contains",{value:function(e){for(;e&&e!==this;)e=e.parentNode;return this===e}}),"head"in h||f(h,"head",{get:function(){return a||(a=h.getElementsByTagName("head")[0])}}),function(){for(var t,n=e.requestAnimationFrame,r=e.cancelAnimationFrame,i=["o","ms","moz","webkit"],o=i.length;!r&&o--;)n=n||e[i[o]+"RequestAnimationFrame"],r=e[i[o]+"CancelAnimationFrame"]||e[i[o]+"CancelRequestAnimationFrame"];r||(n?(t=n,n=function(e){var n=!0;return t(function(){n&&e.apply(this,arguments)}),function(){n=!1}},r=function(e){e()}):(n=function(e){return setTimeout(e,15,15)},r=function(e){clearTimeout(e)})),e.requestAnimationFrame=n,e.cancelAnimationFrame=r}();try{new e.CustomEvent("?")}catch(F){e.CustomEvent=function(e,t){function n(n,i){var o=h.createEvent(e);if("string"!=typeof n)throw new Error("An event name must be provided");return"Event"==e&&(o.initCustomEvent=r),null==i&&(i=t),o.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),o}function r(e,t,n,r){this.initEvent(e,t,n),this.detail=r}return n}(e.CustomEvent?"CustomEvent":"Event",{bubbles:!1,cancelable:!1,detail:null})}try{new Event("_")}catch(F){F=function(e){function t(e,t){r(arguments.length,"Event");var n=h.createEvent("Event");return t||(t={}),n.initEvent(e,!!t.bubbles,!!t.cancelable),n}return t.prototype=e.prototype,t}(e.Event||function(){}),f(e,"Event",{value:F}),Event!==F&&(Event=F)}try{new KeyboardEvent("_",{})}catch(F){F=function(t){function n(e){for(var t=[],n=["ctrlKey","Control","shiftKey","Shift","altKey","Alt","metaKey","Meta","altGraphKey","AltGraph"],r=0;r<n.length;r+=2)e[n[r]]&&t.push(n[r+1]);return t.join(" ")}function i(e,t){for(var n in t)t.hasOwnProperty(n)&&!t.hasOwnProperty.call(e,n)&&(e[n]=t[n]);return e}function o(e,t,n){try{t[e]=n[e]}catch(o_O){}}function a(t,a){r(arguments.length,"KeyboardEvent"),a=i(a||{},s);var u,p=h.createEvent(c),f=a.ctrlKey,v=a.shiftKey,d=a.altKey,y=a.metaKey,m=a.altGraphKey,E=l>3?n(a):null,b=String(a.key),g=String(a["char"]),_=a.location,w=a.keyCode||(a.keyCode=b)&&b.charCodeAt(0)||0,K=a.charCode||(a.charCode=g)&&g.charCodeAt(0)||0,A=a.bubbles,C=a.cancelable,S=a.repeat,M=a.locale,k=a.view||e;if(a.which||(a.which=a.keyCode),"initKeyEvent"in p)p.initKeyEvent(t,A,C,k,f,d,v,y,w,K);else if(0<l&&"initKeyboardEvent"in p){switch(u=[t,A,C,k],l){case 1:u.push(b,_,f,v,d,y,m);break;case 2:u.push(f,d,v,y,w,K);break;case 3:u.push(b,_,f,d,v,y,m);break;case 4:u.push(b,_,E,S,M);break;default:u.push(char,b,_,E,S,M)}p.initKeyboardEvent.apply(p,u)}else p.initEvent(t,A,C);for(b in p)s.hasOwnProperty(b)&&p[b]!==a[b]&&o(b,p,a);return p}var c,l=0,s={"char":"",key:"",location:0,ctrlKey:!1,shiftKey:!1,altKey:!1,metaKey:!1,altGraphKey:!1,repeat:!1,locale:navigator.language,detail:0,bubbles:!1,cancelable:!1,keyCode:0,charCode:0,which:0};try{var u=h.createEvent("KeyboardEvent");u.initKeyboardEvent("keyup",!1,!1,e,"+",3,!0,!1,!0,!1,!1),l="+"==(u.keyIdentifier||u.key)&&3==(u.keyLocation||u.location)&&(u.ctrlKey?u.altKey?1:3:u.shiftKey?2:4)||9}catch(o_O){}return c=0<l?"KeyboardEvent":"Event",a.prototype=t.prototype,a}(e.KeyboardEvent||function(){}),f(e,"KeyboardEvent",{value:F}),KeyboardEvent!==F&&(KeyboardEvent=F)}try{new MouseEvent("_",{})}catch(F){F=function(t){function n(t,n){r(arguments.length,"MouseEvent");var i=h.createEvent("MouseEvent");return n||(n={}),i.initMouseEvent(t,!!n.bubbles,!!n.cancelable,n.view||e,n.detail||1,n.screenX||0,n.screenY||0,n.clientX||0,n.clientY||0,!!n.ctrlKey,!!n.altKey,!!n.shiftKey,!!n.metaKey,n.button||0,n.relatedTarget||null),i}return n.prototype=t.prototype,n}(e.MouseEvent||function(){}),f(e,"MouseEvent",{value:F}),MouseEvent!==F&&(MouseEvent=F)}h.querySelectorAll("*").forEach||function(){function e(e){var t=e.querySelectorAll;e.querySelectorAll=function(e){var n=t.call(this,e);return n.forEach=Array.prototype.forEach,n}}e(h),e(Element.prototype)}();try{h.querySelector(":scope *")}catch(F){!function(){function e(e,n,r){if(e.type!=h.ELEMENT_NODE)return n.call(e,r);e.setAttribute(t,null);var i=n.call(e,String(r).replace(/(^|,\s*)(:scope([ >]|$))/g,function(e,n,r,i){return n+"["+t+"]"+(i||" ")}));return e.removeAttribute(t),i}var t="data-scope-"+(1e9*Math.random()>>>0),n=Element.prototype,r=n.querySelector,i=n.querySelectorAll;n.querySelector=function(t){return e(this,r,t)},n.querySelectorAll=function(t){return e(this,i,t)}}()}}(window),function(e){"use strict";function t(){}function n(e,t,r){function i(e){i.once&&(e.currentTarget.removeEventListener(e.type,t,i),i.removed=!0),i.passive&&(e.preventDefault=n.preventDefault),"function"==typeof i.callback?i.callback.call(this,e):i.callback&&i.callback.handleEvent(e),i.passive&&delete e.preventDefault}return i.type=e,i.callback=t,i.capture=!!r.capture,i.passive=!!r.passive,i.once=!!r.once,i.removed=!1,i}var r=e.WeakMap||function(){function e(e,t,n){c=n,a=!1,r=undefined,e.dispatchEvent(t)}function t(e){this.value=e}function n(){i++,this.__ce__=new o("@DOMMap:"+i+Math.random())}var r,i=0,a=!1,c=!1;return t.prototype.handleEvent=function(e){a=!0,c?e.currentTarget.removeEventListener(e.type,this,!1):r=this.value},n.prototype={constructor:n,"delete":function(t){return e(t,this.__ce__,!0),a},get:function(t){e(t,this.__ce__,!1);var n=r;return r=undefined,n},has:function(t){return e(t,this.__ce__,!1),a},set:function(n,r){return e(n,this.__ce__,!0),n.addEventListener(this.__ce__.type,new t(r),!1),this}},n}();t.prototype=(Object.create||Object)(null),n.preventDefault=function(){};var i,o=e.CustomEvent,a=e.dispatchEvent,c=e.addEventListener,l=e.removeEventListener,s=0,u=function(){s++},h=[].indexOf||function(e){for(var t=this.length;t--&&this[t]!==e;);return t},p=function(e){return"".concat(e.capture?"1":"0",e.passive?"1":"0",e.once?"1":"0")};try{c("_",u,{once:!0}),a(new o("_")),a(new o("_")),l("_",u,{once:!0})}catch(f){}1!==s&&function(){function o(e){return function(r,i,o){if(o&&"boolean"!=typeof o){var a,l,s,u=c.get(this),f=p(o);u||c.set(this,u=new t),r in u||(u[r]={handler:[],wrap:[]}),l=u[r],a=h.call(l.handler,i),a<0?(a=l.handler.push(i)-1,l.wrap[a]=s=new t):s=l.wrap[a],f in s||(s[f]=n(r,i,o),e.call(this,r,s[f],s[f].capture))}else e.call(this,r,i,o)}}function a(e){return function(t,n,r){if(r&&"boolean"!=typeof r){var i,o,a,l,s=c.get(this);if(s&&t in s&&(a=s[t],-1<(o=h.call(a.handler,n))&&(i=p(r),l=a.wrap[o],i in l))){e.call(this,t,l[i],l[i].capture),delete l[i];for(i in l)return;a.handler.splice(o,1),a.wrap.splice(o,1),0===a.handler.length&&delete s[t]}}else e.call(this,t,n,r)}}var c=new r;i=function(e){if(e){var t=e.prototype;t.addEventListener=o(t.addEventListener),t.removeEventListener=a(t.removeEventListener)}},e.EventTarget?i(EventTarget):(i(e.Text),i(e.Element||e.HTMLElement),i(e.HTMLDocument),i(e.Window||{prototype:e}),i(e.XMLHttpRequest))}()}(self);