Commit 76c1889e authored by Richard Worth's avatar Richard Worth

Fixed #1887 - trigger fails if extra is not a function

parent 24e036c7
/* /*
* A number of helper functions used for managing events. * A number of helper functions used for managing events.
* Many of the ideas behind this code orignated from * Many of the ideas behind this code orignated from
* Dean Edwards' addEvent library. * Dean Edwards' addEvent library.
*/ */
jQuery.event = { jQuery.event = {
// Bind an event to an element // Bind an event to an element
// Original by Dean Edwards // Original by Dean Edwards
add: function(elem, types, handler, data) { add: function(elem, types, handler, data) {
if ( elem.nodeType == 3 || elem.nodeType == 8 ) if ( elem.nodeType == 3 || elem.nodeType == 8 )
return; return;
// For whatever reason, IE has trouble passing the window object // For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process // around, causing it to be cloned in the process
if ( jQuery.browser.msie && elem.setInterval != undefined ) if ( jQuery.browser.msie && elem.setInterval != undefined )
elem = window; elem = window;
// Make sure that the function being executed has a unique ID // Make sure that the function being executed has a unique ID
if ( !handler.guid ) if ( !handler.guid )
handler.guid = this.guid++; handler.guid = this.guid++;
// if data is passed, bind to handler // if data is passed, bind to handler
if( data != undefined ) { if( data != undefined ) {
// Create temporary function pointer to original handler // Create temporary function pointer to original handler
var fn = handler; var fn = handler;
// Create unique handler function, wrapped around original handler // Create unique handler function, wrapped around original handler
handler = function() { handler = function() {
// Pass arguments and context to original handler // Pass arguments and context to original handler
return fn.apply(this, arguments); return fn.apply(this, arguments);
}; };
// Store data in unique handler // Store data in unique handler
handler.data = data; handler.data = data;
// Set the guid of unique handler to the same of original handler, so it can be removed // Set the guid of unique handler to the same of original handler, so it can be removed
handler.guid = fn.guid; handler.guid = fn.guid;
} }
// Init the element's event structure // Init the element's event structure
var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}), var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),
handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){ handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
// returned undefined or false // returned undefined or false
var val; var val;
// Handle the second event of a trigger and when // Handle the second event of a trigger and when
// an event is called after a page has unloaded // an event is called after a page has unloaded
if ( typeof jQuery == "undefined" || jQuery.event.triggered ) if ( typeof jQuery == "undefined" || jQuery.event.triggered )
return val; return val;
val = jQuery.event.handle.apply(elem, arguments); val = jQuery.event.handle.apply(elem, arguments);
return val; return val;
}); });
// Handle multiple events seperated by a space // Handle multiple events seperated by a space
// jQuery(...).bind("mouseover mouseout", fn); // jQuery(...).bind("mouseover mouseout", fn);
jQuery.each(types.split(/\s+/), function(index, type) { jQuery.each(types.split(/\s+/), function(index, type) {
// Namespaced event handlers // Namespaced event handlers
var parts = type.split("."); var parts = type.split(".");
type = parts[0]; type = parts[0];
handler.type = parts[1]; handler.type = parts[1];
// Get the current list of functions bound to this event // Get the current list of functions bound to this event
var handlers = events[type]; var handlers = events[type];
// Init the event handler queue // Init the event handler queue
if (!handlers) { if (!handlers) {
handlers = events[type] = {}; handlers = events[type] = {};
// Check for a special event handler // Check for a special event handler
// Only use addEventListener/attachEvent if the special // Only use addEventListener/attachEvent if the special
// events handler returns false // events handler returns false
if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) { if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
// Bind the global event handler to the element // Bind the global event handler to the element
if (elem.addEventListener) if (elem.addEventListener)
elem.addEventListener(type, handle, false); elem.addEventListener(type, handle, false);
else if (elem.attachEvent) else if (elem.attachEvent)
elem.attachEvent("on" + type, handle); elem.attachEvent("on" + type, handle);
} }
} }
// Add the function to the element's handler list // Add the function to the element's handler list
handlers[handler.guid] = handler; handlers[handler.guid] = handler;
// Keep track of which events have been used, for global triggering // Keep track of which events have been used, for global triggering
jQuery.event.global[type] = true; jQuery.event.global[type] = true;
}); });
}, },
guid: 1, guid: 1,
global: {}, global: {},
// Detach an event or set of events from an element // Detach an event or set of events from an element
remove: function(elem, types, handler) { remove: function(elem, types, handler) {
// don't do events on text and comment nodes // don't do events on text and comment nodes
if ( elem.nodeType == 3 || elem.nodeType == 8 ) if ( elem.nodeType == 3 || elem.nodeType == 8 )
return; return;
var events = jQuery.data(elem, "events"), ret, index; var events = jQuery.data(elem, "events"), ret, index;
if ( events ) { if ( events ) {
// Unbind all events for the element // Unbind all events for the element
if ( !types ) if ( !types )
for ( var type in events ) for ( var type in events )
this.remove( elem, type ); this.remove( elem, type );
else { else {
// types is actually an event object here // types is actually an event object here
if ( types.type ) { if ( types.type ) {
handler = types.handler; handler = types.handler;
types = types.type; types = types.type;
} }
// Handle multiple events seperated by a space // Handle multiple events seperated by a space
// jQuery(...).unbind("mouseover mouseout", fn); // jQuery(...).unbind("mouseover mouseout", fn);
jQuery.each(types.split(/\s+/), function(index, type){ jQuery.each(types.split(/\s+/), function(index, type){
// Namespaced event handlers // Namespaced event handlers
var parts = type.split("."); var parts = type.split(".");
type = parts[0]; type = parts[0];
if ( events[type] ) { if ( events[type] ) {
// remove the given handler for the given type // remove the given handler for the given type
if ( handler ) if ( handler )
delete events[type][handler.guid]; delete events[type][handler.guid];
// remove all handlers for the given type // remove all handlers for the given type
else else
for ( handler in events[type] ) for ( handler in events[type] )
// Handle the removal of namespaced events // Handle the removal of namespaced events
if ( !parts[1] || events[type][handler].type == parts[1] ) if ( !parts[1] || events[type][handler].type == parts[1] )
delete events[type][handler]; delete events[type][handler];
// remove generic event handler if no more handlers exist // remove generic event handler if no more handlers exist
for ( ret in events[type] ) break; for ( ret in events[type] ) break;
if ( !ret ) { if ( !ret ) {
if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) { if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) {
if (elem.removeEventListener) if (elem.removeEventListener)
elem.removeEventListener(type, jQuery.data(elem, "handle"), false); elem.removeEventListener(type, jQuery.data(elem, "handle"), false);
else if (elem.detachEvent) else if (elem.detachEvent)
elem.detachEvent("on" + type, jQuery.data(elem, "handle")); elem.detachEvent("on" + type, jQuery.data(elem, "handle"));
} }
ret = null; ret = null;
delete events[type]; delete events[type];
} }
} }
}); });
} }
// Remove the expando if it's no longer used // Remove the expando if it's no longer used
for ( ret in events ) break; for ( ret in events ) break;
if ( !ret ) { if ( !ret ) {
jQuery.removeData( elem, "events" ); jQuery.removeData( elem, "events" );
jQuery.removeData( elem, "handle" ); jQuery.removeData( elem, "handle" );
} }
} }
}, },
trigger: function(type, data, elem, donative, extra) { trigger: function(type, data, elem, donative, extra) {
// Clone the incoming data, if any // Clone the incoming data, if any
data = jQuery.makeArray(data || []); data = jQuery.makeArray(data || []);
// Handle a global trigger // Handle a global trigger
if ( !elem ) { if ( !elem ) {
// Only trigger if we've ever bound an event for it // Only trigger if we've ever bound an event for it
if ( this.global[type] ) if ( this.global[type] )
jQuery("*").add([window, document]).trigger(type, data); jQuery("*").add([window, document]).trigger(type, data);
// Handle triggering a single element // Handle triggering a single element
} else { } else {
// don't do events on text and comment nodes // don't do events on text and comment nodes
if ( elem.nodeType == 3 || elem.nodeType == 8 ) if ( elem.nodeType == 3 || elem.nodeType == 8 )
return undefined; return undefined;
var val, ret, fn = jQuery.isFunction( elem[ type ] || null ), var val, ret, fn = jQuery.isFunction( elem[ type ] || null ),
// Check to see if we need to provide a fake event, or not // Check to see if we need to provide a fake event, or not
event = !data[0] || !data[0].preventDefault; event = !data[0] || !data[0].preventDefault;
// Pass along a fake event // Pass along a fake event
if ( event ) if ( event )
data.unshift( this.fix({ type: type, target: elem }) ); data.unshift( this.fix({ type: type, target: elem }) );
// Enforce the right trigger type // Enforce the right trigger type
data[0].type = type; data[0].type = type;
// Trigger the event // Trigger the event
if ( jQuery.isFunction( jQuery.data(elem, "handle") ) ) if ( jQuery.isFunction( jQuery.data(elem, "handle") ) )
val = jQuery.data(elem, "handle").apply( elem, data ); val = jQuery.data(elem, "handle").apply( elem, data );
// Handle triggering native .onfoo handlers // Handle triggering native .onfoo handlers
if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false ) if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
val = false; val = false;
// Extra functions don't get the custom event object // Extra functions don't get the custom event object
if ( event ) if ( event )
data.shift(); data.shift();
// Handle triggering of extra function // Handle triggering of extra function
if ( extra ) { if ( extra && jQuery.isFunction( extra ) ) {
// call the extra function and tack the current return value on the end for possible inspection // call the extra function and tack the current return value on the end for possible inspection
var ret = extra.apply( elem, data.concat( val ) ); var ret = extra.apply( elem, data.concat( val ) );
// if anything is returned, give it precedence and have it overwrite the previous value // if anything is returned, give it precedence and have it overwrite the previous value
if (ret !== undefined) if (ret !== undefined)
val = ret; val = ret;
} }
// Trigger the native events (except for clicks on links) // Trigger the native events (except for clicks on links)
if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) { if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
this.triggered = true; this.triggered = true;
try { try {
elem[ type ](); elem[ type ]();
// prevent IE from throwing an error for some hidden elements // prevent IE from throwing an error for some hidden elements
} catch (e) {} } catch (e) {}
} }
this.triggered = false; this.triggered = false;
} }
return val; return val;
}, },
handle: function(event) { handle: function(event) {
// returned undefined or false // returned undefined or false
var val; var val;
// 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 || {} ); event = jQuery.event.fix( event || window.event || {} );
// Namespaced event handlers // Namespaced event handlers
var parts = event.type.split("."); var parts = event.type.split(".");
event.type = parts[0]; event.type = parts[0];
var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 ); var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );
args.unshift( event ); args.unshift( event );
for ( var j in handlers ) { for ( var j in handlers ) {
var handler = handlers[j]; var handler = handlers[j];
// Pass in a reference to the handler function itself // Pass in a reference to the handler function itself
// So that we can later remove it // So that we can later remove it
args[0].handler = handler; args[0].handler = handler;
args[0].data = handler.data; args[0].data = handler.data;
// Filter the functions by class // Filter the functions by class
if ( !parts[1] || handler.type == parts[1] ) { if ( !parts[1] || handler.type == parts[1] ) {
var ret = handler.apply( this, args ); var ret = handler.apply( this, args );
if ( val !== false ) if ( val !== false )
val = ret; val = ret;
if ( ret === false ) { if ( ret === false ) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
} }
} }
} }
// Clean up added properties in IE to prevent memory leak // Clean up added properties in IE to prevent memory leak
if (jQuery.browser.msie) if (jQuery.browser.msie)
event.target = event.preventDefault = event.stopPropagation = event.target = event.preventDefault = event.stopPropagation =
event.handler = event.data = null; event.handler = event.data = null;
return val; return val;
}, },
fix: function(event) { fix: function(event) {
// store a copy of the original event object // store a copy of the original event object
// and clone to set read-only properties // and clone to set read-only properties
var originalEvent = event; var originalEvent = event;
event = jQuery.extend({}, originalEvent); event = jQuery.extend({}, originalEvent);
// add preventDefault and stopPropagation since // add preventDefault and stopPropagation since
// they will not work on the clone // they will not work on the clone
event.preventDefault = function() { event.preventDefault = function() {
// if preventDefault exists run it on the original event // if preventDefault exists run it on the original event
if (originalEvent.preventDefault) if (originalEvent.preventDefault)
originalEvent.preventDefault(); originalEvent.preventDefault();
// otherwise set the returnValue property of the original event to false (IE) // otherwise set the returnValue property of the original event to false (IE)
originalEvent.returnValue = false; originalEvent.returnValue = false;
}; };
event.stopPropagation = function() { event.stopPropagation = function() {
// if stopPropagation exists run it on the original event // if stopPropagation exists run it on the original event
if (originalEvent.stopPropagation) if (originalEvent.stopPropagation)
originalEvent.stopPropagation(); originalEvent.stopPropagation();
// otherwise set the cancelBubble property of the original event to true (IE) // otherwise set the cancelBubble property of the original event to true (IE)
originalEvent.cancelBubble = true; originalEvent.cancelBubble = true;
}; };
// Fix target property, if necessary // Fix target property, if necessary
if ( !event.target ) if ( !event.target )
event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
// check if target is a textnode (safari) // check if target is a textnode (safari)
if ( event.target.nodeType == 3 ) if ( event.target.nodeType == 3 )
event.target = originalEvent.target.parentNode; event.target = originalEvent.target.parentNode;
// Add relatedTarget, if necessary // Add relatedTarget, if necessary
if ( !event.relatedTarget && event.fromElement ) if ( !event.relatedTarget && event.fromElement )
event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement; event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
// Calculate pageX/Y if missing and clientX/Y available // Calculate pageX/Y if missing and clientX/Y available
if ( event.pageX == null && event.clientX != null ) { if ( event.pageX == null && event.clientX != null ) {
var doc = document.documentElement, body = document.body; var doc = document.documentElement, body = document.body;
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0); 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.clientTop || 0); event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);
} }
// Add which for key events // Add which for key events
if ( !event.which && (event.charCode || event.keyCode) ) if ( !event.which && (event.charCode || event.keyCode) )
event.which = event.charCode || event.keyCode; event.which = event.charCode || event.keyCode;
// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
if ( !event.metaKey && event.ctrlKey ) if ( !event.metaKey && event.ctrlKey )
event.metaKey = event.ctrlKey; event.metaKey = event.ctrlKey;
// Add which for click: 1 == left; 2 == middle; 3 == right // Add which for click: 1 == left; 2 == middle; 3 == right
// Note: button is not normalized, so don't use it // Note: button is not normalized, so don't use it
if ( !event.which && event.button ) if ( !event.which && event.button )
event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) )); event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
return event; return event;
}, },
special: { special: {
ready: { ready: {
setup: function() { setup: function() {
// Make sure the ready event is setup // Make sure the ready event is setup
bindReady(); bindReady();
return; return;
}, },
teardown: function() { return; } teardown: function() { return; }
}, },
mouseenter: { mouseenter: {
setup: function() { setup: function() {
if ( jQuery.browser.msie ) return false; if ( jQuery.browser.msie ) return false;
jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler); jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler);
return true; return true;
}, },
teardown: function() { teardown: function() {
if ( jQuery.browser.msie ) return false; if ( jQuery.browser.msie ) return false;
jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler); jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler);
return true; return true;
}, },
handler: function(event) { handler: function(event) {
// If we actually just moused on to a sub-element, ignore it // If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true; if ( withinElement(event, this) ) return true;
// Execute the right handlers by setting the event type to mouseenter // Execute the right handlers by setting the event type to mouseenter
arguments[0].type = "mouseenter"; arguments[0].type = "mouseenter";
return jQuery.event.handle.apply(this, arguments); return jQuery.event.handle.apply(this, arguments);
} }
}, },
mouseleave: { mouseleave: {
setup: function() { setup: function() {
if ( jQuery.browser.msie ) return false; if ( jQuery.browser.msie ) return false;
jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler); jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler);
return true; return true;
}, },
teardown: function() { teardown: function() {
if ( jQuery.browser.msie ) return false; if ( jQuery.browser.msie ) return false;
jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler); jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler);
return true; return true;
}, },
handler: function(event) { handler: function(event) {
// If we actually just moused on to a sub-element, ignore it // If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true; if ( withinElement(event, this) ) return true;
// Execute the right handlers by setting the event type to mouseleave // Execute the right handlers by setting the event type to mouseleave
arguments[0].type = "mouseleave"; arguments[0].type = "mouseleave";
return jQuery.event.handle.apply(this, arguments); return jQuery.event.handle.apply(this, arguments);
} }
} }
} }
}; };
jQuery.fn.extend({ jQuery.fn.extend({
bind: function( type, data, fn ) { bind: function( type, data, fn ) {
return type == "unload" ? this.one(type, data, fn) : this.each(function(){ return type == "unload" ? this.one(type, data, fn) : this.each(function(){
jQuery.event.add( this, type, fn || data, fn && data ); jQuery.event.add( this, type, fn || data, fn && data );
}); });
}, },
one: function( type, data, fn ) { one: function( type, data, fn ) {
return this.each(function(){ return this.each(function(){
jQuery.event.add( this, type, function(event) { jQuery.event.add( this, type, function(event) {
jQuery(this).unbind(event); jQuery(this).unbind(event);
return (fn || data).apply( this, arguments); return (fn || data).apply( this, arguments);
}, fn && data); }, fn && data);
}); });
}, },
unbind: function( type, fn ) { unbind: function( type, fn ) {
return this.each(function(){ return this.each(function(){
jQuery.event.remove( this, type, fn ); jQuery.event.remove( this, type, fn );
}); });
}, },
trigger: function( type, data, fn ) { trigger: function( type, data, fn ) {
return this.each(function(){ return this.each(function(){
jQuery.event.trigger( type, data, this, true, fn ); jQuery.event.trigger( type, data, this, true, fn );
}); });
}, },
triggerHandler: function( type, data, fn ) { triggerHandler: function( type, data, fn ) {
if ( this[0] ) if ( this[0] )
return jQuery.event.trigger( type, data, this[0], false, fn ); return jQuery.event.trigger( type, data, this[0], false, fn );
return undefined; return undefined;
}, },
toggle: function() { toggle: function() {
// Save reference to arguments for access in closure // Save reference to arguments for access in closure
var args = arguments; var args = arguments;
return this.click(function(event) { return this.click(function(event) {
// Figure out which function to execute // Figure out which function to execute
this.lastToggle = 0 == this.lastToggle ? 1 : 0; this.lastToggle = 0 == this.lastToggle ? 1 : 0;
// Make sure that clicks stop // Make sure that clicks stop
event.preventDefault(); event.preventDefault();
// and execute the function // and execute the function
return args[this.lastToggle].apply( this, arguments ) || false; return args[this.lastToggle].apply( this, arguments ) || false;
}); });
}, },
hover: function(fnOver, fnOut) { hover: function(fnOver, fnOut) {
return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut); return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
}, },
ready: function(fn) { ready: function(fn) {
// Attach the listeners // Attach the listeners
bindReady(); bindReady();
// If the DOM is already ready // If the DOM is already ready
if ( jQuery.isReady ) if ( jQuery.isReady )
// Execute the function immediately // Execute the function immediately
fn.call( document, jQuery ); fn.call( document, jQuery );
// Otherwise, remember the function for later // Otherwise, remember the function for later
else else
// Add the function to the wait list // Add the function to the wait list
jQuery.readyList.push( function() { return fn.call(this, jQuery); } ); jQuery.readyList.push( function() { return fn.call(this, jQuery); } );
return this; return this;
} }
}); });
jQuery.extend({ jQuery.extend({
isReady: false, isReady: false,
readyList: [], readyList: [],
// Handle when the DOM is ready // Handle when the DOM is ready
ready: function() { ready: function() {
// Make sure that the DOM is not already loaded // Make sure that the DOM is not already loaded
if ( !jQuery.isReady ) { if ( !jQuery.isReady ) {
// Remember that the DOM is ready // Remember that the DOM is ready
jQuery.isReady = true; jQuery.isReady = true;
// If there are functions bound, to execute // If there are functions bound, to execute
if ( jQuery.readyList ) { if ( jQuery.readyList ) {
// Execute all of them // Execute all of them
jQuery.each( jQuery.readyList, function(){ jQuery.each( jQuery.readyList, function(){
this.apply( document ); this.apply( document );
}); });
// Reset the list of functions // Reset the list of functions
jQuery.readyList = null; jQuery.readyList = null;
} }
// Trigger any bound ready events // Trigger any bound ready events
$(document).triggerHandler("ready"); $(document).triggerHandler("ready");
} }
} }
}); });
var readyBound = false; var readyBound = false;
function bindReady(){ function bindReady(){
if ( readyBound ) return; if ( readyBound ) return;
readyBound = true; readyBound = true;
// Mozilla, Opera and webkit nightlies currently support this event // Mozilla, Opera and webkit nightlies currently support this event
if ( document.addEventListener ) if ( document.addEventListener )
// Use the handy event callback // Use the handy event callback
document.addEventListener( "DOMContentLoaded", jQuery.ready, false ); document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
// If Safari or IE is used // If Safari or IE is used
// Continually check to see if the document is ready // 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 { try {
// If IE is used, use the trick by Diego Perini // If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/ // http://javascript.nwbox.com/IEContentLoaded/
if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" ) if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" )
document.documentElement.doScroll("left"); document.documentElement.doScroll("left");
} catch( error ) { } catch( error ) {
return setTimeout( arguments.callee, 0 ); return setTimeout( arguments.callee, 0 );
} }
// and execute any waiting functions // and execute any waiting functions
jQuery.ready(); jQuery.ready();
})(); })();
// A fallback to window.onload, that will always work // A fallback to window.onload, that will always work
jQuery.event.add( window, "load", jQuery.ready ); jQuery.event.add( window, "load", jQuery.ready );
} }
jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
"mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
"submit,keydown,keypress,keyup,error").split(","), function(i, name){ "submit,keydown,keypress,keyup,error").split(","), function(i, name){
// Handle event binding // Handle event binding
jQuery.fn[name] = function(fn){ jQuery.fn[name] = function(fn){
return fn ? this.bind(name, fn) : this.trigger(name); return fn ? this.bind(name, fn) : this.trigger(name);
}; };
}); });
// Checks if an event happened on an element within another element // Checks if an event happened on an element within another element
// Used in jQuery.event.special.mouseenter and mouseleave handlers // Used in jQuery.event.special.mouseenter and mouseleave handlers
var withinElement = function(event, elem) { var withinElement = function(event, elem) {
// Check if mouse(over|out) are still within the same parent element // Check if mouse(over|out) are still within the same parent element
var parent = event.relatedTarget; var parent = event.relatedTarget;
// Traverse up the tree // Traverse up the tree
while ( parent && parent != elem ) try { parent = parent.parentNode } catch(error) { parent = elem; }; while ( parent && parent != elem ) try { parent = parent.parentNode } catch(error) { parent = elem; };
// Return true if we actually just moused on to a sub-element // Return true if we actually just moused on to a sub-element
return parent == elem; return parent == elem;
}; };
// Prevent memory leaks in IE // Prevent memory leaks in IE
// And prevent errors on refresh with events like mouseover in other browsers // And prevent errors on refresh with events like mouseover in other browsers
// Window isn't included so as not to unbind existing unload events // Window isn't included so as not to unbind existing unload events
jQuery(window).bind("unload", function() { jQuery(window).bind("unload", function() {
jQuery("*").add(document).unbind(); jQuery("*").add(document).unbind();
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment