Created
February 6, 2014 14:25
-
-
Save neocotic/8845173 to your computer and use it in GitHub Desktop.
jQuery HTML5 Event Delegation Support
This file contains 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
(function ($) { | |
var html5Events = [ | |
'afterprint', | |
'beforeprint', | |
'canplay', | |
'canplaythrough', | |
'contextmenu', | |
'drag', | |
'dragend', | |
'dragenter', | |
'dragleave', | |
'dragover', | |
'dragstart', | |
'drop', | |
'durationchange', | |
'emptied', | |
'ended', | |
'error', | |
'formchange', | |
'forminput', | |
'input', | |
'invalid', | |
'load', | |
'loadeddata', | |
'loadedmetadata', | |
'loadstart', | |
'mousewheel', | |
'pause', | |
'play', | |
'playing', | |
'progress', | |
'ratechange', | |
'readystatechange', | |
'resize', | |
'scroll', | |
'seeked', | |
'seeking', | |
'stalled', | |
'suspend', | |
'timeupdate', | |
'unload', | |
'volumechange', | |
'waiting' | |
]; | |
$.each(html5Events, function (i, type) { | |
var special = $.event.special[type] || {}; | |
if (!special.setup) { | |
special.setup = function(data, namespaces, handler) { | |
if (this.addEventListener) { | |
this.addEventListener(type, handler, true); | |
} else if (this.attachEvent) { | |
this.attachEvent('on' + type, handler); | |
} | |
}; | |
} | |
if (!special.tearDown) { | |
special.tearDown = function(namespaces, handler) { | |
if (this.removeEventListener) { | |
this.removeEventListener(type, handler, true); | |
} else { | |
$.removeEvent(this, type, handler); | |
} | |
}; | |
} | |
$.event.special[type] = special; | |
}); | |
})(jQuery); |
This file contains 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
(function ($) { | |
var html5Events = [ | |
'afterprint', | |
'beforeprint', | |
'canplay', | |
'canplaythrough', | |
'contextmenu', | |
'drag', | |
'dragend', | |
'dragenter', | |
'dragleave', | |
'dragover', | |
'dragstart', | |
'drop', | |
'durationchange', | |
'emptied', | |
'ended', | |
'error', | |
'formchange', | |
'forminput', | |
'input', | |
'invalid', | |
'load', | |
'loadeddata', | |
'loadedmetadata', | |
'loadstart', | |
'mousewheel', | |
'pause', | |
'play', | |
'playing', | |
'progress', | |
'ratechange', | |
'readystatechange', | |
'resize', | |
'scroll', | |
'seeked', | |
'seeking', | |
'stalled', | |
'suspend', | |
'timeupdate', | |
'unload', | |
'volumechange', | |
'waiting' | |
]; | |
$.each(html5Events, function (i, type) { | |
var special = $.event.special[type] || {}; | |
if (!special.setup) { | |
special.setup = function(data, namespaces, handler) { | |
if (this.addEventListener) { | |
this.addEventListener(type, handler, true); | |
} | |
}; | |
} | |
if (!special.tearDown) { | |
special.tearDown = function(namespaces, handler) { | |
if (this.removeEventListener) { | |
this.removeEventListener(type, handler, true); | |
} | |
}; | |
} | |
$.event.special[type] = special; | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment