2007-12-19 01:10:20 +00:00
|
|
|
/*
|
|
|
|
* A number of helper functions used for managing events.
|
2008-06-27 14:17:28 +00:00
|
|
|
* Many of the ideas behind this code originated from
|
2007-12-19 01:10:20 +00:00
|
|
|
* Dean Edwards' addEvent library.
|
|
|
|
*/
|
|
|
|
jQuery.event = {
|
|
|
|
|
|
|
|
// Bind an event to an element
|
|
|
|
// Original by Dean Edwards
|
2009-04-30 01:26:09 +00:00
|
|
|
add: function( elem, types, handler, data ) {
|
|
|
|
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
return;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// For whatever reason, IE has trouble passing the window object
|
|
|
|
// around, causing it to be cloned in the process
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( elem.setInterval && ( elem !== window && !elem.frameElement ) ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
elem = window;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Make sure that the function being executed has a unique ID
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !handler.guid ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
handler.guid = this.guid++;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
|
|
|
// if data is passed, bind to handler
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( data !== undefined ) {
|
2008-05-13 01:45:58 +00:00
|
|
|
// Create temporary function pointer to original handler
|
|
|
|
var fn = handler;
|
|
|
|
|
|
|
|
// Create unique handler function, wrapped around original handler
|
2009-01-09 22:10:42 +00:00
|
|
|
handler = this.proxy( fn );
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-05-13 01:45:58 +00:00
|
|
|
// Store data in unique handler
|
2007-12-19 01:10:20 +00:00
|
|
|
handler.data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init the element's event structure
|
2009-04-30 01:26:09 +00:00
|
|
|
var events = jQuery.data( elem, "events" ) || jQuery.data( elem, "events", {} ),
|
|
|
|
handle = jQuery.data( elem, "handle" ) || jQuery.data( elem, "handle", function() {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Handle the second event of a trigger and when
|
|
|
|
// an event is called after a page has unloaded
|
2008-12-19 04:36:28 +00:00
|
|
|
return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
|
2009-04-30 01:26:09 +00:00
|
|
|
jQuery.event.handle.apply( arguments.callee.elem, arguments ) :
|
2008-12-19 04:36:28 +00:00
|
|
|
undefined;
|
2007-12-19 01:10:20 +00:00
|
|
|
});
|
2007-12-21 04:53:33 +00:00
|
|
|
// Add elem as a property of the handle function
|
|
|
|
// This is to prevent a memory leak with non-native
|
|
|
|
// event in IE.
|
|
|
|
handle.elem = elem;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-04-29 23:34:50 +00:00
|
|
|
// Handle multiple events separated by a space
|
|
|
|
// jQuery(...).bind("mouseover mouseout", fn);
|
2009-04-30 01:26:09 +00:00
|
|
|
types = types.split( /\s+/ );
|
|
|
|
var type, i=0;
|
|
|
|
while ( (type = types[ i++ ]) ) {
|
2008-04-29 23:34:50 +00:00
|
|
|
// Namespaced event handlers
|
2008-12-22 04:59:34 +00:00
|
|
|
var namespaces = type.split(".");
|
|
|
|
type = namespaces.shift();
|
|
|
|
handler.type = namespaces.slice().sort().join(".");
|
2008-04-29 23:34:50 +00:00
|
|
|
|
|
|
|
// Get the current list of functions bound to this event
|
2009-04-30 21:44:25 +00:00
|
|
|
var handlers = events[ type ],
|
|
|
|
special = this.special[ type ] || {};
|
|
|
|
|
|
|
|
if ( special.add ) {
|
|
|
|
var modifiedHandler = special.add.call( elem, handler, data, namespaces );
|
|
|
|
if ( modifiedHandler && jQuery.isFunction( modifiedHandler ) ) {
|
2009-05-01 00:02:51 +00:00
|
|
|
modifiedHandler.guid = modifiedHandler.guid || handler.guid;
|
2009-04-30 21:44:25 +00:00
|
|
|
handler = modifiedHandler;
|
|
|
|
}
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-04-29 23:34:50 +00:00
|
|
|
|
|
|
|
// Init the event handler queue
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !handlers ) {
|
|
|
|
handlers = events[ type ] = {};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-04-29 23:34:50 +00:00
|
|
|
// Check for a special event handler
|
|
|
|
// Only use addEventListener/attachEvent if the special
|
|
|
|
// events handler returns false
|
2009-04-30 21:44:25 +00:00
|
|
|
if ( !special.setup || special.setup.call( elem, data, namespaces ) === false ) {
|
2008-04-29 23:34:50 +00:00
|
|
|
// Bind the global event handler to the element
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( elem.addEventListener ) {
|
|
|
|
elem.addEventListener( type, handle, false );
|
|
|
|
} else if ( elem.attachEvent ) {
|
|
|
|
elem.attachEvent( "on" + type, handle );
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
2008-04-29 23:34:50 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-04-29 23:34:50 +00:00
|
|
|
// Add the function to the element's handler list
|
2009-04-30 01:26:09 +00:00
|
|
|
handlers[ handler.guid ] = handler;
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-04-29 23:34:50 +00:00
|
|
|
// Keep track of which events have been used, for global triggering
|
2009-04-30 01:26:09 +00:00
|
|
|
this.global[ type ] = true;
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-21 04:53:33 +00:00
|
|
|
// Nullify elem to prevent memory leaks in IE
|
|
|
|
elem = null;
|
2007-12-19 01:10:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
guid: 1,
|
|
|
|
global: {},
|
|
|
|
|
|
|
|
// Detach an event or set of events from an element
|
2009-04-30 01:26:09 +00:00
|
|
|
remove: function( elem, types, handler ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// don't do events on text and comment nodes
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
return;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
var events = jQuery.data( elem, "events" ), ret, type;
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
if ( events ) {
|
|
|
|
// Unbind all events for the element
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( types === undefined || (typeof types === "string" && types.charAt(0) === ".") ) {
|
|
|
|
for ( type in events ) {
|
2008-02-03 04:33:11 +00:00
|
|
|
this.remove( elem, type + (types || "") );
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-12-19 01:10:20 +00:00
|
|
|
// types is actually an event object here
|
|
|
|
if ( types.type ) {
|
|
|
|
handler = types.handler;
|
|
|
|
types = types.type;
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Handle multiple events seperated by a space
|
|
|
|
// jQuery(...).unbind("mouseover mouseout", fn);
|
2009-04-30 01:26:09 +00:00
|
|
|
types = types.split(/\s+/);
|
|
|
|
var i = 0;
|
|
|
|
while ( (type = types[ i++ ]) ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Namespaced event handlers
|
2008-12-22 04:59:34 +00:00
|
|
|
var namespaces = type.split(".");
|
|
|
|
type = namespaces.shift();
|
2009-04-29 21:45:58 +00:00
|
|
|
var all = !namespaces.length,
|
2009-04-30 21:44:25 +00:00
|
|
|
namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"),
|
|
|
|
special = this.special[ type ] || {};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-04-30 21:44:25 +00:00
|
|
|
if ( events[ type ] ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// remove the given handler for the given type
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( handler ) {
|
|
|
|
delete events[ type ][ handler.guid ];
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// remove all handlers for the given type
|
2009-04-30 01:26:09 +00:00
|
|
|
} else {
|
|
|
|
for ( var handle in events[ type ] ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Handle the removal of namespaced events
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( all || namespace.test( events[ type ][ handle ].type ) ) {
|
|
|
|
delete events[ type ][ handle ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2009-04-30 21:44:25 +00:00
|
|
|
if ( special.remove ) {
|
|
|
|
special.remove.call( elem, namespaces );
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// remove generic event handler if no more handlers exist
|
2009-04-30 01:26:09 +00:00
|
|
|
for ( ret in events[ type ] ) {
|
|
|
|
break;
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
if ( !ret ) {
|
2009-05-01 00:36:21 +00:00
|
|
|
if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( elem.removeEventListener ) {
|
|
|
|
elem.removeEventListener( type, jQuery.data( elem, "handle" ), false );
|
|
|
|
} else if ( elem.detachEvent ) {
|
|
|
|
elem.detachEvent( "on" + type, jQuery.data( elem, "handle" ) );
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
ret = null;
|
2009-04-30 01:26:09 +00:00
|
|
|
delete events[ type ];
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the expando if it's no longer used
|
2009-04-30 01:26:09 +00:00
|
|
|
for ( ret in events ) {
|
|
|
|
break;
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
if ( !ret ) {
|
2007-12-21 04:53:33 +00:00
|
|
|
var handle = jQuery.data( elem, "handle" );
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( handle ) {
|
|
|
|
handle.elem = null;
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
jQuery.removeData( elem, "events" );
|
|
|
|
jQuery.removeData( elem, "handle" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-01-05 13:31:21 +00:00
|
|
|
// bubbling is internal
|
2009-05-10 14:38:35 +00:00
|
|
|
trigger: function( event, data, elem /*, bubbling */ ) {
|
2008-12-25 21:44:54 +00:00
|
|
|
// Event object or event type
|
2009-05-10 14:38:35 +00:00
|
|
|
var type = event.type || event,
|
|
|
|
bubbling = arguments[3];
|
2008-12-31 02:58:13 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !bubbling ) {
|
2009-01-02 23:07:16 +00:00
|
|
|
event = typeof event === "object" ?
|
|
|
|
// jQuery.Event object
|
|
|
|
event[expando] ? event :
|
|
|
|
// Object literal
|
|
|
|
jQuery.extend( jQuery.Event(type), event ) :
|
|
|
|
// Just the event type (string)
|
|
|
|
jQuery.Event(type);
|
|
|
|
|
|
|
|
if ( type.indexOf("!") >= 0 ) {
|
|
|
|
event.type = type = type.slice(0, -1);
|
|
|
|
event.exclusive = true;
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2009-01-02 23:07:16 +00:00
|
|
|
// Handle a global trigger
|
|
|
|
if ( !elem ) {
|
|
|
|
// Don't bubble custom events when global (to avoid too much overhead)
|
|
|
|
event.stopPropagation();
|
|
|
|
// Only trigger if we've ever bound an event for it
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( this.global[ type ] ) {
|
2009-05-01 00:59:27 +00:00
|
|
|
jQuery.each( jQuery.cache, function() {
|
|
|
|
if ( this.events && this.events[type] ) {
|
|
|
|
jQuery.event.trigger( event, data, this.handle.elem );
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2009-05-01 00:59:27 +00:00
|
|
|
});
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2009-01-02 23:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle triggering a single element
|
2008-12-25 21:44:54 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// don't do events on text and comment nodes
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
return undefined;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2009-01-05 13:31:21 +00:00
|
|
|
// Clean up in case it is reused
|
|
|
|
event.result = undefined;
|
|
|
|
event.target = elem;
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2009-01-05 13:31:21 +00:00
|
|
|
// Clone the incoming data, if any
|
2009-04-30 01:26:09 +00:00
|
|
|
data = jQuery.makeArray( data );
|
2009-01-05 13:31:21 +00:00
|
|
|
data.unshift( event );
|
2009-01-02 23:07:16 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2009-01-02 23:07:16 +00:00
|
|
|
event.currentTarget = elem;
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2009-01-02 23:07:16 +00:00
|
|
|
// Trigger the event, it is assumed that "handle" is a function
|
2009-04-30 01:26:09 +00:00
|
|
|
var handle = jQuery.data( elem, "handle" );
|
|
|
|
if ( handle ) {
|
2009-01-02 23:07:16 +00:00
|
|
|
handle.apply( elem, data );
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2009-06-17 02:31:45 +00:00
|
|
|
var nativeFn, nativeHandler;
|
|
|
|
try {
|
|
|
|
nativeFn = elem[ type ];
|
|
|
|
nativeHandler = elem[ "on" + type ];
|
|
|
|
// prevent IE from throwing an error for some elements with some event types, see #3533
|
|
|
|
} catch (e) {}
|
2009-01-02 23:07:16 +00:00
|
|
|
// Handle triggering native .onfoo handlers (and on links since we don't call .click() for links)
|
2009-06-17 02:31:45 +00:00
|
|
|
if ( (!nativeFn || (jQuery.nodeName(elem, 'a') && type === "click")) && nativeHandler && nativeHandler.apply( elem, data ) === false ) {
|
2009-01-02 23:07:16 +00:00
|
|
|
event.result = false;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2009-01-02 23:07:16 +00:00
|
|
|
// Trigger the native events (except for clicks on links)
|
2009-06-17 02:31:45 +00:00
|
|
|
if ( !bubbling && nativeFn && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type === "click") ) {
|
2009-01-02 23:07:16 +00:00
|
|
|
this.triggered = true;
|
|
|
|
try {
|
2009-06-17 02:31:45 +00:00
|
|
|
nativeFn();
|
2009-01-02 23:07:16 +00:00
|
|
|
// prevent IE from throwing an error for some hidden elements
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
2008-12-31 02:58:13 +00:00
|
|
|
|
2009-01-05 20:43:24 +00:00
|
|
|
this.triggered = false;
|
|
|
|
|
2009-01-02 23:07:16 +00:00
|
|
|
if ( !event.isPropagationStopped() ) {
|
|
|
|
var parent = elem.parentNode || elem.ownerDocument;
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( parent ) {
|
|
|
|
jQuery.event.trigger( event, data, parent, true );
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
handle: function( event ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// returned undefined or false
|
2008-12-31 02:58:13 +00:00
|
|
|
var all, handlers;
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-04-22 05:23:55 +00:00
|
|
|
event = arguments[0] = jQuery.event.fix( event || window.event );
|
2009-02-17 12:38:16 +00:00
|
|
|
event.currentTarget = this;
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Namespaced event handlers
|
2008-12-22 04:59:34 +00:00
|
|
|
var namespaces = event.type.split(".");
|
|
|
|
event.type = namespaces.shift();
|
2008-12-19 06:49:44 +00:00
|
|
|
|
2008-05-13 01:42:35 +00:00
|
|
|
// Cache this now, all = true means, any handler
|
2008-12-22 04:59:34 +00:00
|
|
|
all = !namespaces.length && !event.exclusive;
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2009-02-26 18:00:41 +00:00
|
|
|
var namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)");
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
handlers = ( jQuery.data(this, "events") || {} )[ event.type ];
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
for ( var j in handlers ) {
|
2009-04-30 01:26:09 +00:00
|
|
|
var handler = handlers[ j ];
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Filter the functions by class
|
2008-12-19 04:34:12 +00:00
|
|
|
if ( all || namespace.test(handler.type) ) {
|
2008-04-22 05:23:55 +00:00
|
|
|
// Pass in a reference to the handler function itself
|
|
|
|
// So that we can later remove it
|
|
|
|
event.handler = handler;
|
|
|
|
event.data = handler.data;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
var ret = handler.apply( this, arguments );
|
2008-04-23 18:57:17 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( ret !== undefined ) {
|
2008-12-31 02:58:13 +00:00
|
|
|
event.result = ret;
|
|
|
|
if ( ret === false ) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2008-04-23 18:57:17 +00:00
|
|
|
}
|
2008-10-18 22:46:04 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( event.isImmediatePropagationStopped() ) {
|
2008-10-18 22:46:04 +00:00
|
|
|
break;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-10-18 22:46:04 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-04-22 02:31:29 +00:00
|
|
|
props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
|
2008-05-28 20:43:13 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
fix: function( event ) {
|
|
|
|
if ( event[ expando ] ) {
|
2008-04-27 23:08:31 +00:00
|
|
|
return event;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
|
|
|
// store a copy of the original event object
|
2008-04-28 21:09:27 +00:00
|
|
|
// and "clone" to set read-only properties
|
2007-12-19 01:10:20 +00:00
|
|
|
var originalEvent = event;
|
2008-12-29 21:57:29 +00:00
|
|
|
event = jQuery.Event( originalEvent );
|
2008-05-28 20:43:13 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
for ( var i = this.props.length, prop; i; ) {
|
2008-05-28 20:43:13 +00:00
|
|
|
prop = this.props[ --i ];
|
|
|
|
event[ prop ] = originalEvent[ prop ];
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Fix target property, if necessary
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !event.target ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// check if target is a textnode (safari)
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( event.target.nodeType === 3 ) {
|
2008-04-28 21:09:27 +00:00
|
|
|
event.target = event.target.parentNode;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Add relatedTarget, if necessary
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !event.relatedTarget && event.fromElement ) {
|
|
|
|
event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement;
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Calculate pageX/Y if missing and clientX/Y available
|
|
|
|
if ( event.pageX == null && event.clientX != null ) {
|
|
|
|
var doc = document.documentElement, body = document.body;
|
2009-05-01 00:21:29 +00:00
|
|
|
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
|
|
|
|
event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Add which for key events
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
event.which = event.charCode || event.keyCode;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !event.metaKey && event.ctrlKey ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
event.metaKey = event.ctrlKey;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Add which for click: 1 == left; 2 == middle; 3 == right
|
|
|
|
// Note: button is not normalized, so don't use it
|
2009-06-17 02:31:45 +00:00
|
|
|
if ( !event.which && event.button !== undefined ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
return event;
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-05-07 00:50:28 +00:00
|
|
|
proxy: function( fn, proxy, thisObject ) {
|
|
|
|
if ( proxy !== undefined && !jQuery.isFunction( proxy ) ) {
|
|
|
|
thisObject = proxy;
|
|
|
|
proxy = undefined;
|
|
|
|
}
|
|
|
|
// FIXME: Should proxy be redefined to be applied with thisObject if defined?
|
|
|
|
proxy = proxy || function() { return fn.apply( thisObject !== undefined ? thisObject : this, arguments ); };
|
2008-05-13 01:45:58 +00:00
|
|
|
// Set the guid of unique handler to the same of original handler, so it can be removed
|
2008-04-29 22:06:54 +00:00
|
|
|
proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++;
|
2008-05-13 01:42:35 +00:00
|
|
|
// So proxy can be declared as an argument
|
|
|
|
return proxy;
|
2008-04-29 22:06:54 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
special: {
|
|
|
|
ready: {
|
2008-07-28 18:31:25 +00:00
|
|
|
// Make sure the ready event is setup
|
|
|
|
setup: bindReady,
|
|
|
|
teardown: function() {}
|
2009-04-30 21:44:25 +00:00
|
|
|
},
|
2009-05-06 01:24:22 +00:00
|
|
|
|
2008-12-22 04:59:34 +00:00
|
|
|
live: {
|
2009-04-30 21:44:25 +00:00
|
|
|
add: function( proxy, data, namespaces ) {
|
|
|
|
jQuery.extend( proxy, data || {} );
|
|
|
|
proxy.guid += data.selector + data.live;
|
|
|
|
jQuery.event.add( this, data.live, liveHandler );
|
2008-12-22 04:59:34 +00:00
|
|
|
},
|
2009-05-06 01:24:22 +00:00
|
|
|
|
2009-05-12 15:43:51 +00:00
|
|
|
remove: function( namespaces ) {
|
|
|
|
if ( namespaces.length ) {
|
|
|
|
var remove = 0, name = new RegExp("(^|\\.)" + namespaces[0] + "(\\.|$)");
|
|
|
|
|
|
|
|
jQuery.each( (jQuery.data(this, "events").live || {}), function() {
|
|
|
|
if ( name.test(this.type) ) {
|
|
|
|
remove++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if ( remove < 1 ) {
|
|
|
|
jQuery.event.remove( this, namespaces[0], liveHandler );
|
|
|
|
}
|
|
|
|
}
|
2008-12-22 04:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-12-25 21:44:54 +00:00
|
|
|
jQuery.Event = function( src ){
|
2008-12-29 21:57:29 +00:00
|
|
|
// Allow instantiation without the 'new' keyword
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !this.preventDefault ) {
|
|
|
|
return new jQuery.Event( src );
|
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2008-12-25 21:44:54 +00:00
|
|
|
// Event object
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( src && src.type ) {
|
2008-12-25 21:44:54 +00:00
|
|
|
this.originalEvent = src;
|
|
|
|
this.type = src.type;
|
|
|
|
// Event type
|
2009-04-30 01:26:09 +00:00
|
|
|
} else {
|
2008-12-25 21:44:54 +00:00
|
|
|
this.type = src;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-12-25 21:44:54 +00:00
|
|
|
|
2009-01-19 22:20:25 +00:00
|
|
|
// timeStamp is buggy for some events on Firefox(#3843)
|
|
|
|
// So we won't rely on the native value
|
|
|
|
this.timeStamp = now();
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2008-12-25 21:44:54 +00:00
|
|
|
// Mark it as fixed
|
2009-04-30 01:26:09 +00:00
|
|
|
this[ expando ] = true;
|
2008-12-25 21:44:54 +00:00
|
|
|
};
|
2008-10-18 22:46:04 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
function returnFalse() {
|
2008-12-31 02:58:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-30 01:26:09 +00:00
|
|
|
function returnTrue() {
|
2008-12-31 02:58:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
|
|
|
|
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
|
2008-12-25 21:44:54 +00:00
|
|
|
jQuery.Event.prototype = {
|
|
|
|
preventDefault: function() {
|
2008-12-31 02:58:13 +00:00
|
|
|
this.isDefaultPrevented = returnTrue;
|
|
|
|
|
2008-12-25 21:44:54 +00:00
|
|
|
var e = this.originalEvent;
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !e ) {
|
2008-12-25 21:44:54 +00:00
|
|
|
return;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-12-25 21:44:54 +00:00
|
|
|
// if preventDefault exists run it on the original event
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( e.preventDefault ) {
|
2008-12-25 21:44:54 +00:00
|
|
|
e.preventDefault();
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-12-25 21:44:54 +00:00
|
|
|
// otherwise set the returnValue property of the original event to false (IE)
|
|
|
|
e.returnValue = false;
|
|
|
|
},
|
|
|
|
stopPropagation: function() {
|
2008-12-31 02:58:13 +00:00
|
|
|
this.isPropagationStopped = returnTrue;
|
|
|
|
|
2008-12-25 21:44:54 +00:00
|
|
|
var e = this.originalEvent;
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( !e ) {
|
2008-12-25 21:44:54 +00:00
|
|
|
return;
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-12-25 21:44:54 +00:00
|
|
|
// if stopPropagation exists run it on the original event
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( e.stopPropagation ) {
|
2008-12-25 21:44:54 +00:00
|
|
|
e.stopPropagation();
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-12-25 21:44:54 +00:00
|
|
|
// otherwise set the cancelBubble property of the original event to true (IE)
|
|
|
|
e.cancelBubble = true;
|
|
|
|
},
|
2009-04-30 01:26:09 +00:00
|
|
|
stopImmediatePropagation: function(){
|
2008-12-31 02:58:13 +00:00
|
|
|
this.isImmediatePropagationStopped = returnTrue;
|
2008-12-25 21:44:54 +00:00
|
|
|
this.stopPropagation();
|
2008-12-31 02:58:13 +00:00
|
|
|
},
|
|
|
|
isDefaultPrevented: returnFalse,
|
|
|
|
isPropagationStopped: returnFalse,
|
|
|
|
isImmediatePropagationStopped: returnFalse
|
2008-12-25 21:44:54 +00:00
|
|
|
};
|
2008-12-21 21:22:44 +00:00
|
|
|
// Checks if an event happened on an element within another element
|
|
|
|
// Used in jQuery.event.special.mouseenter and mouseleave handlers
|
2009-04-30 01:26:09 +00:00
|
|
|
var withinElement = function( event ) {
|
2008-12-21 21:22:44 +00:00
|
|
|
// Check if mouse(over|out) are still within the same parent element
|
|
|
|
var parent = event.relatedTarget;
|
|
|
|
// Traverse up the tree
|
2009-04-30 01:26:09 +00:00
|
|
|
while ( parent && parent != this ) {
|
2009-05-06 01:24:22 +00:00
|
|
|
// Firefox sometimes assigns relatedTarget a XUL element
|
|
|
|
// which we cannot access the parentNode property of
|
2008-12-21 21:22:44 +00:00
|
|
|
try { parent = parent.parentNode; }
|
2009-05-06 01:24:22 +00:00
|
|
|
// assuming we've left the element since we most likely mousedover a xul element
|
|
|
|
catch(e) { break; }
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( parent != this ) {
|
2008-12-21 21:22:44 +00:00
|
|
|
// set the correct event type
|
|
|
|
event.type = event.data;
|
|
|
|
// handle event if we actually just moused on to a non sub-element
|
|
|
|
jQuery.event.handle.apply( this, arguments );
|
|
|
|
}
|
|
|
|
};
|
2009-03-23 01:55:17 +00:00
|
|
|
|
|
|
|
jQuery.each({
|
|
|
|
mouseover: 'mouseenter',
|
2008-12-21 21:22:44 +00:00
|
|
|
mouseout: 'mouseleave'
|
2009-04-30 01:26:09 +00:00
|
|
|
}, function( orig, fix ) {
|
2008-12-21 21:22:44 +00:00
|
|
|
jQuery.event.special[ fix ] = {
|
|
|
|
setup: function(){
|
|
|
|
jQuery.event.add( this, orig, withinElement, fix );
|
|
|
|
},
|
|
|
|
teardown: function(){
|
|
|
|
jQuery.event.remove( this, orig, withinElement );
|
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
};
|
2008-12-21 21:22:44 +00:00
|
|
|
});
|
2008-07-28 18:31:25 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
jQuery.fn.extend({
|
2009-05-07 00:50:28 +00:00
|
|
|
bind: function( type, data, fn, thisObject ) {
|
|
|
|
if ( jQuery.isFunction( data ) ) {
|
|
|
|
if ( fn !== undefined ) {
|
|
|
|
thisObject = fn;
|
|
|
|
}
|
|
|
|
fn = data;
|
|
|
|
data = undefined;
|
|
|
|
}
|
|
|
|
fn = thisObject === undefined ? fn : jQuery.event.proxy( fn, thisObject );
|
|
|
|
return type === "unload" ? this.one(type, data, fn, thisObject) : this.each(function() {
|
2009-05-07 18:09:17 +00:00
|
|
|
jQuery.event.add( this, type, fn, data );
|
2007-12-19 01:10:20 +00:00
|
|
|
});
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-05-07 00:50:28 +00:00
|
|
|
one: function( type, data, fn, thisObject ) {
|
|
|
|
if ( jQuery.isFunction( data ) ) {
|
|
|
|
if ( fn !== undefined ) {
|
|
|
|
thisObject = fn;
|
|
|
|
}
|
|
|
|
fn = data;
|
|
|
|
data = undefined;
|
|
|
|
}
|
|
|
|
fn = thisObject === undefined ? fn : jQuery.event.proxy( fn, thisObject );
|
|
|
|
var one = jQuery.event.proxy( fn, function( event ) {
|
2009-04-30 01:26:09 +00:00
|
|
|
jQuery( this ).unbind( event, one );
|
2009-05-07 00:50:28 +00:00
|
|
|
return fn.apply( this, arguments );
|
2008-04-29 22:06:54 +00:00
|
|
|
});
|
2009-04-30 01:26:09 +00:00
|
|
|
return this.each(function() {
|
2009-05-07 18:09:17 +00:00
|
|
|
jQuery.event.add( this, type, one, data );
|
2007-12-19 01:10:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
unbind: function( type, fn ) {
|
2009-04-30 01:26:09 +00:00
|
|
|
return this.each(function() {
|
2007-12-19 01:10:20 +00:00
|
|
|
jQuery.event.remove( this, type, fn );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-01-02 22:23:52 +00:00
|
|
|
trigger: function( type, data ) {
|
2009-04-30 01:26:09 +00:00
|
|
|
return this.each(function() {
|
2009-01-02 22:23:52 +00:00
|
|
|
jQuery.event.trigger( type, data, this );
|
2007-12-19 01:10:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-01-02 22:23:52 +00:00
|
|
|
triggerHandler: function( type, data ) {
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( this[0] ) {
|
|
|
|
var event = jQuery.Event( type );
|
2008-12-31 02:58:13 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2009-01-02 22:23:52 +00:00
|
|
|
jQuery.event.trigger( event, data, this[0] );
|
2008-12-31 02:58:13 +00:00
|
|
|
return event.result;
|
2009-03-23 01:55:17 +00:00
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
},
|
|
|
|
|
2008-04-29 22:06:54 +00:00
|
|
|
toggle: function( fn ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Save reference to arguments for access in closure
|
2008-04-29 22:06:54 +00:00
|
|
|
var args = arguments, i = 1;
|
|
|
|
|
|
|
|
// link all the functions, so any of them can unbind this click handler
|
2009-04-30 01:26:09 +00:00
|
|
|
while( i < args.length ) {
|
|
|
|
jQuery.event.proxy( fn, args[ i++ ] );
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
return this.click( jQuery.event.proxy( fn, function( event ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Figure out which function to execute
|
2008-04-29 22:06:54 +00:00
|
|
|
this.lastToggle = ( this.lastToggle || 0 ) % i;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Make sure that clicks stop
|
|
|
|
event.preventDefault();
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// and execute the function
|
2008-04-29 21:37:41 +00:00
|
|
|
return args[ this.lastToggle++ ].apply( this, arguments ) || false;
|
2008-04-29 22:06:54 +00:00
|
|
|
}));
|
2007-12-19 01:10:20 +00:00
|
|
|
},
|
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
hover: function( fnOver, fnOut ) {
|
2009-05-06 02:17:24 +00:00
|
|
|
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
|
2007-12-19 01:10:20 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
ready: function( fn ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Attach the listeners
|
|
|
|
bindReady();
|
|
|
|
|
|
|
|
// If the DOM is already ready
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( jQuery.isReady ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Execute the function immediately
|
|
|
|
fn.call( document, jQuery );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Otherwise, remember the function for later
|
2009-04-30 01:26:09 +00:00
|
|
|
} else {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Add the function to the wait list
|
2008-12-31 03:36:51 +00:00
|
|
|
jQuery.readyList.push( fn );
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
return this;
|
2008-12-22 04:59:34 +00:00
|
|
|
},
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2009-05-07 00:50:28 +00:00
|
|
|
live: function( type, data, fn, thisObject ) {
|
|
|
|
if ( jQuery.isFunction( data ) ) {
|
|
|
|
if ( fn !== undefined ) {
|
|
|
|
thisObject = fn;
|
|
|
|
}
|
|
|
|
fn = data;
|
|
|
|
data = undefined;
|
|
|
|
}
|
2009-04-30 21:44:25 +00:00
|
|
|
jQuery( this.context ).bind( liveConvert( type, this.selector ), {
|
2009-05-07 00:50:28 +00:00
|
|
|
data: data, selector: this.selector, live: type
|
|
|
|
}, fn, thisObject );
|
2008-12-22 04:59:34 +00:00
|
|
|
return this;
|
|
|
|
},
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
die: function( type, fn ) {
|
2009-04-30 21:44:25 +00:00
|
|
|
jQuery( this.context ).unbind( liveConvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null );
|
2008-12-22 04:59:34 +00:00
|
|
|
return this;
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
function liveHandler( event ) {
|
2009-04-30 21:50:15 +00:00
|
|
|
var stop = true, elems = [], args = arguments;
|
2008-12-30 23:29:14 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
jQuery.each( jQuery.data( this, "events" ).live || [], function( i, fn ) {
|
2009-04-30 21:44:25 +00:00
|
|
|
if ( fn.live === event.type ) {
|
|
|
|
var elem = jQuery( event.target ).closest( fn.selector )[0];
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( elem ) {
|
2009-01-10 19:57:07 +00:00
|
|
|
elems.push({ elem: elem, fn: fn });
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2008-12-22 04:59:34 +00:00
|
|
|
}
|
|
|
|
});
|
2009-01-10 19:57:07 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
elems.sort(function( a, b ) {
|
|
|
|
return jQuery.data( a.elem, "closest" ) - jQuery.data( b.elem, "closest" );
|
2009-02-09 23:29:57 +00:00
|
|
|
});
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
jQuery.each(elems, function() {
|
2009-02-23 13:27:48 +00:00
|
|
|
event.currentTarget = this.elem;
|
2009-05-07 00:50:28 +00:00
|
|
|
event.data = this.fn.data;
|
2009-04-30 21:50:15 +00:00
|
|
|
if ( this.fn.apply( this.elem, args ) === false ) {
|
2009-02-09 23:29:57 +00:00
|
|
|
return (stop = false);
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
2009-01-10 19:57:07 +00:00
|
|
|
});
|
|
|
|
|
2008-12-30 20:45:33 +00:00
|
|
|
return stop;
|
2008-12-22 04:59:34 +00:00
|
|
|
}
|
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
function liveConvert( type, selector ) {
|
2009-01-04 23:58:43 +00:00
|
|
|
return ["live", type, selector.replace(/\./g, "`").replace(/ /g, "|")].join(".");
|
2008-12-22 04:59:34 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
jQuery.extend({
|
|
|
|
isReady: false,
|
|
|
|
readyList: [],
|
|
|
|
// Handle when the DOM is ready
|
|
|
|
ready: function() {
|
|
|
|
// Make sure that the DOM is not already loaded
|
|
|
|
if ( !jQuery.isReady ) {
|
|
|
|
// Remember that the DOM is ready
|
|
|
|
jQuery.isReady = true;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// If there are functions bound, to execute
|
|
|
|
if ( jQuery.readyList ) {
|
|
|
|
// Execute all of them
|
2009-04-30 01:26:09 +00:00
|
|
|
var fn, i = 0;
|
|
|
|
while ( (fn = jQuery.readyList[ i++ ]) ) {
|
|
|
|
fn.call( document, jQuery );
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Reset the list of functions
|
|
|
|
jQuery.readyList = null;
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Trigger any bound ready events
|
2009-04-30 01:26:09 +00:00
|
|
|
jQuery( document ).triggerHandler( "ready" );
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var readyBound = false;
|
|
|
|
|
2009-04-30 01:26:09 +00:00
|
|
|
function bindReady() {
|
2007-12-19 01:10:20 +00:00
|
|
|
if ( readyBound ) return;
|
|
|
|
readyBound = true;
|
|
|
|
|
2008-12-19 04:29:48 +00:00
|
|
|
// Mozilla, Opera and webkit nightlies currently support this event
|
|
|
|
if ( document.addEventListener ) {
|
2007-12-19 01:10:20 +00:00
|
|
|
// Use the handy event callback
|
2009-04-30 01:26:09 +00:00
|
|
|
document.addEventListener( "DOMContentLoaded", function() {
|
2008-12-19 04:29:48 +00:00
|
|
|
document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
|
|
|
|
jQuery.ready();
|
|
|
|
}, false );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-11-12 13:18:47 +00:00
|
|
|
// If IE event model is used
|
2008-12-19 04:29:48 +00:00
|
|
|
} else if ( document.attachEvent ) {
|
2008-11-12 13:18:47 +00:00
|
|
|
// ensure firing before onload,
|
|
|
|
// maybe late but safe also for iframes
|
2009-04-30 01:26:09 +00:00
|
|
|
document.attachEvent("onreadystatechange", function() {
|
2008-12-19 04:29:48 +00:00
|
|
|
if ( document.readyState === "complete" ) {
|
|
|
|
document.detachEvent( "onreadystatechange", arguments.callee );
|
2008-11-12 13:18:47 +00:00
|
|
|
jQuery.ready();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2008-12-19 04:29:48 +00:00
|
|
|
// If IE and not an iframe
|
2008-11-12 13:18:47 +00:00
|
|
|
// continually check to see if the document is ready
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( document.documentElement.doScroll && window === window.top ) (function() {
|
|
|
|
if ( jQuery.isReady ) {
|
|
|
|
return;
|
|
|
|
}
|
2008-12-19 04:29:48 +00:00
|
|
|
|
2008-11-12 13:18:47 +00:00
|
|
|
try {
|
|
|
|
// If IE is used, use the trick by Diego Perini
|
|
|
|
// http://javascript.nwbox.com/IEContentLoaded/
|
|
|
|
document.documentElement.doScroll("left");
|
|
|
|
} catch( error ) {
|
|
|
|
setTimeout( arguments.callee, 0 );
|
|
|
|
return;
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2007-12-20 06:00:01 +00:00
|
|
|
// and execute any waiting functions
|
|
|
|
jQuery.ready();
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// A fallback to window.onload, that will always work
|
|
|
|
jQuery.event.add( window, "load", jQuery.ready );
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
|
2008-10-21 01:49:11 +00:00
|
|
|
"mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave," +
|
2009-04-30 01:26:09 +00:00
|
|
|
"change,select,submit,keydown,keypress,keyup,error").split(","), function( i, name ) {
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Handle event binding
|
2009-04-30 01:26:09 +00:00
|
|
|
jQuery.fn[ name ] = function( fn ) {
|
2009-05-07 00:50:28 +00:00
|
|
|
return fn ? this.bind( name, fn ) : this.trigger( name );
|
2007-12-19 01:10:20 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// Prevent memory leaks in IE
|
|
|
|
// And prevent errors on refresh with events like mouseover in other browsers
|
|
|
|
// Window isn't included so as not to unbind existing unload events
|
2009-03-19 15:16:02 +00:00
|
|
|
// More info:
|
|
|
|
// - http://isaacschlueter.com/2006/10/msie-memory-leaks/
|
|
|
|
// - https://bugzilla.mozilla.org/show_bug.cgi?id=252542
|
2009-04-30 01:26:09 +00:00
|
|
|
jQuery( window ).bind( 'unload', function() {
|
|
|
|
for ( var id in jQuery.cache ) {
|
2008-07-01 02:50:38 +00:00
|
|
|
// Skip the window
|
2009-04-30 01:26:09 +00:00
|
|
|
if ( id != 1 && jQuery.cache[ id ].handle ) {
|
2008-07-01 02:50:38 +00:00
|
|
|
jQuery.event.remove( jQuery.cache[ id ].handle.elem );
|
2009-04-30 01:26:09 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
});
|