X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=src%2Fevent%2Fevent.js;h=3c5a1190da8b548923d22bde21b9a4594615886a;hb=042a46386a4e5efe787f963245aa534663559838;hp=cbad528f3e9f3a4e8a67c4fc006b9cf899fa70c9;hpb=bd78d4f65dea2fc5fbfd58a0f099f8839ee9707d;p=jquery.git diff --git a/src/event/event.js b/src/event/event.js index cbad528..3c5a119 100644 --- a/src/event/event.js +++ b/src/event/event.js @@ -122,7 +122,7 @@ jQuery.event = { } }, - trigger: function(type, data, element) { + trigger: function(type, data, element, native, extra) { // Clone the incoming data, if any data = jQuery.makeArray(data || []); @@ -130,7 +130,7 @@ jQuery.event = { if ( !element ) { // Only trigger if we've ever bound an event for it if ( this.global[type] ) - jQuery("*").trigger(type, data); + jQuery("*").add([window, document]).trigger(type, data); // Handle triggering a single element } else { @@ -142,16 +142,25 @@ jQuery.event = { // Trigger the event if ( jQuery.isFunction( element.$handle ) ) val = element.$handle.apply( element, data ); + + // Handle triggering native .onfoo handlers if ( !fn && element["on"+type] && element["on"+type].apply( element, data ) === false ) val = false; - if ( fn && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) { + // Handle triggering of extra function + if ( extra && extra.apply( element, data ) === false ) + val = false; + + // Trigger the native events (except for clicks on links) + if ( fn && native !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) { this.triggered = true; element[ type ](); } this.triggered = false; } + + return val; }, handle: function(event) { @@ -170,10 +179,14 @@ jQuery.event = { args[0].handler = c[j]; args[0].data = c[j].data; - if ( c[j].apply( this, args ) === false ) { + var tmp = c[j].apply( this, args ); + + if ( val !== false ) + val = tmp; + + if ( tmp === false ) { event.preventDefault(); event.stopPropagation(); - val = false; } } @@ -403,12 +416,17 @@ jQuery.fn.extend({ * @param Array data (optional) Additional data to pass as arguments (after the event object) to the event handler * @cat Events */ - trigger: function( type, data ) { + trigger: function( type, data, fn ) { return this.each(function(){ - jQuery.event.trigger( type, data, this ); + jQuery.event.trigger( type, data, this, true, fn ); }); }, + triggerHandler: function( type, data, fn ) { + if ( this[0] ) + return jQuery.event.trigger( type, data, this[0], false, fn ); + }, + /** * Toggle between two function calls every other click. * Whenever a matched element is clicked, the first specified function @@ -529,6 +547,9 @@ jQuery.fn.extend({ * @see $(Function) */ ready: function(f) { + // Attach the listeners + bindReady(); + // If the DOM is already ready if ( jQuery.isReady ) // Execute the function immediately @@ -578,8 +599,6 @@ jQuery.extend({ } }); -new function(){ - /** * Bind a function to the scroll event of each matched element. * @@ -930,7 +949,13 @@ new function(){ }; }); - + +var readyBound = false; + +function bindReady(){ + if ( readyBound ) return; + readyBound = true; + // If Mozilla is used if ( jQuery.browser.mozilla || jQuery.browser.opera ) // Use the handy event callback @@ -976,5 +1001,4 @@ new function(){ // A fallback to window.onload, that will always work jQuery.event.add( window, "load", jQuery.ready ); - -}; +}