2006-12-31 04:58:43 +01:00
|
|
|
/*
|
|
|
|
* A number of helper functions used for managing events.
|
|
|
|
* Many of the ideas behind this code orignated from
|
|
|
|
* Dean Edwards' addEvent library.
|
|
|
|
*/
|
|
|
|
jQuery.event = {
|
|
|
|
|
|
|
|
// Bind an event to an element
|
|
|
|
// Original by Dean Edwards
|
|
|
|
add: function(element, type, handler, data) {
|
|
|
|
// For whatever reason, IE has trouble passing the window object
|
|
|
|
// around, causing it to be cloned in the process
|
|
|
|
if ( jQuery.browser.msie && element.setInterval != undefined )
|
|
|
|
element = window;
|
2007-09-03 16:53:09 +02:00
|
|
|
|
2007-05-23 15:51:04 +02:00
|
|
|
// Make sure that the function being executed has a unique ID
|
|
|
|
if ( !handler.guid )
|
|
|
|
handler.guid = this.guid++;
|
|
|
|
|
2007-04-22 05:16:53 +02:00
|
|
|
// if data is passed, bind to handler
|
2007-04-24 23:50:49 +02:00
|
|
|
if( data != undefined ) {
|
2007-11-27 20:20:36 +01:00
|
|
|
// Create temporary function pointer to original handler
|
2007-04-22 05:16:53 +02:00
|
|
|
var fn = handler;
|
|
|
|
|
|
|
|
// Create unique handler function, wrapped around original handler
|
|
|
|
handler = function() {
|
|
|
|
// Pass arguments and context to original handler
|
|
|
|
return fn.apply(this, arguments);
|
2007-04-22 06:17:43 +02:00
|
|
|
};
|
2007-04-22 05:16:53 +02:00
|
|
|
|
|
|
|
// Store data in unique handler
|
2007-04-22 06:17:43 +02:00
|
|
|
handler.data = data;
|
2007-04-22 05:16:53 +02:00
|
|
|
|
|
|
|
// Set the guid of unique handler to the same of original handler, so it can be removed
|
2007-04-22 06:17:43 +02:00
|
|
|
handler.guid = fn.guid;
|
2007-04-22 05:16:53 +02:00
|
|
|
}
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-09-03 16:53:09 +02:00
|
|
|
// Namespaced event handlers
|
|
|
|
var parts = type.split(".");
|
|
|
|
type = parts[0];
|
|
|
|
handler.type = parts[1];
|
|
|
|
|
2006-12-31 04:58:43 +01:00
|
|
|
// Init the element's event structure
|
2007-09-09 01:31:23 +02:00
|
|
|
var events = jQuery.data(element, "events") || jQuery.data(element, "events", {});
|
2007-04-22 06:17:43 +02:00
|
|
|
|
2007-10-06 19:04:20 +02:00
|
|
|
var handle = jQuery.data(element, "handle") || jQuery.data(element, "handle", function(){
|
2007-09-09 01:31:23 +02:00
|
|
|
// returned undefined or false
|
|
|
|
var val;
|
|
|
|
|
|
|
|
// Handle the second event of a trigger and when
|
|
|
|
// an event is called after a page has unloaded
|
|
|
|
if ( typeof jQuery == "undefined" || jQuery.event.triggered )
|
2007-05-31 06:15:41 +02:00
|
|
|
return val;
|
2007-09-09 01:31:23 +02:00
|
|
|
|
|
|
|
val = jQuery.event.handle.apply(element, arguments);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
});
|
2007-04-22 06:17:43 +02:00
|
|
|
|
2007-04-22 18:34:23 +02:00
|
|
|
// Get the current list of functions bound to this event
|
2007-09-09 01:31:23 +02:00
|
|
|
var handlers = events[type];
|
2007-04-22 18:34:23 +02:00
|
|
|
|
|
|
|
// Init the event handler queue
|
|
|
|
if (!handlers) {
|
2007-09-09 01:31:23 +02:00
|
|
|
handlers = events[type] = {};
|
2007-04-22 18:34:23 +02:00
|
|
|
|
2007-04-22 06:17:43 +02:00
|
|
|
// And bind the global event handler to the element
|
|
|
|
if (element.addEventListener)
|
2007-09-09 01:31:23 +02:00
|
|
|
element.addEventListener(type, handle, false);
|
2007-06-30 15:57:49 +02:00
|
|
|
else
|
2007-09-09 01:31:23 +02:00
|
|
|
element.attachEvent("on" + type, handle);
|
2007-04-22 06:17:43 +02:00
|
|
|
}
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-04-22 18:34:23 +02:00
|
|
|
// Add the function to the element's handler list
|
|
|
|
handlers[handler.guid] = handler;
|
|
|
|
|
2007-08-20 01:37:26 +02:00
|
|
|
// Keep track of which events have been used, for global triggering
|
|
|
|
this.global[type] = true;
|
2006-12-31 04:58:43 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
guid: 1,
|
|
|
|
global: {},
|
|
|
|
|
|
|
|
// Detach an event or set of events from an element
|
|
|
|
remove: function(element, type, handler) {
|
2007-09-09 01:31:23 +02:00
|
|
|
var events = jQuery.data(element, "events"), ret, index;
|
2007-03-01 05:54:51 +01:00
|
|
|
|
2007-09-03 16:53:09 +02:00
|
|
|
// Namespaced event handlers
|
|
|
|
if ( typeof type == "string" ) {
|
|
|
|
var parts = type.split(".");
|
|
|
|
type = parts[0];
|
|
|
|
}
|
|
|
|
|
2007-03-01 05:54:51 +01:00
|
|
|
if ( events ) {
|
|
|
|
// type is actually an event object here
|
|
|
|
if ( type && type.type ) {
|
2007-02-25 20:36:29 +01:00
|
|
|
handler = type.handler;
|
2007-03-01 05:54:51 +01:00
|
|
|
type = type.type;
|
2007-02-25 20:36:29 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 05:54:51 +01:00
|
|
|
if ( !type ) {
|
|
|
|
for ( type in events )
|
|
|
|
this.remove( element, type );
|
|
|
|
|
|
|
|
} else if ( events[type] ) {
|
2007-02-25 20:36:29 +01:00
|
|
|
// remove the given handler for the given type
|
2006-12-31 04:58:43 +01:00
|
|
|
if ( handler )
|
2007-03-01 05:54:51 +01:00
|
|
|
delete events[type][handler.guid];
|
|
|
|
|
2007-02-25 20:36:29 +01:00
|
|
|
// remove all handlers for the given type
|
2006-12-31 04:58:43 +01:00
|
|
|
else
|
2007-09-09 01:31:23 +02:00
|
|
|
for ( handler in events[type] )
|
2007-09-03 16:53:09 +02:00
|
|
|
// Handle the removal of namespaced events
|
|
|
|
if ( !parts[1] || events[type][handler].type == parts[1] )
|
|
|
|
delete events[type][handler];
|
2007-03-01 05:54:51 +01:00
|
|
|
|
|
|
|
// remove generic event handler if no more handlers exist
|
|
|
|
for ( ret in events[type] ) break;
|
|
|
|
if ( !ret ) {
|
2007-04-22 05:16:53 +02:00
|
|
|
if (element.removeEventListener)
|
2007-09-09 01:31:23 +02:00
|
|
|
element.removeEventListener(type, jQuery.data(element, "handle"), false);
|
2007-06-30 15:57:49 +02:00
|
|
|
else
|
2007-09-09 01:31:23 +02:00
|
|
|
element.detachEvent("on" + type, jQuery.data(element, "handle"));
|
2007-04-22 18:34:23 +02:00
|
|
|
ret = null;
|
2007-03-05 18:42:12 +01:00
|
|
|
delete events[type];
|
2007-02-25 20:36:29 +01:00
|
|
|
}
|
2007-03-01 05:54:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the expando if it's no longer used
|
|
|
|
for ( ret in events ) break;
|
2007-09-09 01:31:23 +02:00
|
|
|
if ( !ret ) {
|
|
|
|
jQuery.removeData( element, "events" );
|
|
|
|
jQuery.removeData( element, "handle" );
|
|
|
|
}
|
2007-02-25 20:36:29 +01:00
|
|
|
}
|
2006-12-31 04:58:43 +01:00
|
|
|
},
|
|
|
|
|
2007-09-07 21:28:25 +02:00
|
|
|
trigger: function(type, data, element, donative, extra) {
|
2006-12-31 04:58:43 +01:00
|
|
|
// Clone the incoming data, if any
|
|
|
|
data = jQuery.makeArray(data || []);
|
|
|
|
|
|
|
|
// Handle a global trigger
|
2007-08-20 01:37:26 +02:00
|
|
|
if ( !element ) {
|
|
|
|
// Only trigger if we've ever bound an event for it
|
|
|
|
if ( this.global[type] )
|
2007-08-22 08:19:47 +02:00
|
|
|
jQuery("*").add([window, document]).trigger(type, data);
|
2006-12-31 04:58:43 +01:00
|
|
|
|
|
|
|
// Handle triggering a single element
|
2007-08-20 01:37:26 +02:00
|
|
|
} else {
|
2007-08-30 18:34:34 +02:00
|
|
|
var val, ret, fn = jQuery.isFunction( element[ type ] || null ),
|
|
|
|
// Check to see if we need to provide a fake event, or not
|
2007-10-06 19:04:20 +02:00
|
|
|
event = !data[0] || !data[0].preventDefault;
|
2007-04-22 05:16:53 +02:00
|
|
|
|
|
|
|
// Pass along a fake event
|
2007-10-06 19:04:20 +02:00
|
|
|
if ( event )
|
2007-08-30 18:34:34 +02:00
|
|
|
data.unshift( this.fix({ type: type, target: element }) );
|
2007-04-22 05:16:53 +02:00
|
|
|
|
2007-09-15 01:58:51 +02:00
|
|
|
// Enforce the right trigger type
|
|
|
|
data[0].type = type;
|
|
|
|
|
2007-04-22 05:16:53 +02:00
|
|
|
// Trigger the event
|
2007-09-09 01:31:23 +02:00
|
|
|
if ( jQuery.isFunction( jQuery.data(element, "handle") ) )
|
|
|
|
val = jQuery.data(element, "handle").apply( element, data );
|
2007-08-28 06:42:35 +02:00
|
|
|
|
|
|
|
// Handle triggering native .onfoo handlers
|
2007-07-21 03:04:59 +02:00
|
|
|
if ( !fn && element["on"+type] && element["on"+type].apply( element, data ) === false )
|
|
|
|
val = false;
|
2007-01-13 23:29:59 +01:00
|
|
|
|
2007-08-30 18:34:34 +02:00
|
|
|
// Extra functions don't get the custom event object
|
2007-10-06 19:04:20 +02:00
|
|
|
if ( event )
|
2007-08-30 18:34:34 +02:00
|
|
|
data.shift();
|
|
|
|
|
2007-08-30 07:51:11 +02:00
|
|
|
// Handle triggering of extra function
|
|
|
|
if ( extra && extra.apply( element, data ) === false )
|
|
|
|
val = false;
|
|
|
|
|
2007-08-28 06:42:35 +02:00
|
|
|
// Trigger the native events (except for clicks on links)
|
2007-09-07 21:28:25 +02:00
|
|
|
if ( fn && donative !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) {
|
2007-07-21 03:04:59 +02:00
|
|
|
this.triggered = true;
|
2007-01-13 23:29:59 +01:00
|
|
|
element[ type ]();
|
2007-07-21 03:04:59 +02:00
|
|
|
}
|
2007-01-22 06:14:45 +01:00
|
|
|
|
|
|
|
this.triggered = false;
|
|
|
|
}
|
2007-08-28 06:42:35 +02:00
|
|
|
|
|
|
|
return val;
|
2006-12-31 04:58:43 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
handle: function(event) {
|
2007-04-29 20:39:07 +02:00
|
|
|
// returned undefined or false
|
|
|
|
var val;
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-01-02 17:43:05 +01:00
|
|
|
// Empty object is for triggered events with no data
|
|
|
|
event = jQuery.event.fix( event || window.event || {} );
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-09-03 16:53:09 +02:00
|
|
|
// Namespaced event handlers
|
|
|
|
var parts = event.type.split(".");
|
|
|
|
event.type = parts[0];
|
|
|
|
|
2007-10-06 19:04:20 +02:00
|
|
|
var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );
|
2006-12-31 04:58:43 +01:00
|
|
|
args.unshift( event );
|
|
|
|
|
2007-10-06 19:04:20 +02:00
|
|
|
for ( var j in handlers ) {
|
|
|
|
var handler = handlers[j];
|
2006-12-31 04:58:43 +01:00
|
|
|
// Pass in a reference to the handler function itself
|
|
|
|
// So that we can later remove it
|
2007-10-06 19:04:20 +02:00
|
|
|
args[0].handler = handler;
|
|
|
|
args[0].data = handler.data;
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-09-03 16:53:09 +02:00
|
|
|
// Filter the functions by class
|
2007-10-06 19:04:20 +02:00
|
|
|
if ( !parts[1] || handler.type == parts[1] ) {
|
|
|
|
var ret = handler.apply( this, args );
|
2007-08-28 06:34:23 +02:00
|
|
|
|
2007-09-03 16:53:09 +02:00
|
|
|
if ( val !== false )
|
2007-10-06 19:04:20 +02:00
|
|
|
val = ret;
|
2007-08-28 06:34:23 +02:00
|
|
|
|
2007-10-06 19:04:20 +02:00
|
|
|
if ( ret === false ) {
|
2007-09-03 16:53:09 +02:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2006-12-31 04:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up added properties in IE to prevent memory leak
|
2007-04-29 20:39:07 +02:00
|
|
|
if (jQuery.browser.msie)
|
|
|
|
event.target = event.preventDefault = event.stopPropagation =
|
|
|
|
event.handler = event.data = null;
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-04-29 20:39:07 +02:00
|
|
|
return val;
|
2006-12-31 04:58:43 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
fix: function(event) {
|
2007-05-30 21:22:24 +02:00
|
|
|
// store a copy of the original event object
|
|
|
|
// and clone to set read-only properties
|
|
|
|
var originalEvent = event;
|
|
|
|
event = jQuery.extend({}, originalEvent);
|
|
|
|
|
|
|
|
// add preventDefault and stopPropagation since
|
|
|
|
// they will not work on the clone
|
|
|
|
event.preventDefault = function() {
|
|
|
|
// if preventDefault exists run it on the original event
|
|
|
|
if (originalEvent.preventDefault)
|
2007-08-20 05:59:34 +02:00
|
|
|
originalEvent.preventDefault();
|
2007-05-30 21:22:24 +02:00
|
|
|
// 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)
|
2007-08-20 05:59:34 +02:00
|
|
|
originalEvent.stopPropagation();
|
2007-05-30 21:22:24 +02:00
|
|
|
// otherwise set the cancelBubble property of the original event to true (IE)
|
|
|
|
originalEvent.cancelBubble = true;
|
|
|
|
};
|
|
|
|
|
2006-12-31 04:58:43 +01:00
|
|
|
// Fix target property, if necessary
|
2007-11-14 22:55:45 +01:00
|
|
|
if ( !event.target )
|
|
|
|
event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
|
2007-05-30 21:22:24 +02:00
|
|
|
|
|
|
|
// check if target is a textnode (safari)
|
2007-11-14 22:55:45 +01:00
|
|
|
if ( event.target.nodeType == 3 )
|
2007-05-30 21:22:24 +02:00
|
|
|
event.target = originalEvent.target.parentNode;
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-05-20 18:51:52 +02:00
|
|
|
// Add relatedTarget, if necessary
|
|
|
|
if ( !event.relatedTarget && event.fromElement )
|
|
|
|
event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
|
|
|
|
|
2006-12-31 04:58:43 +01:00
|
|
|
// Calculate pageX/Y if missing and clientX/Y available
|
2007-05-20 18:51:52 +02:00
|
|
|
if ( event.pageX == null && event.clientX != null ) {
|
2007-10-06 19:04:20 +02:00
|
|
|
var doc = document.documentElement, body = document.body;
|
2007-10-06 23:00:37 +02:00
|
|
|
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
|
|
|
|
event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientLeft || 0);
|
2006-12-31 04:58:43 +01:00
|
|
|
}
|
2006-12-31 23:03:34 +01:00
|
|
|
|
2007-05-30 21:22:24 +02:00
|
|
|
// Add which for key events
|
|
|
|
if ( !event.which && (event.charCode || event.keyCode) )
|
|
|
|
event.which = event.charCode || event.keyCode;
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-05-30 21:22:24 +02: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 ) ));
|
2006-12-31 04:58:43 +01:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-10-10 03:59:20 +02:00
|
|
|
jQuery.fn.extend({
|
2006-12-31 04:58:43 +01:00
|
|
|
bind: function( type, data, fn ) {
|
2007-05-31 02:13:54 +02:00
|
|
|
return type == "unload" ? this.one(type, data, fn) : this.each(function(){
|
2007-04-24 23:48:52 +02:00
|
|
|
jQuery.event.add( this, type, fn || data, fn && data );
|
2006-12-31 04:58:43 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
one: function( type, data, fn ) {
|
|
|
|
return this.each(function(){
|
|
|
|
jQuery.event.add( this, type, function(event) {
|
|
|
|
jQuery(this).unbind(event);
|
|
|
|
return (fn || data).apply( this, arguments);
|
2007-04-24 23:48:52 +02:00
|
|
|
}, fn && data);
|
2006-12-31 04:58:43 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
unbind: function( type, fn ) {
|
|
|
|
return this.each(function(){
|
|
|
|
jQuery.event.remove( this, type, fn );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2007-08-30 07:51:11 +02:00
|
|
|
trigger: function( type, data, fn ) {
|
2006-12-31 04:58:43 +01:00
|
|
|
return this.each(function(){
|
2007-08-30 07:51:11 +02:00
|
|
|
jQuery.event.trigger( type, data, this, true, fn );
|
2006-12-31 04:58:43 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2007-08-30 07:51:11 +02:00
|
|
|
triggerHandler: function( type, data, fn ) {
|
|
|
|
if ( this[0] )
|
|
|
|
return jQuery.event.trigger( type, data, this[0], false, fn );
|
|
|
|
},
|
|
|
|
|
2006-12-24 02:16:20 +01:00
|
|
|
toggle: function() {
|
2007-01-07 22:43:38 +01:00
|
|
|
// Save reference to arguments for access in closure
|
2007-10-06 19:04:20 +02:00
|
|
|
var args = arguments;
|
2007-01-07 22:43:38 +01:00
|
|
|
|
2007-10-06 19:04:20 +02:00
|
|
|
return this.click(function(event) {
|
2006-10-10 03:59:20 +02:00
|
|
|
// Figure out which function to execute
|
2007-04-29 20:39:07 +02:00
|
|
|
this.lastToggle = 0 == this.lastToggle ? 1 : 0;
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
// Make sure that clicks stop
|
2007-10-06 19:04:20 +02:00
|
|
|
event.preventDefault();
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
// and execute the function
|
2007-11-28 23:23:40 +01:00
|
|
|
return args[this.lastToggle].apply( this, arguments ) || false;
|
2007-01-07 22:43:38 +01:00
|
|
|
});
|
2006-10-10 03:59:20 +02:00
|
|
|
},
|
2007-09-04 03:57:35 +02:00
|
|
|
|
2007-10-06 19:04:20 +02:00
|
|
|
hover: function(fnOver, fnOut) {
|
2006-10-10 03:59:20 +02:00
|
|
|
|
2007-01-01 15:54:55 +01:00
|
|
|
// A private function for handling mouse 'hovering'
|
2007-10-06 19:04:20 +02:00
|
|
|
function handleHover(event) {
|
2006-10-10 03:59:20 +02:00
|
|
|
// Check if mouse(over|out) are still within the same parent element
|
2007-10-06 19:04:20 +02:00
|
|
|
var parent = event.relatedTarget;
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
// Traverse up the tree
|
2007-10-06 19:04:20 +02:00
|
|
|
while ( parent && parent != this ) try { parent = parent.parentNode; } catch(error) { parent = this; };
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
// If we actually just moused on to a sub-element, ignore it
|
2007-11-27 20:20:36 +01:00
|
|
|
if ( parent == this )
|
|
|
|
return true;
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
// Execute the right function
|
2007-10-06 19:04:20 +02:00
|
|
|
return (event.type == "mouseover" ? fnOver : fnOut).apply(this, [event]);
|
2006-10-10 03:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bind the function to the two event listeners
|
|
|
|
return this.mouseover(handleHover).mouseout(handleHover);
|
|
|
|
},
|
|
|
|
|
2007-10-06 19:04:20 +02:00
|
|
|
ready: function(fn) {
|
2007-08-22 08:51:41 +02:00
|
|
|
// Attach the listeners
|
|
|
|
bindReady();
|
|
|
|
|
2006-10-10 03:59:20 +02:00
|
|
|
// If the DOM is already ready
|
|
|
|
if ( jQuery.isReady )
|
|
|
|
// Execute the function immediately
|
2007-10-06 19:04:20 +02:00
|
|
|
fn.apply( document, [jQuery] );
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
// Otherwise, remember the function for later
|
2007-06-30 15:57:49 +02:00
|
|
|
else
|
2006-10-10 03:59:20 +02:00
|
|
|
// Add the function to the wait list
|
2007-10-06 19:04:20 +02:00
|
|
|
jQuery.readyList.push( function() { return fn.apply(this, [jQuery]); } );
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.extend({
|
|
|
|
/*
|
|
|
|
* All the code that makes DOM Ready work nicely.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
// If there are functions bound, to execute
|
|
|
|
if ( jQuery.readyList ) {
|
|
|
|
// Execute all of them
|
2007-01-14 22:49:59 +01:00
|
|
|
jQuery.each( jQuery.readyList, function(){
|
|
|
|
this.apply( document );
|
|
|
|
});
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
// Reset the list of functions
|
|
|
|
jQuery.readyList = null;
|
|
|
|
}
|
2007-05-22 09:11:50 +02:00
|
|
|
// Remove event listener to avoid memory leak
|
2007-11-14 22:55:45 +01:00
|
|
|
if ( document.removeEventListener )
|
2006-10-10 03:59:20 +02:00
|
|
|
document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2007-01-01 15:54:55 +01:00
|
|
|
|
2007-09-04 03:57:35 +02:00
|
|
|
jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
|
|
|
|
"mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
|
2007-10-06 19:04:20 +02:00
|
|
|
"submit,keydown,keypress,keyup,error").split(","), function(i, name){
|
2007-09-04 03:57:35 +02:00
|
|
|
|
|
|
|
// Handle event binding
|
2007-10-06 19:04:20 +02:00
|
|
|
jQuery.fn[name] = function(fn){
|
|
|
|
return fn ? this.bind(name, fn) : this.trigger(name);
|
2007-09-04 03:57:35 +02:00
|
|
|
};
|
|
|
|
});
|
2007-08-22 08:51:41 +02:00
|
|
|
|
|
|
|
var readyBound = false;
|
|
|
|
|
|
|
|
function bindReady(){
|
|
|
|
if ( readyBound ) return;
|
|
|
|
readyBound = true;
|
|
|
|
|
2007-11-14 22:55:45 +01:00
|
|
|
// Mozilla, Opera and webkit nightlies currently support this event
|
|
|
|
if ( document.addEventListener )
|
2006-10-10 03:59:20 +02:00
|
|
|
// Use the handy event callback
|
|
|
|
document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
|
|
|
|
|
2007-09-27 17:23:07 +02:00
|
|
|
// If Safari or IE is used
|
2007-10-15 19:55:54 +02:00
|
|
|
// Continually check to see if the document is ready
|
2007-11-14 22:55:45 +01:00
|
|
|
if (jQuery.browser.msie || jQuery.browser.safari ) (function(){
|
2007-10-15 19:55:54 +02:00
|
|
|
try {
|
|
|
|
// If IE is used, use the trick by Diego Perini
|
|
|
|
// http://javascript.nwbox.com/IEContentLoaded/
|
|
|
|
if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" )
|
|
|
|
document.documentElement.doScroll("left");
|
|
|
|
} catch( error ) {
|
|
|
|
return setTimeout( arguments.callee, 0 );
|
2007-10-01 16:14:09 +02:00
|
|
|
}
|
|
|
|
|
2007-10-15 19:55:54 +02:00
|
|
|
// and execute any waiting functions
|
|
|
|
jQuery.ready();
|
|
|
|
})();
|
2006-10-10 03:59:20 +02:00
|
|
|
|
|
|
|
// A fallback to window.onload, that will always work
|
|
|
|
jQuery.event.add( window, "load", jQuery.ready );
|
2007-08-22 08:51:41 +02:00
|
|
|
}
|
2007-10-06 19:04:20 +02:00
|
|
|
|
|
|
|
// Prevent memory leaks in IE
|
2007-11-14 16:06:48 +01:00
|
|
|
// And prevent errors on refresh with events like mouseover
|
|
|
|
// Window isn't included so as not to unbind existing unload events
|
|
|
|
jQuery(window).bind("unload", function() {
|
2007-11-19 17:15:51 +01:00
|
|
|
jQuery("*").add(document).unbind();
|
2007-11-14 16:06:48 +01:00
|
|
|
});
|