X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fevent%2Fevent.js;h=55e205ae2a6edc1d244eb576eae8a60f1f9f8f6c;hb=897fbfe89c90de5f20a3eed2aeb187c625cfb43d;hp=186fa0daeb4fe189b54e9814476b20548272ed9d;hpb=47200bc76f83784f448bda31ac2cb166647aca71;p=jquery.git diff --git a/src/event/event.js b/src/event/event.js index 186fa0d..55e205a 100644 --- a/src/event/event.js +++ b/src/event/event.js @@ -80,7 +80,7 @@ jQuery.fn.extend({ var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; // Traverse up the tree - while ( p && p != this ) p = p.parentNode; + while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; }; // If we actually just moused on to a sub-element, ignore it if ( p == this ) return false; @@ -107,6 +107,8 @@ jQuery.fn.extend({ * Please ensure you have no code in your <body> onload event handler, * otherwise $(document).ready() may not fire. * + * You can have as many $(document).ready events on your page as you like. + * * @example $(document).ready(function(){ Your code here... }); * * @name ready @@ -153,6 +155,9 @@ jQuery.extend({ // Reset the list of functions jQuery.readyList = null; } + // Remove event lisenter to avoid memory leak + if ( jQuery.browser.mozilla || jQuery.browser.opera ) + document.removeEventListener( "DOMContentLoaded", jQuery.ready, false ); } } }); @@ -1578,8 +1583,8 @@ new function(){ var o = e[i]; // Handle event binding - jQuery.fn[o] = function(f){ - return f ? this.bind(o, f) : this.trigger(o); + jQuery.fn[o] = function(f, amount){ + return f ? this.bind(o, f, amount) : this.trigger(o); }; // Handle event unbinding @@ -1587,20 +1592,8 @@ new function(){ // Finally, handle events that only fire once jQuery.fn["one"+o] = function(f){ - // Attach the event listener - return this.each(function(){ - - var count = 0; - - // Add the event - jQuery.event.add( this, o, function(e){ - // If this function has already been executed, stop - if ( count++ ) return; - - // And execute the bound function - return f.apply(this, [e]); - }); - }); + // use bind with amount param to bind only once + return this.bind(o, f, 1); }; }; @@ -1653,10 +1646,10 @@ new function(){ }; // Clean up after IE to avoid memory leaks -if ($.browser.msie) $(window).unload(function() { +if (jQuery.browser.msie) jQuery(window).unload(function() { var event = jQuery.event, global = event.global; for (var type in global) { var els = global[type], i = els.length; - if (i>0) do event.remove(els[i-1], type); while (--i); + if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i); } });