X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent.js;h=f6b3d316d82373d2e0d71be0ee1dd4cb13786d88;hb=31432e048f879b93ffa44c39d6f5989ab2620bd8;hp=602332fb653414644148b66653404ddef0b35ff8;hpb=0252b78201f817f87d10f14c85d0f37e4c50ce22;p=jquery.git diff --git a/src/event.js b/src/event.js index 602332f..f6b3d31 100644 --- a/src/event.js +++ b/src/event.js @@ -221,11 +221,7 @@ jQuery.event = { if ( !ret ) { if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) { - if ( elem.removeEventListener ) { - elem.removeEventListener( type, elemData.handle, false ); - } else if ( elem.detachEvent ) { - elem.detachEvent( "on" + type, elemData.handle ); - } + removeEvent( elem, type, elemData.handle ); } ret = null; @@ -529,6 +525,14 @@ jQuery.event = { } }; +var removeEvent = document.removeEventListener ? + function( elem, type, handle ) { + elem.removeEventListener( type, handle, false ); + } : + function( elem, type, handle ) { + elem.detachEvent( "on" + type, handle ); + }; + jQuery.Event = function( src ) { // Allow instantiation without the 'new' keyword if ( !this.preventDefault ) { @@ -862,6 +866,20 @@ jQuery.fn.extend({ return this; }, + + delegate: function( selector, types, data, fn ) { + return this.live( types, data, fn, selector ); + }, + + undelegate: function( selector, types, fn ) { + if ( arguments.length === 0 ) { + return this.unbind( "live" ); + + } else { + return this.die( types, null, fn, selector ); + } + }, + trigger: function( type, data ) { return this.each(function() { jQuery.event.trigger( type, data, this ); @@ -906,8 +924,10 @@ jQuery.fn.extend({ }); jQuery.each(["live", "die"], function( i, name ) { - jQuery.fn[ name ] = function( types, data, fn ) { - var type, i = 0; + jQuery.fn[ name ] = function( types, data, fn, origSelector /* Internal Use Only */ ) { + var type, i = 0, + selector = origSelector || this.selector, + context = origSelector ? this : jQuery( this.context ); if ( jQuery.isFunction( data ) ) { fn = data; @@ -924,13 +944,13 @@ jQuery.each(["live", "die"], function( i, name ) { if ( name === "live" ) { // bind live handler - jQuery( this.context ).bind( liveConvert( type, this.selector ), { - data: data, selector: this.selector, live: type + context.bind( liveConvert( type, selector ), { + data: data, selector: selector, live: type }, fn ); } else { // unbind live handler - jQuery( this.context ).unbind( liveConvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null ); + context.unbind( liveConvert( type, selector ), fn ? { guid: fn.guid + selector + type } : null ); } } @@ -998,7 +1018,7 @@ function liveHandler( event ) { } function liveConvert( type, selector ) { - return "live." + (type ? type + "." : "") + selector.replace(/\./g, "`").replace(/ /g, "&"); + return "live." + (type && type !== "*" ? type + "." : "") + selector.replace(/\./g, "`").replace(/ /g, "&"); } jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +