Skip to content

Instantly share code, notes, and snippets.

@lski
Last active March 25, 2016 16:08
Show Gist options
  • Save lski/39c59b03a60e31541cda to your computer and use it in GitHub Desktop.
Save lski/39c59b03a60e31541cda to your computer and use it in GitHub Desktop.
addEventListener/removeEventListener/dispatchEvent - Deprecated use lski/addeventlistener-with-dispatch instead
!function(){"use strict;";function e(e){var t=this,n=e.eventName||e.type;if(t.fireEvent&&r["on"+n])t.fireEvent("on"+n,e);else if(t[n]&&"function"==typeof t[n])t[n](e);else if(t["on"+n]&&"function"==typeof t["on"+n])t["on"+n](e);else for(var a=0,p=o.length;p>a;a++){var i=o[a];if(this===i.object&&i.type===e.eventName){i.wrapper.call(t,e);break}}}function t(e,t){var n=this,r=function(e){e.target=e.srcElement,e.currentTarget=n,t.handleEvent?t.handleEvent(e):t.call(n,e)};if("DOMContentLoaded"==e){var a=function(e){"interactive"===document.readyState&&r(e)};/interactive|complete|loaded/.test(document.readyState)||(document.attachEvent("onreadystatechange",a),o.push({object:n,type:e,listener:t,wrapper:a}))}else n.attachEvent("on"+e,r),o.push({object:n,type:e,listener:t,wrapper:r})}function n(e,t){for(var n=0;n<o.length;){var r=o[n];if(r.object==this&&r.type==e&&r.listener==t){var a="DOMContentLoaded"===e?"onreadystatechange":"on"+e;this.detachEvent(a,r.wrapper);break}++n}}if(Event.prototype.preventDefault||(Event.prototype.preventDefault=function(){this.returnValue=!1}),Event.prototype.stopPropagation||(Event.prototype.stopPropagation=function(){this.cancelBubble=!0}),!Element.prototype.addEventListener){var o=[];Element.prototype.addEventListener=HTMLDocument.prototype.addEventListener=Window.prototype.addEventListener=t,Element.prototype.removeEventListener=HTMLDocument.prototype.removeEventListener=Window.prototype.removeEventListener=n,Element.prototype.dispatchEvent=HTMLDocument.prototype.dispatchEvent=Window.prototype.dispatchEvent=e;var r={onload:1,onunload:1,onblur:1,onchange:1,onfocus:1,onreset:1,onselect:1,onsubmit:1,onabort:1,onkeydown:1,onkeypress:1,onkeyup:1,onclick:1,ondblclick:1,onmousedown:1,onmousemove:1,onmouseout:1,onmouseover:1,onmouseup:1}}}();
{
"name": "addeventlistener-shim",
"version": "2.0.0",
"main": "addeventlistener-shim.min.js"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment