3 // We're overriding the old toggle function, so
4 // remember it for later
5 _toggle: jQuery.fn.toggle,
8 * Toggle between two function calls every other click.
9 * Whenever a matched element is clicked, the first specified function
10 * is fired, when clicked again, the second is fired. All subsequent
11 * clicks continue to rotate through the two functions.
13 * @example $("p").toggle(function(){
14 * $(this).addClass("selected");
16 * $(this).removeClass("selected");
19 * @test var count = 0;
20 * var fn1 = function() { count++; }
21 * var fn2 = function() { count--; }
22 * var link = $('#mark');
23 * link.click().toggle(fn1, fn2).click().click().click().click().click();
24 * ok( count == 1, "Check for toggle(fn, fn)" );
28 * @param Function even The function to execute on every even click.
29 * @param Function odd The function to execute on every odd click.
32 toggle: function(a,b) {
33 // If two functions are passed in, we're
34 // toggling on a click
35 return a && b && a.constructor == Function && b.constructor == Function ? this.click(function(e){
36 // Figure out which function to execute
37 this.last = this.last == a ? b : a;
39 // Make sure that clicks stop
42 // and execute the function
43 return this.last.apply( this, [e] ) || false;
46 // Otherwise, execute the old toggle function
47 this._toggle.apply( this, arguments );
51 * A method for simulating hovering (moving the mouse on, and off,
52 * an object). This is a custom method which provides an 'in' to a
55 * Whenever the mouse cursor is moved over a matched
56 * element, the first specified function is fired. Whenever the mouse
57 * moves off of the element, the second specified function fires.
58 * Additionally, checks are in place to see if the mouse is still within
59 * the specified element itself (for example, an image inside of a div),
60 * and if it is, it will continue to 'hover', and not move out
61 * (a common error in using a mouseout event handler).
63 * @example $("p").hover(function(){
64 * $(this).addClass("over");
66 * $(this).addClass("out");
71 * @param Function over The function to fire whenever the mouse is moved over a matched element.
72 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
75 hover: function(f,g) {
77 // A private function for haandling mouse 'hovering'
78 function handleHover(e) {
79 // Check if mouse(over|out) are still within the same parent element
80 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
82 // Traverse up the tree
83 while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
85 // If we actually just moused on to a sub-element, ignore it
86 if ( p == this ) return false;
88 // Execute the right function
89 return (e.type == "mouseover" ? f : g).apply(this, [e]);
92 // Bind the function to the two event listeners
93 return this.mouseover(handleHover).mouseout(handleHover);
97 * Bind a function to be executed whenever the DOM is ready to be
98 * traversed and manipulated. This is probably the most important
99 * function included in the event module, as it can greatly improve
100 * the response times of your web applications.
102 * In a nutshell, this is a solid replacement for using window.onload,
103 * and attaching a function to that. By using this method, your bound Function
104 * will be called the instant the DOM is ready to be read and manipulated,
105 * which is exactly what 99.99% of all Javascript code needs to run.
107 * Please ensure you have no code in your <body> onload event handler,
108 * otherwise $(document).ready() may not fire.
110 * You can have as many $(document).ready events on your page as you like.
112 * @example $(document).ready(function(){ Your code here... });
116 * @param Function fn The function to be executed when the DOM is ready.
120 // If the DOM is already ready
121 if ( jQuery.isReady )
122 // Execute the function immediately
125 // Otherwise, remember the function for later
127 // Add the function to the wait list
128 jQuery.readyList.push( f );
137 * All the code that makes DOM Ready work nicely.
142 // Handle when the DOM is ready
144 // Make sure that the DOM is not already loaded
145 if ( !jQuery.isReady ) {
146 // Remember that the DOM is ready
147 jQuery.isReady = true;
149 // If there are functions bound, to execute
150 if ( jQuery.readyList ) {
151 // Execute all of them
152 for ( var i = 0; i < jQuery.readyList.length; i++ )
153 jQuery.readyList[i].apply( document );
155 // Reset the list of functions
156 jQuery.readyList = null;
158 // Remove event lisenter to avoid memory leak
159 if ( jQuery.browser.mozilla || jQuery.browser.opera )
160 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
168 * Bind a function to the scroll event of each matched element.
170 * @example $("p").scroll( function() { alert("Hello"); } );
171 * @before <p>Hello</p>
172 * @result <p onscroll="alert('Hello');">Hello</p>
176 * @param Function fn A function to bind to the scroll event on each of the matched elements.
177 * @cat Events/Browser
181 * Trigger the scroll event of each matched element. This causes all of the functions
182 * that have been bound to thet scroll event to be executed.
184 * @example $("p").scroll();
185 * @before <p onscroll="alert('Hello');">Hello</p>
186 * @result alert('Hello');
190 * @cat Events/Browser
194 * Bind a function to the scroll event of each matched element, which will only be executed once.
195 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
196 * only executed the first time it is triggered, and never again (unless it is re-bound).
198 * @example $("p").onescroll( function() { alert("Hello"); } );
199 * @before <p onscroll="alert('Hello');">Hello</p>
200 * @result alert('Hello'); // Only executed for the first scroll
204 * @param Function fn A function to bind to the scroll event on each of the matched elements.
205 * @cat Events/Browser
209 * Removes a bound scroll event from each of the matched
210 * elements. You must pass the identical function that was used in the original
213 * @example $("p").unscroll( myFunction );
214 * @before <p onscroll="myFunction">Hello</p>
215 * @result <p>Hello</p>
219 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
220 * @cat Events/Browser
224 * Removes all bound scroll events from each of the matched elements.
226 * @example $("p").unscroll();
227 * @before <p onscroll="alert('Hello');">Hello</p>
228 * @result <p>Hello</p>
232 * @cat Events/Browser
236 * Bind a function to the submit event of each matched element.
238 * @example $("p").submit( function() { alert("Hello"); } );
239 * @before <p>Hello</p>
240 * @result <p onsubmit="alert('Hello');">Hello</p>
244 * @param Function fn A function to bind to the submit event on each of the matched elements.
249 * Trigger the submit event of each matched element. This causes all of the functions
250 * that have been bound to thet submit event to be executed.
252 * @example $("p").submit();
253 * @before <p onsubmit="alert('Hello');">Hello</p>
254 * @result alert('Hello');
262 * Bind a function to the submit event of each matched element, which will only be executed once.
263 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
264 * only executed the first time it is triggered, and never again (unless it is re-bound).
266 * @example $("p").onesubmit( function() { alert("Hello"); } );
267 * @before <p onsubmit="alert('Hello');">Hello</p>
268 * @result alert('Hello'); // Only executed for the first submit
272 * @param Function fn A function to bind to the submit event on each of the matched elements.
277 * Removes a bound submit event from each of the matched
278 * elements. You must pass the identical function that was used in the original
281 * @example $("p").unsubmit( myFunction );
282 * @before <p onsubmit="myFunction">Hello</p>
283 * @result <p>Hello</p>
287 * @param Function fn A function to unbind from the submit event on each of the matched elements.
292 * Removes all bound submit events from each of the matched elements.
294 * @example $("p").unsubmit();
295 * @before <p onsubmit="alert('Hello');">Hello</p>
296 * @result <p>Hello</p>
304 * Bind a function to the focus event of each matched element.
306 * @example $("p").focus( function() { alert("Hello"); } );
307 * @before <p>Hello</p>
308 * @result <p onfocus="alert('Hello');">Hello</p>
312 * @param Function fn A function to bind to the focus event on each of the matched elements.
317 * Trigger the focus event of each matched element. This causes all of the functions
318 * that have been bound to thet focus event to be executed.
320 * @example $("p").focus();
321 * @before <p onfocus="alert('Hello');">Hello</p>
322 * @result alert('Hello');
330 * Bind a function to the focus event of each matched element, which will only be executed once.
331 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
332 * only executed the first time it is triggered, and never again (unless it is re-bound).
334 * @example $("p").onefocus( function() { alert("Hello"); } );
335 * @before <p onfocus="alert('Hello');">Hello</p>
336 * @result alert('Hello'); // Only executed for the first focus
340 * @param Function fn A function to bind to the focus event on each of the matched elements.
345 * Removes a bound focus event from each of the matched
346 * elements. You must pass the identical function that was used in the original
349 * @example $("p").unfocus( myFunction );
350 * @before <p onfocus="myFunction">Hello</p>
351 * @result <p>Hello</p>
355 * @param Function fn A function to unbind from the focus event on each of the matched elements.
360 * Removes all bound focus events from each of the matched elements.
362 * @example $("p").unfocus();
363 * @before <p onfocus="alert('Hello');">Hello</p>
364 * @result <p>Hello</p>
372 * Bind a function to the keydown event of each matched element.
374 * @example $("p").keydown( function() { alert("Hello"); } );
375 * @before <p>Hello</p>
376 * @result <p onkeydown="alert('Hello');">Hello</p>
380 * @param Function fn A function to bind to the keydown event on each of the matched elements.
381 * @cat Events/Keyboard
385 * Trigger the keydown event of each matched element. This causes all of the functions
386 * that have been bound to thet keydown event to be executed.
388 * @example $("p").keydown();
389 * @before <p onkeydown="alert('Hello');">Hello</p>
390 * @result alert('Hello');
394 * @cat Events/Keyboard
398 * Bind a function to the keydown event of each matched element, which will only be executed once.
399 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
400 * only executed the first time it is triggered, and never again (unless it is re-bound).
402 * @example $("p").onekeydown( function() { alert("Hello"); } );
403 * @before <p onkeydown="alert('Hello');">Hello</p>
404 * @result alert('Hello'); // Only executed for the first keydown
408 * @param Function fn A function to bind to the keydown event on each of the matched elements.
409 * @cat Events/Keyboard
413 * Removes a bound keydown event from each of the matched
414 * elements. You must pass the identical function that was used in the original
417 * @example $("p").unkeydown( myFunction );
418 * @before <p onkeydown="myFunction">Hello</p>
419 * @result <p>Hello</p>
423 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
424 * @cat Events/Keyboard
428 * Removes all bound keydown events from each of the matched elements.
430 * @example $("p").unkeydown();
431 * @before <p onkeydown="alert('Hello');">Hello</p>
432 * @result <p>Hello</p>
436 * @cat Events/Keyboard
440 * Bind a function to the dblclick event of each matched element.
442 * @example $("p").dblclick( function() { alert("Hello"); } );
443 * @before <p>Hello</p>
444 * @result <p ondblclick="alert('Hello');">Hello</p>
448 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
453 * Trigger the dblclick event of each matched element. This causes all of the functions
454 * that have been bound to thet dblclick event to be executed.
456 * @example $("p").dblclick();
457 * @before <p ondblclick="alert('Hello');">Hello</p>
458 * @result alert('Hello');
466 * Bind a function to the dblclick event of each matched element, which will only be executed once.
467 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
468 * only executed the first time it is triggered, and never again (unless it is re-bound).
470 * @example $("p").onedblclick( function() { alert("Hello"); } );
471 * @before <p ondblclick="alert('Hello');">Hello</p>
472 * @result alert('Hello'); // Only executed for the first dblclick
476 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
481 * Removes a bound dblclick event from each of the matched
482 * elements. You must pass the identical function that was used in the original
485 * @example $("p").undblclick( myFunction );
486 * @before <p ondblclick="myFunction">Hello</p>
487 * @result <p>Hello</p>
491 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
496 * Removes all bound dblclick events from each of the matched elements.
498 * @example $("p").undblclick();
499 * @before <p ondblclick="alert('Hello');">Hello</p>
500 * @result <p>Hello</p>
508 * Bind a function to the keypress event of each matched element.
510 * @example $("p").keypress( function() { alert("Hello"); } );
511 * @before <p>Hello</p>
512 * @result <p onkeypress="alert('Hello');">Hello</p>
516 * @param Function fn A function to bind to the keypress event on each of the matched elements.
517 * @cat Events/Keyboard
521 * Trigger the keypress event of each matched element. This causes all of the functions
522 * that have been bound to thet keypress event to be executed.
524 * @example $("p").keypress();
525 * @before <p onkeypress="alert('Hello');">Hello</p>
526 * @result alert('Hello');
530 * @cat Events/Keyboard
534 * Bind a function to the keypress event of each matched element, which will only be executed once.
535 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
536 * only executed the first time it is triggered, and never again (unless it is re-bound).
538 * @example $("p").onekeypress( function() { alert("Hello"); } );
539 * @before <p onkeypress="alert('Hello');">Hello</p>
540 * @result alert('Hello'); // Only executed for the first keypress
544 * @param Function fn A function to bind to the keypress event on each of the matched elements.
545 * @cat Events/Keyboard
549 * Removes a bound keypress event from each of the matched
550 * elements. You must pass the identical function that was used in the original
553 * @example $("p").unkeypress( myFunction );
554 * @before <p onkeypress="myFunction">Hello</p>
555 * @result <p>Hello</p>
559 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
560 * @cat Events/Keyboard
564 * Removes all bound keypress events from each of the matched elements.
566 * @example $("p").unkeypress();
567 * @before <p onkeypress="alert('Hello');">Hello</p>
568 * @result <p>Hello</p>
572 * @cat Events/Keyboard
576 * Bind a function to the error event of each matched element.
578 * @example $("p").error( function() { alert("Hello"); } );
579 * @before <p>Hello</p>
580 * @result <p onerror="alert('Hello');">Hello</p>
584 * @param Function fn A function to bind to the error event on each of the matched elements.
585 * @cat Events/Browser
589 * Trigger the error event of each matched element. This causes all of the functions
590 * that have been bound to thet error event to be executed.
592 * @example $("p").error();
593 * @before <p onerror="alert('Hello');">Hello</p>
594 * @result alert('Hello');
598 * @cat Events/Browser
602 * Bind a function to the error event of each matched element, which will only be executed once.
603 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
604 * only executed the first time it is triggered, and never again (unless it is re-bound).
606 * @example $("p").oneerror( function() { alert("Hello"); } );
607 * @before <p onerror="alert('Hello');">Hello</p>
608 * @result alert('Hello'); // Only executed for the first error
612 * @param Function fn A function to bind to the error event on each of the matched elements.
613 * @cat Events/Browser
617 * Removes a bound error event from each of the matched
618 * elements. You must pass the identical function that was used in the original
621 * @example $("p").unerror( myFunction );
622 * @before <p onerror="myFunction">Hello</p>
623 * @result <p>Hello</p>
627 * @param Function fn A function to unbind from the error event on each of the matched elements.
628 * @cat Events/Browser
632 * Removes all bound error events from each of the matched elements.
634 * @example $("p").unerror();
635 * @before <p onerror="alert('Hello');">Hello</p>
636 * @result <p>Hello</p>
640 * @cat Events/Browser
644 * Bind a function to the blur event of each matched element.
646 * @example $("p").blur( function() { alert("Hello"); } );
647 * @before <p>Hello</p>
648 * @result <p onblur="alert('Hello');">Hello</p>
652 * @param Function fn A function to bind to the blur event on each of the matched elements.
657 * Trigger the blur event of each matched element. This causes all of the functions
658 * that have been bound to thet blur event to be executed.
660 * @example $("p").blur();
661 * @before <p onblur="alert('Hello');">Hello</p>
662 * @result alert('Hello');
670 * Bind a function to the blur event of each matched element, which will only be executed once.
671 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
672 * only executed the first time it is triggered, and never again (unless it is re-bound).
674 * @example $("p").oneblur( function() { alert("Hello"); } );
675 * @before <p onblur="alert('Hello');">Hello</p>
676 * @result alert('Hello'); // Only executed for the first blur
680 * @param Function fn A function to bind to the blur event on each of the matched elements.
685 * Removes a bound blur event from each of the matched
686 * elements. You must pass the identical function that was used in the original
689 * @example $("p").unblur( myFunction );
690 * @before <p onblur="myFunction">Hello</p>
691 * @result <p>Hello</p>
695 * @param Function fn A function to unbind from the blur event on each of the matched elements.
700 * Removes all bound blur events from each of the matched elements.
702 * @example $("p").unblur();
703 * @before <p onblur="alert('Hello');">Hello</p>
704 * @result <p>Hello</p>
712 * Bind a function to the load event of each matched element.
714 * @example $("p").load( function() { alert("Hello"); } );
715 * @before <p>Hello</p>
716 * @result <p onload="alert('Hello');">Hello</p>
720 * @param Function fn A function to bind to the load event on each of the matched elements.
721 * @cat Events/Browser
725 * Trigger the load event of each matched element. This causes all of the functions
726 * that have been bound to thet load event to be executed.
728 * Marked as private: Calling load() without arguments throws exception because the ajax load
729 * does not handle it.
731 * @example $("p").load();
732 * @before <p onload="alert('Hello');">Hello</p>
733 * @result alert('Hello');
738 * @cat Events/Browser
742 * Bind a function to the load event of each matched element, which will only be executed once.
743 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
744 * only executed the first time it is triggered, and never again (unless it is re-bound).
746 * @example $("p").oneload( function() { alert("Hello"); } );
747 * @before <p onload="alert('Hello');">Hello</p>
748 * @result alert('Hello'); // Only executed for the first load
752 * @param Function fn A function to bind to the load event on each of the matched elements.
753 * @cat Events/Browser
757 * Removes a bound load event from each of the matched
758 * elements. You must pass the identical function that was used in the original
761 * @example $("p").unload( myFunction );
762 * @before <p onload="myFunction">Hello</p>
763 * @result <p>Hello</p>
767 * @param Function fn A function to unbind from the load event on each of the matched elements.
768 * @cat Events/Browser
772 * Removes all bound load events from each of the matched elements.
774 * @example $("p").unload();
775 * @before <p onload="alert('Hello');">Hello</p>
776 * @result <p>Hello</p>
780 * @cat Events/Browser
784 * Bind a function to the select event of each matched element.
786 * @example $("p").select( function() { alert("Hello"); } );
787 * @before <p>Hello</p>
788 * @result <p onselect="alert('Hello');">Hello</p>
792 * @param Function fn A function to bind to the select event on each of the matched elements.
797 * Trigger the select event of each matched element. This causes all of the functions
798 * that have been bound to thet select event to be executed.
800 * @example $("p").select();
801 * @before <p onselect="alert('Hello');">Hello</p>
802 * @result alert('Hello');
810 * Bind a function to the select event of each matched element, which will only be executed once.
811 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
812 * only executed the first time it is triggered, and never again (unless it is re-bound).
814 * @example $("p").oneselect( function() { alert("Hello"); } );
815 * @before <p onselect="alert('Hello');">Hello</p>
816 * @result alert('Hello'); // Only executed for the first select
820 * @param Function fn A function to bind to the select event on each of the matched elements.
825 * Removes a bound select event from each of the matched
826 * elements. You must pass the identical function that was used in the original
829 * @example $("p").unselect( myFunction );
830 * @before <p onselect="myFunction">Hello</p>
831 * @result <p>Hello</p>
835 * @param Function fn A function to unbind from the select event on each of the matched elements.
840 * Removes all bound select events from each of the matched elements.
842 * @example $("p").unselect();
843 * @before <p onselect="alert('Hello');">Hello</p>
844 * @result <p>Hello</p>
852 * Bind a function to the mouseup event of each matched element.
854 * @example $("p").mouseup( function() { alert("Hello"); } );
855 * @before <p>Hello</p>
856 * @result <p onmouseup="alert('Hello');">Hello</p>
860 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
865 * Trigger the mouseup event of each matched element. This causes all of the functions
866 * that have been bound to thet mouseup event to be executed.
868 * @example $("p").mouseup();
869 * @before <p onmouseup="alert('Hello');">Hello</p>
870 * @result alert('Hello');
878 * Bind a function to the mouseup event of each matched element, which will only be executed once.
879 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
880 * only executed the first time it is triggered, and never again (unless it is re-bound).
882 * @example $("p").onemouseup( function() { alert("Hello"); } );
883 * @before <p onmouseup="alert('Hello');">Hello</p>
884 * @result alert('Hello'); // Only executed for the first mouseup
888 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
893 * Removes a bound mouseup event from each of the matched
894 * elements. You must pass the identical function that was used in the original
897 * @example $("p").unmouseup( myFunction );
898 * @before <p onmouseup="myFunction">Hello</p>
899 * @result <p>Hello</p>
903 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
908 * Removes all bound mouseup events from each of the matched elements.
910 * @example $("p").unmouseup();
911 * @before <p onmouseup="alert('Hello');">Hello</p>
912 * @result <p>Hello</p>
920 * Bind a function to the unload event of each matched element.
922 * @example $("p").unload( function() { alert("Hello"); } );
923 * @before <p>Hello</p>
924 * @result <p onunload="alert('Hello');">Hello</p>
928 * @param Function fn A function to bind to the unload event on each of the matched elements.
929 * @cat Events/Browser
933 * Trigger the unload event of each matched element. This causes all of the functions
934 * that have been bound to thet unload event to be executed.
936 * @example $("p").unload();
937 * @before <p onunload="alert('Hello');">Hello</p>
938 * @result alert('Hello');
942 * @cat Events/Browser
946 * Bind a function to the unload event of each matched element, which will only be executed once.
947 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
948 * only executed the first time it is triggered, and never again (unless it is re-bound).
950 * @example $("p").oneunload( function() { alert("Hello"); } );
951 * @before <p onunload="alert('Hello');">Hello</p>
952 * @result alert('Hello'); // Only executed for the first unload
956 * @param Function fn A function to bind to the unload event on each of the matched elements.
957 * @cat Events/Browser
961 * Removes a bound unload event from each of the matched
962 * elements. You must pass the identical function that was used in the original
965 * @example $("p").ununload( myFunction );
966 * @before <p onunload="myFunction">Hello</p>
967 * @result <p>Hello</p>
971 * @param Function fn A function to unbind from the unload event on each of the matched elements.
972 * @cat Events/Browser
976 * Removes all bound unload events from each of the matched elements.
978 * @example $("p").ununload();
979 * @before <p onunload="alert('Hello');">Hello</p>
980 * @result <p>Hello</p>
984 * @cat Events/Browser
988 * Bind a function to the change event of each matched element.
990 * @example $("p").change( function() { alert("Hello"); } );
991 * @before <p>Hello</p>
992 * @result <p onchange="alert('Hello');">Hello</p>
996 * @param Function fn A function to bind to the change event on each of the matched elements.
1001 * Trigger the change event of each matched element. This causes all of the functions
1002 * that have been bound to thet change event to be executed.
1004 * @example $("p").change();
1005 * @before <p onchange="alert('Hello');">Hello</p>
1006 * @result alert('Hello');
1014 * Bind a function to the change event of each matched element, which will only be executed once.
1015 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
1016 * only executed the first time it is triggered, and never again (unless it is re-bound).
1018 * @example $("p").onechange( function() { alert("Hello"); } );
1019 * @before <p onchange="alert('Hello');">Hello</p>
1020 * @result alert('Hello'); // Only executed for the first change
1024 * @param Function fn A function to bind to the change event on each of the matched elements.
1029 * Removes a bound change event from each of the matched
1030 * elements. You must pass the identical function that was used in the original
1033 * @example $("p").unchange( myFunction );
1034 * @before <p onchange="myFunction">Hello</p>
1035 * @result <p>Hello</p>
1039 * @param Function fn A function to unbind from the change event on each of the matched elements.
1044 * Removes all bound change events from each of the matched elements.
1046 * @example $("p").unchange();
1047 * @before <p onchange="alert('Hello');">Hello</p>
1048 * @result <p>Hello</p>
1056 * Bind a function to the mouseout event of each matched element.
1058 * @example $("p").mouseout( function() { alert("Hello"); } );
1059 * @before <p>Hello</p>
1060 * @result <p onmouseout="alert('Hello');">Hello</p>
1064 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1069 * Trigger the mouseout event of each matched element. This causes all of the functions
1070 * that have been bound to thet mouseout event to be executed.
1072 * @example $("p").mouseout();
1073 * @before <p onmouseout="alert('Hello');">Hello</p>
1074 * @result alert('Hello');
1082 * Bind a function to the mouseout event of each matched element, which will only be executed once.
1083 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
1084 * only executed the first time it is triggered, and never again (unless it is re-bound).
1086 * @example $("p").onemouseout( function() { alert("Hello"); } );
1087 * @before <p onmouseout="alert('Hello');">Hello</p>
1088 * @result alert('Hello'); // Only executed for the first mouseout
1092 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1097 * Removes a bound mouseout event from each of the matched
1098 * elements. You must pass the identical function that was used in the original
1101 * @example $("p").unmouseout( myFunction );
1102 * @before <p onmouseout="myFunction">Hello</p>
1103 * @result <p>Hello</p>
1107 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
1112 * Removes all bound mouseout events from each of the matched elements.
1114 * @example $("p").unmouseout();
1115 * @before <p onmouseout="alert('Hello');">Hello</p>
1116 * @result <p>Hello</p>
1124 * Bind a function to the keyup event of each matched element.
1126 * @example $("p").keyup( function() { alert("Hello"); } );
1127 * @before <p>Hello</p>
1128 * @result <p onkeyup="alert('Hello');">Hello</p>
1132 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1133 * @cat Events/Keyboard
1137 * Trigger the keyup event of each matched element. This causes all of the functions
1138 * that have been bound to thet keyup event to be executed.
1140 * @example $("p").keyup();
1141 * @before <p onkeyup="alert('Hello');">Hello</p>
1142 * @result alert('Hello');
1146 * @cat Events/Keyboard
1150 * Bind a function to the keyup event of each matched element, which will only be executed once.
1151 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1152 * only executed the first time it is triggered, and never again (unless it is re-bound).
1154 * @example $("p").onekeyup( function() { alert("Hello"); } );
1155 * @before <p onkeyup="alert('Hello');">Hello</p>
1156 * @result alert('Hello'); // Only executed for the first keyup
1160 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1161 * @cat Events/Keyboard
1165 * Removes a bound keyup event from each of the matched
1166 * elements. You must pass the identical function that was used in the original
1169 * @example $("p").unkeyup( myFunction );
1170 * @before <p onkeyup="myFunction">Hello</p>
1171 * @result <p>Hello</p>
1175 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1176 * @cat Events/Keyboard
1180 * Removes all bound keyup events from each of the matched elements.
1182 * @example $("p").unkeyup();
1183 * @before <p onkeyup="alert('Hello');">Hello</p>
1184 * @result <p>Hello</p>
1188 * @cat Events/Keyboard
1192 * Bind a function to the click event of each matched element.
1194 * @example $("p").click( function() { alert("Hello"); } );
1195 * @before <p>Hello</p>
1196 * @result <p onclick="alert('Hello');">Hello</p>
1200 * @param Function fn A function to bind to the click event on each of the matched elements.
1205 * Trigger the click event of each matched element. This causes all of the functions
1206 * that have been bound to thet click event to be executed.
1208 * @example $("p").click();
1209 * @before <p onclick="alert('Hello');">Hello</p>
1210 * @result alert('Hello');
1218 * Bind a function to the click event of each matched element, which will only be executed once.
1219 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
1220 * only executed the first time it is triggered, and never again (unless it is re-bound).
1222 * @example $("p").oneclick( function() { alert("Hello"); } );
1223 * @before <p onclick="alert('Hello');">Hello</p>
1224 * @result alert('Hello'); // Only executed for the first click
1228 * @param Function fn A function to bind to the click event on each of the matched elements.
1233 * Removes a bound click event from each of the matched
1234 * elements. You must pass the identical function that was used in the original
1237 * @example $("p").unclick( myFunction );
1238 * @before <p onclick="myFunction">Hello</p>
1239 * @result <p>Hello</p>
1243 * @param Function fn A function to unbind from the click event on each of the matched elements.
1248 * Removes all bound click events from each of the matched elements.
1250 * @example $("p").unclick();
1251 * @before <p onclick="alert('Hello');">Hello</p>
1252 * @result <p>Hello</p>
1260 * Bind a function to the resize event of each matched element.
1262 * @example $("p").resize( function() { alert("Hello"); } );
1263 * @before <p>Hello</p>
1264 * @result <p onresize="alert('Hello');">Hello</p>
1268 * @param Function fn A function to bind to the resize event on each of the matched elements.
1269 * @cat Events/Browser
1273 * Trigger the resize event of each matched element. This causes all of the functions
1274 * that have been bound to thet resize event to be executed.
1276 * @example $("p").resize();
1277 * @before <p onresize="alert('Hello');">Hello</p>
1278 * @result alert('Hello');
1282 * @cat Events/Browser
1286 * Bind a function to the resize event of each matched element, which will only be executed once.
1287 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
1288 * only executed the first time it is triggered, and never again (unless it is re-bound).
1290 * @example $("p").oneresize( function() { alert("Hello"); } );
1291 * @before <p onresize="alert('Hello');">Hello</p>
1292 * @result alert('Hello'); // Only executed for the first resize
1296 * @param Function fn A function to bind to the resize event on each of the matched elements.
1297 * @cat Events/Browser
1301 * Removes a bound resize event from each of the matched
1302 * elements. You must pass the identical function that was used in the original
1305 * @example $("p").unresize( myFunction );
1306 * @before <p onresize="myFunction">Hello</p>
1307 * @result <p>Hello</p>
1311 * @param Function fn A function to unbind from the resize event on each of the matched elements.
1312 * @cat Events/Browser
1316 * Removes all bound resize events from each of the matched elements.
1318 * @example $("p").unresize();
1319 * @before <p onresize="alert('Hello');">Hello</p>
1320 * @result <p>Hello</p>
1324 * @cat Events/Browser
1328 * Bind a function to the mousemove event of each matched element.
1330 * @example $("p").mousemove( function() { alert("Hello"); } );
1331 * @before <p>Hello</p>
1332 * @result <p onmousemove="alert('Hello');">Hello</p>
1336 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1341 * Trigger the mousemove event of each matched element. This causes all of the functions
1342 * that have been bound to thet mousemove event to be executed.
1344 * @example $("p").mousemove();
1345 * @before <p onmousemove="alert('Hello');">Hello</p>
1346 * @result alert('Hello');
1354 * Bind a function to the mousemove event of each matched element, which will only be executed once.
1355 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
1356 * only executed the first time it is triggered, and never again (unless it is re-bound).
1358 * @example $("p").onemousemove( function() { alert("Hello"); } );
1359 * @before <p onmousemove="alert('Hello');">Hello</p>
1360 * @result alert('Hello'); // Only executed for the first mousemove
1362 * @name onemousemove
1364 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1369 * Removes a bound mousemove event from each of the matched
1370 * elements. You must pass the identical function that was used in the original
1373 * @example $("p").unmousemove( myFunction );
1374 * @before <p onmousemove="myFunction">Hello</p>
1375 * @result <p>Hello</p>
1379 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
1384 * Removes all bound mousemove events from each of the matched elements.
1386 * @example $("p").unmousemove();
1387 * @before <p onmousemove="alert('Hello');">Hello</p>
1388 * @result <p>Hello</p>
1396 * Bind a function to the mousedown event of each matched element.
1398 * @example $("p").mousedown( function() { alert("Hello"); } );
1399 * @before <p>Hello</p>
1400 * @result <p onmousedown="alert('Hello');">Hello</p>
1404 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1409 * Trigger the mousedown event of each matched element. This causes all of the functions
1410 * that have been bound to thet mousedown event to be executed.
1412 * @example $("p").mousedown();
1413 * @before <p onmousedown="alert('Hello');">Hello</p>
1414 * @result alert('Hello');
1422 * Bind a function to the mousedown event of each matched element, which will only be executed once.
1423 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
1424 * only executed the first time it is triggered, and never again (unless it is re-bound).
1426 * @example $("p").onemousedown( function() { alert("Hello"); } );
1427 * @before <p onmousedown="alert('Hello');">Hello</p>
1428 * @result alert('Hello'); // Only executed for the first mousedown
1430 * @name onemousedown
1432 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1437 * Removes a bound mousedown event from each of the matched
1438 * elements. You must pass the identical function that was used in the original
1441 * @example $("p").unmousedown( myFunction );
1442 * @before <p onmousedown="myFunction">Hello</p>
1443 * @result <p>Hello</p>
1447 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
1452 * Removes all bound mousedown events from each of the matched elements.
1454 * @example $("p").unmousedown();
1455 * @before <p onmousedown="alert('Hello');">Hello</p>
1456 * @result <p>Hello</p>
1464 * Bind a function to the mouseover event of each matched element.
1466 * @example $("p").mouseover( function() { alert("Hello"); } );
1467 * @before <p>Hello</p>
1468 * @result <p onmouseover="alert('Hello');">Hello</p>
1472 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1477 * Trigger the mouseover event of each matched element. This causes all of the functions
1478 * that have been bound to thet mousedown event to be executed.
1480 * @example $("p").mouseover();
1481 * @before <p onmouseover="alert('Hello');">Hello</p>
1482 * @result alert('Hello');
1490 * Bind a function to the mouseover event of each matched element, which will only be executed once.
1491 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
1492 * only executed the first time it is triggered, and never again (unless it is re-bound).
1494 * @example $("p").onemouseover( function() { alert("Hello"); } );
1495 * @before <p onmouseover="alert('Hello');">Hello</p>
1496 * @result alert('Hello'); // Only executed for the first mouseover
1498 * @name onemouseover
1500 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
1505 * Removes a bound mouseover event from each of the matched
1506 * elements. You must pass the identical function that was used in the original
1509 * @example $("p").unmouseover( myFunction );
1510 * @before <p onmouseover="myFunction">Hello</p>
1511 * @result <p>Hello</p>
1515 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
1520 * Removes all bound mouseover events from each of the matched elements.
1522 * @example $("p").unmouseover();
1523 * @before <p onmouseover="alert('Hello');">Hello</p>
1524 * @result <p>Hello</p>
1534 * var e = ("blur,focus,resize,scroll,unload,click,dblclick," +
1535 * "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1536 * "submit,keydown,keypress,keyup,error").split(",");
1537 * var handler1 = function(event) {
1540 * var handler2 = function(event) {
1543 * for( var i=0; i < e.length; i++) {
1547 * $(document)[event](handler1);
1548 * $(document)[event](handler2);
1549 * $(document)["one"+event](handler1);
1551 * // call event two times
1552 * $(document)[event]();
1553 * $(document)[event]();
1556 * $(document)["un"+event](handler1);
1558 * $(document)[event]();
1560 * // remove all handlers
1561 * $(document)["un"+event]();
1564 * $(document)[event]();
1567 * ok( count == 6, 'Checking event ' + event);
1571 * @name eventTesting
1575 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1576 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1577 "submit,keydown,keypress,keyup,error").split(",");
1579 // Go through all the event names, but make sure that
1580 // it is enclosed properly
1581 for ( var i = 0; i < e.length; i++ ) new function(){
1585 // Handle event binding
1586 jQuery.fn[o] = function(f){
1587 return f ? this.bind(o, f) : this.trigger(o);
1590 // Handle event unbinding
1591 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1593 // Finally, handle events that only fire once
1594 jQuery.fn["one"+o] = function(f){
1595 // Attach the event listener
1596 return this.each(function(){
1601 jQuery.event.add( this, o, function(e){
1602 // If this function has already been executed, stop
1603 if ( count++ ) return;
1605 // And execute the bound function
1606 return f.apply(this, [e]);
1613 // If Mozilla is used
1614 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1615 // Use the handy event callback
1616 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1618 // If IE is used, use the excellent hack by Matthias Miller
1619 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1620 } else if ( jQuery.browser.msie ) {
1622 // Only works if you document.write() it
1623 document.write("<scr" + "ipt id=__ie_init defer=true " +
1624 "src=//:><\/script>");
1626 // Use the defer script hack
1627 var script = document.getElementById("__ie_init");
1628 script.onreadystatechange = function() {
1629 if ( this.readyState != "complete" ) return;
1630 this.parentNode.removeChild( this );
1634 // Clear from memory
1637 // If Safari is used
1638 } else if ( jQuery.browser.safari ) {
1639 // Continually check to see if the document.readyState is valid
1640 jQuery.safariTimer = setInterval(function(){
1641 // loaded and complete are both valid states
1642 if ( document.readyState == "loaded" ||
1643 document.readyState == "complete" ) {
1645 // If either one are found, remove the timer
1646 clearInterval( jQuery.safariTimer );
1647 jQuery.safariTimer = null;
1649 // and execute any waiting functions
1655 // A fallback to window.onload, that will always work
1656 jQuery.event.add( window, "load", jQuery.ready );
1660 // Clean up after IE to avoid memory leaks
1661 if (jQuery.browser.msie) jQuery(window).unload(function() {
1662 var event = jQuery.event, global = event.global;
1663 for (var type in global) {
1664 var els = global[type], i = els.length;
1665 if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i);