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");
21 * @param Function even The function to execute on every even click.
22 * @param Function odd The function to execute on every odd click.
25 toggle: function(a,b) {
26 // If two functions are passed in, we're
27 // toggling on a click
28 return a && b ? this.click(function(e){
29 // Figure out which function to execute
30 this.last = this.last == a ? b : a;
32 // Make sure that clicks stop
35 // and execute the function
36 return this.last.apply( this, [e] ) || false;
39 // Otherwise, execute the old toggle function
44 * A method for simulating hovering (moving the mouse on, and off,
45 * an object). This is a custom method which provides an 'in' to a
48 * Whenever the mouse cursor is moved over a matched
49 * element, the first specified function is fired. Whenever the mouse
50 * moves off of the element, the second specified function fires.
51 * Additionally, checks are in place to see if the mouse is still within
52 * the specified element itself (for example, an image inside of a div),
53 * and if it is, it will continue to 'hover', and not move out
54 * (a common error in using a mouseout event handler).
56 * @example $("p").hover(function(){
57 * $(this).addClass("over");
59 * $(this).addClass("out");
64 * @param Function over The function to fire whenever the mouse is moved over a matched element.
65 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
68 hover: function(f,g) {
70 // A private function for haandling mouse 'hovering'
71 function handleHover(e) {
72 // Check if mouse(over|out) are still within the same parent element
73 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
75 // Traverse up the tree
76 while ( p && p != this ) p = p.parentNode;
78 // If we actually just moused on to a sub-element, ignore it
79 if ( p == this ) return false;
81 // Execute the right function
82 return (e.type == "mouseover" ? f : g).apply(this, [e]);
85 // Bind the function to the two event listeners
86 return this.mouseover(handleHover).mouseout(handleHover);
90 * Bind a function to be executed whenever the DOM is ready to be
91 * traversed and manipulated. This is probably the most important
92 * function included in the event module, as it can greatly improve
93 * the response times of your web applications.
95 * In a nutshell, this is a solid replacement for using window.onload,
96 * and attaching a function to that. By using this method, your bound Function
97 * will be called the instant the DOM is ready to be read and manipulated,
98 * which is exactly what 99.99% of all Javascript code needs to run.
100 * Please ensure you have no code in your <body> onload event handler,
101 * otherwise $(document).ready() may not fire.
103 * @example $(document).ready(function(){ Your code here... });
107 * @param Function fn The function to be executed when the DOM is ready.
111 // If the DOM is already ready
112 if ( jQuery.isReady )
113 // Execute the function immediately
116 // Otherwise, remember the function for later
118 // Add the function to the wait list
119 jQuery.readyList.push( f );
128 * All the code that makes DOM Ready work nicely.
133 // Handle when the DOM is ready
135 // Make sure that the DOM is not already loaded
136 if ( !jQuery.isReady ) {
137 // Remember that the DOM is ready
138 jQuery.isReady = true;
140 // If there are functions bound, to execute
141 if ( jQuery.readyList ) {
142 // Execute all of them
143 for ( var i = 0; i < jQuery.readyList.length; i++ )
144 jQuery.readyList[i].apply( document );
146 // Reset the list of functions
147 jQuery.readyList = null;
156 * Bind a function to the blur event of each matched element.
158 * @example $("p").blur( function() { alert("Hello"); } );
159 * @before <p>Hello</p>
160 * @result <p onblur="alert('Hello');">Hello</p>
164 * @param Function fn A function to bind to the blur event on each of the matched elements.
169 * Trigger the blur event of each matched element. This causes all of the functions
170 * that have been bound to thet blur event to be executed.
172 * @example $("p").blur();
173 * @before <p onblur="alert('Hello');">Hello</p>
174 * @result alert('Hello');
182 * Bind a function to the blur event of each matched element, which will only be executed once.
183 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
184 * only executed the first time it is triggered, and never again (unless it is re-bound).
186 * @example $("p").oneblur( function() { alert("Hello"); } );
187 * @before <p onblur="alert('Hello');">Hello</p>
188 * @result alert('Hello'); // Only executed for the first blur
192 * @param Function fn A function to bind to the blur event on each of the matched elements.
197 * Removes a bound blur event from each of the matched
198 * elements. You must pass the identical function that was used in the original
201 * @example $("p").unblur( myFunction );
202 * @before <p onblur="myFunction">Hello</p>
203 * @result <p>Hello</p>
207 * @param Function fn A function to unbind from the blur event on each of the matched elements.
212 * Removes all bound blur events from each of the matched elements.
214 * @example $("p").unblur();
215 * @before <p onblur="alert('Hello');">Hello</p>
216 * @result <p>Hello</p>
224 * Bind a function to the focus event of each matched element.
226 * @example $("p").focus( function() { alert("Hello"); } );
227 * @before <p>Hello</p>
228 * @result <p onfocus="alert('Hello');">Hello</p>
232 * @param Function fn A function to bind to the focus event on each of the matched elements.
237 * Trigger the focus event of each matched element. This causes all of the functions
238 * that have been bound to thet focus event to be executed.
240 * @example $("p").focus();
241 * @before <p onfocus="alert('Hello');">Hello</p>
242 * @result alert('Hello');
250 * Bind a function to the focus event of each matched element, which will only be executed once.
251 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
252 * only executed the first time it is triggered, and never again (unless it is re-bound).
254 * @example $("p").onefocus( function() { alert("Hello"); } );
255 * @before <p onfocus="alert('Hello');">Hello</p>
256 * @result alert('Hello'); // Only executed for the first focus
260 * @param Function fn A function to bind to the focus event on each of the matched elements.
265 * Removes a bound focus event from each of the matched
266 * elements. You must pass the identical function that was used in the original
269 * @example $("p").unfocus( myFunction );
270 * @before <p onfocus="myFunction">Hello</p>
271 * @result <p>Hello</p>
275 * @param Function fn A function to unbind from the focus event on each of the matched elements.
280 * Removes all bound focus events from each of the matched elements.
282 * @example $("p").unfocus();
283 * @before <p onfocus="alert('Hello');">Hello</p>
284 * @result <p>Hello</p>
292 * Bind a function to the load event of each matched element.
294 * @example $("p").load( function() { alert("Hello"); } );
295 * @before <p>Hello</p>
296 * @result <p onload="alert('Hello');">Hello</p>
300 * @param Function fn A function to bind to the load event on each of the matched elements.
305 * Trigger the load event of each matched element. This causes all of the functions
306 * that have been bound to thet load event to be executed.
308 * @example $("p").load();
309 * @before <p onload="alert('Hello');">Hello</p>
310 * @result alert('Hello');
318 * Bind a function to the load event of each matched element, which will only be executed once.
319 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
320 * only executed the first time it is triggered, and never again (unless it is re-bound).
322 * @example $("p").oneload( function() { alert("Hello"); } );
323 * @before <p onload="alert('Hello');">Hello</p>
324 * @result alert('Hello'); // Only executed for the first load
328 * @param Function fn A function to bind to the load event on each of the matched elements.
333 * Removes a bound load event from each of the matched
334 * elements. You must pass the identical function that was used in the original
337 * @example $("p").unload( myFunction );
338 * @before <p onload="myFunction">Hello</p>
339 * @result <p>Hello</p>
343 * @param Function fn A function to unbind from the load event on each of the matched elements.
348 * Removes all bound load events from each of the matched elements.
350 * @example $("p").unload();
351 * @before <p onload="alert('Hello');">Hello</p>
352 * @result <p>Hello</p>
360 * Bind a function to the resize event of each matched element.
362 * @example $("p").resize( function() { alert("Hello"); } );
363 * @before <p>Hello</p>
364 * @result <p onresize="alert('Hello');">Hello</p>
368 * @param Function fn A function to bind to the resize event on each of the matched elements.
373 * Trigger the resize event of each matched element. This causes all of the functions
374 * that have been bound to thet resize event to be executed.
376 * @example $("p").resize();
377 * @before <p onresize="alert('Hello');">Hello</p>
378 * @result alert('Hello');
386 * Bind a function to the resize event of each matched element, which will only be executed once.
387 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
388 * only executed the first time it is triggered, and never again (unless it is re-bound).
390 * @example $("p").oneresize( function() { alert("Hello"); } );
391 * @before <p onresize="alert('Hello');">Hello</p>
392 * @result alert('Hello'); // Only executed for the first resize
396 * @param Function fn A function to bind to the resize event on each of the matched elements.
401 * Removes a bound resize event from each of the matched
402 * elements. You must pass the identical function that was used in the original
405 * @example $("p").unresize( myFunction );
406 * @before <p onresize="myFunction">Hello</p>
407 * @result <p>Hello</p>
411 * @param Function fn A function to unbind from the resize event on each of the matched elements.
416 * Removes all bound resize events from each of the matched elements.
418 * @example $("p").unresize();
419 * @before <p onresize="alert('Hello');">Hello</p>
420 * @result <p>Hello</p>
428 * Bind a function to the scroll event of each matched element.
430 * @example $("p").scroll( function() { alert("Hello"); } );
431 * @before <p>Hello</p>
432 * @result <p onscroll="alert('Hello');">Hello</p>
436 * @param Function fn A function to bind to the scroll event on each of the matched elements.
441 * Trigger the scroll event of each matched element. This causes all of the functions
442 * that have been bound to thet scroll event to be executed.
444 * @example $("p").scroll();
445 * @before <p onscroll="alert('Hello');">Hello</p>
446 * @result alert('Hello');
454 * Bind a function to the scroll event of each matched element, which will only be executed once.
455 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
456 * only executed the first time it is triggered, and never again (unless it is re-bound).
458 * @example $("p").onescroll( function() { alert("Hello"); } );
459 * @before <p onscroll="alert('Hello');">Hello</p>
460 * @result alert('Hello'); // Only executed for the first scroll
464 * @param Function fn A function to bind to the scroll event on each of the matched elements.
469 * Removes a bound scroll event from each of the matched
470 * elements. You must pass the identical function that was used in the original
473 * @example $("p").unscroll( myFunction );
474 * @before <p onscroll="myFunction">Hello</p>
475 * @result <p>Hello</p>
479 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
484 * Removes all bound scroll events from each of the matched elements.
486 * @example $("p").unscroll();
487 * @before <p onscroll="alert('Hello');">Hello</p>
488 * @result <p>Hello</p>
496 * Bind a function to the unload event of each matched element.
498 * @example $("p").unload( function() { alert("Hello"); } );
499 * @before <p>Hello</p>
500 * @result <p onunload="alert('Hello');">Hello</p>
504 * @param Function fn A function to bind to the unload event on each of the matched elements.
509 * Trigger the unload event of each matched element. This causes all of the functions
510 * that have been bound to thet unload event to be executed.
512 * @example $("p").unload();
513 * @before <p onunload="alert('Hello');">Hello</p>
514 * @result alert('Hello');
522 * Bind a function to the unload event of each matched element, which will only be executed once.
523 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
524 * only executed the first time it is triggered, and never again (unless it is re-bound).
526 * @example $("p").oneunload( function() { alert("Hello"); } );
527 * @before <p onunload="alert('Hello');">Hello</p>
528 * @result alert('Hello'); // Only executed for the first unload
532 * @param Function fn A function to bind to the unload event on each of the matched elements.
537 * Removes a bound unload event from each of the matched
538 * elements. You must pass the identical function that was used in the original
541 * @example $("p").ununload( myFunction );
542 * @before <p onunload="myFunction">Hello</p>
543 * @result <p>Hello</p>
547 * @param Function fn A function to unbind from the unload event on each of the matched elements.
552 * Removes all bound unload events from each of the matched elements.
554 * @example $("p").ununload();
555 * @before <p onunload="alert('Hello');">Hello</p>
556 * @result <p>Hello</p>
564 * Bind a function to the click event of each matched element.
566 * @example $("p").click( function() { alert("Hello"); } );
567 * @before <p>Hello</p>
568 * @result <p onclick="alert('Hello');">Hello</p>
572 * @param Function fn A function to bind to the click event on each of the matched elements.
577 * Trigger the click event of each matched element. This causes all of the functions
578 * that have been bound to thet click event to be executed.
580 * @example $("p").click();
581 * @before <p onclick="alert('Hello');">Hello</p>
582 * @result alert('Hello');
590 * Bind a function to the click event of each matched element, which will only be executed once.
591 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
592 * only executed the first time it is triggered, and never again (unless it is re-bound).
594 * @example $("p").oneclick( function() { alert("Hello"); } );
595 * @before <p onclick="alert('Hello');">Hello</p>
596 * @result alert('Hello'); // Only executed for the first click
600 * @param Function fn A function to bind to the click event on each of the matched elements.
605 * Removes a bound click event from each of the matched
606 * elements. You must pass the identical function that was used in the original
609 * @example $("p").unclick( myFunction );
610 * @before <p onclick="myFunction">Hello</p>
611 * @result <p>Hello</p>
615 * @param Function fn A function to unbind from the click event on each of the matched elements.
620 * Removes all bound click events from each of the matched elements.
622 * @example $("p").unclick();
623 * @before <p onclick="alert('Hello');">Hello</p>
624 * @result <p>Hello</p>
632 * Bind a function to the dblclick event of each matched element.
634 * @example $("p").dblclick( function() { alert("Hello"); } );
635 * @before <p>Hello</p>
636 * @result <p ondblclick="alert('Hello');">Hello</p>
640 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
645 * Trigger the dblclick event of each matched element. This causes all of the functions
646 * that have been bound to thet dblclick event to be executed.
648 * @example $("p").dblclick();
649 * @before <p ondblclick="alert('Hello');">Hello</p>
650 * @result alert('Hello');
658 * Bind a function to the dblclick event of each matched element, which will only be executed once.
659 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
660 * only executed the first time it is triggered, and never again (unless it is re-bound).
662 * @example $("p").onedblclick( function() { alert("Hello"); } );
663 * @before <p ondblclick="alert('Hello');">Hello</p>
664 * @result alert('Hello'); // Only executed for the first dblclick
668 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
673 * Removes a bound dblclick event from each of the matched
674 * elements. You must pass the identical function that was used in the original
677 * @example $("p").undblclick( myFunction );
678 * @before <p ondblclick="myFunction">Hello</p>
679 * @result <p>Hello</p>
683 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
688 * Removes all bound dblclick events from each of the matched elements.
690 * @example $("p").undblclick();
691 * @before <p ondblclick="alert('Hello');">Hello</p>
692 * @result <p>Hello</p>
700 * Bind a function to the mousedown event of each matched element.
702 * @example $("p").mousedown( function() { alert("Hello"); } );
703 * @before <p>Hello</p>
704 * @result <p onmousedown="alert('Hello');">Hello</p>
708 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
713 * Trigger the mousedown event of each matched element. This causes all of the functions
714 * that have been bound to thet mousedown event to be executed.
716 * @example $("p").mousedown();
717 * @before <p onmousedown="alert('Hello');">Hello</p>
718 * @result alert('Hello');
726 * Bind a function to the mousedown event of each matched element, which will only be executed once.
727 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
728 * only executed the first time it is triggered, and never again (unless it is re-bound).
730 * @example $("p").onemousedown( function() { alert("Hello"); } );
731 * @before <p onmousedown="alert('Hello');">Hello</p>
732 * @result alert('Hello'); // Only executed for the first mousedown
736 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
741 * Removes a bound mousedown event from each of the matched
742 * elements. You must pass the identical function that was used in the original
745 * @example $("p").unmousedown( myFunction );
746 * @before <p onmousedown="myFunction">Hello</p>
747 * @result <p>Hello</p>
751 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
756 * Removes all bound mousedown events from each of the matched elements.
758 * @example $("p").unmousedown();
759 * @before <p onmousedown="alert('Hello');">Hello</p>
760 * @result <p>Hello</p>
768 * Bind a function to the mouseup event of each matched element.
770 * @example $("p").mouseup( function() { alert("Hello"); } );
771 * @before <p>Hello</p>
772 * @result <p onmouseup="alert('Hello');">Hello</p>
776 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
781 * Trigger the mouseup event of each matched element. This causes all of the functions
782 * that have been bound to thet mouseup event to be executed.
784 * @example $("p").mouseup();
785 * @before <p onmouseup="alert('Hello');">Hello</p>
786 * @result alert('Hello');
794 * Bind a function to the mouseup event of each matched element, which will only be executed once.
795 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
796 * only executed the first time it is triggered, and never again (unless it is re-bound).
798 * @example $("p").onemouseup( function() { alert("Hello"); } );
799 * @before <p onmouseup="alert('Hello');">Hello</p>
800 * @result alert('Hello'); // Only executed for the first mouseup
804 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
809 * Removes a bound mouseup event from each of the matched
810 * elements. You must pass the identical function that was used in the original
813 * @example $("p").unmouseup( myFunction );
814 * @before <p onmouseup="myFunction">Hello</p>
815 * @result <p>Hello</p>
819 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
824 * Removes all bound mouseup events from each of the matched elements.
826 * @example $("p").unmouseup();
827 * @before <p onmouseup="alert('Hello');">Hello</p>
828 * @result <p>Hello</p>
836 * Bind a function to the mousemove event of each matched element.
838 * @example $("p").mousemove( function() { alert("Hello"); } );
839 * @before <p>Hello</p>
840 * @result <p onmousemove="alert('Hello');">Hello</p>
844 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
849 * Trigger the mousemove event of each matched element. This causes all of the functions
850 * that have been bound to thet mousemove event to be executed.
852 * @example $("p").mousemove();
853 * @before <p onmousemove="alert('Hello');">Hello</p>
854 * @result alert('Hello');
862 * Bind a function to the mousemove event of each matched element, which will only be executed once.
863 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
864 * only executed the first time it is triggered, and never again (unless it is re-bound).
866 * @example $("p").onemousemove( function() { alert("Hello"); } );
867 * @before <p onmousemove="alert('Hello');">Hello</p>
868 * @result alert('Hello'); // Only executed for the first mousemove
872 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
877 * Removes a bound mousemove event from each of the matched
878 * elements. You must pass the identical function that was used in the original
881 * @example $("p").unmousemove( myFunction );
882 * @before <p onmousemove="myFunction">Hello</p>
883 * @result <p>Hello</p>
887 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
892 * Removes all bound mousemove events from each of the matched elements.
894 * @example $("p").unmousemove();
895 * @before <p onmousemove="alert('Hello');">Hello</p>
896 * @result <p>Hello</p>
904 * Bind a function to the mouseover event of each matched element.
906 * @example $("p").mouseover( function() { alert("Hello"); } );
907 * @before <p>Hello</p>
908 * @result <p onmouseover="alert('Hello');">Hello</p>
912 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
917 * Trigger the mouseover event of each matched element. This causes all of the functions
918 * that have been bound to thet mouseover event to be executed.
920 * @example $("p").mouseover();
921 * @before <p onmouseover="alert('Hello');">Hello</p>
922 * @result alert('Hello');
930 * Bind a function to the mouseover event of each matched element, which will only be executed once.
931 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
932 * only executed the first time it is triggered, and never again (unless it is re-bound).
934 * @example $("p").onemouseover( function() { alert("Hello"); } );
935 * @before <p onmouseover="alert('Hello');">Hello</p>
936 * @result alert('Hello'); // Only executed for the first mouseover
940 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
945 * Removes a bound mouseover event from each of the matched
946 * elements. You must pass the identical function that was used in the original
949 * @example $("p").unmouseover( myFunction );
950 * @before <p onmouseover="myFunction">Hello</p>
951 * @result <p>Hello</p>
955 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
960 * Removes all bound mouseover events from each of the matched elements.
962 * @example $("p").unmouseover();
963 * @before <p onmouseover="alert('Hello');">Hello</p>
964 * @result <p>Hello</p>
972 * Bind a function to the mouseout event of each matched element.
974 * @example $("p").mouseout( function() { alert("Hello"); } );
975 * @before <p>Hello</p>
976 * @result <p onmouseout="alert('Hello');">Hello</p>
980 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
985 * Trigger the mouseout event of each matched element. This causes all of the functions
986 * that have been bound to thet mouseout event to be executed.
988 * @example $("p").mouseout();
989 * @before <p onmouseout="alert('Hello');">Hello</p>
990 * @result alert('Hello');
998 * Bind a function to the mouseout event of each matched element, which will only be executed once.
999 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
1000 * only executed the first time it is triggered, and never again (unless it is re-bound).
1002 * @example $("p").onemouseout( function() { alert("Hello"); } );
1003 * @before <p onmouseout="alert('Hello');">Hello</p>
1004 * @result alert('Hello'); // Only executed for the first mouseout
1008 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1013 * Removes a bound mouseout event from each of the matched
1014 * elements. You must pass the identical function that was used in the original
1017 * @example $("p").unmouseout( myFunction );
1018 * @before <p onmouseout="myFunction">Hello</p>
1019 * @result <p>Hello</p>
1023 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
1028 * Removes all bound mouseout events from each of the matched elements.
1030 * @example $("p").unmouseout();
1031 * @before <p onmouseout="alert('Hello');">Hello</p>
1032 * @result <p>Hello</p>
1040 * Bind a function to the change event of each matched element.
1042 * @example $("p").change( function() { alert("Hello"); } );
1043 * @before <p>Hello</p>
1044 * @result <p onchange="alert('Hello');">Hello</p>
1048 * @param Function fn A function to bind to the change event on each of the matched elements.
1053 * Trigger the change event of each matched element. This causes all of the functions
1054 * that have been bound to thet change event to be executed.
1056 * @example $("p").change();
1057 * @before <p onchange="alert('Hello');">Hello</p>
1058 * @result alert('Hello');
1066 * Bind a function to the change event of each matched element, which will only be executed once.
1067 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
1068 * only executed the first time it is triggered, and never again (unless it is re-bound).
1070 * @example $("p").onechange( function() { alert("Hello"); } );
1071 * @before <p onchange="alert('Hello');">Hello</p>
1072 * @result alert('Hello'); // Only executed for the first change
1076 * @param Function fn A function to bind to the change event on each of the matched elements.
1081 * Removes a bound change event from each of the matched
1082 * elements. You must pass the identical function that was used in the original
1085 * @example $("p").unchange( myFunction );
1086 * @before <p onchange="myFunction">Hello</p>
1087 * @result <p>Hello</p>
1091 * @param Function fn A function to unbind from the change event on each of the matched elements.
1096 * Removes all bound change events from each of the matched elements.
1098 * @example $("p").unchange();
1099 * @before <p onchange="alert('Hello');">Hello</p>
1100 * @result <p>Hello</p>
1108 * Bind a function to the reset event of each matched element.
1110 * @example $("p").reset( function() { alert("Hello"); } );
1111 * @before <p>Hello</p>
1112 * @result <p onreset="alert('Hello');">Hello</p>
1116 * @param Function fn A function to bind to the reset event on each of the matched elements.
1121 * Trigger the reset event of each matched element. This causes all of the functions
1122 * that have been bound to thet reset event to be executed.
1124 * @example $("p").reset();
1125 * @before <p onreset="alert('Hello');">Hello</p>
1126 * @result alert('Hello');
1134 * Bind a function to the reset event of each matched element, which will only be executed once.
1135 * Unlike a call to the normal .reset() method, calling .onereset() causes the bound function to be
1136 * only executed the first time it is triggered, and never again (unless it is re-bound).
1138 * @example $("p").onereset( function() { alert("Hello"); } );
1139 * @before <p onreset="alert('Hello');">Hello</p>
1140 * @result alert('Hello'); // Only executed for the first reset
1144 * @param Function fn A function to bind to the reset event on each of the matched elements.
1149 * Removes a bound reset event from each of the matched
1150 * elements. You must pass the identical function that was used in the original
1153 * @example $("p").unreset( myFunction );
1154 * @before <p onreset="myFunction">Hello</p>
1155 * @result <p>Hello</p>
1159 * @param Function fn A function to unbind from the reset event on each of the matched elements.
1164 * Removes all bound reset events from each of the matched elements.
1166 * @example $("p").unreset();
1167 * @before <p onreset="alert('Hello');">Hello</p>
1168 * @result <p>Hello</p>
1176 * Bind a function to the select event of each matched element.
1178 * @example $("p").select( function() { alert("Hello"); } );
1179 * @before <p>Hello</p>
1180 * @result <p onselect="alert('Hello');">Hello</p>
1184 * @param Function fn A function to bind to the select event on each of the matched elements.
1189 * Trigger the select event of each matched element. This causes all of the functions
1190 * that have been bound to thet select event to be executed.
1192 * @example $("p").select();
1193 * @before <p onselect="alert('Hello');">Hello</p>
1194 * @result alert('Hello');
1202 * Bind a function to the select event of each matched element, which will only be executed once.
1203 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
1204 * only executed the first time it is triggered, and never again (unless it is re-bound).
1206 * @example $("p").oneselect( function() { alert("Hello"); } );
1207 * @before <p onselect="alert('Hello');">Hello</p>
1208 * @result alert('Hello'); // Only executed for the first select
1212 * @param Function fn A function to bind to the select event on each of the matched elements.
1217 * Removes a bound select event from each of the matched
1218 * elements. You must pass the identical function that was used in the original
1221 * @example $("p").unselect( myFunction );
1222 * @before <p onselect="myFunction">Hello</p>
1223 * @result <p>Hello</p>
1227 * @param Function fn A function to unbind from the select event on each of the matched elements.
1232 * Removes all bound select events from each of the matched elements.
1234 * @example $("p").unselect();
1235 * @before <p onselect="alert('Hello');">Hello</p>
1236 * @result <p>Hello</p>
1244 * Bind a function to the submit event of each matched element.
1246 * @example $("p").submit( function() { alert("Hello"); } );
1247 * @before <p>Hello</p>
1248 * @result <p onsubmit="alert('Hello');">Hello</p>
1252 * @param Function fn A function to bind to the submit event on each of the matched elements.
1257 * Trigger the submit event of each matched element. This causes all of the functions
1258 * that have been bound to thet submit event to be executed.
1260 * @example $("p").submit();
1261 * @before <p onsubmit="alert('Hello');">Hello</p>
1262 * @result alert('Hello');
1270 * Bind a function to the submit event of each matched element, which will only be executed once.
1271 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
1272 * only executed the first time it is triggered, and never again (unless it is re-bound).
1274 * @example $("p").onesubmit( function() { alert("Hello"); } );
1275 * @before <p onsubmit="alert('Hello');">Hello</p>
1276 * @result alert('Hello'); // Only executed for the first submit
1280 * @param Function fn A function to bind to the submit event on each of the matched elements.
1285 * Removes a bound submit event from each of the matched
1286 * elements. You must pass the identical function that was used in the original
1289 * @example $("p").unsubmit( myFunction );
1290 * @before <p onsubmit="myFunction">Hello</p>
1291 * @result <p>Hello</p>
1295 * @param Function fn A function to unbind from the submit event on each of the matched elements.
1300 * Removes all bound submit events from each of the matched elements.
1302 * @example $("p").unsubmit();
1303 * @before <p onsubmit="alert('Hello');">Hello</p>
1304 * @result <p>Hello</p>
1312 * Bind a function to the keydown event of each matched element.
1314 * @example $("p").keydown( function() { alert("Hello"); } );
1315 * @before <p>Hello</p>
1316 * @result <p onkeydown="alert('Hello');">Hello</p>
1320 * @param Function fn A function to bind to the keydown event on each of the matched elements.
1325 * Trigger the keydown event of each matched element. This causes all of the functions
1326 * that have been bound to thet keydown event to be executed.
1328 * @example $("p").keydown();
1329 * @before <p onkeydown="alert('Hello');">Hello</p>
1330 * @result alert('Hello');
1338 * Bind a function to the keydown event of each matched element, which will only be executed once.
1339 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
1340 * only executed the first time it is triggered, and never again (unless it is re-bound).
1342 * @example $("p").onekeydown( function() { alert("Hello"); } );
1343 * @before <p onkeydown="alert('Hello');">Hello</p>
1344 * @result alert('Hello'); // Only executed for the first keydown
1348 * @param Function fn A function to bind to the keydown event on each of the matched elements.
1353 * Removes a bound keydown event from each of the matched
1354 * elements. You must pass the identical function that was used in the original
1357 * @example $("p").unkeydown( myFunction );
1358 * @before <p onkeydown="myFunction">Hello</p>
1359 * @result <p>Hello</p>
1363 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
1368 * Removes all bound keydown events from each of the matched elements.
1370 * @example $("p").unkeydown();
1371 * @before <p onkeydown="alert('Hello');">Hello</p>
1372 * @result <p>Hello</p>
1380 * Bind a function to the keypress event of each matched element.
1382 * @example $("p").keypress( function() { alert("Hello"); } );
1383 * @before <p>Hello</p>
1384 * @result <p onkeypress="alert('Hello');">Hello</p>
1388 * @param Function fn A function to bind to the keypress event on each of the matched elements.
1393 * Trigger the keypress event of each matched element. This causes all of the functions
1394 * that have been bound to thet keypress event to be executed.
1396 * @example $("p").keypress();
1397 * @before <p onkeypress="alert('Hello');">Hello</p>
1398 * @result alert('Hello');
1406 * Bind a function to the keypress event of each matched element, which will only be executed once.
1407 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
1408 * only executed the first time it is triggered, and never again (unless it is re-bound).
1410 * @example $("p").onekeypress( function() { alert("Hello"); } );
1411 * @before <p onkeypress="alert('Hello');">Hello</p>
1412 * @result alert('Hello'); // Only executed for the first keypress
1416 * @param Function fn A function to bind to the keypress event on each of the matched elements.
1421 * Removes a bound keypress event from each of the matched
1422 * elements. You must pass the identical function that was used in the original
1425 * @example $("p").unkeypress( myFunction );
1426 * @before <p onkeypress="myFunction">Hello</p>
1427 * @result <p>Hello</p>
1431 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
1436 * Removes all bound keypress events from each of the matched elements.
1438 * @example $("p").unkeypress();
1439 * @before <p onkeypress="alert('Hello');">Hello</p>
1440 * @result <p>Hello</p>
1448 * Bind a function to the keyup event of each matched element.
1450 * @example $("p").keyup( function() { alert("Hello"); } );
1451 * @before <p>Hello</p>
1452 * @result <p onkeyup="alert('Hello');">Hello</p>
1456 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1461 * Trigger the keyup event of each matched element. This causes all of the functions
1462 * that have been bound to thet keyup event to be executed.
1464 * @example $("p").keyup();
1465 * @before <p onkeyup="alert('Hello');">Hello</p>
1466 * @result alert('Hello');
1474 * Bind a function to the keyup event of each matched element, which will only be executed once.
1475 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1476 * only executed the first time it is triggered, and never again (unless it is re-bound).
1478 * @example $("p").onekeyup( function() { alert("Hello"); } );
1479 * @before <p onkeyup="alert('Hello');">Hello</p>
1480 * @result alert('Hello'); // Only executed for the first keyup
1484 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1489 * Removes a bound keyup event from each of the matched
1490 * elements. You must pass the identical function that was used in the original
1493 * @example $("p").unkeyup( myFunction );
1494 * @before <p onkeyup="myFunction">Hello</p>
1495 * @result <p>Hello</p>
1499 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1504 * Removes all bound keyup events from each of the matched elements.
1506 * @example $("p").unkeyup();
1507 * @before <p onkeyup="alert('Hello');">Hello</p>
1508 * @result <p>Hello</p>
1516 * Bind a function to the error event of each matched element.
1518 * @example $("p").error( function() { alert("Hello"); } );
1519 * @before <p>Hello</p>
1520 * @result <p onerror="alert('Hello');">Hello</p>
1524 * @param Function fn A function to bind to the error event on each of the matched elements.
1529 * Trigger the error event of each matched element. This causes all of the functions
1530 * that have been bound to thet error event to be executed.
1532 * @example $("p").error();
1533 * @before <p onerror="alert('Hello');">Hello</p>
1534 * @result alert('Hello');
1542 * Bind a function to the error event of each matched element, which will only be executed once.
1543 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
1544 * only executed the first time it is triggered, and never again (unless it is re-bound).
1546 * @example $("p").oneerror( function() { alert("Hello"); } );
1547 * @before <p onerror="alert('Hello');">Hello</p>
1548 * @result alert('Hello'); // Only executed for the first error
1552 * @param Function fn A function to bind to the error event on each of the matched elements.
1557 * Removes a bound error event from each of the matched
1558 * elements. You must pass the identical function that was used in the original
1561 * @example $("p").unerror( myFunction );
1562 * @before <p onerror="myFunction">Hello</p>
1563 * @result <p>Hello</p>
1567 * @param Function fn A function to unbind from the error event on each of the matched elements.
1572 * Removes all bound error events from each of the matched elements.
1574 * @example $("p").unerror();
1575 * @before <p onerror="alert('Hello');">Hello</p>
1576 * @result <p>Hello</p>
1583 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1584 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1585 "submit,keydown,keypress,keyup,error").split(",");
1587 // Go through all the event names, but make sure that
1588 // it is enclosed properly
1589 for ( var i = 0; i < e.length; i++ ) new function(){
1593 // Handle event binding
1594 jQuery.fn[o] = function(f){
1595 return f ? this.bind(o, f) : this.trigger(o);
1598 // Handle event unbinding
1599 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1601 // Finally, handle events that only fire once
1602 jQuery.fn["one"+o] = function(f){
1603 // Attach the event listener
1604 return this.each(function(){
1609 jQuery.event.add( this, o, function(e){
1610 // If this function has already been executed, stop
1611 if ( count++ ) return;
1613 // And execute the bound function
1614 return f.apply(this, [e]);
1621 // If Mozilla is used
1622 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1623 // Use the handy event callback
1624 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1626 // If IE is used, use the excellent hack by Matthias Miller
1627 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1628 } else if ( jQuery.browser.msie ) {
1630 // Only works if you document.write() it
1631 document.write("<scr" + "ipt id=__ie_init defer=true " +
1632 "src=//:><\/script>");
1634 // Use the defer script hack
1635 var script = document.getElementById("__ie_init");
1636 script.onreadystatechange = function() {
1637 if ( this.readyState == "complete" )
1641 // Clear from memory
1644 // If Safari is used
1645 } else if ( jQuery.browser.safari ) {
1646 // Continually check to see if the document.readyState is valid
1647 jQuery.safariTimer = setInterval(function(){
1648 // loaded and complete are both valid states
1649 if ( document.readyState == "loaded" ||
1650 document.readyState == "complete" ) {
1652 // If either one are found, remove the timer
1653 clearInterval( jQuery.safariTimer );
1654 jQuery.safariTimer = null;
1656 // and execute any waiting functions
1662 // A fallback to window.onload, that will always work
1663 jQuery.event.add( window, "load", jQuery.ready );