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
|
2007-12-16 05:09:53 +01:00
|
|
|
add: function(elem, types, handler, data) {
|
|
|
|
if ( elem.nodeType == 3 || elem.nodeType == 8 )
|
2007-12-07 02:52:21 +01:00
|
|
|
return;
|
|
|
|
|
2006-12-31 04:58:43 +01:00
|
|
|
// For whatever reason, IE has trouble passing the window object
|
|
|
|
// around, causing it to be cloned in the process
|
2007-12-16 05:09:53 +01:00
|
|
|
if ( jQuery.browser.msie && elem.setInterval != undefined )
|
|
|
|
elem = 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
|
|
|
|
|
|
|
// Init the element's event structure
|
2007-12-16 05:09:53 +01:00
|
|
|
var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),
|
|
|
|
handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
|
2007-12-15 06:55:33 +01: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 )
|
|
|
|
return val;
|
|
|
|
|
2007-12-16 05:09:53 +01:00
|
|
|
val = jQuery.event.handle.apply(elem, arguments);
|
2007-04-22 06:17:43 +02:00
|
|
|
|
2007-05-31 06:15:41 +02:00
|
|
|
return val;
|
2007-12-15 06:55:33 +01:00
|
|
|
});
|
2007-09-09 01:31:23 +02:00
|
|
|
|
2007-12-15 06:55:33 +01:00
|
|
|
// Handle multiple events seperated 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] = {};
|
|
|
|
|
|
|
|
// Check for a special event handler
|
|
|
|
// Only use addEventListener/attachEvent if the special
|
|
|
|
// events handler returns false
|
2007-12-16 05:09:53 +01:00
|
|
|
if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
|
2007-12-15 06:55:33 +01:00
|
|
|
// Bind the global event handler to the element
|
2007-12-16 05:09:53 +01:00
|
|
|
if (elem.addEventListener)
|
|
|
|
elem.addEventListener(type, handle, false);
|
|
|
|
else if (elem.attachEvent)
|
|
|
|
elem.attachEvent("on" + type, handle);
|
2007-12-15 06:55:33 +01:00
|
|
|
}
|
|
|
|
}
|
2006-12-31 04:58:43 +01:00
|
|
|
|
2007-12-15 06:55:33 +01:00
|
|
|
// Add the function to the element's handler list
|
|
|
|
handlers[handler.guid] = handler;
|
2007-04-22 18:34:23 +02:00
|
|
|
|
2007-12-15 06:55:33 +01:00
|
|
|
// Keep track of which events have been used, for global triggering
|
|
|
|
jQuery.event.global[type] = true;
|
|
|
|
});
|
2006-12-31 04:58:43 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
guid: 1,
|
|
|
|
global: {},
|
|
|
|
|
|
|
|
// Detach an event or set of events from an element
|
2007-12-16 05:09:53 +01:00
|
|
|
remove: function(elem, types, handler) {
|
2007-12-07 02:52:21 +01:00
|
|
|
// don't do events on text and comment nodes
|
2007-12-16 05:09:53 +01:00
|
|
|
if ( elem.nodeType == 3 || elem.nodeType == 8 )
|
2007-12-07 02:52:21 +01:00
|
|
|
return;
|
|
|
|
|
2007-12-16 05:09:53 +01:00
|
|
|
var events = jQuery.data(elem, "events"), ret, index;
|
2007-03-01 05:54:51 +01:00
|
|
|
|
|
|
|
if ( events ) {
|
2007-12-15 06:55:33 +01:00
|
|
|
// Unbind all events for the element
|
|
|
|
if ( !types )
|
|
|
|
for ( var type in events )
|
2007-12-16 05:09:53 +01:00
|
|
|
this.remove( elem, type );
|
2007-12-15 06:55:33 +01:00
|
|
|
else {
|
|
|
|
// types is actually an event object here
|
|
|
|
if ( types.type ) {
|
|
|
|
handler = types.handler;
|
|
|
|
types = types.type;
|
2007-02-25 20:36:29 +01:00
|
|
|
}
|
2007-12-15 06:55:33 +01: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];
|
|
|
|
|
|
|
|
if ( events[type] ) {
|
|
|
|
// remove the given handler for the given type
|
|
|
|
if ( handler )
|
|
|
|
delete events[type][handler.guid];
|
|
|
|
|
|
|
|
// 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 ) {
|
2007-12-16 05:09:53 +01:00
|
|
|
if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(this, 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"));
|
2007-12-15 06:55:33 +01:00
|
|
|
}
|
|
|
|
ret = null;
|
|
|
|
delete events[type];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
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 ) {
|
2007-12-16 05:09:53 +01:00
|
|
|
jQuery.removeData( elem, "events" );
|
|
|
|
jQuery.removeData( elem, "handle" );
|
2007-09-09 01:31:23 +02:00
|
|
|
}
|
2007-02-25 20:36:29 +01:00
|
|
|
}
|
2006-12-31 04:58:43 +01:00
|
|
|
},
|
|
|
|
|
2007-12-16 05:09:53 +01:00
|
|
|
trigger: function(type, data, elem, 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-12-16 05:09:53 +01:00
|
|
|
if ( !elem ) {
|
2007-08-20 01:37:26 +02:00
|
|
|
// 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-12-07 02:52:21 +01:00
|
|
|
// don't do events on text and comment nodes
|
2007-12-16 05:09:53 +01:00
|
|
|
if ( elem.nodeType == 3 || elem.nodeType == 8 )
|
2007-12-16 02:03:50 +01:00
|
|
|
return undefined;
|
2007-12-07 02:52:21 +01:00
|
|
|
|
2007-12-16 05:09:53 +01:00
|
|
|
var val, ret, fn = jQuery.isFunction( elem[ type ] || null ),
|
2007-08-30 18:34:34 +02:00
|
|
|
// 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-12-16 05:09:53 +01:00
|
|
|
data.unshift( this.fix({ type: type, target: elem }) );
|
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-12-16 05:09:53 +01:00
|
|
|
if ( jQuery.isFunction( jQuery.data(elem, "handle") ) )
|
|
|
|
val = jQuery.data(elem, "handle").apply( elem, data );
|
2007-08-28 06:42:35 +02:00
|
|
|
|
|
|
|
// Handle triggering native .onfoo handlers
|
2007-12-16 05:09:53 +01:00
|
|
|
if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
|
2007-07-21 03:04:59 +02:00
|
|
|
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
|
2007-12-03 22:41:10 +01:00
|
|
|
if ( extra ) {
|
|
|
|
// call the extra function and tack the current return value on the end for possible inspection
|
2007-12-16 05:09:53 +01:00
|
|
|
var ret = extra.apply( elem, data.concat( val ) );
|
2007-12-03 22:41:10 +01:00
|
|
|
// if anything is returned, give it precedence and have it overwrite the previous value
|
|
|
|
if (ret !== undefined)
|
|
|
|
val = ret;
|
|
|
|
}
|
2007-08-30 07:51:11 +02:00
|
|
|
|
2007-08-28 06:42:35 +02:00
|
|
|
// Trigger the native events (except for clicks on links)
|
2007-12-16 05:09:53 +01:00
|
|
|
if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
|
2007-07-21 03:04:59 +02:00
|
|
|
this.triggered = true;
|
2007-12-08 03:54:09 +01:00
|
|
|
try {
|
2007-12-16 05:09:53 +01:00
|
|
|
elem[ type ]();
|
2007-12-08 03:54:09 +01:00
|
|
|
// prevent IE from throwing an error for some hidden elements
|
|
|
|
} catch (e) {}
|
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);
|
2007-12-11 04:17:44 +01:00
|
|
|
event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 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;
|
2007-12-15 06:55:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
special: {
|
|
|
|
ready: {
|
|
|
|
setup: function() {
|
|
|
|
var handler = jQuery.event.special.ready.handler;
|
|
|
|
|
|
|
|
// Mozilla, Opera and webkit nightlies currently support this event
|
|
|
|
if ( document.addEventListener )
|
|
|
|
// Use the handy event callback
|
|
|
|
document.addEventListener( "DOMContentLoaded", handler, false );
|
|
|
|
|
|
|
|
// If Safari or IE is used
|
|
|
|
// Continually check to see if the document is ready
|
2007-12-16 11:33:38 +01:00
|
|
|
if ((jQuery.browser.msie && window == top) || jQuery.browser.safari ) (function(){
|
2007-12-15 06:55:33 +01: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 ) {
|
2007-12-16 02:03:50 +01:00
|
|
|
setTimeout( arguments.callee, 0 );
|
|
|
|
return;
|
2007-12-15 06:55:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// and execute any waiting functions
|
|
|
|
handler();
|
|
|
|
})();
|
|
|
|
|
|
|
|
// A fallback to window.onload, that will always work
|
|
|
|
jQuery.event.add( window, "load", handler );
|
|
|
|
},
|
|
|
|
|
|
|
|
teardown: function() {return;},
|
|
|
|
|
|
|
|
handler: function() {
|
|
|
|
// Make sure that the DOM is not already loaded
|
|
|
|
if ( !jQuery.isReady ) {
|
|
|
|
// Remember that the DOM is ready
|
|
|
|
jQuery.isReady = true;
|
|
|
|
jQuery(document).triggerHandler("ready");
|
|
|
|
jQuery(document).unbind("ready");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mouseenter: {
|
|
|
|
setup: function() {
|
2007-12-16 23:18:35 +01:00
|
|
|
if ( jQuery.browser.msie ) return false;
|
|
|
|
jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler);
|
2007-12-16 02:03:50 +01:00
|
|
|
return true;
|
2007-12-15 06:55:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
teardown: function() {
|
2007-12-16 23:18:35 +01:00
|
|
|
if ( jQuery.browser.msie ) return false;
|
|
|
|
jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler);
|
2007-12-16 02:03:50 +01:00
|
|
|
return true;
|
2007-12-15 06:55:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
handler: function(event) {
|
|
|
|
// If we actually just moused on to a sub-element, ignore it
|
2007-12-16 02:03:50 +01:00
|
|
|
if ( withinElement(event, this) ) return true;
|
2007-12-15 06:55:33 +01:00
|
|
|
// Execute the right handlers by setting the event type to mouseenter
|
2007-12-16 23:18:35 +01:00
|
|
|
arguments[0].type = "mouseenter";
|
|
|
|
return jQuery.event.handle.apply(this, arguments);
|
2007-12-15 06:55:33 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mouseleave: {
|
|
|
|
setup: function() {
|
2007-12-16 23:18:35 +01:00
|
|
|
if ( jQuery.browser.msie ) return false;
|
|
|
|
jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler);
|
2007-12-16 02:03:50 +01:00
|
|
|
return true;
|
2007-12-15 06:55:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
teardown: function() {
|
2007-12-16 23:18:35 +01:00
|
|
|
if ( jQuery.browser.msie ) return false;
|
|
|
|
jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler);
|
2007-12-16 02:03:50 +01:00
|
|
|
return true;
|
2007-12-15 06:55:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
handler: function(event) {
|
|
|
|
// If we actually just moused on to a sub-element, ignore it
|
2007-12-16 02:03:50 +01:00
|
|
|
if ( withinElement(event, this) ) return true;
|
2007-12-15 06:55:33 +01:00
|
|
|
// Execute the right handlers by setting the event type to mouseleave
|
2007-12-16 23:18:35 +01:00
|
|
|
arguments[0].type = "mouseleave";
|
|
|
|
return jQuery.event.handle.apply(this, arguments);
|
2007-12-15 06:55:33 +01:00
|
|
|
}
|
|
|
|
}
|
2006-12-31 04:58:43 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 );
|
2007-12-16 02:03:50 +01:00
|
|
|
return undefined;
|
2007-08-30 07:51:11 +02:00
|
|
|
},
|
|
|
|
|
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) {
|
2007-12-15 06:55:33 +01:00
|
|
|
return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
|
2006-10-10 03:59:20 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.extend({
|
2007-12-15 06:55:33 +01:00
|
|
|
isReady: false
|
2006-10-10 03:59:20 +02:00
|
|
|
});
|
|
|
|
|
2007-12-15 06:55:33 +01:00
|
|
|
jQuery.each( ("blur,focus,load,ready,resize,scroll,unload,click,dblclick," +
|
2007-09-04 03:57:35 +02:00
|
|
|
"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
|
|
|
|
2007-12-15 06:55:33 +01:00
|
|
|
// Checks if an event happened on an element within another element
|
|
|
|
// Used in jQuery.event.special.mouseenter and mouseleave handlers
|
2007-12-16 05:09:53 +01:00
|
|
|
var withinElement = function(event, elem) {
|
2007-12-15 06:55:33 +01:00
|
|
|
// Check if mouse(over|out) are still within the same parent element
|
|
|
|
var parent = event.relatedTarget;
|
|
|
|
// Traverse up the tree
|
2007-12-16 05:09:53 +01:00
|
|
|
while ( parent && parent != elem ) try { parent = parent.parentNode } catch(error) { parent = elem; };
|
2007-12-15 06:55:33 +01:00
|
|
|
// Return true if we actually just moused on to a sub-element
|
2007-12-16 05:09:53 +01:00
|
|
|
return parent == elem;
|
2007-12-15 06:55:33 +01:00
|
|
|
};
|
2007-10-06 19:04:20 +02:00
|
|
|
|
|
|
|
// Prevent memory leaks in IE
|
2007-12-15 06:55:33 +01:00
|
|
|
// And prevent errors on refresh with events like mouseover in other browsers
|
2007-11-14 16:06:48 +01:00
|
|
|
// 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
|
|
|
});
|