2 * A number of helper functions used for managing events.
3 * Many of the ideas behind this code orignated from
4 * Dean Edwards' addEvent library.
8 // Bind an event to an element
9 // Original by Dean Edwards
10 add: function(element, type, handler, data) {
11 // For whatever reason, IE has trouble passing the window object
12 // around, causing it to be cloned in the process
13 if ( jQuery.browser.msie && element.setInterval != undefined )
16 // if data is passed, bind to handler
17 if( data != undefined ) {
18 // Create temporary function pointer to original handler
21 // Create unique handler function, wrapped around original handler
22 handler = function() {
23 // Pass arguments and context to original handler
24 return fn.apply(this, arguments);
27 // Store data in unique handler
30 // Set the guid of unique handler to the same of original handler, so it can be removed
31 handler.guid = fn.guid;
34 // Make sure that the function being executed has a unique ID
35 if ( !handler.guid ) {
36 handler.guid = this.guid++;
37 // Don't forget to set guid for the original handler function
38 if (fn) fn.guid = handler.guid;
41 // Init the element's event structure
46 element.$handle = function() {
47 jQuery.event.handle.apply(element, arguments);
50 // Get the current list of functions bound to this event
51 var handlers = element.$events[type];
53 // Init the event handler queue
55 handlers = element.$events[type] = {};
57 // And bind the global event handler to the element
58 if (element.addEventListener)
59 element.addEventListener(type, element.$handle, false);
60 else if (element.attachEvent)
61 element.attachEvent("on" + type, element.$handle);
64 // Add the function to the element's handler list
65 handlers[handler.guid] = handler;
67 // Remember the function in a global list (for triggering)
68 if (!this.global[type])
69 this.global[type] = [];
70 this.global[type].push( element );
76 // Detach an event or set of events from an element
77 remove: function(element, type, handler) {
78 var events = element.$events, ret;
81 // type is actually an event object here
82 if ( type && type.type ) {
83 handler = type.handler;
88 for ( type in events )
89 this.remove( element, type );
91 } else if ( events[type] ) {
92 // remove the given handler for the given type
94 delete events[type][handler.guid];
96 // remove all handlers for the given type
98 for ( handler in element.$events[type] )
99 delete events[type][handler];
101 // remove generic event handler if no more handlers exist
102 for ( ret in events[type] ) break;
104 if (element.removeEventListener)
105 element.removeEventListener(type, element.$handle, false);
106 else if (element.detachEvent)
107 element.detachEvent("on" + type, element.$handle);
113 // Remove the expando if it's no longer used
114 for ( ret in events ) break;
116 element.$handle = element.$events = null;
120 trigger: function(type, data, element) {
121 // Clone the incoming data, if any
122 data = jQuery.makeArray(data || []);
124 // Handle a global trigger
126 jQuery.each( this.global[type] || [], function(){
127 jQuery.event.trigger( type, data, this );
130 // Handle triggering a single element
132 var val, ret, fn = jQuery.isFunction( element[ type ] || null );
134 // Pass along a fake event
135 data.unshift( this.fix({ type: type, target: element }) );
138 if ( (val = this.handle.apply( element, data )) !== false )
139 this.triggered = true;
141 if ( fn && val !== false && !jQuery.nodeName(element, 'a') )
144 this.triggered = false;
148 handle: function(event) {
149 // returned undefined or false
152 // Handle the second event of a trigger and when
153 // an event is called after a page has unloaded
154 if ( typeof jQuery == "undefined" || jQuery.event.triggered )
157 // Empty object is for triggered events with no data
158 event = jQuery.event.fix( event || window.event || {} );
160 var c = this.$events && this.$events[event.type], args = [].slice.call( arguments, 1 );
161 args.unshift( event );
164 // Pass in a reference to the handler function itself
165 // So that we can later remove it
166 args[0].handler = c[j];
167 args[0].data = c[j].data;
169 if ( c[j].apply( this, args ) === false ) {
170 event.preventDefault();
171 event.stopPropagation();
176 // Clean up added properties in IE to prevent memory leak
177 if (jQuery.browser.msie)
178 event.target = event.preventDefault = event.stopPropagation =
179 event.handler = event.data = null;
184 fix: function(event) {
185 // Fix target property, if necessary
186 if ( !event.target && event.srcElement )
187 event.target = event.srcElement;
189 // Add relatedTarget, if necessary
190 if ( !event.relatedTarget && event.fromElement )
191 event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
193 // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
194 if ( event.metaKey == null && event.ctrlKey != null )
195 event.metaKey = event.ctrlKey;
197 // Add which for click: 1 == left; 2 == middle; 3 == right
198 // Note: button is not normalized, so don't use it
199 if ( event.which == null && event.button != null )
200 event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
202 // Calculate pageX/Y if missing and clientX/Y available
203 if ( event.pageX == null && event.clientX != null ) {
204 var e = document.documentElement || document.body;
205 event.pageX = event.clientX + e.scrollLeft;
206 event.pageY = event.clientY + e.scrollTop;
209 // Add which for keypresses: keyCode
210 if ( (event.which == null || event.type == "keypress") && event.keyCode != null )
211 event.which = event.keyCode;
213 // If it's a keypress event, add charCode to IE
214 if ( event.charCode == null && event.type == "keypress" )
215 event.charCode = event.keyCode;
217 // check if target is a textnode (safari)
218 if (jQuery.browser.safari && event.target.nodeType == 3) {
219 // store a copy of the original event object
220 // and clone because target is read only
221 var originalEvent = event;
222 event = jQuery.extend({}, originalEvent);
224 // get parentnode from textnode
225 event.target = originalEvent.target.parentNode;
227 // add preventDefault and stopPropagation since
228 // they will not work on the clone
229 event.preventDefault = function() {
230 return originalEvent.preventDefault();
232 event.stopPropagation = function() {
233 return originalEvent.stopPropagation();
237 // fix preventDefault and stopPropagation
238 if (!event.preventDefault)
239 event.preventDefault = function() {
240 this.returnValue = false;
243 if (!event.stopPropagation)
244 event.stopPropagation = function() {
245 this.cancelBubble = true;
255 * Binds a handler to a particular event (like click) for each matched element.
256 * The event handler is passed an event object that you can use to prevent
257 * default behaviour. To stop both default action and event bubbling, your handler
258 * has to return false.
260 * In most cases, you can define your event handlers as anonymous functions
261 * (see first example). In cases where that is not possible, you can pass additional
262 * data as the second parameter (and the handler function as the third), see
265 * @example $("p").bind("click", function(){
266 * alert( $(this).text() );
268 * @before <p>Hello</p>
269 * @result alert("Hello")
271 * @example function handler(event) {
272 * alert(event.data.foo);
274 * $("p").bind("click", {foo: "bar"}, handler)
275 * @result alert("bar")
276 * @desc Pass some additional data to the event handler.
278 * @example $("form").bind("submit", function() { return false; })
279 * @desc Cancel a default action and prevent it from bubbling by returning false
280 * from your function.
282 * @example $("form").bind("submit", function(event){
283 * event.preventDefault();
285 * @desc Cancel only the default action by using the preventDefault method.
288 * @example $("form").bind("submit", function(event){
289 * event.stopPropagation();
291 * @desc Stop only an event from bubbling by using the stopPropagation method.
295 * @param String type An event type
296 * @param Object data (optional) Additional data passed to the event handler as event.data
297 * @param Function fn A function to bind to the event on each of the set of matched elements
300 bind: function( type, data, fn ) {
301 return this.each(function(){
302 jQuery.event.add( this, type, fn || data, fn && data );
307 * Binds a handler to a particular event (like click) for each matched element.
308 * The handler is executed only once for each element. Otherwise, the same rules
309 * as described in bind() apply.
310 The event handler is passed an event object that you can use to prevent
311 * default behaviour. To stop both default action and event bubbling, your handler
312 * has to return false.
314 * In most cases, you can define your event handlers as anonymous functions
315 * (see first example). In cases where that is not possible, you can pass additional
316 * data as the second paramter (and the handler function as the third), see
319 * @example $("p").one("click", function(){
320 * alert( $(this).text() );
322 * @before <p>Hello</p>
323 * @result alert("Hello")
327 * @param String type An event type
328 * @param Object data (optional) Additional data passed to the event handler as event.data
329 * @param Function fn A function to bind to the event on each of the set of matched elements
332 one: function( type, data, fn ) {
333 return this.each(function(){
334 jQuery.event.add( this, type, function(event) {
335 jQuery(this).unbind(event);
336 return (fn || data).apply( this, arguments);
342 * The opposite of bind, removes a bound event from each of the matched
345 * Without any arguments, all bound events are removed.
347 * If the type is provided, all bound events of that type are removed.
349 * If the function that was passed to bind is provided as the second argument,
350 * only that specific event handler is removed.
352 * @example $("p").unbind()
353 * @before <p onclick="alert('Hello');">Hello</p>
354 * @result [ <p>Hello</p> ]
356 * @example $("p").unbind( "click" )
357 * @before <p onclick="alert('Hello');">Hello</p>
358 * @result [ <p>Hello</p> ]
360 * @example $("p").unbind( "click", function() { alert("Hello"); } )
361 * @before <p onclick="alert('Hello');">Hello</p>
362 * @result [ <p>Hello</p> ]
366 * @param String type (optional) An event type
367 * @param Function fn (optional) A function to unbind from the event on each of the set of matched elements
370 unbind: function( type, fn ) {
371 return this.each(function(){
372 jQuery.event.remove( this, type, fn );
377 * Trigger a type of event on every matched element. This will also cause
378 * the default action of the browser with the same name (if one exists)
379 * to be executed. For example, passing 'submit' to the trigger()
380 * function will also cause the browser to submit the form. This
381 * default action can be prevented by returning false from one of
382 * the functions bound to the event.
384 * You can also trigger custom events registered with bind.
386 * @example $("p").trigger("click")
387 * @before <p click="alert('hello')">Hello</p>
388 * @result alert('hello')
390 * @example $("p").click(function(event, a, b) {
391 * // when a normal click fires, a and b are undefined
392 * // for a trigger like below a refers too "foo" and b refers to "bar"
393 * }).trigger("click", ["foo", "bar"]);
394 * @desc Example of how to pass arbitrary data to an event
396 * @example $("p").bind("myEvent",function(event,message1,message2) {
397 * alert(message1 + ' ' + message2);
399 * $("p").trigger("myEvent",["Hello","World"]);
400 * @result alert('Hello World') // One for each paragraph
404 * @param String type An event type to trigger.
405 * @param Array data (optional) Additional data to pass as arguments (after the event object) to the event handler
408 trigger: function( type, data ) {
409 return this.each(function(){
410 jQuery.event.trigger( type, data, this );
415 * Toggle between two function calls every other click.
416 * Whenever a matched element is clicked, the first specified function
417 * is fired, when clicked again, the second is fired. All subsequent
418 * clicks continue to rotate through the two functions.
420 * Use unbind("click") to remove.
422 * @example $("p").toggle(function(){
423 * $(this).addClass("selected");
425 * $(this).removeClass("selected");
430 * @param Function even The function to execute on every even click.
431 * @param Function odd The function to execute on every odd click.
435 // Save reference to arguments for access in closure
438 return this.click(function(e) {
439 // Figure out which function to execute
440 this.lastToggle = 0 == this.lastToggle ? 1 : 0;
442 // Make sure that clicks stop
445 // and execute the function
446 return a[this.lastToggle].apply( this, [e] ) || false;
451 * A method for simulating hovering (moving the mouse on, and off,
452 * an object). This is a custom method which provides an 'in' to a
455 * Whenever the mouse cursor is moved over a matched
456 * element, the first specified function is fired. Whenever the mouse
457 * moves off of the element, the second specified function fires.
458 * Additionally, checks are in place to see if the mouse is still within
459 * the specified element itself (for example, an image inside of a div),
460 * and if it is, it will continue to 'hover', and not move out
461 * (a common error in using a mouseout event handler).
463 * @example $("p").hover(function(){
464 * $(this).addClass("hover");
466 * $(this).removeClass("hover");
471 * @param Function over The function to fire whenever the mouse is moved over a matched element.
472 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
475 hover: function(f,g) {
477 // A private function for handling mouse 'hovering'
478 function handleHover(e) {
479 // Check if mouse(over|out) are still within the same parent element
480 var p = e.relatedTarget;
482 // Traverse up the tree
483 while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
485 // If we actually just moused on to a sub-element, ignore it
486 if ( p == this ) return false;
488 // Execute the right function
489 return (e.type == "mouseover" ? f : g).apply(this, [e]);
492 // Bind the function to the two event listeners
493 return this.mouseover(handleHover).mouseout(handleHover);
497 * Bind a function to be executed whenever the DOM is ready to be
498 * traversed and manipulated. This is probably the most important
499 * function included in the event module, as it can greatly improve
500 * the response times of your web applications.
502 * In a nutshell, this is a solid replacement for using window.onload,
503 * and attaching a function to that. By using this method, your bound function
504 * will be called the instant the DOM is ready to be read and manipulated,
505 * which is when what 99.99% of all JavaScript code needs to run.
507 * There is one argument passed to the ready event handler: A reference to
508 * the jQuery function. You can name that argument whatever you like, and
509 * can therefore stick with the $ alias without risk of naming collisions.
511 * Please ensure you have no code in your <body> onload event handler,
512 * otherwise $(document).ready() may not fire.
514 * You can have as many $(document).ready events on your page as you like.
515 * The functions are then executed in the order they were added.
517 * @example $(document).ready(function(){ Your code here... });
519 * @example jQuery(function($) {
520 * // Your code using failsafe $ alias here...
522 * @desc Uses both the [[Core#.24.28_fn_.29|shortcut]] for $(document).ready() and the argument
523 * to write failsafe jQuery code using the $ alias, without relying on the
528 * @param Function fn The function to be executed when the DOM is ready.
530 * @see $.noConflict()
534 // If the DOM is already ready
535 if ( jQuery.isReady )
536 // Execute the function immediately
537 f.apply( document, [jQuery] );
539 // Otherwise, remember the function for later
541 // Add the function to the wait list
542 jQuery.readyList.push( function() { return f.apply(this, [jQuery]) } );
551 * All the code that makes DOM Ready work nicely.
556 // Handle when the DOM is ready
558 // Make sure that the DOM is not already loaded
559 if ( !jQuery.isReady ) {
560 // Remember that the DOM is ready
561 jQuery.isReady = true;
563 // If there are functions bound, to execute
564 if ( jQuery.readyList ) {
565 // Execute all of them
566 jQuery.each( jQuery.readyList, function(){
567 this.apply( document );
570 // Reset the list of functions
571 jQuery.readyList = null;
573 // Remove event lisenter to avoid memory leak
574 if ( jQuery.browser.mozilla || jQuery.browser.opera )
575 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
577 // Remove script element used by IE hack
578 jQuery(window).load(function(){ jQuery("#__ie_init").remove(); });
586 * Bind a function to the scroll event of each matched element.
588 * @example $("p").scroll( function() { alert("Hello"); } );
589 * @before <p>Hello</p>
590 * @result <p onscroll="alert('Hello');">Hello</p>
594 * @param Function fn A function to bind to the scroll event on each of the matched elements.
599 * Bind a function to the submit event of each matched element.
601 * @example $("#myform").submit( function() {
602 * return $("input", this).val().length > 0;
604 * @before <form id="myform"><input /></form>
605 * @desc Prevents the form submission when the input has no value entered.
609 * @param Function fn A function to bind to the submit event on each of the matched elements.
614 * Trigger the submit event of each matched element. This causes all of the functions
615 * that have been bound to that submit event to be executed, and calls the browser's
616 * default submit action on the matching element(s). This default action can be prevented
617 * by returning false from one of the functions bound to the submit event.
619 * Note: This does not execute the submit method of the form element! If you need to
620 * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
622 * @example $("form").submit();
623 * @desc Triggers all submit events registered to the matched form(s), and submits them.
631 * Bind a function to the focus event of each matched element.
633 * @example $("p").focus( function() { alert("Hello"); } );
634 * @before <p>Hello</p>
635 * @result <p onfocus="alert('Hello');">Hello</p>
639 * @param Function fn A function to bind to the focus event on each of the matched elements.
644 * Trigger the focus event of each matched element. This causes all of the functions
645 * that have been bound to thet focus event to be executed.
647 * Note: This does not execute the focus method of the underlying elements! If you need to
648 * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
650 * @example $("p").focus();
651 * @before <p onfocus="alert('Hello');">Hello</p>
652 * @result alert('Hello');
660 * Bind a function to the keydown event of each matched element.
662 * @example $("p").keydown( function() { alert("Hello"); } );
663 * @before <p>Hello</p>
664 * @result <p onkeydown="alert('Hello');">Hello</p>
668 * @param Function fn A function to bind to the keydown event on each of the matched elements.
673 * Bind a function to the dblclick event of each matched element.
675 * @example $("p").dblclick( function() { alert("Hello"); } );
676 * @before <p>Hello</p>
677 * @result <p ondblclick="alert('Hello');">Hello</p>
681 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
686 * Bind a function to the keypress event of each matched element.
688 * @example $("p").keypress( function() { alert("Hello"); } );
689 * @before <p>Hello</p>
690 * @result <p onkeypress="alert('Hello');">Hello</p>
694 * @param Function fn A function to bind to the keypress event on each of the matched elements.
699 * Bind a function to the error event of each matched element.
701 * @example $("p").error( function() { alert("Hello"); } );
702 * @before <p>Hello</p>
703 * @result <p onerror="alert('Hello');">Hello</p>
707 * @param Function fn A function to bind to the error event on each of the matched elements.
712 * Bind a function to the blur event of each matched element.
714 * @example $("p").blur( function() { alert("Hello"); } );
715 * @before <p>Hello</p>
716 * @result <p onblur="alert('Hello');">Hello</p>
720 * @param Function fn A function to bind to the blur event on each of the matched elements.
725 * Trigger the blur event of each matched element. This causes all of the functions
726 * that have been bound to that blur event to be executed, and calls the browser's
727 * default blur action on the matching element(s). This default action can be prevented
728 * by returning false from one of the functions bound to the blur event.
730 * Note: This does not execute the blur method of the underlying elements! If you need to
731 * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
733 * @example $("p").blur();
734 * @before <p onblur="alert('Hello');">Hello</p>
735 * @result alert('Hello');
743 * Bind a function to the load event of each matched element.
745 * @example $("p").load( function() { alert("Hello"); } );
746 * @before <p>Hello</p>
747 * @result <p onload="alert('Hello');">Hello</p>
751 * @param Function fn A function to bind to the load event on each of the matched elements.
756 * Bind a function to the select event of each matched element.
758 * @example $("p").select( function() { alert("Hello"); } );
759 * @before <p>Hello</p>
760 * @result <p onselect="alert('Hello');">Hello</p>
764 * @param Function fn A function to bind to the select event on each of the matched elements.
769 * Trigger the select event of each matched element. This causes all of the functions
770 * that have been bound to that select event to be executed, and calls the browser's
771 * default select action on the matching element(s). This default action can be prevented
772 * by returning false from one of the functions bound to the select event.
774 * @example $("p").select();
775 * @before <p onselect="alert('Hello');">Hello</p>
776 * @result alert('Hello');
784 * Bind a function to the mouseup event of each matched element.
786 * @example $("p").mouseup( function() { alert("Hello"); } );
787 * @before <p>Hello</p>
788 * @result <p onmouseup="alert('Hello');">Hello</p>
792 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
797 * Bind a function to the unload event of each matched element.
799 * @example $("p").unload( function() { alert("Hello"); } );
800 * @before <p>Hello</p>
801 * @result <p onunload="alert('Hello');">Hello</p>
805 * @param Function fn A function to bind to the unload event on each of the matched elements.
810 * Bind a function to the change event of each matched element.
812 * @example $("p").change( function() { alert("Hello"); } );
813 * @before <p>Hello</p>
814 * @result <p onchange="alert('Hello');">Hello</p>
818 * @param Function fn A function to bind to the change event on each of the matched elements.
823 * Bind a function to the mouseout event of each matched element.
825 * @example $("p").mouseout( function() { alert("Hello"); } );
826 * @before <p>Hello</p>
827 * @result <p onmouseout="alert('Hello');">Hello</p>
831 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
836 * Bind a function to the keyup event of each matched element.
838 * @example $("p").keyup( function() { alert("Hello"); } );
839 * @before <p>Hello</p>
840 * @result <p onkeyup="alert('Hello');">Hello</p>
844 * @param Function fn A function to bind to the keyup event on each of the matched elements.
849 * Bind a function to the click event of each matched element.
851 * @example $("p").click( function() { alert("Hello"); } );
852 * @before <p>Hello</p>
853 * @result <p onclick="alert('Hello');">Hello</p>
857 * @param Function fn A function to bind to the click event on each of the matched elements.
862 * Trigger the click event of each matched element. This causes all of the functions
863 * that have been bound to thet click event to be executed.
865 * @example $("p").click();
866 * @before <p onclick="alert('Hello');">Hello</p>
867 * @result alert('Hello');
875 * Bind a function to the resize event of each matched element.
877 * @example $("p").resize( function() { alert("Hello"); } );
878 * @before <p>Hello</p>
879 * @result <p onresize="alert('Hello');">Hello</p>
883 * @param Function fn A function to bind to the resize event on each of the matched elements.
888 * Bind a function to the mousemove event of each matched element.
890 * @example $("p").mousemove( function() { alert("Hello"); } );
891 * @before <p>Hello</p>
892 * @result <p onmousemove="alert('Hello');">Hello</p>
896 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
901 * Bind a function to the mousedown event of each matched element.
903 * @example $("p").mousedown( function() { alert("Hello"); } );
904 * @before <p>Hello</p>
905 * @result <p onmousedown="alert('Hello');">Hello</p>
909 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
914 * Bind a function to the mouseover event of each matched element.
916 * @example $("p").mouseover( function() { alert("Hello"); } );
917 * @before <p>Hello</p>
918 * @result <p onmouseover="alert('Hello');">Hello</p>
922 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
925 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
926 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
927 "submit,keydown,keypress,keyup,error").split(","), function(i,o){
929 // Handle event binding
930 jQuery.fn[o] = function(f){
931 return f ? this.bind(o, f) : this.trigger(o);
936 // If Mozilla is used
937 if ( jQuery.browser.mozilla || jQuery.browser.opera )
938 // Use the handy event callback
939 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
941 // If IE is used, use the excellent hack by Matthias Miller
942 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
943 else if ( jQuery.browser.msie ) {
945 // Only works if you document.write() it
946 document.write("<scr" + "ipt id=__ie_init defer=true " +
947 "src=//:><\/script>");
949 // Use the defer script hack
950 var script = document.getElementById("__ie_init");
952 // script does not exist if jQuery is loaded dynamically
954 script.onreadystatechange = function() {
955 if ( this.readyState != "complete" ) return;
963 } else if ( jQuery.browser.safari )
964 // Continually check to see if the document.readyState is valid
965 jQuery.safariTimer = setInterval(function(){
966 // loaded and complete are both valid states
967 if ( document.readyState == "loaded" ||
968 document.readyState == "complete" ) {
970 // If either one are found, remove the timer
971 clearInterval( jQuery.safariTimer );
972 jQuery.safariTimer = null;
974 // and execute any waiting functions
979 // A fallback to window.onload, that will always work
980 jQuery.event.add( window, "load", jQuery.ready );
984 // Clean up after IE to avoid memory leaks
985 if (jQuery.browser.msie)
986 jQuery(window).one("unload", function() {
987 var global = jQuery.event.global;
988 for ( var type in global ) {
989 var els = global[type], i = els.length;
990 if ( i && type != 'unload' )
992 jQuery.event.remove(els[i-1], type);