// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
- if ( jQuery.browser.msie && elem.setInterval != undefined )
+ if ( jQuery.browser.msie && elem.setInterval )
elem = window;
// Make sure that the function being executed has a unique ID
var fn = handler;
// Create unique handler function, wrapped around original handler
- handler = function() {
+ handler = this.proxy( fn, function() {
// Pass arguments and context to original handler
return fn.apply(this, arguments);
- };
+ });
// Store data in unique handler
handler.data = data;
// event in IE.
handle.elem = elem;
- // Handle multiple events seperated by a space
- // jQuery(...).bind("mouseover mouseout", fn);
- jQuery.each(types.split(/\s+/), function(index, type) {
- // Namespaced event handlers
- var parts = type.split(".");
- type = parts[0];
- handler.type = parts[1];
-
- // Get the current list of functions bound to this event
- var handlers = events[type];
-
- // Init the event handler queue
- if (!handlers) {
- handlers = events[type] = {};
-
- // Check for a special event handler
- // Only use addEventListener/attachEvent if the special
- // events handler returns false
- if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
- // Bind the global event handler to the element
- if (elem.addEventListener)
- elem.addEventListener(type, handle, false);
- else if (elem.attachEvent)
- elem.attachEvent("on" + type, handle);
- }
+ // Handle multiple events separated by a space
+ // jQuery(...).bind("mouseover mouseout", fn);
+ jQuery.each(types.split(/\s+/), function(index, type) {
+ // Namespaced event handlers
+ var parts = type.split(".");
+ type = parts[0];
+ handler.type = parts[1];
+
+ // Get the current list of functions bound to this event
+ var handlers = events[type];
+
+ // Init the event handler queue
+ if (!handlers) {
+ handlers = events[type] = {};
+
+ // Check for a special event handler
+ // Only use addEventListener/attachEvent if the special
+ // events handler returns false
+ if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
+ // Bind the global event handler to the element
+ if (elem.addEventListener)
+ elem.addEventListener(type, handle, false);
+ else if (elem.attachEvent)
+ elem.attachEvent("on" + type, handle);
}
+ }
- // Add the function to the element's handler list
- handlers[handler.guid] = handler;
+ // Add the function to the element's handler list
+ handlers[handler.guid] = handler;
- // Keep track of which events have been used, for global triggering
- jQuery.event.global[type] = true;
- });
+ // Keep track of which events have been used, for global triggering
+ jQuery.event.global[type] = true;
+ });
// Nullify elem to prevent memory leaks in IE
elem = null;
target: elem,
preventDefault: function(){},
stopPropagation: function(){},
- timeStamp: +new Date
+ timeStamp: now()
});
data[0][expando] = true; // no need to fix fake event
}
};
// Fix timeStamp
- event.timeStamp = event.timeStamp || +new Date;
+ event.timeStamp = event.timeStamp || now();
// Fix target property, if necessary
if ( !event.target )
return event;
},
+ proxy: function( fn, proxy ){
+ // Set the guid of unique handler to the same of original handler, so it can be removed
+ proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++;
+ return proxy;//so proxy can be declared as an argument
+ },
+
special: {
ready: {
setup: function() {
// If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true;
// Execute the right handlers by setting the event type to mouseenter
- arguments[0].type = "mouseenter";
+ event.type = "mouseenter";
return jQuery.event.handle.apply(this, arguments);
}
},
// If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true;
// Execute the right handlers by setting the event type to mouseleave
- arguments[0].type = "mouseleave";
+ event.type = "mouseleave";
return jQuery.event.handle.apply(this, arguments);
}
}
},
one: function( type, data, fn ) {
+ var one = jQuery.event.proxy( fn || data, function(event) {
+ jQuery(this).unbind(event, one);
+ return (fn || data).apply( this, arguments );
+ });
return this.each(function(){
- jQuery.event.add( this, type, function(event) {
- jQuery(this).unbind(event);
- return (fn || data).apply( this, arguments);
- }, fn && data);
+ jQuery.event.add( this, type, one, fn && data);
});
},
},
triggerHandler: function( type, data, fn ) {
- if ( this[0] )
- return jQuery.event.trigger( type, data, this[0], false, fn );
- return undefined;
+ return this[0] && jQuery.event.trigger( type, data, this[0], false, fn );
},
- toggle: function() {
+ toggle: function( fn ) {
// Save reference to arguments for access in closure
- var args = arguments;
+ var args = arguments, i = 1;
+
+ // link all the functions, so any of them can unbind this click handler
+ while( i < args.length )
+ jQuery.event.proxy( fn, args[i++] );
- return this.click(function(event) {
+ return this.click( jQuery.event.proxy( fn, function(event) {
// Figure out which function to execute
- this.lastToggle = (this.lastToggle||0) % args.length;
+ this.lastToggle = ( this.lastToggle || 0 ) % i;
// Make sure that clicks stop
event.preventDefault();
// and execute the function
- return args[this.lastToggle++].apply( this, arguments ) || false;
- });
+ return args[ this.lastToggle++ ].apply( this, arguments ) || false;
+ }));
},
hover: function(fnOver, fnOut) {