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 // Make sure that the function being executed has a unique ID
18 handler.guid = this.guid++;
20 // if data is passed, bind to handler
21 if( data != undefined ) {
22 // Create temporary function pointer to original handler
25 // Create unique handler function, wrapped around original handler
26 handler = function() {
27 // Pass arguments and context to original handler
28 return fn.apply(this, arguments);
31 // Store data in unique handler
34 // Set the guid of unique handler to the same of original handler, so it can be removed
35 handler.guid = fn.guid;
38 // Init the element's event structure
43 element.$handle = function() {
44 jQuery.event.handle.apply(element, arguments);
47 // Get the current list of functions bound to this event
48 var handlers = element.$events[type];
50 // Init the event handler queue
52 handlers = element.$events[type] = {};
54 // And bind the global event handler to the element
55 if (element.addEventListener)
56 element.addEventListener(type, element.$handle, false);
57 else if (element.attachEvent)
58 element.attachEvent("on" + type, element.$handle);
61 // Add the function to the element's handler list
62 handlers[handler.guid] = handler;
64 // Remember the function in a global list (for triggering)
65 if (!this.global[type])
66 this.global[type] = [];
67 this.global[type].push( element );
73 // Detach an event or set of events from an element
74 remove: function(element, type, handler) {
75 var events = element.$events, ret;
78 // type is actually an event object here
79 if ( type && type.type ) {
80 handler = type.handler;
85 for ( type in events )
86 this.remove( element, type );
88 } else if ( events[type] ) {
89 // remove the given handler for the given type
91 delete events[type][handler.guid];
93 // remove all handlers for the given type
95 for ( handler in element.$events[type] )
96 delete events[type][handler];
98 // remove generic event handler if no more handlers exist
99 for ( ret in events[type] ) break;
101 if (element.removeEventListener)
102 element.removeEventListener(type, element.$handle, false);
103 else if (element.detachEvent)
104 element.detachEvent("on" + type, element.$handle);
110 // Remove the expando if it's no longer used
111 for ( ret in events ) break;
113 element.$handle = element.$events = null;
117 trigger: function(type, data, element) {
118 // Clone the incoming data, if any
119 data = jQuery.makeArray(data || []);
121 // Handle a global trigger
123 jQuery.each( this.global[type] || [], function(){
124 jQuery.event.trigger( type, data, this );
127 // Handle triggering a single element
129 var val, ret, fn = jQuery.isFunction( element[ type ] || null );
131 // Pass along a fake event
132 data.unshift( this.fix({ type: type, target: element }) );
135 if ( (val = this.handle.apply( element, data )) !== false )
136 this.triggered = true;
138 if ( fn && val !== false && !jQuery.nodeName(element, 'a') )
141 this.triggered = false;
145 handle: function(event) {
146 // returned undefined or false
149 // Handle the second event of a trigger and when
150 // an event is called after a page has unloaded
151 if ( typeof jQuery == "undefined" || jQuery.event.triggered )
154 // Empty object is for triggered events with no data
155 event = jQuery.event.fix( event || window.event || {} );
157 var c = this.$events && this.$events[event.type], args = [].slice.call( arguments, 1 );
158 args.unshift( event );
161 // Pass in a reference to the handler function itself
162 // So that we can later remove it
163 args[0].handler = c[j];
164 args[0].data = c[j].data;
166 if ( c[j].apply( this, args ) === false ) {
167 event.preventDefault();
168 event.stopPropagation();
173 // Clean up added properties in IE to prevent memory leak
174 if (jQuery.browser.msie)
175 event.target = event.preventDefault = event.stopPropagation =
176 event.handler = event.data = null;
181 fix: function(event) {
182 // store a copy of the original event object
183 // and clone to set read-only properties
184 var originalEvent = event;
185 event = jQuery.extend({}, originalEvent);
187 // add preventDefault and stopPropagation since
188 // they will not work on the clone
189 event.preventDefault = function() {
190 // if preventDefault exists run it on the original event
191 if (originalEvent.preventDefault)
192 return originalEvent.preventDefault();
193 // otherwise set the returnValue property of the original event to false (IE)
194 originalEvent.returnValue = false;
196 event.stopPropagation = function() {
197 // if stopPropagation exists run it on the original event
198 if (originalEvent.stopPropagation)
199 return originalEvent.stopPropagation();
200 // otherwise set the cancelBubble property of the original event to true (IE)
201 originalEvent.cancelBubble = true;
204 // Fix target property, if necessary
205 if ( !event.target && event.srcElement )
206 event.target = event.srcElement;
208 // check if target is a textnode (safari)
209 if (jQuery.browser.safari && event.target.nodeType == 3)
210 event.target = originalEvent.target.parentNode;
212 // Add relatedTarget, if necessary
213 if ( !event.relatedTarget && event.fromElement )
214 event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
216 // Calculate pageX/Y if missing and clientX/Y available
217 if ( event.pageX == null && event.clientX != null ) {
218 var e = document.documentElement || document.body;
219 event.pageX = event.clientX + e.scrollLeft;
220 event.pageY = event.clientY + e.scrollTop;
223 // Add which for key events
224 if ( !event.which && (event.charCode || event.keyCode) )
225 event.which = event.charCode || event.keyCode;
227 // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
228 if ( !event.metaKey && event.ctrlKey )
229 event.metaKey = event.ctrlKey;
231 // Add which for click: 1 == left; 2 == middle; 3 == right
232 // Note: button is not normalized, so don't use it
233 if ( !event.which && event.button )
234 event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
243 * Binds a handler to a particular event (like click) for each matched element.
244 * The event handler is passed an event object that you can use to prevent
245 * default behaviour. To stop both default action and event bubbling, your handler
246 * has to return false.
248 * In most cases, you can define your event handlers as anonymous functions
249 * (see first example). In cases where that is not possible, you can pass additional
250 * data as the second parameter (and the handler function as the third), see
253 * Calling bind with an event type of "unload" will automatically
254 * use the one method instead of bind to prevent memory leaks.
256 * @example $("p").bind("click", function(){
257 * alert( $(this).text() );
259 * @before <p>Hello</p>
260 * @result alert("Hello")
262 * @example function handler(event) {
263 * alert(event.data.foo);
265 * $("p").bind("click", {foo: "bar"}, handler)
266 * @result alert("bar")
267 * @desc Pass some additional data to the event handler.
269 * @example $("form").bind("submit", function() { return false; })
270 * @desc Cancel a default action and prevent it from bubbling by returning false
271 * from your function.
273 * @example $("form").bind("submit", function(event){
274 * event.preventDefault();
276 * @desc Cancel only the default action by using the preventDefault method.
279 * @example $("form").bind("submit", function(event){
280 * event.stopPropagation();
282 * @desc Stop only an event from bubbling by using the stopPropagation method.
286 * @param String type An event type
287 * @param Object data (optional) Additional data passed to the event handler as event.data
288 * @param Function fn A function to bind to the event on each of the set of matched elements
291 bind: function( type, data, fn ) {
292 return type == "unload" ? this.one(type, data, fn) : this.each(function(){
293 jQuery.event.add( this, type, fn || data, fn && data );
298 * Binds a handler to a particular event (like click) for each matched element.
299 * The handler is executed only once for each element. Otherwise, the same rules
300 * as described in bind() apply.
301 * The event handler is passed an event object that you can use to prevent
302 * default behaviour. To stop both default action and event bubbling, your handler
303 * has to return false.
305 * In most cases, you can define your event handlers as anonymous functions
306 * (see first example). In cases where that is not possible, you can pass additional
307 * data as the second paramter (and the handler function as the third), see
310 * @example $("p").one("click", function(){
311 * alert( $(this).text() );
313 * @before <p>Hello</p>
314 * @result alert("Hello")
318 * @param String type An event type
319 * @param Object data (optional) Additional data passed to the event handler as event.data
320 * @param Function fn A function to bind to the event on each of the set of matched elements
323 one: function( type, data, fn ) {
324 return this.each(function(){
325 jQuery.event.add( this, type, function(event) {
326 jQuery(this).unbind(event);
327 return (fn || data).apply( this, arguments);
333 * The opposite of bind, removes a bound event from each of the matched
336 * Without any arguments, all bound events are removed.
338 * If the type is provided, all bound events of that type are removed.
340 * If the function that was passed to bind is provided as the second argument,
341 * only that specific event handler is removed.
343 * @example $("p").unbind()
344 * @before <p onclick="alert('Hello');">Hello</p>
345 * @result [ <p>Hello</p> ]
347 * @example $("p").unbind( "click" )
348 * @before <p onclick="alert('Hello');">Hello</p>
349 * @result [ <p>Hello</p> ]
351 * @example $("p").unbind( "click", function() { alert("Hello"); } )
352 * @before <p onclick="alert('Hello');">Hello</p>
353 * @result [ <p>Hello</p> ]
357 * @param String type (optional) An event type
358 * @param Function fn (optional) A function to unbind from the event on each of the set of matched elements
361 unbind: function( type, fn ) {
362 return this.each(function(){
363 jQuery.event.remove( this, type, fn );
368 * Trigger a type of event on every matched element. This will also cause
369 * the default action of the browser with the same name (if one exists)
370 * to be executed. For example, passing 'submit' to the trigger()
371 * function will also cause the browser to submit the form. This
372 * default action can be prevented by returning false from one of
373 * the functions bound to the event.
375 * You can also trigger custom events registered with bind.
377 * @example $("p").trigger("click")
378 * @before <p click="alert('hello')">Hello</p>
379 * @result alert('hello')
381 * @example $("p").click(function(event, a, b) {
382 * // when a normal click fires, a and b are undefined
383 * // for a trigger like below a refers too "foo" and b refers to "bar"
384 * }).trigger("click", ["foo", "bar"]);
385 * @desc Example of how to pass arbitrary data to an event
387 * @example $("p").bind("myEvent",function(event,message1,message2) {
388 * alert(message1 + ' ' + message2);
390 * $("p").trigger("myEvent",["Hello","World"]);
391 * @result alert('Hello World') // One for each paragraph
395 * @param String type An event type to trigger.
396 * @param Array data (optional) Additional data to pass as arguments (after the event object) to the event handler
399 trigger: function( type, data ) {
400 return this.each(function(){
401 jQuery.event.trigger( type, data, this );
406 * Toggle between two function calls every other click.
407 * Whenever a matched element is clicked, the first specified function
408 * is fired, when clicked again, the second is fired. All subsequent
409 * clicks continue to rotate through the two functions.
411 * Use unbind("click") to remove.
413 * @example $("p").toggle(function(){
414 * $(this).addClass("selected");
416 * $(this).removeClass("selected");
421 * @param Function even The function to execute on every even click.
422 * @param Function odd The function to execute on every odd click.
426 // Save reference to arguments for access in closure
429 return this.click(function(e) {
430 // Figure out which function to execute
431 this.lastToggle = 0 == this.lastToggle ? 1 : 0;
433 // Make sure that clicks stop
436 // and execute the function
437 return a[this.lastToggle].apply( this, [e] ) || false;
442 * A method for simulating hovering (moving the mouse on, and off,
443 * an object). This is a custom method which provides an 'in' to a
446 * Whenever the mouse cursor is moved over a matched
447 * element, the first specified function is fired. Whenever the mouse
448 * moves off of the element, the second specified function fires.
449 * Additionally, checks are in place to see if the mouse is still within
450 * the specified element itself (for example, an image inside of a div),
451 * and if it is, it will continue to 'hover', and not move out
452 * (a common error in using a mouseout event handler).
454 * @example $("p").hover(function(){
455 * $(this).addClass("hover");
457 * $(this).removeClass("hover");
462 * @param Function over The function to fire whenever the mouse is moved over a matched element.
463 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
466 hover: function(f,g) {
468 // A private function for handling mouse 'hovering'
469 function handleHover(e) {
470 // Check if mouse(over|out) are still within the same parent element
471 var p = e.relatedTarget;
473 // Traverse up the tree
474 while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
476 // If we actually just moused on to a sub-element, ignore it
477 if ( p == this ) return false;
479 // Execute the right function
480 return (e.type == "mouseover" ? f : g).apply(this, [e]);
483 // Bind the function to the two event listeners
484 return this.mouseover(handleHover).mouseout(handleHover);
488 * Bind a function to be executed whenever the DOM is ready to be
489 * traversed and manipulated. This is probably the most important
490 * function included in the event module, as it can greatly improve
491 * the response times of your web applications.
493 * In a nutshell, this is a solid replacement for using window.onload,
494 * and attaching a function to that. By using this method, your bound function
495 * will be called the instant the DOM is ready to be read and manipulated,
496 * which is when what 99.99% of all JavaScript code needs to run.
498 * There is one argument passed to the ready event handler: A reference to
499 * the jQuery function. You can name that argument whatever you like, and
500 * can therefore stick with the $ alias without risk of naming collisions.
502 * Please ensure you have no code in your <body> onload event handler,
503 * otherwise $(document).ready() may not fire.
505 * You can have as many $(document).ready events on your page as you like.
506 * The functions are then executed in the order they were added.
508 * @example $(document).ready(function(){ Your code here... });
510 * @example jQuery(function($) {
511 * // Your code using failsafe $ alias here...
513 * @desc Uses both the [[Core#.24.28_fn_.29|shortcut]] for $(document).ready() and the argument
514 * to write failsafe jQuery code using the $ alias, without relying on the
519 * @param Function fn The function to be executed when the DOM is ready.
521 * @see $.noConflict()
525 // If the DOM is already ready
526 if ( jQuery.isReady )
527 // Execute the function immediately
528 f.apply( document, [jQuery] );
530 // Otherwise, remember the function for later
532 // Add the function to the wait list
533 jQuery.readyList.push( function() { return f.apply(this, [jQuery]) } );
542 * All the code that makes DOM Ready work nicely.
547 // Handle when the DOM is ready
549 // Make sure that the DOM is not already loaded
550 if ( !jQuery.isReady ) {
551 // Remember that the DOM is ready
552 jQuery.isReady = true;
554 // If there are functions bound, to execute
555 if ( jQuery.readyList ) {
556 // Execute all of them
557 jQuery.each( jQuery.readyList, function(){
558 this.apply( document );
561 // Reset the list of functions
562 jQuery.readyList = null;
564 // Remove event listener to avoid memory leak
565 if ( jQuery.browser.mozilla || jQuery.browser.opera )
566 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
568 // Remove script element used by IE hack
569 jQuery(window).load(function(){ jQuery("#__ie_init").remove(); });
577 * Bind a function to the scroll event of each matched element.
579 * @example $("p").scroll( function() { alert("Hello"); } );
580 * @before <p>Hello</p>
581 * @result <p onscroll="alert('Hello');">Hello</p>
585 * @param Function fn A function to bind to the scroll event on each of the matched elements.
590 * Bind a function to the submit event of each matched element.
592 * @example $("#myform").submit( function() {
593 * return $("input", this).val().length > 0;
595 * @before <form id="myform"><input /></form>
596 * @desc Prevents the form submission when the input has no value entered.
600 * @param Function fn A function to bind to the submit event on each of the matched elements.
605 * Trigger the submit event of each matched element. This causes all of the functions
606 * that have been bound to that submit event to be executed, and calls the browser's
607 * default submit action on the matching element(s). This default action can be prevented
608 * by returning false from one of the functions bound to the submit event.
610 * Note: This does not execute the submit method of the form element! If you need to
611 * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
613 * @example $("form").submit();
614 * @desc Triggers all submit events registered to the matched form(s), and submits them.
622 * Bind a function to the focus event of each matched element.
624 * @example $("p").focus( function() { alert("Hello"); } );
625 * @before <p>Hello</p>
626 * @result <p onfocus="alert('Hello');">Hello</p>
630 * @param Function fn A function to bind to the focus event on each of the matched elements.
635 * Trigger the focus event of each matched element. This causes all of the functions
636 * that have been bound to thet focus event to be executed.
638 * Note: This does not execute the focus method of the underlying elements! If you need to
639 * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
641 * @example $("p").focus();
642 * @before <p onfocus="alert('Hello');">Hello</p>
643 * @result alert('Hello');
651 * Bind a function to the keydown event of each matched element.
653 * @example $("p").keydown( function() { alert("Hello"); } );
654 * @before <p>Hello</p>
655 * @result <p onkeydown="alert('Hello');">Hello</p>
659 * @param Function fn A function to bind to the keydown event on each of the matched elements.
664 * Bind a function to the dblclick event of each matched element.
666 * @example $("p").dblclick( function() { alert("Hello"); } );
667 * @before <p>Hello</p>
668 * @result <p ondblclick="alert('Hello');">Hello</p>
672 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
677 * Bind a function to the keypress event of each matched element.
679 * @example $("p").keypress( function() { alert("Hello"); } );
680 * @before <p>Hello</p>
681 * @result <p onkeypress="alert('Hello');">Hello</p>
685 * @param Function fn A function to bind to the keypress event on each of the matched elements.
690 * Bind a function to the error event of each matched element.
692 * @example $("p").error( function() { alert("Hello"); } );
693 * @before <p>Hello</p>
694 * @result <p onerror="alert('Hello');">Hello</p>
698 * @param Function fn A function to bind to the error event on each of the matched elements.
703 * Bind a function to the blur event of each matched element.
705 * @example $("p").blur( function() { alert("Hello"); } );
706 * @before <p>Hello</p>
707 * @result <p onblur="alert('Hello');">Hello</p>
711 * @param Function fn A function to bind to the blur event on each of the matched elements.
716 * Trigger the blur event of each matched element. This causes all of the functions
717 * that have been bound to that blur event to be executed, and calls the browser's
718 * default blur action on the matching element(s). This default action can be prevented
719 * by returning false from one of the functions bound to the blur event.
721 * Note: This does not execute the blur method of the underlying elements! If you need to
722 * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
724 * @example $("p").blur();
725 * @before <p onblur="alert('Hello');">Hello</p>
726 * @result alert('Hello');
734 * Bind a function to the load event of each matched element.
736 * @example $("p").load( function() { alert("Hello"); } );
737 * @before <p>Hello</p>
738 * @result <p onload="alert('Hello');">Hello</p>
742 * @param Function fn A function to bind to the load event on each of the matched elements.
747 * Bind a function to the select event of each matched element.
749 * @example $("p").select( function() { alert("Hello"); } );
750 * @before <p>Hello</p>
751 * @result <p onselect="alert('Hello');">Hello</p>
755 * @param Function fn A function to bind to the select event on each of the matched elements.
760 * Trigger the select event of each matched element. This causes all of the functions
761 * that have been bound to that select event to be executed, and calls the browser's
762 * default select action on the matching element(s). This default action can be prevented
763 * by returning false from one of the functions bound to the select event.
765 * @example $("p").select();
766 * @before <p onselect="alert('Hello');">Hello</p>
767 * @result alert('Hello');
775 * Bind a function to the mouseup event of each matched element.
777 * @example $("p").mouseup( function() { alert("Hello"); } );
778 * @before <p>Hello</p>
779 * @result <p onmouseup="alert('Hello');">Hello</p>
783 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
788 * Bind a function to the unload event of each matched element.
790 * @example $("p").unload( function() { alert("Hello"); } );
791 * @before <p>Hello</p>
792 * @result <p onunload="alert('Hello');">Hello</p>
796 * @param Function fn A function to bind to the unload event on each of the matched elements.
801 * Bind a function to the change event of each matched element.
803 * @example $("p").change( function() { alert("Hello"); } );
804 * @before <p>Hello</p>
805 * @result <p onchange="alert('Hello');">Hello</p>
809 * @param Function fn A function to bind to the change event on each of the matched elements.
814 * Bind a function to the mouseout event of each matched element.
816 * @example $("p").mouseout( function() { alert("Hello"); } );
817 * @before <p>Hello</p>
818 * @result <p onmouseout="alert('Hello');">Hello</p>
822 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
827 * Bind a function to the keyup event of each matched element.
829 * @example $("p").keyup( function() { alert("Hello"); } );
830 * @before <p>Hello</p>
831 * @result <p onkeyup="alert('Hello');">Hello</p>
835 * @param Function fn A function to bind to the keyup event on each of the matched elements.
840 * Bind a function to the click event of each matched element.
842 * @example $("p").click( function() { alert("Hello"); } );
843 * @before <p>Hello</p>
844 * @result <p onclick="alert('Hello');">Hello</p>
848 * @param Function fn A function to bind to the click event on each of the matched elements.
853 * Trigger the click event of each matched element. This causes all of the functions
854 * that have been bound to thet click event to be executed.
856 * @example $("p").click();
857 * @before <p onclick="alert('Hello');">Hello</p>
858 * @result alert('Hello');
866 * Bind a function to the resize event of each matched element.
868 * @example $("p").resize( function() { alert("Hello"); } );
869 * @before <p>Hello</p>
870 * @result <p onresize="alert('Hello');">Hello</p>
874 * @param Function fn A function to bind to the resize event on each of the matched elements.
879 * Bind a function to the mousemove event of each matched element.
881 * @example $("p").mousemove( function() { alert("Hello"); } );
882 * @before <p>Hello</p>
883 * @result <p onmousemove="alert('Hello');">Hello</p>
887 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
892 * Bind a function to the mousedown event of each matched element.
894 * @example $("p").mousedown( function() { alert("Hello"); } );
895 * @before <p>Hello</p>
896 * @result <p onmousedown="alert('Hello');">Hello</p>
900 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
905 * Bind a function to the mouseover event of each matched element.
907 * @example $("p").mouseover( function() { alert("Hello"); } );
908 * @before <p>Hello</p>
909 * @result <p onmouseover="alert('Hello');">Hello</p>
913 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
916 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
917 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
918 "submit,keydown,keypress,keyup,error").split(","), function(i,o){
920 // Handle event binding
921 jQuery.fn[o] = function(f){
922 return f ? this.bind(o, f) : this.trigger(o);
927 // If Mozilla is used
928 if ( jQuery.browser.mozilla || jQuery.browser.opera )
929 // Use the handy event callback
930 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
932 // If IE is used, use the excellent hack by Matthias Miller
933 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
934 else if ( jQuery.browser.msie ) {
936 // Only works if you document.write() it
937 document.write("<scr" + "ipt id=__ie_init defer=true " +
938 "src=//:><\/script>");
940 // Use the defer script hack
941 var script = document.getElementById("__ie_init");
943 // script does not exist if jQuery is loaded dynamically
945 script.onreadystatechange = function() {
946 if ( this.readyState != "complete" ) return;
954 } else if ( jQuery.browser.safari )
955 // Continually check to see if the document.readyState is valid
956 jQuery.safariTimer = setInterval(function(){
957 // loaded and complete are both valid states
958 if ( document.readyState == "loaded" ||
959 document.readyState == "complete" ) {
961 // If either one are found, remove the timer
962 clearInterval( jQuery.safariTimer );
963 jQuery.safariTimer = null;
965 // and execute any waiting functions
970 // A fallback to window.onload, that will always work
971 jQuery.event.add( window, "load", jQuery.ready );
975 // Clean up after IE to avoid memory leaks
976 if (jQuery.browser.msie)
977 jQuery(window).one("unload", function() {
978 var global = jQuery.event.global;
979 for ( var type in global ) {
980 var els = global[type], i = els.length;
981 if ( i && type != 'unload' )
983 jQuery.event.remove(els[i-1], type);