-
Notifications
You must be signed in to change notification settings - Fork 0
/
shim.customEvent.js
2 lines (2 loc) · 2.29 KB
/
shim.customEvent.js
1
2
// EventListener | CC0 | github.com/jonathantneal/EventListener
this.Element&&Element.prototype.attachEvent&&!Element.prototype.addEventListener&&(function(){function a(c,d){Window.prototype[c]=HTMLDocument.prototype[c]=Element.prototype[c]=d}a("addEventListener",function(e,f){var g=this,d=g.addEventListener.listeners=g.addEventListener.listeners||{},c=d[e]=d[e]||[];if(!c.length){g.attachEvent("on"+e,c.event=function(h){var o=g.document&&g.document.documentElement||g.documentElement||{scrollLeft:0,scrollTop:0};h.currentTarget=g;h.pageX=h.clientX+o.scrollLeft;h.pageY=h.clientY+o.scrollTop;h.preventDefault=function(){h.returnValue=false};h.relatedTarget=h.fromElement||null;h.stopImmediatePropagation=function(){k=false;h.cancelBubble=true};h.stopPropagation=function(){h.cancelBubble=true};h.target=h.srcElement||g;h.timeStamp=+new Date;var j={};for(var l in h){j[l]=h[l]}for(var l=0,q=[].concat(c),m,k=true;k&&(m=q[l]);++l){for(var p=0,n;n=c[p];++p){if(n==m){n.call(g,j);break}}}})}c.push(f)});a("removeEventListener",function(f,g){var h=this,e=h.addEventListener.listeners=h.addEventListener.listeners||{},c=e[f]=e[f]||[];for(var d=c.length-1,j;j=c[d];--d){if(j==g){c.splice(d,1);break}}if(!c.length&&c.event){h.detachEvent("on"+f,c.event)}});a("dispatchEvent",function(d){var h=this,g=d.type,f=h.addEventListener.listeners=h.addEventListener.listeners||{},c=f[g]=f[g]||[];try{return h.fireEvent("on"+g,d)}catch(e){if(c.event){c.event(d)}return}});Object.defineProperty(Window.prototype,"CustomEvent",{get:function(){var c=this;return function d(f,h){var g=c.document.createEventObject(),e;g.type=f;for(e in h){if(e=="cancelable"){g.returnValue=!h.cancelable}else{if(e=="bubbles"){g.cancelBubble=!h.bubbles}else{if(e=="detail"){g.detail=h.detail}}}}return g}}});function b(c){if(b.interval&&document.body){b.interval=clearInterval(b.interval);document.dispatchEvent(new CustomEvent("DOMContentLoaded"))}}b.interval=setInterval(b,1);window.addEventListener("load",b)})();(!this.CustomEvent||typeof this.CustomEvent==="object")&&(function(){this.CustomEvent=function a(c,e){var d;e=e||{bubbles:false,cancelable:false,detail:undefined};try{d=document.createEvent("CustomEvent");d.initCustomEvent(c,e.bubbles,e.cancelable,e.detail)}catch(b){d=document.createEvent("Event");d.initEvent(c,e.bubbles,e.cancelable);d.detail=e.detail}return d}})();