X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/aae232dcf008ab39db553bc1b20573fa00e3b191..0bd2c341a8b55f817c2e193a6c4658d52ef95961:/apps/wolnelektury_core/static/js/contrib/jquery.eventdelegation.js?ds=sidebyside diff --git a/apps/wolnelektury_core/static/js/contrib/jquery.eventdelegation.js b/apps/wolnelektury_core/static/js/contrib/jquery.eventdelegation.js new file mode 100644 index 000000000..52fce074a --- /dev/null +++ b/apps/wolnelektury_core/static/js/contrib/jquery.eventdelegation.js @@ -0,0 +1,55 @@ +/* + * jQuery Event Delegation Plugin - jquery.eventdelegation.js + * Fast flexible event handling + * + * January 2008 - Randy Morey (http://dev.distilldesign.com/) + */ + +(function ($) { + /* setup list of allowed events for event delegation + * only events that bubble are appropriate + */ + var allowed = {}; + $.each([ + 'click', + 'dblclick', + 'mousedown', + 'mouseup', + 'mousemove', + 'mouseover', + 'mouseout', + 'keydown', + 'keypress', + 'keyup' + ], function(i, eventName) { + allowed[eventName] = true; + }); + + $.fn.extend({ + delegate: function (event, selector, f) { + return $(this).each(function () { + if (allowed[event]) + $(this).bind(event, function (e) { + var el = $(e.target), + result = false; + + while (!$(el).is('body')) { + if ($(el).is(selector)) { + result = f.apply($(el)[0], [e]); + if (result === false) + e.preventDefault(); + return; + } + + el = $(el).parent(); + } + }); + }); + }, + undelegate: function (event) { + return $(this).each(function () { + $(this).unbind(event); + }); + } + }); +})(jQuery); \ No newline at end of file