}
},
- trigger: function(type, data, element) {
+ trigger: function(type, data, element, native, extra) {
// Clone the incoming data, if any
data = jQuery.makeArray(data || []);
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 {
// 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) {
// Empty object is for triggered events with no data
event = jQuery.event.fix( event || window.event || {} );
- var c = this.$events && this.$events[event.type], args = [].slice.call( arguments, 1 );
+ var c = this.$events && this.$events[event.type], args = Array.prototype.slice.call( arguments, 1 );
args.unshift( event );
for ( var j in c ) {
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;
}
}
* @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
* @see $(Function)
*/
ready: function(f) {
+ // Attach the listeners
+ bindReady();
+
// If the DOM is already ready
if ( jQuery.isReady )
// Execute the function immediately
}
});
-new function(){
-
/**
* Bind a function to the scroll event of each matched element.
*
};
});
-
+
+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
// A fallback to window.onload, that will always work
jQuery.event.add( window, "load", jQuery.ready );
-
-};
+}