// Bind an event to an element
// Original by Dean Edwards
add: function(element, type, handler, data) {
+ if ( element.nodeType == 3 || element.nodeType == 8 )
+ return;
+
// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
if ( jQuery.browser.msie && element.setInterval != undefined )
// if data is passed, bind to handler
if( data != undefined ) {
- // Create temporary function pointer to original handler
+ // Create temporary function pointer to original handler
var fn = handler;
// Create unique handler function, wrapped around original handler
// Detach an event or set of events from an element
remove: function(element, type, handler) {
+ // don't do events on text and comment nodes
+ if ( element.nodeType == 3 || element.nodeType == 8 )
+ return;
+
var events = jQuery.data(element, "events"), ret, index;
// Namespaced event handlers
// Handle triggering a single element
} else {
+ // don't do events on text and comment nodes
+ if ( element.nodeType == 3 || element.nodeType == 8 )
+ return;
+
var val, ret, fn = jQuery.isFunction( element[ type ] || null ),
// Check to see if we need to provide a fake event, or not
event = !data[0] || !data[0].preventDefault;
data.shift();
// Handle triggering of extra function
- if ( extra && extra.apply( element, data ) === false )
- val = false;
+ if ( extra ) {
+ // call the extra function and tack the current return value on the end for possible inspection
+ var ret = extra.apply( element, data.concat( val ) );
+ // if anything is returned, give it precedence and have it overwrite the previous value
+ if (ret !== undefined)
+ val = ret;
+ }
// Trigger the native events (except for clicks on links)
if ( fn && donative !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) {
if ( event.pageX == null && event.clientX != null ) {
var doc = document.documentElement, body = document.body;
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
- event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientLeft || 0);
+ event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientLeft || 0);
}
// Add which for key events
event.preventDefault();
// and execute the function
- return args[this.lastToggle].apply( this, [event] ) || false;
+ return args[this.lastToggle].apply( this, arguments ) || false;
});
},
while ( parent && parent != this ) try { parent = parent.parentNode; } catch(error) { parent = this; };
// If we actually just moused on to a sub-element, ignore it
- if ( parent == this ) return false;
+ if ( parent == this )
+ return true;
// Execute the right function
return (event.type == "mouseover" ? fnOver : fnOut).apply(this, [event]);
// If Safari or IE is used
// Continually check to see if the document is ready
- if (jQuery.browser.msie || jQuery.browser.safari ) (function(){
+ if (jQuery.browser.msie || jQuery.browser.safari ) (function(){
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
// And prevent errors on refresh with events like mouseover
// Window isn't included so as not to unbind existing unload events
jQuery(window).bind("unload", function() {
- $("*").add(document).unbind();
+ jQuery("*").add(document).unbind();
});