Skip to content

Instantly share code, notes, and snippets.

@neocotic
Created February 6, 2014 14:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neocotic/8845173 to your computer and use it in GitHub Desktop.
Save neocotic/8845173 to your computer and use it in GitHub Desktop.
jQuery HTML5 Event Delegation Support
(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);
(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