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
|
|
|
|
add: function(elem, types, handler, data) {
|
|
|
|
if ( elem.nodeType == 3 || elem.nodeType == 8 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// For whatever reason, IE has trouble passing the window object
|
|
|
|
// around, causing it to be cloned in the process
|
2008-04-29 23:34:50 +00:00
|
|
|
if ( jQuery.browser.msie && elem.setInterval )
|
2007-12-19 01:10:20 +00:00
|
|
|
elem = window;
|
|
|
|
|
|
|
|
// Make sure that the function being executed has a unique ID
|
|
|
|
if ( !handler.guid )
|
|
|
|
handler.guid = this.guid++;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
|
|
|
// if data is passed, bind to handler
|
|
|
|
if( data != undefined ) {
|
|
|
|
// Create temporary function pointer to original handler
|
|
|
|
var fn = handler;
|
|
|
|
|
|
|
|
// Create unique handler function, wrapped around original handler
|
|
|
|
handler = this.proxy( fn, function() {
|
|
|
|
// Pass arguments and context to original handler
|
|
|
|
return fn.apply(this, arguments);
|
2008-04-29 22:06:54 +00:00
|
|
|
});
|
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
|
|
|
|
var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),
|
|
|
|
handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
|
|
|
|
// Handle the second event of a trigger and when
|
|
|
|
// an event is called after a page has unloaded
|
2008-04-22 05:23:55 +00:00
|
|
|
if ( typeof jQuery != "undefined" && !jQuery.event.triggered )
|
|
|
|
return jQuery.event.handle.apply(arguments.callee.elem, arguments);
|
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);
|
|
|
|
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] = {};
|
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
|
2008-07-09 21:38:28 +00:00
|
|
|
if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem,data) === false ) {
|
2008-04-29 23:34:50 +00:00
|
|
|
// 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);
|
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
|
|
|
|
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
|
|
|
|
jQuery.event.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
|
|
|
|
remove: function(elem, types, handler) {
|
|
|
|
// don't do events on text and comment nodes
|
|
|
|
if ( elem.nodeType == 3 || elem.nodeType == 8 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var events = jQuery.data(elem, "events"), ret, index;
|
|
|
|
|
|
|
|
if ( events ) {
|
|
|
|
// Unbind all events for the element
|
2008-02-05 19:32:00 +00:00
|
|
|
if ( types == undefined || (typeof types == "string" && types.charAt(0) == ".") )
|
2007-12-19 01:10:20 +00:00
|
|
|
for ( var type in events )
|
2008-02-03 04:33:11 +00:00
|
|
|
this.remove( elem, type + (types || "") );
|
2007-12-19 01:10:20 +00:00
|
|
|
else {
|
|
|
|
// 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);
|
|
|
|
jQuery.each(types.split(/\s+/), function(index, type){
|
|
|
|
// Namespaced event handlers
|
|
|
|
var parts = type.split(".");
|
|
|
|
type = parts[0];
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
if ( events[type] ) {
|
|
|
|
// remove the given handler for the given type
|
|
|
|
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
|
|
|
|
else
|
|
|
|
for ( handler in events[type] )
|
|
|
|
// Handle the removal of namespaced events
|
|
|
|
if ( !parts[1] || events[type][handler].type == parts[1] )
|
|
|
|
delete events[type][handler];
|
|
|
|
|
|
|
|
// remove generic event handler if no more handlers exist
|
|
|
|
for ( ret in events[type] ) break;
|
|
|
|
if ( !ret ) {
|
|
|
|
if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) {
|
|
|
|
if (elem.removeEventListener)
|
|
|
|
elem.removeEventListener(type, jQuery.data(elem, "handle"), false);
|
|
|
|
else if (elem.detachEvent)
|
|
|
|
elem.detachEvent("on" + type, jQuery.data(elem, "handle"));
|
|
|
|
}
|
|
|
|
ret = null;
|
|
|
|
delete events[type];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the expando if it's no longer used
|
|
|
|
for ( ret in events ) break;
|
|
|
|
if ( !ret ) {
|
2007-12-21 04:53:33 +00:00
|
|
|
var handle = jQuery.data( elem, "handle" );
|
|
|
|
if ( handle ) handle.elem = null;
|
2007-12-19 01:10:20 +00:00
|
|
|
jQuery.removeData( elem, "events" );
|
|
|
|
jQuery.removeData( elem, "handle" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
trigger: function(type, data, elem, donative, extra) {
|
|
|
|
// Clone the incoming data, if any
|
2008-04-24 21:46:22 +00:00
|
|
|
data = jQuery.makeArray(data);
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-02-03 04:05:24 +00:00
|
|
|
if ( type.indexOf("!") >= 0 ) {
|
|
|
|
type = type.slice(0, -1);
|
|
|
|
var exclusive = true;
|
|
|
|
}
|
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Handle a global trigger
|
|
|
|
if ( !elem ) {
|
|
|
|
// Only trigger if we've ever bound an event for it
|
|
|
|
if ( this.global[type] )
|
2008-07-01 02:25:55 +00:00
|
|
|
jQuery.each( jQuery.cache, function(){
|
|
|
|
if ( this.events && this.events[type] )
|
|
|
|
jQuery.event.trigger( type, data, this.handle.elem );
|
|
|
|
});
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Handle triggering a single element
|
|
|
|
} else {
|
|
|
|
// don't do events on text and comment nodes
|
|
|
|
if ( elem.nodeType == 3 || elem.nodeType == 8 )
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
var val, ret, fn = jQuery.isFunction( elem[ type ] || null ),
|
|
|
|
// Check to see if we need to provide a fake event, or not
|
|
|
|
event = !data[0] || !data[0].preventDefault;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Pass along a fake event
|
2008-04-28 21:09:27 +00:00
|
|
|
if ( event ) {
|
2008-05-13 01:45:58 +00:00
|
|
|
data.unshift({
|
|
|
|
type: type,
|
|
|
|
target: elem,
|
|
|
|
preventDefault: function(){},
|
|
|
|
stopPropagation: function(){},
|
2008-10-18 22:46:04 +00:00
|
|
|
stopImmediatePropagation:stopImmediatePropagation,
|
2008-04-29 23:34:50 +00:00
|
|
|
timeStamp: now()
|
2008-04-28 21:09:27 +00:00
|
|
|
});
|
|
|
|
data[0][expando] = true; // no need to fix fake event
|
|
|
|
}
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Enforce the right trigger type
|
|
|
|
data[0].type = type;
|
2008-02-03 04:05:24 +00:00
|
|
|
if ( exclusive )
|
|
|
|
data[0].exclusive = true;
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-04-22 05:23:55 +00:00
|
|
|
// Trigger the event, it is assumed that "handle" is a function
|
2008-05-13 01:45:58 +00:00
|
|
|
var handle = jQuery.data(elem, "handle");
|
|
|
|
if ( handle )
|
2008-04-22 05:23:55 +00:00
|
|
|
val = handle.apply( elem, data );
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-04-21 20:39:17 +00:00
|
|
|
// Handle triggering native .onfoo handlers (and on links since we don't call .click() for links)
|
|
|
|
if ( (!fn || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
|
2007-12-19 01:10:20 +00:00
|
|
|
val = false;
|
|
|
|
|
|
|
|
// Extra functions don't get the custom event object
|
|
|
|
if ( event )
|
|
|
|
data.shift();
|
|
|
|
|
|
|
|
// Handle triggering of extra function
|
|
|
|
if ( extra && jQuery.isFunction( extra ) ) {
|
|
|
|
// call the extra function and tack the current return value on the end for possible inspection
|
2008-01-14 18:46:44 +00:00
|
|
|
ret = extra.apply( elem, val == null ? data : data.concat( val ) );
|
2007-12-19 01:10:20 +00:00
|
|
|
// 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(elem, 'a') && type == "click") ) {
|
|
|
|
this.triggered = true;
|
|
|
|
try {
|
|
|
|
elem[ type ]();
|
|
|
|
// prevent IE from throwing an error for some hidden elements
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.triggered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
},
|
|
|
|
|
|
|
|
handle: function(event) {
|
|
|
|
// returned undefined or false
|
2008-04-23 18:57:17 +00:00
|
|
|
var val, ret, namespace, 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 );
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Namespaced event handlers
|
2008-04-22 05:23:55 +00:00
|
|
|
namespace = event.type.split(".");
|
|
|
|
event.type = namespace[0];
|
|
|
|
namespace = namespace[1];
|
2008-05-13 01:42:35 +00:00
|
|
|
// Cache this now, all = true means, any handler
|
|
|
|
all = !namespace && !event.exclusive;
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-04-22 05:23:55 +00:00
|
|
|
handlers = ( jQuery.data(this, "events") || {} )[event.type];
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
for ( var j in handlers ) {
|
|
|
|
var handler = handlers[j];
|
|
|
|
|
|
|
|
// Filter the functions by class
|
2008-04-22 05:23:55 +00:00
|
|
|
if ( all || handler.type == namespace ) {
|
|
|
|
// 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
|
|
|
|
2008-04-23 18:57:17 +00:00
|
|
|
ret = handler.apply( this, arguments );
|
|
|
|
|
|
|
|
if ( val !== false )
|
|
|
|
val = ret;
|
|
|
|
|
|
|
|
if ( ret === false ) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2008-10-18 22:46:04 +00:00
|
|
|
|
|
|
|
if( event._sip )
|
|
|
|
break;
|
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
},
|
|
|
|
|
2008-05-28 20:43:13 +00:00
|
|
|
props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" "),
|
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
fix: function(event) {
|
2008-10-18 22:46:04 +00:00
|
|
|
if ( event[expando] )
|
2008-04-27 23:08:31 +00:00
|
|
|
return event;
|
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-04-28 21:09:27 +00:00
|
|
|
event = { originalEvent: originalEvent };
|
2008-05-28 20:43:13 +00:00
|
|
|
|
|
|
|
for ( var i = this.props.length, prop; i; ){
|
|
|
|
prop = this.props[ --i ];
|
|
|
|
event[ prop ] = originalEvent[ prop ];
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-04-27 23:08:31 +00:00
|
|
|
// Mark it as fixed
|
|
|
|
event[expando] = true;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
|
|
|
// add preventDefault and stopPropagation since
|
2007-12-19 01:10:20 +00:00
|
|
|
// they will not work on the clone
|
|
|
|
event.preventDefault = function() {
|
|
|
|
// if preventDefault exists run it on the original event
|
|
|
|
if (originalEvent.preventDefault)
|
|
|
|
originalEvent.preventDefault();
|
|
|
|
// otherwise set the returnValue property of the original event to false (IE)
|
|
|
|
originalEvent.returnValue = false;
|
|
|
|
};
|
|
|
|
event.stopPropagation = function() {
|
|
|
|
// if stopPropagation exists run it on the original event
|
|
|
|
if (originalEvent.stopPropagation)
|
|
|
|
originalEvent.stopPropagation();
|
|
|
|
// otherwise set the cancelBubble property of the original event to true (IE)
|
|
|
|
originalEvent.cancelBubble = true;
|
|
|
|
};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-10-18 22:46:04 +00:00
|
|
|
event.stopImmediatePropagation = stopImmediatePropagation;
|
|
|
|
|
2008-04-22 21:59:40 +00:00
|
|
|
// Fix timeStamp
|
2008-04-29 23:34:50 +00:00
|
|
|
event.timeStamp = event.timeStamp || now();
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Fix target property, if necessary
|
|
|
|
if ( !event.target )
|
|
|
|
event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// check if target is a textnode (safari)
|
|
|
|
if ( event.target.nodeType == 3 )
|
2008-04-28 21:09:27 +00:00
|
|
|
event.target = event.target.parentNode;
|
2007-12-19 01:10:20 +00:00
|
|
|
|
|
|
|
// Add relatedTarget, if necessary
|
|
|
|
if ( !event.relatedTarget && event.fromElement )
|
|
|
|
event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
|
|
|
|
|
|
|
|
// Calculate pageX/Y if missing and clientX/Y available
|
|
|
|
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.clientTop || 0);
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
// Add which for key events
|
2007-12-28 19:08:36 +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;
|
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)
|
|
|
|
if ( !event.metaKey && event.ctrlKey )
|
|
|
|
event.metaKey = event.ctrlKey;
|
|
|
|
|
|
|
|
// Add which for click: 1 == left; 2 == middle; 3 == right
|
|
|
|
// Note: button is not normalized, so don't use it
|
|
|
|
if ( !event.which && event.button )
|
|
|
|
event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
|
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
|
|
|
|
2008-04-29 22:06:54 +00:00
|
|
|
proxy: function( fn, proxy ){
|
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() {}
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-10-18 22:46:04 +00:00
|
|
|
function stopImmediatePropagation(){
|
|
|
|
this._sip = 1;
|
|
|
|
this.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2008-07-28 18:31:25 +00:00
|
|
|
if ( !jQuery.browser.msie ){
|
|
|
|
// Checks if an event happened on an element within another element
|
|
|
|
// Used in jQuery.event.special.mouseenter and mouseleave handlers
|
|
|
|
var withinElement = function(event) {
|
|
|
|
// Check if mouse(over|out) are still within the same parent element
|
|
|
|
var parent = event.relatedTarget;
|
|
|
|
// Traverse up the tree
|
|
|
|
while ( parent && parent != this )
|
|
|
|
try { parent = parent.parentNode; }
|
|
|
|
catch(e) { parent = this; }
|
|
|
|
|
|
|
|
if( parent != this ){
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
jQuery.each({
|
|
|
|
mouseover: 'mouseenter',
|
|
|
|
mouseout: 'mouseleave'
|
|
|
|
}, function( orig, fix ){
|
|
|
|
jQuery.event.special[ fix ] = {
|
|
|
|
setup: function(){
|
|
|
|
jQuery.event.add( this, orig, withinElement, fix );
|
|
|
|
},
|
|
|
|
teardown: function(){
|
|
|
|
jQuery.event.remove( this, orig, withinElement );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
jQuery.fn.extend({
|
|
|
|
bind: function( type, data, fn ) {
|
|
|
|
return type == "unload" ? this.one(type, data, fn) : this.each(function(){
|
|
|
|
jQuery.event.add( this, type, fn || data, fn && data );
|
|
|
|
});
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
one: function( type, data, fn ) {
|
2008-04-29 22:06:54 +00:00
|
|
|
var one = jQuery.event.proxy( fn || data, function(event) {
|
|
|
|
jQuery(this).unbind(event, one);
|
|
|
|
return (fn || data).apply( this, arguments );
|
|
|
|
});
|
2007-12-19 01:10:20 +00:00
|
|
|
return this.each(function(){
|
2008-04-29 22:06:54 +00:00
|
|
|
jQuery.event.add( this, type, one, fn && data);
|
2007-12-19 01:10:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
unbind: function( type, fn ) {
|
|
|
|
return this.each(function(){
|
|
|
|
jQuery.event.remove( this, type, fn );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
trigger: function( type, data, fn ) {
|
|
|
|
return this.each(function(){
|
|
|
|
jQuery.event.trigger( type, data, this, true, fn );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
triggerHandler: function( type, data, fn ) {
|
2008-04-29 23:34:50 +00:00
|
|
|
return this[0] && jQuery.event.trigger( type, data, this[0], false, fn );
|
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
|
|
|
|
while( i < args.length )
|
|
|
|
jQuery.event.proxy( fn, args[i++] );
|
2007-12-19 01:10:20 +00:00
|
|
|
|
2008-04-29 22:06:54 +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
|
|
|
},
|
|
|
|
|
|
|
|
hover: function(fnOver, fnOut) {
|
|
|
|
return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
ready: function(fn) {
|
|
|
|
// Attach the listeners
|
|
|
|
bindReady();
|
|
|
|
|
|
|
|
// If the DOM is already ready
|
|
|
|
if ( jQuery.isReady )
|
|
|
|
// 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
|
|
|
|
else
|
|
|
|
// Add the function to the wait list
|
|
|
|
jQuery.readyList.push( function() { return fn.call(this, jQuery); } );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-19 01:10:20 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
jQuery.each( jQuery.readyList, function(){
|
2008-05-12 19:45:02 +00:00
|
|
|
this.call( document );
|
2007-12-19 01:10:20 +00:00
|
|
|
});
|
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
|
2007-12-20 19:31:02 +00:00
|
|
|
jQuery(document).triggerHandler("ready");
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var readyBound = false;
|
|
|
|
|
|
|
|
function bindReady(){
|
|
|
|
if ( readyBound ) return;
|
|
|
|
readyBound = true;
|
|
|
|
|
2007-12-20 06:00:01 +00:00
|
|
|
// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
|
|
|
|
if ( document.addEventListener && !jQuery.browser.opera)
|
2007-12-19 01:10:20 +00:00
|
|
|
// Use the handy event callback
|
|
|
|
document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2007-12-20 06:00:01 +00:00
|
|
|
// If IE is used and is not in a frame
|
2007-12-19 01:10:20 +00:00
|
|
|
// Continually check to see if the document is ready
|
2007-12-20 06:00:01 +00:00
|
|
|
if ( jQuery.browser.msie && window == top ) (function(){
|
|
|
|
if (jQuery.isReady) return;
|
2007-12-19 01:10:20 +00:00
|
|
|
try {
|
|
|
|
// If IE is used, use the trick by Diego Perini
|
|
|
|
// http://javascript.nwbox.com/IEContentLoaded/
|
2007-12-20 06:00:01 +00:00
|
|
|
document.documentElement.doScroll("left");
|
2007-12-19 01:10:20 +00:00
|
|
|
} catch( error ) {
|
2007-12-20 06:00:01 +00:00
|
|
|
setTimeout( arguments.callee, 0 );
|
|
|
|
return;
|
2007-12-19 01:10:20 +00:00
|
|
|
}
|
|
|
|
// and execute any waiting functions
|
|
|
|
jQuery.ready();
|
|
|
|
})();
|
|
|
|
|
2007-12-20 06:00:01 +00:00
|
|
|
if ( jQuery.browser.opera )
|
|
|
|
document.addEventListener( "DOMContentLoaded", function () {
|
|
|
|
if (jQuery.isReady) return;
|
|
|
|
for (var i = 0; i < document.styleSheets.length; i++)
|
|
|
|
if (document.styleSheets[i].disabled) {
|
|
|
|
setTimeout( arguments.callee, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// and execute any waiting functions
|
|
|
|
jQuery.ready();
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
if ( jQuery.browser.safari ) {
|
|
|
|
var numStyles;
|
|
|
|
(function(){
|
|
|
|
if (jQuery.isReady) return;
|
|
|
|
if ( document.readyState != "loaded" && document.readyState != "complete" ) {
|
|
|
|
setTimeout( arguments.callee, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( numStyles === undefined )
|
|
|
|
numStyles = jQuery("style, link[rel=stylesheet]").length;
|
|
|
|
if ( document.styleSheets.length != numStyles ) {
|
|
|
|
setTimeout( arguments.callee, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 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," +
|
|
|
|
"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
|
|
|
|
jQuery.fn[name] = function(fn){
|
|
|
|
return fn ? this.bind(name, fn) : this.trigger(name);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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
|
2008-07-01 02:50:38 +00:00
|
|
|
jQuery( window ).bind( 'unload', function(){
|
|
|
|
for ( var id in jQuery.cache )
|
|
|
|
// Skip the window
|
|
|
|
if ( id != 1 && jQuery.cache[ id ].handle )
|
|
|
|
jQuery.event.remove( jQuery.cache[ id ].handle.elem );
|
|
|
|
});
|