]> source.dussan.org Git - jquery.git/commitdiff
Fixed #1887 - trigger fails if extra is not a function
authorRichard Worth <rdworth@gmail.com>
Tue, 18 Dec 2007 03:13:39 +0000 (03:13 +0000)
committerRichard Worth <rdworth@gmail.com>
Tue, 18 Dec 2007 03:13:39 +0000 (03:13 +0000)
src/event.js

index b27b418430cab1a8e96d2b7e0cd0700a13d3c115..6a21fc3a68bad4e2fd8a5b4824b69e0131a5c74a 100644 (file)
-/*
- * 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(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
-               if ( jQuery.browser.msie && elem.setInterval != undefined )
-                       elem = window;
-
-               // 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 = function() { 
-                               // Pass arguments and context to original handler 
-                               return fn.apply(this, arguments); 
-                       };
-
-                       // 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
-               var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),
-                       handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
-                               // 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;
-               
-                               val = jQuery.event.handle.apply(elem, arguments);
-               
-                               return val;
-                       });
-                       
-                       // 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
-                                       if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
-                                               // 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);
-                                       }
-                               }
-
-                               // Add the function to the element's handler list
-                               handlers[handler.guid] = handler;
-
-                               // Keep track of which events have been used, for global triggering
-                               jQuery.event.global[type] = true;
-                       });
-       },
-
-       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
-                       if ( !types )
-                               for ( var type in events )
-                                       this.remove( elem, type );
-                       else {
-                               // types is actually an event object here
-                               if ( types.type ) {
-                                       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] )
-                                                               // 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 ) {
-                               jQuery.removeData( elem, "events" );
-                               jQuery.removeData( elem, "handle" );
-                       }
-               }
-       },
-
-       trigger: function(type, data, elem, donative, extra) {
-               // Clone the incoming data, if any
-               data = jQuery.makeArray(data || []);
-
-               // Handle a global trigger
-               if ( !elem ) {
-                       // Only trigger if we've ever bound an event for it
-                       if ( this.global[type] )
-                               jQuery("*").add([window, document]).trigger(type, data);
-
-               // 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;
-                       
-                       // Pass along a fake event
-                       if ( event )
-                               data.unshift( this.fix({ type: type, target: elem }) );
-
-                       // Enforce the right trigger type
-                       data[0].type = type;
-
-                       // Trigger the event
-                       if ( jQuery.isFunction( jQuery.data(elem, "handle") ) )
-                               val = jQuery.data(elem, "handle").apply( elem, data );
-
-                       // Handle triggering native .onfoo handlers
-                       if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
-                               val = false;
-
-                       // Extra functions don't get the custom event object
-                       if ( event )
-                               data.shift();
-
-                       // Handle triggering of extra function
-                       if ( extra ) {
-                               // call the extra function and tack the current return value on the end for possible inspection
-                               var ret = extra.apply( elem, data.concat( val ) );
-                               // 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
-               var val;
-
-               // Empty object is for triggered events with no data
-               event = jQuery.event.fix( event || window.event || {} ); 
-
-               // Namespaced event handlers
-               var parts = event.type.split(".");
-               event.type = parts[0];
-
-               var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );
-               args.unshift( event );
-
-               for ( var j in handlers ) {
-                       var handler = handlers[j];
-                       // Pass in a reference to the handler function itself
-                       // So that we can later remove it
-                       args[0].handler = handler;
-                       args[0].data = handler.data;
-
-                       // Filter the functions by class
-                       if ( !parts[1] || handler.type == parts[1] ) {
-                               var ret = handler.apply( this, args );
-
-                               if ( val !== false )
-                                       val = ret;
-
-                               if ( ret === false ) {
-                                       event.preventDefault();
-                                       event.stopPropagation();
-                               }
-                       }
-               }
-
-               // Clean up added properties in IE to prevent memory leak
-               if (jQuery.browser.msie)
-                       event.target = event.preventDefault = event.stopPropagation =
-                               event.handler = event.data = null;
-
-               return val;
-       },
-
-       fix: function(event) {
-               // 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)
-                               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;
-               };
-               
-               // 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 = originalEvent.target.parentNode;
-
-               // 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);
-               }
-                       
-               // Add which for key events
-               if ( !event.which && (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;
-
-               // 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 ) ));
-                       
-               return event;
-       },
-       
-       special: {
-               ready: {
-                       setup: function() {
-                               // Make sure the ready event is setup
-                               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;
-                               // Execute the right handlers by setting the event type to mouseenter
-                               arguments[0].type = "mouseenter";
-                               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;
-                               // Execute the right handlers by setting the event type to mouseleave
-                               arguments[0].type = "mouseleave";
-                               return jQuery.event.handle.apply(this, arguments);
-                       }
-               }
-       }
-};
-
-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 );
-               });
-       },
-       
-       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);
-                       }, fn && data);
-               });
-       },
-
-       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 ) {
-               if ( this[0] )
-                       return jQuery.event.trigger( type, data, this[0], false, fn );
-               return undefined;
-       },
-
-       toggle: function() {
-               // Save reference to arguments for access in closure
-               var args = arguments;
-
-               return this.click(function(event) {
-                       // Figure out which function to execute
-                       this.lastToggle = 0 == this.lastToggle ? 1 : 0;
-                       
-                       // 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 the DOM is already ready
-               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;
-       }
-});
-
-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;
-                       
-                       // If there are functions bound, to execute
-                       if ( jQuery.readyList ) {
-                               // Execute all of them
-                               jQuery.each( jQuery.readyList, function(){
-                                       this.apply( document );
-                               });
-                               
-                               // Reset the list of functions
-                               jQuery.readyList = null;
-                       }
-               
-                       // Trigger any bound ready events
-                       $(document).triggerHandler("ready");
-               }
-       }
-});
-
-var readyBound = false;
-
-function bindReady(){
-       if ( readyBound ) return;
-       readyBound = true;
-
-       // Mozilla, Opera and webkit nightlies currently support this event
-       if ( document.addEventListener )
-               // Use the handy event callback
-               document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
-       
-       // If Safari or IE is used
-       // Continually check to see if the document is ready
-       if (jQuery.browser.msie || jQuery.browser.safari ) (function(){
-               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 );
-               }
-
-               // and execute any waiting functions
-               jQuery.ready();
-       })();
-
-       // 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," +
-       "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);
-       };
-});
-
-// Checks if an event happened on an element within another element
-// Used in jQuery.event.special.mouseenter and mouseleave handlers
-var withinElement = function(event, elem) {
-       // Check if mouse(over|out) are still within the same parent element
-       var parent = event.relatedTarget;
-       // Traverse up the tree
-       while ( parent && parent != elem ) try { parent = parent.parentNode } catch(error) { parent = elem; };
-       // Return true if we actually just moused on to a sub-element
-       return parent == elem;
-};
-
-// 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
-jQuery(window).bind("unload", function() {
-       jQuery("*").add(document).unbind();
-});
+/*\r
+ * A number of helper functions used for managing events.\r
+ * Many of the ideas behind this code orignated from \r
+ * Dean Edwards' addEvent library.\r
+ */\r
+jQuery.event = {\r
+\r
+       // Bind an event to an element\r
+       // Original by Dean Edwards\r
+       add: function(elem, types, handler, data) {\r
+               if ( elem.nodeType == 3 || elem.nodeType == 8 )\r
+                       return;\r
+\r
+               // For whatever reason, IE has trouble passing the window object\r
+               // around, causing it to be cloned in the process\r
+               if ( jQuery.browser.msie && elem.setInterval != undefined )\r
+                       elem = window;\r
+\r
+               // Make sure that the function being executed has a unique ID\r
+               if ( !handler.guid )\r
+                       handler.guid = this.guid++;\r
+                       \r
+               // if data is passed, bind to handler \r
+               if( data != undefined ) { \r
+                       // Create temporary function pointer to original handler \r
+                       var fn = handler; \r
+\r
+                       // Create unique handler function, wrapped around original handler \r
+                       handler = function() { \r
+                               // Pass arguments and context to original handler \r
+                               return fn.apply(this, arguments); \r
+                       };\r
+\r
+                       // Store data in unique handler \r
+                       handler.data = data;\r
+\r
+                       // Set the guid of unique handler to the same of original handler, so it can be removed \r
+                       handler.guid = fn.guid;\r
+               }\r
+\r
+               // Init the element's event structure\r
+               var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),\r
+                       handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){\r
+                               // returned undefined or false\r
+                               var val;\r
+\r
+                               // Handle the second event of a trigger and when\r
+                               // an event is called after a page has unloaded\r
+                               if ( typeof jQuery == "undefined" || jQuery.event.triggered )\r
+                                       return val;\r
+               \r
+                               val = jQuery.event.handle.apply(elem, arguments);\r
+               \r
+                               return val;\r
+                       });\r
+                       \r
+                       // Handle multiple events seperated by a space\r
+                       // jQuery(...).bind("mouseover mouseout", fn);\r
+                       jQuery.each(types.split(/\s+/), function(index, type) {\r
+                               // Namespaced event handlers\r
+                               var parts = type.split(".");\r
+                               type = parts[0];\r
+                               handler.type = parts[1];\r
+\r
+                               // Get the current list of functions bound to this event\r
+                               var handlers = events[type];\r
+\r
+                               // Init the event handler queue\r
+                               if (!handlers) {\r
+                                       handlers = events[type] = {};\r
+               \r
+                                       // Check for a special event handler\r
+                                       // Only use addEventListener/attachEvent if the special\r
+                                       // events handler returns false\r
+                                       if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {\r
+                                               // Bind the global event handler to the element\r
+                                               if (elem.addEventListener)\r
+                                                       elem.addEventListener(type, handle, false);\r
+                                               else if (elem.attachEvent)\r
+                                                       elem.attachEvent("on" + type, handle);\r
+                                       }\r
+                               }\r
+\r
+                               // Add the function to the element's handler list\r
+                               handlers[handler.guid] = handler;\r
+\r
+                               // Keep track of which events have been used, for global triggering\r
+                               jQuery.event.global[type] = true;\r
+                       });\r
+       },\r
+\r
+       guid: 1,\r
+       global: {},\r
+\r
+       // Detach an event or set of events from an element\r
+       remove: function(elem, types, handler) {\r
+               // don't do events on text and comment nodes\r
+               if ( elem.nodeType == 3 || elem.nodeType == 8 )\r
+                       return;\r
+\r
+               var events = jQuery.data(elem, "events"), ret, index;\r
+\r
+               if ( events ) {\r
+                       // Unbind all events for the element\r
+                       if ( !types )\r
+                               for ( var type in events )\r
+                                       this.remove( elem, type );\r
+                       else {\r
+                               // types is actually an event object here\r
+                               if ( types.type ) {\r
+                                       handler = types.handler;\r
+                                       types = types.type;\r
+                               }\r
+                               \r
+                               // Handle multiple events seperated by a space\r
+                               // jQuery(...).unbind("mouseover mouseout", fn);\r
+                               jQuery.each(types.split(/\s+/), function(index, type){\r
+                                       // Namespaced event handlers\r
+                                       var parts = type.split(".");\r
+                                       type = parts[0];\r
+                                       \r
+                                       if ( events[type] ) {\r
+                                               // remove the given handler for the given type\r
+                                               if ( handler )\r
+                                                       delete events[type][handler.guid];\r
+                       \r
+                                               // remove all handlers for the given type\r
+                                               else\r
+                                                       for ( handler in events[type] )\r
+                                                               // Handle the removal of namespaced events\r
+                                                               if ( !parts[1] || events[type][handler].type == parts[1] )\r
+                                                                       delete events[type][handler];\r
+\r
+                                               // remove generic event handler if no more handlers exist\r
+                                               for ( ret in events[type] ) break;\r
+                                               if ( !ret ) {\r
+                                                       if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) {\r
+                                                               if (elem.removeEventListener)\r
+                                                                       elem.removeEventListener(type, jQuery.data(elem, "handle"), false);\r
+                                                               else if (elem.detachEvent)\r
+                                                                       elem.detachEvent("on" + type, jQuery.data(elem, "handle"));\r
+                                                       }\r
+                                                       ret = null;\r
+                                                       delete events[type];\r
+                                               }\r
+                                       }\r
+                               });\r
+                       }\r
+\r
+                       // Remove the expando if it's no longer used\r
+                       for ( ret in events ) break;\r
+                       if ( !ret ) {\r
+                               jQuery.removeData( elem, "events" );\r
+                               jQuery.removeData( elem, "handle" );\r
+                       }\r
+               }\r
+       },\r
+\r
+       trigger: function(type, data, elem, donative, extra) {\r
+               // Clone the incoming data, if any\r
+               data = jQuery.makeArray(data || []);\r
+\r
+               // Handle a global trigger\r
+               if ( !elem ) {\r
+                       // Only trigger if we've ever bound an event for it\r
+                       if ( this.global[type] )\r
+                               jQuery("*").add([window, document]).trigger(type, data);\r
+\r
+               // Handle triggering a single element\r
+               } else {\r
+                       // don't do events on text and comment nodes\r
+                       if ( elem.nodeType == 3 || elem.nodeType == 8 )\r
+                               return undefined;\r
+\r
+                       var val, ret, fn = jQuery.isFunction( elem[ type ] || null ),\r
+                               // Check to see if we need to provide a fake event, or not\r
+                               event = !data[0] || !data[0].preventDefault;\r
+                       \r
+                       // Pass along a fake event\r
+                       if ( event )\r
+                               data.unshift( this.fix({ type: type, target: elem }) );\r
+\r
+                       // Enforce the right trigger type\r
+                       data[0].type = type;\r
+\r
+                       // Trigger the event\r
+                       if ( jQuery.isFunction( jQuery.data(elem, "handle") ) )\r
+                               val = jQuery.data(elem, "handle").apply( elem, data );\r
+\r
+                       // Handle triggering native .onfoo handlers\r
+                       if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )\r
+                               val = false;\r
+\r
+                       // Extra functions don't get the custom event object\r
+                       if ( event )\r
+                               data.shift();\r
+\r
+                       // Handle triggering of extra function\r
+                       if ( extra && jQuery.isFunction( extra ) ) {\r
+                               // call the extra function and tack the current return value on the end for possible inspection\r
+                               var ret = extra.apply( elem, data.concat( val ) );\r
+                               // if anything is returned, give it precedence and have it overwrite the previous value\r
+                               if (ret !== undefined)\r
+                                       val = ret;\r
+                       }\r
+\r
+                       // Trigger the native events (except for clicks on links)\r
+                       if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) {\r
+                               this.triggered = true;\r
+                               try {\r
+                                       elem[ type ]();\r
+                               // prevent IE from throwing an error for some hidden elements\r
+                               } catch (e) {}\r
+                       }\r
+\r
+                       this.triggered = false;\r
+               }\r
+\r
+               return val;\r
+       },\r
+\r
+       handle: function(event) {\r
+               // returned undefined or false\r
+               var val;\r
+\r
+               // Empty object is for triggered events with no data\r
+               event = jQuery.event.fix( event || window.event || {} ); \r
+\r
+               // Namespaced event handlers\r
+               var parts = event.type.split(".");\r
+               event.type = parts[0];\r
+\r
+               var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );\r
+               args.unshift( event );\r
+\r
+               for ( var j in handlers ) {\r
+                       var handler = handlers[j];\r
+                       // Pass in a reference to the handler function itself\r
+                       // So that we can later remove it\r
+                       args[0].handler = handler;\r
+                       args[0].data = handler.data;\r
+\r
+                       // Filter the functions by class\r
+                       if ( !parts[1] || handler.type == parts[1] ) {\r
+                               var ret = handler.apply( this, args );\r
+\r
+                               if ( val !== false )\r
+                                       val = ret;\r
+\r
+                               if ( ret === false ) {\r
+                                       event.preventDefault();\r
+                                       event.stopPropagation();\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // Clean up added properties in IE to prevent memory leak\r
+               if (jQuery.browser.msie)\r
+                       event.target = event.preventDefault = event.stopPropagation =\r
+                               event.handler = event.data = null;\r
+\r
+               return val;\r
+       },\r
+\r
+       fix: function(event) {\r
+               // store a copy of the original event object \r
+               // and clone to set read-only properties\r
+               var originalEvent = event;\r
+               event = jQuery.extend({}, originalEvent);\r
+               \r
+               // add preventDefault and stopPropagation since \r
+               // they will not work on the clone\r
+               event.preventDefault = function() {\r
+                       // if preventDefault exists run it on the original event\r
+                       if (originalEvent.preventDefault)\r
+                               originalEvent.preventDefault();\r
+                       // otherwise set the returnValue property of the original event to false (IE)\r
+                       originalEvent.returnValue = false;\r
+               };\r
+               event.stopPropagation = function() {\r
+                       // if stopPropagation exists run it on the original event\r
+                       if (originalEvent.stopPropagation)\r
+                               originalEvent.stopPropagation();\r
+                       // otherwise set the cancelBubble property of the original event to true (IE)\r
+                       originalEvent.cancelBubble = true;\r
+               };\r
+               \r
+               // Fix target property, if necessary\r
+               if ( !event.target )\r
+                       event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either\r
+                               \r
+               // check if target is a textnode (safari)\r
+               if ( event.target.nodeType == 3 )\r
+                       event.target = originalEvent.target.parentNode;\r
+\r
+               // Add relatedTarget, if necessary\r
+               if ( !event.relatedTarget && event.fromElement )\r
+                       event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;\r
+\r
+               // Calculate pageX/Y if missing and clientX/Y available\r
+               if ( event.pageX == null && event.clientX != null ) {\r
+                       var doc = document.documentElement, body = document.body;\r
+                       event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);\r
+                       event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);\r
+               }\r
+                       \r
+               // Add which for key events\r
+               if ( !event.which && (event.charCode || event.keyCode) )\r
+                       event.which = event.charCode || event.keyCode;\r
+               \r
+               // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)\r
+               if ( !event.metaKey && event.ctrlKey )\r
+                       event.metaKey = event.ctrlKey;\r
+\r
+               // Add which for click: 1 == left; 2 == middle; 3 == right\r
+               // Note: button is not normalized, so don't use it\r
+               if ( !event.which && event.button )\r
+                       event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));\r
+                       \r
+               return event;\r
+       },\r
+       \r
+       special: {\r
+               ready: {\r
+                       setup: function() {\r
+                               // Make sure the ready event is setup\r
+                               bindReady();\r
+                               return;\r
+                       },\r
+                       \r
+                       teardown: function() { return; }\r
+               },\r
+               \r
+               mouseenter: {\r
+                       setup: function() {\r
+                               if ( jQuery.browser.msie ) return false;\r
+                               jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler);\r
+                               return true;\r
+                       },\r
+               \r
+                       teardown: function() {\r
+                               if ( jQuery.browser.msie ) return false;\r
+                               jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler);\r
+                               return true;\r
+                       },\r
+                       \r
+                       handler: function(event) {\r
+                               // If we actually just moused on to a sub-element, ignore it\r
+                               if ( withinElement(event, this) ) return true;\r
+                               // Execute the right handlers by setting the event type to mouseenter\r
+                               arguments[0].type = "mouseenter";\r
+                               return jQuery.event.handle.apply(this, arguments);\r
+                       }\r
+               },\r
+       \r
+               mouseleave: {\r
+                       setup: function() {\r
+                               if ( jQuery.browser.msie ) return false;\r
+                               jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler);\r
+                               return true;\r
+                       },\r
+               \r
+                       teardown: function() {\r
+                               if ( jQuery.browser.msie ) return false;\r
+                               jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler);\r
+                               return true;\r
+                       },\r
+                       \r
+                       handler: function(event) {\r
+                               // If we actually just moused on to a sub-element, ignore it\r
+                               if ( withinElement(event, this) ) return true;\r
+                               // Execute the right handlers by setting the event type to mouseleave\r
+                               arguments[0].type = "mouseleave";\r
+                               return jQuery.event.handle.apply(this, arguments);\r
+                       }\r
+               }\r
+       }\r
+};\r
+\r
+jQuery.fn.extend({\r
+       bind: function( type, data, fn ) {\r
+               return type == "unload" ? this.one(type, data, fn) : this.each(function(){\r
+                       jQuery.event.add( this, type, fn || data, fn && data );\r
+               });\r
+       },\r
+       \r
+       one: function( type, data, fn ) {\r
+               return this.each(function(){\r
+                       jQuery.event.add( this, type, function(event) {\r
+                               jQuery(this).unbind(event);\r
+                               return (fn || data).apply( this, arguments);\r
+                       }, fn && data);\r
+               });\r
+       },\r
+\r
+       unbind: function( type, fn ) {\r
+               return this.each(function(){\r
+                       jQuery.event.remove( this, type, fn );\r
+               });\r
+       },\r
+\r
+       trigger: function( type, data, fn ) {\r
+               return this.each(function(){\r
+                       jQuery.event.trigger( type, data, this, true, fn );\r
+               });\r
+       },\r
+\r
+       triggerHandler: function( type, data, fn ) {\r
+               if ( this[0] )\r
+                       return jQuery.event.trigger( type, data, this[0], false, fn );\r
+               return undefined;\r
+       },\r
+\r
+       toggle: function() {\r
+               // Save reference to arguments for access in closure\r
+               var args = arguments;\r
+\r
+               return this.click(function(event) {\r
+                       // Figure out which function to execute\r
+                       this.lastToggle = 0 == this.lastToggle ? 1 : 0;\r
+                       \r
+                       // Make sure that clicks stop\r
+                       event.preventDefault();\r
+                       \r
+                       // and execute the function\r
+                       return args[this.lastToggle].apply( this, arguments ) || false;\r
+               });\r
+       },\r
+\r
+       hover: function(fnOver, fnOut) {\r
+               return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);\r
+       },\r
+       \r
+       ready: function(fn) {\r
+               // Attach the listeners\r
+               bindReady();\r
+\r
+               // If the DOM is already ready\r
+               if ( jQuery.isReady )\r
+                       // Execute the function immediately\r
+                       fn.call( document, jQuery );\r
+                       \r
+               // Otherwise, remember the function for later\r
+               else\r
+                       // Add the function to the wait list\r
+                       jQuery.readyList.push( function() { return fn.call(this, jQuery); } );\r
+       \r
+               return this;\r
+       }\r
+});\r
+\r
+jQuery.extend({\r
+       isReady: false,\r
+       readyList: [],\r
+       // Handle when the DOM is ready\r
+       ready: function() {\r
+               // Make sure that the DOM is not already loaded\r
+               if ( !jQuery.isReady ) {\r
+                       // Remember that the DOM is ready\r
+                       jQuery.isReady = true;\r
+                       \r
+                       // If there are functions bound, to execute\r
+                       if ( jQuery.readyList ) {\r
+                               // Execute all of them\r
+                               jQuery.each( jQuery.readyList, function(){\r
+                                       this.apply( document );\r
+                               });\r
+                               \r
+                               // Reset the list of functions\r
+                               jQuery.readyList = null;\r
+                       }\r
+               \r
+                       // Trigger any bound ready events\r
+                       $(document).triggerHandler("ready");\r
+               }\r
+       }\r
+});\r
+\r
+var readyBound = false;\r
+\r
+function bindReady(){\r
+       if ( readyBound ) return;\r
+       readyBound = true;\r
+\r
+       // Mozilla, Opera and webkit nightlies currently support this event\r
+       if ( document.addEventListener )\r
+               // Use the handy event callback\r
+               document.addEventListener( "DOMContentLoaded", jQuery.ready, false );\r
+       \r
+       // If Safari or IE is used\r
+       // Continually check to see if the document is ready\r
+       if (jQuery.browser.msie || jQuery.browser.safari ) (function(){\r
+               try {\r
+                       // If IE is used, use the trick by Diego Perini\r
+                       // http://javascript.nwbox.com/IEContentLoaded/\r
+                       if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" )\r
+                               document.documentElement.doScroll("left");\r
+               } catch( error ) {\r
+                       return setTimeout( arguments.callee, 0 );\r
+               }\r
+\r
+               // and execute any waiting functions\r
+               jQuery.ready();\r
+       })();\r
+\r
+       // A fallback to window.onload, that will always work\r
+       jQuery.event.add( window, "load", jQuery.ready );\r
+}\r
+\r
+jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +\r
+       "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + \r
+       "submit,keydown,keypress,keyup,error").split(","), function(i, name){\r
+       \r
+       // Handle event binding\r
+       jQuery.fn[name] = function(fn){\r
+               return fn ? this.bind(name, fn) : this.trigger(name);\r
+       };\r
+});\r
+\r
+// Checks if an event happened on an element within another element\r
+// Used in jQuery.event.special.mouseenter and mouseleave handlers\r
+var withinElement = function(event, elem) {\r
+       // Check if mouse(over|out) are still within the same parent element\r
+       var parent = event.relatedTarget;\r
+       // Traverse up the tree\r
+       while ( parent && parent != elem ) try { parent = parent.parentNode } catch(error) { parent = elem; };\r
+       // Return true if we actually just moused on to a sub-element\r
+       return parent == elem;\r
+};\r
+\r
+// Prevent memory leaks in IE\r
+// And prevent errors on refresh with events like mouseover in other browsers\r
+// Window isn't included so as not to unbind existing unload events\r
+jQuery(window).bind("unload", function() {\r
+       jQuery("*").add(document).unbind();\r
+});\r