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 ) p = p.parentNode;
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 * @example $(document).ready(function(){ Your code here... });
114 * @param Function fn The function to be executed when the DOM is ready.
118 // If the DOM is already ready
119 if ( jQuery.isReady )
120 // Execute the function immediately
123 // Otherwise, remember the function for later
125 // Add the function to the wait list
126 jQuery.readyList.push( f );
135 * All the code that makes DOM Ready work nicely.
140 // Handle when the DOM is ready
142 // Make sure that the DOM is not already loaded
143 if ( !jQuery.isReady ) {
144 // Remember that the DOM is ready
145 jQuery.isReady = true;
147 // If there are functions bound, to execute
148 if ( jQuery.readyList ) {
149 // Execute all of them
150 for ( var i = 0; i < jQuery.readyList.length; i++ )
151 jQuery.readyList[i].apply( document );
153 // Reset the list of functions
154 jQuery.readyList = null;
163 * Bind a function to the scroll event of each matched element.
165 * @example $("p").scroll( function() { alert("Hello"); } );
166 * @before <p>Hello</p>
167 * @result <p onscroll="alert('Hello');">Hello</p>
171 * @param Function fn A function to bind to the scroll event on each of the matched elements.
172 * @cat Events/Browser
176 * Trigger the scroll event of each matched element. This causes all of the functions
177 * that have been bound to thet scroll event to be executed.
179 * @example $("p").scroll();
180 * @before <p onscroll="alert('Hello');">Hello</p>
181 * @result alert('Hello');
185 * @cat Events/Browser
189 * Bind a function to the scroll event of each matched element, which will only be executed once.
190 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
191 * only executed the first time it is triggered, and never again (unless it is re-bound).
193 * @example $("p").onescroll( function() { alert("Hello"); } );
194 * @before <p onscroll="alert('Hello');">Hello</p>
195 * @result alert('Hello'); // Only executed for the first scroll
199 * @param Function fn A function to bind to the scroll event on each of the matched elements.
200 * @cat Events/Browser
204 * Removes a bound scroll event from each of the matched
205 * elements. You must pass the identical function that was used in the original
208 * @example $("p").unscroll( myFunction );
209 * @before <p onscroll="myFunction">Hello</p>
210 * @result <p>Hello</p>
214 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
215 * @cat Events/Browser
219 * Removes all bound scroll events from each of the matched elements.
221 * @example $("p").unscroll();
222 * @before <p onscroll="alert('Hello');">Hello</p>
223 * @result <p>Hello</p>
227 * @cat Events/Browser
231 * Bind a function to the submit event of each matched element.
233 * @example $("p").submit( function() { alert("Hello"); } );
234 * @before <p>Hello</p>
235 * @result <p onsubmit="alert('Hello');">Hello</p>
239 * @param Function fn A function to bind to the submit event on each of the matched elements.
244 * Trigger the submit event of each matched element. This causes all of the functions
245 * that have been bound to thet submit event to be executed.
247 * @example $("p").submit();
248 * @before <p onsubmit="alert('Hello');">Hello</p>
249 * @result alert('Hello');
257 * Bind a function to the submit event of each matched element, which will only be executed once.
258 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
259 * only executed the first time it is triggered, and never again (unless it is re-bound).
261 * @example $("p").onesubmit( function() { alert("Hello"); } );
262 * @before <p onsubmit="alert('Hello');">Hello</p>
263 * @result alert('Hello'); // Only executed for the first submit
267 * @param Function fn A function to bind to the submit event on each of the matched elements.
272 * Removes a bound submit event from each of the matched
273 * elements. You must pass the identical function that was used in the original
276 * @example $("p").unsubmit( myFunction );
277 * @before <p onsubmit="myFunction">Hello</p>
278 * @result <p>Hello</p>
282 * @param Function fn A function to unbind from the submit event on each of the matched elements.
287 * Removes all bound submit events from each of the matched elements.
289 * @example $("p").unsubmit();
290 * @before <p onsubmit="alert('Hello');">Hello</p>
291 * @result <p>Hello</p>
299 * Bind a function to the focus event of each matched element.
301 * @example $("p").focus( function() { alert("Hello"); } );
302 * @before <p>Hello</p>
303 * @result <p onfocus="alert('Hello');">Hello</p>
307 * @param Function fn A function to bind to the focus event on each of the matched elements.
312 * Trigger the focus event of each matched element. This causes all of the functions
313 * that have been bound to thet focus event to be executed.
315 * @example $("p").focus();
316 * @before <p onfocus="alert('Hello');">Hello</p>
317 * @result alert('Hello');
325 * Bind a function to the focus event of each matched element, which will only be executed once.
326 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
327 * only executed the first time it is triggered, and never again (unless it is re-bound).
329 * @example $("p").onefocus( function() { alert("Hello"); } );
330 * @before <p onfocus="alert('Hello');">Hello</p>
331 * @result alert('Hello'); // Only executed for the first focus
335 * @param Function fn A function to bind to the focus event on each of the matched elements.
340 * Removes a bound focus event from each of the matched
341 * elements. You must pass the identical function that was used in the original
344 * @example $("p").unfocus( myFunction );
345 * @before <p onfocus="myFunction">Hello</p>
346 * @result <p>Hello</p>
350 * @param Function fn A function to unbind from the focus event on each of the matched elements.
355 * Removes all bound focus events from each of the matched elements.
357 * @example $("p").unfocus();
358 * @before <p onfocus="alert('Hello');">Hello</p>
359 * @result <p>Hello</p>
367 * Bind a function to the keydown event of each matched element.
369 * @example $("p").keydown( function() { alert("Hello"); } );
370 * @before <p>Hello</p>
371 * @result <p onkeydown="alert('Hello');">Hello</p>
375 * @param Function fn A function to bind to the keydown event on each of the matched elements.
376 * @cat Events/Keyboard
380 * Trigger the keydown event of each matched element. This causes all of the functions
381 * that have been bound to thet keydown event to be executed.
383 * @example $("p").keydown();
384 * @before <p onkeydown="alert('Hello');">Hello</p>
385 * @result alert('Hello');
389 * @cat Events/Keyboard
393 * Bind a function to the keydown event of each matched element, which will only be executed once.
394 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
395 * only executed the first time it is triggered, and never again (unless it is re-bound).
397 * @example $("p").onekeydown( function() { alert("Hello"); } );
398 * @before <p onkeydown="alert('Hello');">Hello</p>
399 * @result alert('Hello'); // Only executed for the first keydown
403 * @param Function fn A function to bind to the keydown event on each of the matched elements.
404 * @cat Events/Keyboard
408 * Removes a bound keydown event from each of the matched
409 * elements. You must pass the identical function that was used in the original
412 * @example $("p").unkeydown( myFunction );
413 * @before <p onkeydown="myFunction">Hello</p>
414 * @result <p>Hello</p>
418 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
419 * @cat Events/Keyboard
423 * Removes all bound keydown events from each of the matched elements.
425 * @example $("p").unkeydown();
426 * @before <p onkeydown="alert('Hello');">Hello</p>
427 * @result <p>Hello</p>
431 * @cat Events/Keyboard
435 * Bind a function to the dblclick event of each matched element.
437 * @example $("p").dblclick( function() { alert("Hello"); } );
438 * @before <p>Hello</p>
439 * @result <p ondblclick="alert('Hello');">Hello</p>
443 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
448 * Trigger the dblclick event of each matched element. This causes all of the functions
449 * that have been bound to thet dblclick event to be executed.
451 * @example $("p").dblclick();
452 * @before <p ondblclick="alert('Hello');">Hello</p>
453 * @result alert('Hello');
461 * Bind a function to the dblclick event of each matched element, which will only be executed once.
462 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
463 * only executed the first time it is triggered, and never again (unless it is re-bound).
465 * @example $("p").onedblclick( function() { alert("Hello"); } );
466 * @before <p ondblclick="alert('Hello');">Hello</p>
467 * @result alert('Hello'); // Only executed for the first dblclick
471 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
476 * Removes a bound dblclick event from each of the matched
477 * elements. You must pass the identical function that was used in the original
480 * @example $("p").undblclick( myFunction );
481 * @before <p ondblclick="myFunction">Hello</p>
482 * @result <p>Hello</p>
486 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
491 * Removes all bound dblclick events from each of the matched elements.
493 * @example $("p").undblclick();
494 * @before <p ondblclick="alert('Hello');">Hello</p>
495 * @result <p>Hello</p>
503 * Bind a function to the keypress event of each matched element.
505 * @example $("p").keypress( function() { alert("Hello"); } );
506 * @before <p>Hello</p>
507 * @result <p onkeypress="alert('Hello');">Hello</p>
511 * @param Function fn A function to bind to the keypress event on each of the matched elements.
512 * @cat Events/Keyboard
516 * Trigger the keypress event of each matched element. This causes all of the functions
517 * that have been bound to thet keypress event to be executed.
519 * @example $("p").keypress();
520 * @before <p onkeypress="alert('Hello');">Hello</p>
521 * @result alert('Hello');
525 * @cat Events/Keyboard
529 * Bind a function to the keypress event of each matched element, which will only be executed once.
530 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
531 * only executed the first time it is triggered, and never again (unless it is re-bound).
533 * @example $("p").onekeypress( function() { alert("Hello"); } );
534 * @before <p onkeypress="alert('Hello');">Hello</p>
535 * @result alert('Hello'); // Only executed for the first keypress
539 * @param Function fn A function to bind to the keypress event on each of the matched elements.
540 * @cat Events/Keyboard
544 * Removes a bound keypress event from each of the matched
545 * elements. You must pass the identical function that was used in the original
548 * @example $("p").unkeypress( myFunction );
549 * @before <p onkeypress="myFunction">Hello</p>
550 * @result <p>Hello</p>
554 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
555 * @cat Events/Keyboard
559 * Removes all bound keypress events from each of the matched elements.
561 * @example $("p").unkeypress();
562 * @before <p onkeypress="alert('Hello');">Hello</p>
563 * @result <p>Hello</p>
567 * @cat Events/Keyboard
571 * Bind a function to the error event of each matched element.
573 * @example $("p").error( function() { alert("Hello"); } );
574 * @before <p>Hello</p>
575 * @result <p onerror="alert('Hello');">Hello</p>
579 * @param Function fn A function to bind to the error event on each of the matched elements.
580 * @cat Events/Browser
584 * Trigger the error event of each matched element. This causes all of the functions
585 * that have been bound to thet error event to be executed.
587 * @example $("p").error();
588 * @before <p onerror="alert('Hello');">Hello</p>
589 * @result alert('Hello');
593 * @cat Events/Browser
597 * Bind a function to the error event of each matched element, which will only be executed once.
598 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
599 * only executed the first time it is triggered, and never again (unless it is re-bound).
601 * @example $("p").oneerror( function() { alert("Hello"); } );
602 * @before <p onerror="alert('Hello');">Hello</p>
603 * @result alert('Hello'); // Only executed for the first error
607 * @param Function fn A function to bind to the error event on each of the matched elements.
608 * @cat Events/Browser
612 * Removes a bound error event from each of the matched
613 * elements. You must pass the identical function that was used in the original
616 * @example $("p").unerror( myFunction );
617 * @before <p onerror="myFunction">Hello</p>
618 * @result <p>Hello</p>
622 * @param Function fn A function to unbind from the error event on each of the matched elements.
623 * @cat Events/Browser
627 * Removes all bound error events from each of the matched elements.
629 * @example $("p").unerror();
630 * @before <p onerror="alert('Hello');">Hello</p>
631 * @result <p>Hello</p>
635 * @cat Events/Browser
639 * Bind a function to the blur event of each matched element.
641 * @example $("p").blur( function() { alert("Hello"); } );
642 * @before <p>Hello</p>
643 * @result <p onblur="alert('Hello');">Hello</p>
647 * @param Function fn A function to bind to the blur event on each of the matched elements.
652 * Trigger the blur event of each matched element. This causes all of the functions
653 * that have been bound to thet blur event to be executed.
655 * @example $("p").blur();
656 * @before <p onblur="alert('Hello');">Hello</p>
657 * @result alert('Hello');
665 * Bind a function to the blur event of each matched element, which will only be executed once.
666 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
667 * only executed the first time it is triggered, and never again (unless it is re-bound).
669 * @example $("p").oneblur( function() { alert("Hello"); } );
670 * @before <p onblur="alert('Hello');">Hello</p>
671 * @result alert('Hello'); // Only executed for the first blur
675 * @param Function fn A function to bind to the blur event on each of the matched elements.
680 * Removes a bound blur event from each of the matched
681 * elements. You must pass the identical function that was used in the original
684 * @example $("p").unblur( myFunction );
685 * @before <p onblur="myFunction">Hello</p>
686 * @result <p>Hello</p>
690 * @param Function fn A function to unbind from the blur event on each of the matched elements.
695 * Removes all bound blur events from each of the matched elements.
697 * @example $("p").unblur();
698 * @before <p onblur="alert('Hello');">Hello</p>
699 * @result <p>Hello</p>
707 * Bind a function to the load event of each matched element.
709 * @example $("p").load( function() { alert("Hello"); } );
710 * @before <p>Hello</p>
711 * @result <p onload="alert('Hello');">Hello</p>
715 * @param Function fn A function to bind to the load event on each of the matched elements.
716 * @cat Events/Browser
720 * Trigger the load event of each matched element. This causes all of the functions
721 * that have been bound to thet load event to be executed.
723 * Marked as private: Calling load() without arguments throws exception because the ajax load
724 * does not handle it.
726 * @example $("p").load();
727 * @before <p onload="alert('Hello');">Hello</p>
728 * @result alert('Hello');
733 * @cat Events/Browser
737 * Bind a function to the load event of each matched element, which will only be executed once.
738 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
739 * only executed the first time it is triggered, and never again (unless it is re-bound).
741 * @example $("p").oneload( function() { alert("Hello"); } );
742 * @before <p onload="alert('Hello');">Hello</p>
743 * @result alert('Hello'); // Only executed for the first load
747 * @param Function fn A function to bind to the load event on each of the matched elements.
748 * @cat Events/Browser
752 * Removes a bound load event from each of the matched
753 * elements. You must pass the identical function that was used in the original
756 * @example $("p").unload( myFunction );
757 * @before <p onload="myFunction">Hello</p>
758 * @result <p>Hello</p>
762 * @param Function fn A function to unbind from the load event on each of the matched elements.
763 * @cat Events/Browser
767 * Removes all bound load events from each of the matched elements.
769 * @example $("p").unload();
770 * @before <p onload="alert('Hello');">Hello</p>
771 * @result <p>Hello</p>
775 * @cat Events/Browser
779 * Bind a function to the select event of each matched element.
781 * @example $("p").select( function() { alert("Hello"); } );
782 * @before <p>Hello</p>
783 * @result <p onselect="alert('Hello');">Hello</p>
787 * @param Function fn A function to bind to the select event on each of the matched elements.
792 * Trigger the select event of each matched element. This causes all of the functions
793 * that have been bound to thet select event to be executed.
795 * @example $("p").select();
796 * @before <p onselect="alert('Hello');">Hello</p>
797 * @result alert('Hello');
805 * Bind a function to the select event of each matched element, which will only be executed once.
806 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
807 * only executed the first time it is triggered, and never again (unless it is re-bound).
809 * @example $("p").oneselect( function() { alert("Hello"); } );
810 * @before <p onselect="alert('Hello');">Hello</p>
811 * @result alert('Hello'); // Only executed for the first select
815 * @param Function fn A function to bind to the select event on each of the matched elements.
820 * Removes a bound select event from each of the matched
821 * elements. You must pass the identical function that was used in the original
824 * @example $("p").unselect( myFunction );
825 * @before <p onselect="myFunction">Hello</p>
826 * @result <p>Hello</p>
830 * @param Function fn A function to unbind from the select event on each of the matched elements.
835 * Removes all bound select events from each of the matched elements.
837 * @example $("p").unselect();
838 * @before <p onselect="alert('Hello');">Hello</p>
839 * @result <p>Hello</p>
847 * Bind a function to the mouseup event of each matched element.
849 * @example $("p").mouseup( function() { alert("Hello"); } );
850 * @before <p>Hello</p>
851 * @result <p onmouseup="alert('Hello');">Hello</p>
855 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
860 * Trigger the mouseup event of each matched element. This causes all of the functions
861 * that have been bound to thet mouseup event to be executed.
863 * @example $("p").mouseup();
864 * @before <p onmouseup="alert('Hello');">Hello</p>
865 * @result alert('Hello');
873 * Bind a function to the mouseup event of each matched element, which will only be executed once.
874 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
875 * only executed the first time it is triggered, and never again (unless it is re-bound).
877 * @example $("p").onemouseup( function() { alert("Hello"); } );
878 * @before <p onmouseup="alert('Hello');">Hello</p>
879 * @result alert('Hello'); // Only executed for the first mouseup
883 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
888 * Removes a bound mouseup event from each of the matched
889 * elements. You must pass the identical function that was used in the original
892 * @example $("p").unmouseup( myFunction );
893 * @before <p onmouseup="myFunction">Hello</p>
894 * @result <p>Hello</p>
898 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
903 * Removes all bound mouseup events from each of the matched elements.
905 * @example $("p").unmouseup();
906 * @before <p onmouseup="alert('Hello');">Hello</p>
907 * @result <p>Hello</p>
915 * Bind a function to the unload event of each matched element.
917 * @example $("p").unload( function() { alert("Hello"); } );
918 * @before <p>Hello</p>
919 * @result <p onunload="alert('Hello');">Hello</p>
923 * @param Function fn A function to bind to the unload event on each of the matched elements.
924 * @cat Events/Browser
928 * Trigger the unload event of each matched element. This causes all of the functions
929 * that have been bound to thet unload event to be executed.
931 * @example $("p").unload();
932 * @before <p onunload="alert('Hello');">Hello</p>
933 * @result alert('Hello');
937 * @cat Events/Browser
941 * Bind a function to the unload event of each matched element, which will only be executed once.
942 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
943 * only executed the first time it is triggered, and never again (unless it is re-bound).
945 * @example $("p").oneunload( function() { alert("Hello"); } );
946 * @before <p onunload="alert('Hello');">Hello</p>
947 * @result alert('Hello'); // Only executed for the first unload
951 * @param Function fn A function to bind to the unload event on each of the matched elements.
952 * @cat Events/Browser
956 * Removes a bound unload event from each of the matched
957 * elements. You must pass the identical function that was used in the original
960 * @example $("p").ununload( myFunction );
961 * @before <p onunload="myFunction">Hello</p>
962 * @result <p>Hello</p>
966 * @param Function fn A function to unbind from the unload event on each of the matched elements.
967 * @cat Events/Browser
971 * Removes all bound unload events from each of the matched elements.
973 * @example $("p").ununload();
974 * @before <p onunload="alert('Hello');">Hello</p>
975 * @result <p>Hello</p>
979 * @cat Events/Browser
983 * Bind a function to the change event of each matched element.
985 * @example $("p").change( function() { alert("Hello"); } );
986 * @before <p>Hello</p>
987 * @result <p onchange="alert('Hello');">Hello</p>
991 * @param Function fn A function to bind to the change event on each of the matched elements.
996 * Trigger the change event of each matched element. This causes all of the functions
997 * that have been bound to thet change event to be executed.
999 * @example $("p").change();
1000 * @before <p onchange="alert('Hello');">Hello</p>
1001 * @result alert('Hello');
1009 * Bind a function to the change event of each matched element, which will only be executed once.
1010 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
1011 * only executed the first time it is triggered, and never again (unless it is re-bound).
1013 * @example $("p").onechange( function() { alert("Hello"); } );
1014 * @before <p onchange="alert('Hello');">Hello</p>
1015 * @result alert('Hello'); // Only executed for the first change
1019 * @param Function fn A function to bind to the change event on each of the matched elements.
1024 * Removes a bound change event from each of the matched
1025 * elements. You must pass the identical function that was used in the original
1028 * @example $("p").unchange( myFunction );
1029 * @before <p onchange="myFunction">Hello</p>
1030 * @result <p>Hello</p>
1034 * @param Function fn A function to unbind from the change event on each of the matched elements.
1039 * Removes all bound change events from each of the matched elements.
1041 * @example $("p").unchange();
1042 * @before <p onchange="alert('Hello');">Hello</p>
1043 * @result <p>Hello</p>
1051 * Bind a function to the mouseout event of each matched element.
1053 * @example $("p").mouseout( function() { alert("Hello"); } );
1054 * @before <p>Hello</p>
1055 * @result <p onmouseout="alert('Hello');">Hello</p>
1059 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1064 * Trigger the mouseout event of each matched element. This causes all of the functions
1065 * that have been bound to thet mouseout event to be executed.
1067 * @example $("p").mouseout();
1068 * @before <p onmouseout="alert('Hello');">Hello</p>
1069 * @result alert('Hello');
1077 * Bind a function to the mouseout event of each matched element, which will only be executed once.
1078 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
1079 * only executed the first time it is triggered, and never again (unless it is re-bound).
1081 * @example $("p").onemouseout( function() { alert("Hello"); } );
1082 * @before <p onmouseout="alert('Hello');">Hello</p>
1083 * @result alert('Hello'); // Only executed for the first mouseout
1087 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1092 * Removes a bound mouseout event from each of the matched
1093 * elements. You must pass the identical function that was used in the original
1096 * @example $("p").unmouseout( myFunction );
1097 * @before <p onmouseout="myFunction">Hello</p>
1098 * @result <p>Hello</p>
1102 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
1107 * Removes all bound mouseout events from each of the matched elements.
1109 * @example $("p").unmouseout();
1110 * @before <p onmouseout="alert('Hello');">Hello</p>
1111 * @result <p>Hello</p>
1119 * Bind a function to the keyup event of each matched element.
1121 * @example $("p").keyup( function() { alert("Hello"); } );
1122 * @before <p>Hello</p>
1123 * @result <p onkeyup="alert('Hello');">Hello</p>
1127 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1128 * @cat Events/Keyboard
1132 * Trigger the keyup event of each matched element. This causes all of the functions
1133 * that have been bound to thet keyup event to be executed.
1135 * @example $("p").keyup();
1136 * @before <p onkeyup="alert('Hello');">Hello</p>
1137 * @result alert('Hello');
1141 * @cat Events/Keyboard
1145 * Bind a function to the keyup event of each matched element, which will only be executed once.
1146 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1147 * only executed the first time it is triggered, and never again (unless it is re-bound).
1149 * @example $("p").onekeyup( function() { alert("Hello"); } );
1150 * @before <p onkeyup="alert('Hello');">Hello</p>
1151 * @result alert('Hello'); // Only executed for the first keyup
1155 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1156 * @cat Events/Keyboard
1160 * Removes a bound keyup event from each of the matched
1161 * elements. You must pass the identical function that was used in the original
1164 * @example $("p").unkeyup( myFunction );
1165 * @before <p onkeyup="myFunction">Hello</p>
1166 * @result <p>Hello</p>
1170 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1171 * @cat Events/Keyboard
1175 * Removes all bound keyup events from each of the matched elements.
1177 * @example $("p").unkeyup();
1178 * @before <p onkeyup="alert('Hello');">Hello</p>
1179 * @result <p>Hello</p>
1183 * @cat Events/Keyboard
1187 * Bind a function to the click event of each matched element.
1189 * @example $("p").click( function() { alert("Hello"); } );
1190 * @before <p>Hello</p>
1191 * @result <p onclick="alert('Hello');">Hello</p>
1195 * @param Function fn A function to bind to the click event on each of the matched elements.
1200 * Trigger the click event of each matched element. This causes all of the functions
1201 * that have been bound to thet click event to be executed.
1203 * @example $("p").click();
1204 * @before <p onclick="alert('Hello');">Hello</p>
1205 * @result alert('Hello');
1213 * Bind a function to the click event of each matched element, which will only be executed once.
1214 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
1215 * only executed the first time it is triggered, and never again (unless it is re-bound).
1217 * @example $("p").oneclick( function() { alert("Hello"); } );
1218 * @before <p onclick="alert('Hello');">Hello</p>
1219 * @result alert('Hello'); // Only executed for the first click
1223 * @param Function fn A function to bind to the click event on each of the matched elements.
1228 * Removes a bound click event from each of the matched
1229 * elements. You must pass the identical function that was used in the original
1232 * @example $("p").unclick( myFunction );
1233 * @before <p onclick="myFunction">Hello</p>
1234 * @result <p>Hello</p>
1238 * @param Function fn A function to unbind from the click event on each of the matched elements.
1243 * Removes all bound click events from each of the matched elements.
1245 * @example $("p").unclick();
1246 * @before <p onclick="alert('Hello');">Hello</p>
1247 * @result <p>Hello</p>
1255 * Bind a function to the resize event of each matched element.
1257 * @example $("p").resize( function() { alert("Hello"); } );
1258 * @before <p>Hello</p>
1259 * @result <p onresize="alert('Hello');">Hello</p>
1263 * @param Function fn A function to bind to the resize event on each of the matched elements.
1264 * @cat Events/Browser
1268 * Trigger the resize event of each matched element. This causes all of the functions
1269 * that have been bound to thet resize event to be executed.
1271 * @example $("p").resize();
1272 * @before <p onresize="alert('Hello');">Hello</p>
1273 * @result alert('Hello');
1277 * @cat Events/Browser
1281 * Bind a function to the resize event of each matched element, which will only be executed once.
1282 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
1283 * only executed the first time it is triggered, and never again (unless it is re-bound).
1285 * @example $("p").oneresize( function() { alert("Hello"); } );
1286 * @before <p onresize="alert('Hello');">Hello</p>
1287 * @result alert('Hello'); // Only executed for the first resize
1291 * @param Function fn A function to bind to the resize event on each of the matched elements.
1292 * @cat Events/Browser
1296 * Removes a bound resize event from each of the matched
1297 * elements. You must pass the identical function that was used in the original
1300 * @example $("p").unresize( myFunction );
1301 * @before <p onresize="myFunction">Hello</p>
1302 * @result <p>Hello</p>
1306 * @param Function fn A function to unbind from the resize event on each of the matched elements.
1307 * @cat Events/Browser
1311 * Removes all bound resize events from each of the matched elements.
1313 * @example $("p").unresize();
1314 * @before <p onresize="alert('Hello');">Hello</p>
1315 * @result <p>Hello</p>
1319 * @cat Events/Browser
1323 * Bind a function to the mousemove event of each matched element.
1325 * @example $("p").mousemove( function() { alert("Hello"); } );
1326 * @before <p>Hello</p>
1327 * @result <p onmousemove="alert('Hello');">Hello</p>
1331 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1336 * Trigger the mousemove event of each matched element. This causes all of the functions
1337 * that have been bound to thet mousemove event to be executed.
1339 * @example $("p").mousemove();
1340 * @before <p onmousemove="alert('Hello');">Hello</p>
1341 * @result alert('Hello');
1349 * Bind a function to the mousemove event of each matched element, which will only be executed once.
1350 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
1351 * only executed the first time it is triggered, and never again (unless it is re-bound).
1353 * @example $("p").onemousemove( function() { alert("Hello"); } );
1354 * @before <p onmousemove="alert('Hello');">Hello</p>
1355 * @result alert('Hello'); // Only executed for the first mousemove
1357 * @name onemousemove
1359 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1364 * Removes a bound mousemove event from each of the matched
1365 * elements. You must pass the identical function that was used in the original
1368 * @example $("p").unmousemove( myFunction );
1369 * @before <p onmousemove="myFunction">Hello</p>
1370 * @result <p>Hello</p>
1374 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
1379 * Removes all bound mousemove events from each of the matched elements.
1381 * @example $("p").unmousemove();
1382 * @before <p onmousemove="alert('Hello');">Hello</p>
1383 * @result <p>Hello</p>
1391 * Bind a function to the mousedown event of each matched element.
1393 * @example $("p").mousedown( function() { alert("Hello"); } );
1394 * @before <p>Hello</p>
1395 * @result <p onmousedown="alert('Hello');">Hello</p>
1399 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1404 * Trigger the mousedown event of each matched element. This causes all of the functions
1405 * that have been bound to thet mousedown event to be executed.
1407 * @example $("p").mousedown();
1408 * @before <p onmousedown="alert('Hello');">Hello</p>
1409 * @result alert('Hello');
1417 * Bind a function to the mousedown event of each matched element, which will only be executed once.
1418 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
1419 * only executed the first time it is triggered, and never again (unless it is re-bound).
1421 * @example $("p").onemousedown( function() { alert("Hello"); } );
1422 * @before <p onmousedown="alert('Hello');">Hello</p>
1423 * @result alert('Hello'); // Only executed for the first mousedown
1425 * @name onemousedown
1427 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1432 * Removes a bound mousedown event from each of the matched
1433 * elements. You must pass the identical function that was used in the original
1436 * @example $("p").unmousedown( myFunction );
1437 * @before <p onmousedown="myFunction">Hello</p>
1438 * @result <p>Hello</p>
1442 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
1447 * Removes all bound mousedown events from each of the matched elements.
1449 * @example $("p").unmousedown();
1450 * @before <p onmousedown="alert('Hello');">Hello</p>
1451 * @result <p>Hello</p>
1459 * Bind a function to the mouseover event of each matched element.
1461 * @example $("p").mouseover( function() { alert("Hello"); } );
1462 * @before <p>Hello</p>
1463 * @result <p onmouseover="alert('Hello');">Hello</p>
1467 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1472 * Trigger the mouseover event of each matched element. This causes all of the functions
1473 * that have been bound to thet mousedown event to be executed.
1475 * @example $("p").mouseover();
1476 * @before <p onmouseover="alert('Hello');">Hello</p>
1477 * @result alert('Hello');
1485 * Bind a function to the mouseover event of each matched element, which will only be executed once.
1486 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
1487 * only executed the first time it is triggered, and never again (unless it is re-bound).
1489 * @example $("p").onemouseover( function() { alert("Hello"); } );
1490 * @before <p onmouseover="alert('Hello');">Hello</p>
1491 * @result alert('Hello'); // Only executed for the first mouseover
1493 * @name onemouseover
1495 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
1500 * Removes a bound mouseover event from each of the matched
1501 * elements. You must pass the identical function that was used in the original
1504 * @example $("p").unmouseover( myFunction );
1505 * @before <p onmouseover="myFunction">Hello</p>
1506 * @result <p>Hello</p>
1510 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
1515 * Removes all bound mouseover events from each of the matched elements.
1517 * @example $("p").unmouseover();
1518 * @before <p onmouseover="alert('Hello');">Hello</p>
1519 * @result <p>Hello</p>
1529 * var e = ("blur,focus,resize,scroll,unload,click,dblclick," +
1530 * "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1531 * "submit,keydown,keypress,keyup,error").split(",");
1532 * var handler1 = function(event) {
1535 * var handler2 = function(event) {
1538 * for( var i=0; i < e.length; i++) {
1542 * $(document)[event](handler1);
1543 * $(document)[event](handler2);
1544 * $(document)["one"+event](handler1);
1546 * // call event two times
1547 * $(document)[event]();
1548 * $(document)[event]();
1551 * $(document)["un"+event](handler1);
1553 * $(document)[event]();
1555 * // remove all handlers
1556 * $(document)["un"+event]();
1559 * $(document)[event]();
1562 * ok( count == 6, 'Checking event ' + event);
1566 * @name eventTesting
1570 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1571 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1572 "submit,keydown,keypress,keyup,error").split(",");
1574 // Go through all the event names, but make sure that
1575 // it is enclosed properly
1576 for ( var i = 0; i < e.length; i++ ) new function(){
1580 // Handle event binding
1581 jQuery.fn[o] = function(f){
1582 return f ? this.bind(o, f) : this.trigger(o);
1585 // Handle event unbinding
1586 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1588 // Finally, handle events that only fire once
1589 jQuery.fn["one"+o] = function(f){
1590 // Attach the event listener
1591 return this.each(function(){
1596 jQuery.event.add( this, o, function(e){
1597 // If this function has already been executed, stop
1598 if ( count++ ) return;
1600 // And execute the bound function
1601 return f.apply(this, [e]);
1608 // If Mozilla is used
1609 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1610 // Use the handy event callback
1611 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1613 // If IE is used, use the excellent hack by Matthias Miller
1614 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1615 } else if ( jQuery.browser.msie ) {
1617 // Only works if you document.write() it
1618 document.write("<scr" + "ipt id=__ie_init defer=true " +
1619 "src=//:><\/script>");
1621 // Use the defer script hack
1622 var script = document.getElementById("__ie_init");
1623 script.onreadystatechange = function() {
1624 if ( this.readyState != "complete" ) return;
1625 this.parentNode.removeChild( this );
1629 // Clear from memory
1632 // If Safari is used
1633 } else if ( jQuery.browser.safari ) {
1634 // Continually check to see if the document.readyState is valid
1635 jQuery.safariTimer = setInterval(function(){
1636 // loaded and complete are both valid states
1637 if ( document.readyState == "loaded" ||
1638 document.readyState == "complete" ) {
1640 // If either one are found, remove the timer
1641 clearInterval( jQuery.safariTimer );
1642 jQuery.safariTimer = null;
1644 // and execute any waiting functions
1650 // A fallback to window.onload, that will always work
1651 jQuery.event.add( window, "load", jQuery.ready );
1655 // Clean up after IE to avoid memory leaks
1656 if ($.browser.msie) $(window).unload(function() {
1657 var event = jQuery.event, global = event.global;
1658 for (var type in global) {
1659 var els = global[type], i = els.length;
1660 if (i>0) do event.remove(els[i-1], type); while (--i);