X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent.js;h=018d4d9809929e27bf36224f0721c08251412414;hb=5197ac9fc8aa71c2ebc0d7217f41a3679eb1b902;hp=d2e106a6aca9b48320f4cab347805cfe0060073e;hpb=98ce35d52b17a033822f31d8a36232222d0d365e;p=jquery.git diff --git a/src/event.js b/src/event.js index d2e106a..018d4d9 100644 --- a/src/event.js +++ b/src/event.js @@ -253,8 +253,10 @@ jQuery.event = { var nativeFn, nativeHandler; try { - nativeFn = elem[ type ]; - nativeHandler = elem[ "on" + type ]; + if ( !(elem && elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()]) ) { + nativeFn = elem[ type ]; + nativeHandler = elem[ "on" + type ]; + } // prevent IE from throwing an error for some elements with some event types, see #3533 } catch (e) {} @@ -264,12 +266,12 @@ jQuery.event = { if ( !bubbling && nativeFn && !event.isDefaultPrevented() && !isClick ) { this.triggered = true; try { - nativeFn(); + elem[ type ](); // prevent IE from throwing an error for some hidden elements } catch (e) {} // Handle triggering native .onfoo handlers - } else if ( nativeHandler && nativeHandler.apply( elem, data ) === false ) { + } else if ( nativeHandler && elem[ "on" + type ].apply( elem, data ) === false ) { event.result = false; } @@ -678,7 +680,7 @@ function trigger( type, elem, args ) { if ( !jQuery.support.focusBubbles ) { jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ){ - event.special[ orig ] = { + jQuery.event.special[ orig ] = { setup: function() { jQuery.event.add( this, fix, ieHandler ); }, @@ -695,13 +697,12 @@ jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ){ } -jQuery.fn.extend({ - // TODO: make bind(), unbind() and one() DRY! - bind: function( type, data, fn, thisObject ) { +jQuery.each(["bind", "one"], function(i, name) { + jQuery.fn[ name ] = function( type, data, fn, thisObject ) { // Handle object literals if ( typeof type === "object" ) { for ( var key in type ) { - this.bind(key, data, type[key], fn); + this[ name ](key, data, type[key], fn); } return this; } @@ -712,35 +713,17 @@ jQuery.fn.extend({ data = undefined; } fn = thisObject === undefined ? fn : jQuery.event.proxy( fn, thisObject ); - return type === "unload" ? this.one(type, data, fn, thisObject) : this.each(function() { - jQuery.event.add( this, type, fn, data ); - }); - }, - - one: function( type, data, fn, thisObject ) { - // Handle object literals - if ( typeof type === "object" ) { - for ( var key in type ) { - this.one(key, data, type[key], fn); - } - return this; - } - - if ( jQuery.isFunction( data ) ) { - thisObject = fn; - fn = data; - data = undefined; - } - fn = thisObject === undefined ? fn : jQuery.event.proxy( fn, thisObject ); - var one = jQuery.event.proxy( fn, function( event ) { - jQuery( this ).unbind( event, one ); + var handler = name == "one" ? jQuery.event.proxy( fn, function( event ) { + jQuery( this ).unbind( event, handler ); return fn.apply( this, arguments ); + }) : fn; + return type === "unload" ? this.one(type, data, handler, thisObject) : this.each(function() { + jQuery.event.add( this, type, handler, data ); }); - return this.each(function() { - jQuery.event.add( this, type, one, data ); - }); - }, + }; +}); +jQuery.fn.extend({ unbind: function( type, fn ) { // Handle object literals if ( typeof type === "object" && !type.preventDefault ) { @@ -749,12 +732,11 @@ jQuery.fn.extend({ } return this; } - + return this.each(function() { jQuery.event.remove( this, type, fn ); }); }, - trigger: function( type, data ) { return this.each(function() { jQuery.event.trigger( type, data, this ); @@ -872,9 +854,7 @@ function liveHandler( event ) { } function liveConvert( type, selector ) { - return ["live", type, selector//.replace(/[^\w\s\.]/g, function(ch){ return "\\"+ch}) - .replace(/\./g, "`") - .replace(/ /g, "|")].join("."); + return ["live", type, selector.replace(/\./g, "`").replace(/ /g, "&")].join("."); } jQuery.each( ("blur focus load resize scroll unload click dblclick " + @@ -885,6 +865,10 @@ jQuery.each( ("blur focus load resize scroll unload click dblclick " + jQuery.fn[ name ] = function( fn ) { return fn ? this.bind( name, fn ) : this.trigger( name ); }; + + if ( jQuery.fnAttr ) { + jQuery.fnAttr[ name ] = true; + } }); // Prevent memory leaks in IE @@ -896,7 +880,10 @@ jQuery( window ).bind( 'unload', function() { for ( var id in jQuery.cache ) { // Skip the window if ( id != 1 && jQuery.cache[ id ].handle ) { - jQuery.event.remove( jQuery.cache[ id ].handle.elem ); + // Try/Catch is to handle iframes being unloaded, see #4280 + try { + jQuery.event.remove( jQuery.cache[ id ].handle.elem ); + } catch(e) {} } } });