Created
February 7, 2014 18:02
-
-
Save cvan/8868213 to your computer and use it in GitHub Desktop.
trigger custom events in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!('CustomEvent' in window)) { | |
// For IE 9/10 lol. | |
function CustomEvent(eventName, params) { | |
params = params || {bubbles: false, cancelable: false, detail: undefined}; | |
var e = document.createEvent('CustomEvent'); | |
e.initCustomEvent(eventName, params.bubbles, params.cancelable, params.detail); | |
return e; | |
} | |
CustomEvent.prototype = window.CustomEvent.prototype; | |
window.CustomEvent = CustomEvent; | |
} | |
function trigger(el, eventName, params) { | |
return el.dispatchEvent(new CustomEvent(eventName, params)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment