X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent.js;h=e5f6a453a46eb4e00b5e6fd490ea885bdddb8732;hb=9476530fa1e39ce1324e98f4dbb79576895372e5;hp=1ba0357d2252760091d6310bcade548de394a9d9;hpb=ec7baf230d3c246dadf00c94115e6668425b9354;p=jquery.git diff --git a/src/event.js b/src/event.js index 1ba0357..e5f6a45 100644 --- a/src/event.js +++ b/src/event.js @@ -116,7 +116,7 @@ jQuery.event = { // Namespaced event handlers var namespaces = type.split("."); type = namespaces.shift(); - var namespace = RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"); + var namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"); if ( events[type] ) { // remove the given handler for the given type @@ -240,7 +240,8 @@ jQuery.event = { var all, handlers; event = arguments[0] = jQuery.event.fix( event || window.event ); - + event.currentTarget = this; + // Namespaced event handlers var namespaces = event.type.split("."); event.type = namespaces.shift(); @@ -248,7 +249,7 @@ jQuery.event = { // Cache this now, all = true means, any handler all = !namespaces.length && !event.exclusive; - var namespace = RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"); + var namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"); handlers = ( jQuery.data(this, "events") || {} )[event.type]; @@ -353,7 +354,7 @@ jQuery.event = { }, teardown: function( namespaces ){ if ( namespaces.length ) { - var remove = 0, name = RegExp("(^|\\.)" + namespaces[0] + "(\\.|$)"); + var remove = 0, name = new RegExp("(^|\\.)" + namespaces[0] + "(\\.|$)"); jQuery.each( (jQuery.data(this, "events").live || {}), function(){ if ( name.test(this.type) ) @@ -377,13 +378,13 @@ jQuery.Event = function( src ){ if( src && src.type ){ this.originalEvent = src; this.type = src.type; - this.timeStamp = src.timeStamp; // Event type }else this.type = src; - if( !this.timeStamp ) - this.timeStamp = now(); + // timeStamp is buggy for some events on Firefox(#3843) + // So we won't rely on the native value + this.timeStamp = now(); // Mark it as fixed this[expando] = true; @@ -547,28 +548,40 @@ jQuery.fn.extend({ var proxy = jQuery.event.proxy( fn ); proxy.guid += this.selector + type; - jQuery(document).bind( liveConvert(type, this.selector), this.selector, proxy ); + jQuery( this.context ).bind( liveConvert(type, this.selector), this.selector, proxy ); return this; }, die: function( type, fn ){ - jQuery(document).unbind( liveConvert(type, this.selector), fn ? { guid: fn.guid + this.selector + type } : null ); + jQuery( this.context ).unbind( liveConvert(type, this.selector), fn ? { guid: fn.guid + this.selector + type } : null ); return this; } }); function liveHandler( event ){ - var check = RegExp("(^|\\.)" + event.type + "(\\.|$)"), - stop = true; + var check = new RegExp("(^|\\.)" + event.type + "(\\.|$)"), + stop = true, + elems = []; jQuery.each(jQuery.data(this, "events").live || [], function(i, fn){ - if ( !event.isImmediatePropagationStopped() && check.test(fn.type) ) { + if ( check.test(fn.type) ) { var elem = jQuery(event.target).closest(fn.data)[0]; - if ( elem && fn.call(elem, event, fn.data) === false ) - stop = false; + if ( elem ) + elems.push({ elem: elem, fn: fn }); } }); + + elems.sort(function(a,b) { + return jQuery.data(a.elem, "closest") - jQuery.data(b.elem, "closest"); + }); + + jQuery.each(elems, function(){ + event.currentTarget = this.elem; + if ( this.fn.call(this.elem, event, this.fn.data) === false ) + return (stop = false); + }); + return stop; } @@ -630,7 +643,7 @@ function bindReady(){ // If IE and not an iframe // continually check to see if the document is ready - if ( document.documentElement.doScroll && !window.frameElement ) (function(){ + if ( document.documentElement.doScroll && window == window.top ) (function(){ if ( jQuery.isReady ) return; try { @@ -664,6 +677,9 @@ jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + // Prevent memory leaks in IE // And prevent errors on refresh with events like mouseover in other browsers // Window isn't included so as not to unbind existing unload events +// More info: +// - http://isaacschlueter.com/2006/10/msie-memory-leaks/ +// - https://bugzilla.mozilla.org/show_bug.cgi?id=252542 jQuery( window ).bind( 'unload', function(){ for ( var id in jQuery.cache ) // Skip the window