X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent%2Fevent.js;h=eaf6858c53cd6c1a31f7de9cf199f08290750ecb;hb=783f589fbf005a6a3211bff20e3e8aeb1ea0ac22;hp=2ceaa9375769f85a47a97ee4675c22faa21ccd67;hpb=79f9678bf51285bc7b00470cf130abe0218b6cbb;p=jquery.git diff --git a/src/event/event.js b/src/event/event.js index 2ceaa93..eaf6858 100644 --- a/src/event/event.js +++ b/src/event/event.js @@ -82,18 +82,23 @@ jQuery.event = { // Handle triggering a single element } else if ( element["on" + type] ) { - // Pass along a fake event - data.unshift( this.fix({ type: type, target: element }) ); - - // Trigger the event - element["on" + type].apply( element, data ); + if ( element[ type ] && element[ type ].constructor == Function ) + element[ type ](); + else { + // Pass along a fake event + data.unshift( this.fix({ type: type, target: element }) ); + + // Trigger the event + element["on" + type].apply( element, data ); + } } }, handle: function(event) { if ( typeof jQuery == "undefined" ) return false; - event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data + // Empty object is for triggered events with no data + event = jQuery.event.fix( event || window.event || {} ); // returned undefined or false var returnValue; @@ -135,15 +140,17 @@ jQuery.event = { } // check if target is a textnode (safari) - if (event.target.nodeType == 3) { - // store a copy of the original event object and clone because target is read only + if (jQuery.browser.safari && event.target.nodeType == 3) { + // store a copy of the original event object + // and clone because target is read only var originalEvent = event; event = jQuery.extend({}, originalEvent); // get parentnode from textnode event.target = originalEvent.target.parentNode; - // add preventDefault and stopPropagation since they will not work on the clone + // add preventDefault and stopPropagation since + // they will not work on the clone event.preventDefault = function() { return originalEvent.preventDefault(); }; @@ -153,17 +160,15 @@ jQuery.event = { } // fix preventDefault and stopPropagation - if (!event.preventDefault) { + if (!event.preventDefault) event.preventDefault = function() { this.returnValue = false; }; - } - if (!event.stopPropagation) { + if (!event.stopPropagation) event.stopPropagation = function() { this.cancelBubble = true; }; - } return event; } @@ -260,43 +265,31 @@ jQuery.fn.extend({ /** * The opposite of bind, removes a bound event from each of the matched - * elements. You must pass the identical function that was used in the original - * bind method. + * elements. * - * @example $("p").unbind( "click", function() { alert("Hello"); } ) + * Without any arguments, all bound events are removed. + * + * If the type is provided, all bound events of that type are removed. + * + * If the function that was passed to bind is provided as the second argument, + * only that specific event handler is removed. + * + * @example $("p").unbind() * @before

Hello

* @result [

Hello

] * - * @name unbind - * @type jQuery - * @param String type An event type - * @param Function fn A function to unbind from the event on each of the set of matched elements - * @cat Events - */ - - /** - * Removes all bound events of a particular type from each of the matched - * elements. - * * @example $("p").unbind( "click" ) * @before

Hello

* @result [

Hello

] * - * @name unbind - * @type jQuery - * @param String type An event type - * @cat Events - */ - - /** - * Removes all bound events from each of the matched elements. - * - * @example $("p").unbind() + * @example $("p").unbind( "click", function() { alert("Hello"); } ) * @before

Hello

* @result [

Hello

] * * @name unbind * @type jQuery + * @param String type (optional) An event type + * @param Function fn (optional) A function to unbind from the event on each of the set of matched elements * @cat Events */ unbind: function( type, fn ) { @@ -1031,36 +1024,17 @@ new function(){ jQuery.fn[o] = function(f){ return f ? this.bind(o, f) : this.trigger(o); }; - - // Handle event unbinding - // TODO remove - jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); }; - - // Finally, handle events that only fire once - // TODO remove - jQuery.fn["one"+o] = function(f){ - // save cloned reference to this - var element = jQuery(this); - var handler = function() { - // unbind itself when executed - element.unbind(o, handler); - element = null; - // apply original handler with the same arguments - return f.apply(this, arguments); - }; - return this.bind(o, handler); - }; }; // If Mozilla is used - if ( jQuery.browser.mozilla || jQuery.browser.opera ) { + if ( jQuery.browser.mozilla || jQuery.browser.opera ) // Use the handy event callback document.addEventListener( "DOMContentLoaded", jQuery.ready, false ); // If IE is used, use the excellent hack by Matthias Miller // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited - } else if ( jQuery.browser.msie ) { + else if ( jQuery.browser.msie ) { // Only works if you document.write() it document.write("0) do if (type != 'unload') event.remove(els[i-1], type); while (--i); - } -}); +if (jQuery.browser.msie) + jQuery(window).one("unload", function() { + var global = jQuery.event.global; + for ( var type in global ) { + var els = global[type], i = els.length; + if ( i && type != 'unload' ) + do + jQuery.event.remove(els[i-1], type); + while (--i); + } + }); \ No newline at end of file