/*
* A number of helper functions used for managing events.
- * Many of the ideas behind this code orignated from
+ * Many of the ideas behind this code orignated from
* Dean Edwards' addEvent library.
*/
jQuery.event = {
// Make sure that the function being executed has a unique ID
if ( !handler.guid )
handler.guid = this.guid++;
-
- // 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);
+
+ // 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);
});
- // Store data in unique handler
+ // Store data in unique handler
handler.data = data;
-
- // Set the guid of unique handler to the same of original handler, so it can be removed
- handler.guid = fn.guid;
}
// Init the element's event structure
// This is to prevent a memory leak with non-native
// event in IE.
handle.elem = elem;
-
+
// Handle multiple events separated by a space
// jQuery(...).bind("mouseover mouseout", fn);
jQuery.each(types.split(/\s+/), function(index, 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
// Keep track of which events have been used, for global triggering
jQuery.event.global[type] = true;
});
-
+
// Nullify elem to prevent memory leaks in IE
elem = null;
},
handler = types.handler;
types = types.type;
}
-
+
// 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] )
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;
-
+
// Pass along a fake event
if ( event ) {
- data.unshift({
- type: type,
- target: elem,
- preventDefault: function(){},
- stopPropagation: function(){},
+ data.unshift({
+ type: type,
+ target: elem,
+ preventDefault: function(){},
+ stopPropagation: function(){},
timeStamp: now()
});
data[0][expando] = true; // no need to fix fake event
data[0].exclusive = true;
// Trigger the event, it is assumed that "handle" is a function
- var handle = jQuery.data(elem, "handle");
- if ( handle )
+ var handle = jQuery.data(elem, "handle");
+ if ( handle )
val = handle.apply( elem, data );
// Handle triggering native .onfoo handlers (and on links since we don't call .click() for links)
namespace = event.type.split(".");
event.type = namespace[0];
namespace = namespace[1];
- all = !namespace && !event.exclusive; //cache this now, all = true means, any handler
+ // Cache this now, all = true means, any handler
+ all = !namespace && !event.exclusive;
handlers = ( jQuery.data(this, "events") || {} )[event.type];
// So that we can later remove it
event.handler = handler;
event.data = handler.data;
-
+
ret = handler.apply( this, arguments );
if ( val !== false )
},
fix: function(event) {
- if ( event[expando] == true )
+ if ( event[expando] == true )
return event;
-
- // store a copy of the original event object
+
+ // store a copy of the original event object
// and "clone" to set read-only properties
var originalEvent = event;
event = { originalEvent: originalEvent };
- var props = "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" ");
+ var 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(" ");
for ( var i=props.length; i; i-- )
event[ props[i] ] = originalEvent[ props[i] ];
-
+
// Mark it as fixed
event[expando] = true;
-
- // add preventDefault and stopPropagation since
+
+ // add preventDefault and stopPropagation since
// they will not work on the clone
event.preventDefault = function() {
// if preventDefault exists run it on the original event
// otherwise set the cancelBubble property of the original event to true (IE)
originalEvent.cancelBubble = true;
};
-
+
// Fix timeStamp
event.timeStamp = event.timeStamp || now();
-
+
// Fix target property, if necessary
if ( !event.target )
event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
-
+
// check if target is a textnode (safari)
if ( event.target.nodeType == 3 )
event.target = event.target.parentNode;
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);
}
-
+
// Add which for key events
if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) )
event.which = event.charCode || event.keyCode;
-
+
// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
if ( !event.metaKey && event.ctrlKey )
event.metaKey = event.ctrlKey;
// 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 ) ));
-
+
return event;
},
-
+
proxy: function( fn, proxy ){
- // Set the guid of unique handler to the same of original handler, so it can be removed
+ // Set the guid of unique handler to the same of original handler, so it can be removed
proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++;
- return proxy;//so proxy can be declared as an argument
+ // So proxy can be declared as an argument
+ return proxy;
},
-
+
special: {
ready: {
setup: function() {
bindReady();
return;
},
-
+
teardown: function() { return; }
},
-
+
mouseenter: {
setup: function() {
if ( jQuery.browser.msie ) return false;
jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler);
return true;
},
-
+
teardown: function() {
if ( jQuery.browser.msie ) return false;
jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler);
return true;
},
-
+
handler: function(event) {
// If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true;
return jQuery.event.handle.apply(this, arguments);
}
},
-
+
mouseleave: {
setup: function() {
if ( jQuery.browser.msie ) return false;
jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler);
return true;
},
-
+
teardown: function() {
if ( jQuery.browser.msie ) return false;
jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler);
return true;
},
-
+
handler: function(event) {
// If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true;
jQuery.event.add( this, type, fn || data, fn && data );
});
},
-
+
one: function( type, data, fn ) {
var one = jQuery.event.proxy( fn || data, function(event) {
jQuery(this).unbind(event, one);
return this.click( jQuery.event.proxy( fn, function(event) {
// Figure out which function to execute
this.lastToggle = ( this.lastToggle || 0 ) % i;
-
+
// Make sure that clicks stop
event.preventDefault();
-
+
// and execute the function
return args[ this.lastToggle++ ].apply( this, arguments ) || false;
}));
hover: function(fnOver, fnOut) {
return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
},
-
+
ready: function(fn) {
// Attach the listeners
bindReady();
if ( jQuery.isReady )
// Execute the function immediately
fn.call( document, jQuery );
-
+
// Otherwise, remember the function for later
else
// Add the function to the wait list
jQuery.readyList.push( function() { return fn.call(this, jQuery); } );
-
+
return this;
}
});
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
jQuery.each( jQuery.readyList, function(){
- this.apply( document );
+ this.call( document );
});
-
+
// Reset the list of functions
jQuery.readyList = null;
}
-
+
// Trigger any bound ready events
jQuery(document).triggerHandler("ready");
}
if ( document.addEventListener && !jQuery.browser.opera)
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
-
+
// If IE is used and is not in a frame
// Continually check to see if the document is ready
if ( jQuery.browser.msie && window == top ) (function(){
}
jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
- "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
+ "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
"submit,keydown,keypress,keyup,error").split(","), function(i, name){
-
+
// Handle event binding
jQuery.fn[name] = function(fn){
return fn ? this.bind(name, fn) : this.trigger(name);