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 && a.constructor == Function && b.constructor == Function ? 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
40 this._toggle.apply( this, arguments );
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 ) try { p = p.parentNode } catch(e) { p = this; };
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 * You can have as many $(document).ready events on your page as you like.
105 * @example $(document).ready(function(){ Your code here... });
109 * @param Function fn The function to be executed when the DOM is ready.
113 // If the DOM is already ready
114 if ( jQuery.isReady )
115 // Execute the function immediately
118 // Otherwise, remember the function for later
120 // Add the function to the wait list
121 jQuery.readyList.push( f );
130 * All the code that makes DOM Ready work nicely.
135 // Handle when the DOM is ready
137 // Make sure that the DOM is not already loaded
138 if ( !jQuery.isReady ) {
139 // Remember that the DOM is ready
140 jQuery.isReady = true;
142 // If there are functions bound, to execute
143 if ( jQuery.readyList ) {
144 // Execute all of them
145 for ( var i = 0; i < jQuery.readyList.length; i++ )
146 jQuery.readyList[i].apply( document );
148 // Reset the list of functions
149 jQuery.readyList = null;
151 // Remove event lisenter to avoid memory leak
152 if ( jQuery.browser.mozilla || jQuery.browser.opera )
153 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
161 * Bind a function to the scroll event of each matched element.
163 * @example $("p").scroll( function() { alert("Hello"); } );
164 * @before <p>Hello</p>
165 * @result <p onscroll="alert('Hello');">Hello</p>
169 * @param Function fn A function to bind to the scroll event on each of the matched elements.
170 * @cat Events/Browser
174 * Trigger the scroll event of each matched element. This causes all of the functions
175 * that have been bound to thet scroll event to be executed.
177 * @example $("p").scroll();
178 * @before <p onscroll="alert('Hello');">Hello</p>
179 * @result alert('Hello');
183 * @cat Events/Browser
187 * Bind a function to the scroll event of each matched element, which will only be executed once.
188 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
189 * only executed the first time it is triggered, and never again (unless it is re-bound).
191 * @example $("p").onescroll( function() { alert("Hello"); } );
192 * @before <p onscroll="alert('Hello');">Hello</p>
193 * @result alert('Hello'); // Only executed for the first scroll
197 * @param Function fn A function to bind to the scroll event on each of the matched elements.
198 * @cat Events/Browser
202 * Removes a bound scroll event from each of the matched
203 * elements. You must pass the identical function that was used in the original
206 * @example $("p").unscroll( myFunction );
207 * @before <p onscroll="myFunction">Hello</p>
208 * @result <p>Hello</p>
212 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
213 * @cat Events/Browser
217 * Removes all bound scroll events from each of the matched elements.
219 * @example $("p").unscroll();
220 * @before <p onscroll="alert('Hello');">Hello</p>
221 * @result <p>Hello</p>
225 * @cat Events/Browser
229 * Bind a function to the submit event of each matched element.
231 * @example $("p").submit( function() { alert("Hello"); } );
232 * @before <p>Hello</p>
233 * @result <p onsubmit="alert('Hello');">Hello</p>
237 * @param Function fn A function to bind to the submit event on each of the matched elements.
242 * Trigger the submit event of each matched element. This causes all of the functions
243 * that have been bound to thet submit event to be executed.
245 * @example $("p").submit();
246 * @before <p onsubmit="alert('Hello');">Hello</p>
247 * @result alert('Hello');
255 * Bind a function to the submit event of each matched element, which will only be executed once.
256 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
257 * only executed the first time it is triggered, and never again (unless it is re-bound).
259 * @example $("p").onesubmit( function() { alert("Hello"); } );
260 * @before <p onsubmit="alert('Hello');">Hello</p>
261 * @result alert('Hello'); // Only executed for the first submit
265 * @param Function fn A function to bind to the submit event on each of the matched elements.
270 * Removes a bound submit event from each of the matched
271 * elements. You must pass the identical function that was used in the original
274 * @example $("p").unsubmit( myFunction );
275 * @before <p onsubmit="myFunction">Hello</p>
276 * @result <p>Hello</p>
280 * @param Function fn A function to unbind from the submit event on each of the matched elements.
285 * Removes all bound submit events from each of the matched elements.
287 * @example $("p").unsubmit();
288 * @before <p onsubmit="alert('Hello');">Hello</p>
289 * @result <p>Hello</p>
297 * Bind a function to the focus event of each matched element.
299 * @example $("p").focus( function() { alert("Hello"); } );
300 * @before <p>Hello</p>
301 * @result <p onfocus="alert('Hello');">Hello</p>
305 * @param Function fn A function to bind to the focus event on each of the matched elements.
310 * Trigger the focus event of each matched element. This causes all of the functions
311 * that have been bound to thet focus event to be executed.
313 * @example $("p").focus();
314 * @before <p onfocus="alert('Hello');">Hello</p>
315 * @result alert('Hello');
323 * Bind a function to the focus event of each matched element, which will only be executed once.
324 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
325 * only executed the first time it is triggered, and never again (unless it is re-bound).
327 * @example $("p").onefocus( function() { alert("Hello"); } );
328 * @before <p onfocus="alert('Hello');">Hello</p>
329 * @result alert('Hello'); // Only executed for the first focus
333 * @param Function fn A function to bind to the focus event on each of the matched elements.
338 * Removes a bound focus event from each of the matched
339 * elements. You must pass the identical function that was used in the original
342 * @example $("p").unfocus( myFunction );
343 * @before <p onfocus="myFunction">Hello</p>
344 * @result <p>Hello</p>
348 * @param Function fn A function to unbind from the focus event on each of the matched elements.
353 * Removes all bound focus events from each of the matched elements.
355 * @example $("p").unfocus();
356 * @before <p onfocus="alert('Hello');">Hello</p>
357 * @result <p>Hello</p>
365 * Bind a function to the keydown event of each matched element.
367 * @example $("p").keydown( function() { alert("Hello"); } );
368 * @before <p>Hello</p>
369 * @result <p onkeydown="alert('Hello');">Hello</p>
373 * @param Function fn A function to bind to the keydown event on each of the matched elements.
374 * @cat Events/Keyboard
378 * Trigger the keydown event of each matched element. This causes all of the functions
379 * that have been bound to thet keydown event to be executed.
381 * @example $("p").keydown();
382 * @before <p onkeydown="alert('Hello');">Hello</p>
383 * @result alert('Hello');
387 * @cat Events/Keyboard
391 * Bind a function to the keydown event of each matched element, which will only be executed once.
392 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
393 * only executed the first time it is triggered, and never again (unless it is re-bound).
395 * @example $("p").onekeydown( function() { alert("Hello"); } );
396 * @before <p onkeydown="alert('Hello');">Hello</p>
397 * @result alert('Hello'); // Only executed for the first keydown
401 * @param Function fn A function to bind to the keydown event on each of the matched elements.
402 * @cat Events/Keyboard
406 * Removes a bound keydown event from each of the matched
407 * elements. You must pass the identical function that was used in the original
410 * @example $("p").unkeydown( myFunction );
411 * @before <p onkeydown="myFunction">Hello</p>
412 * @result <p>Hello</p>
416 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
417 * @cat Events/Keyboard
421 * Removes all bound keydown events from each of the matched elements.
423 * @example $("p").unkeydown();
424 * @before <p onkeydown="alert('Hello');">Hello</p>
425 * @result <p>Hello</p>
429 * @cat Events/Keyboard
433 * Bind a function to the dblclick event of each matched element.
435 * @example $("p").dblclick( function() { alert("Hello"); } );
436 * @before <p>Hello</p>
437 * @result <p ondblclick="alert('Hello');">Hello</p>
441 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
446 * Trigger the dblclick event of each matched element. This causes all of the functions
447 * that have been bound to thet dblclick event to be executed.
449 * @example $("p").dblclick();
450 * @before <p ondblclick="alert('Hello');">Hello</p>
451 * @result alert('Hello');
459 * Bind a function to the dblclick event of each matched element, which will only be executed once.
460 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
461 * only executed the first time it is triggered, and never again (unless it is re-bound).
463 * @example $("p").onedblclick( function() { alert("Hello"); } );
464 * @before <p ondblclick="alert('Hello');">Hello</p>
465 * @result alert('Hello'); // Only executed for the first dblclick
469 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
474 * Removes a bound dblclick event from each of the matched
475 * elements. You must pass the identical function that was used in the original
478 * @example $("p").undblclick( myFunction );
479 * @before <p ondblclick="myFunction">Hello</p>
480 * @result <p>Hello</p>
484 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
489 * Removes all bound dblclick events from each of the matched elements.
491 * @example $("p").undblclick();
492 * @before <p ondblclick="alert('Hello');">Hello</p>
493 * @result <p>Hello</p>
501 * Bind a function to the keypress event of each matched element.
503 * @example $("p").keypress( function() { alert("Hello"); } );
504 * @before <p>Hello</p>
505 * @result <p onkeypress="alert('Hello');">Hello</p>
509 * @param Function fn A function to bind to the keypress event on each of the matched elements.
510 * @cat Events/Keyboard
514 * Trigger the keypress event of each matched element. This causes all of the functions
515 * that have been bound to thet keypress event to be executed.
517 * @example $("p").keypress();
518 * @before <p onkeypress="alert('Hello');">Hello</p>
519 * @result alert('Hello');
523 * @cat Events/Keyboard
527 * Bind a function to the keypress event of each matched element, which will only be executed once.
528 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
529 * only executed the first time it is triggered, and never again (unless it is re-bound).
531 * @example $("p").onekeypress( function() { alert("Hello"); } );
532 * @before <p onkeypress="alert('Hello');">Hello</p>
533 * @result alert('Hello'); // Only executed for the first keypress
537 * @param Function fn A function to bind to the keypress event on each of the matched elements.
538 * @cat Events/Keyboard
542 * Removes a bound keypress event from each of the matched
543 * elements. You must pass the identical function that was used in the original
546 * @example $("p").unkeypress( myFunction );
547 * @before <p onkeypress="myFunction">Hello</p>
548 * @result <p>Hello</p>
552 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
553 * @cat Events/Keyboard
557 * Removes all bound keypress events from each of the matched elements.
559 * @example $("p").unkeypress();
560 * @before <p onkeypress="alert('Hello');">Hello</p>
561 * @result <p>Hello</p>
565 * @cat Events/Keyboard
569 * Bind a function to the error event of each matched element.
571 * @example $("p").error( function() { alert("Hello"); } );
572 * @before <p>Hello</p>
573 * @result <p onerror="alert('Hello');">Hello</p>
577 * @param Function fn A function to bind to the error event on each of the matched elements.
578 * @cat Events/Browser
582 * Trigger the error event of each matched element. This causes all of the functions
583 * that have been bound to thet error event to be executed.
585 * @example $("p").error();
586 * @before <p onerror="alert('Hello');">Hello</p>
587 * @result alert('Hello');
591 * @cat Events/Browser
595 * Bind a function to the error event of each matched element, which will only be executed once.
596 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
597 * only executed the first time it is triggered, and never again (unless it is re-bound).
599 * @example $("p").oneerror( function() { alert("Hello"); } );
600 * @before <p onerror="alert('Hello');">Hello</p>
601 * @result alert('Hello'); // Only executed for the first error
605 * @param Function fn A function to bind to the error event on each of the matched elements.
606 * @cat Events/Browser
610 * Removes a bound error event from each of the matched
611 * elements. You must pass the identical function that was used in the original
614 * @example $("p").unerror( myFunction );
615 * @before <p onerror="myFunction">Hello</p>
616 * @result <p>Hello</p>
620 * @param Function fn A function to unbind from the error event on each of the matched elements.
621 * @cat Events/Browser
625 * Removes all bound error events from each of the matched elements.
627 * @example $("p").unerror();
628 * @before <p onerror="alert('Hello');">Hello</p>
629 * @result <p>Hello</p>
633 * @cat Events/Browser
637 * Bind a function to the blur event of each matched element.
639 * @example $("p").blur( function() { alert("Hello"); } );
640 * @before <p>Hello</p>
641 * @result <p onblur="alert('Hello');">Hello</p>
645 * @param Function fn A function to bind to the blur event on each of the matched elements.
650 * Trigger the blur event of each matched element. This causes all of the functions
651 * that have been bound to thet blur event to be executed.
653 * @example $("p").blur();
654 * @before <p onblur="alert('Hello');">Hello</p>
655 * @result alert('Hello');
663 * Bind a function to the blur event of each matched element, which will only be executed once.
664 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
665 * only executed the first time it is triggered, and never again (unless it is re-bound).
667 * @example $("p").oneblur( function() { alert("Hello"); } );
668 * @before <p onblur="alert('Hello');">Hello</p>
669 * @result alert('Hello'); // Only executed for the first blur
673 * @param Function fn A function to bind to the blur event on each of the matched elements.
678 * Removes a bound blur event from each of the matched
679 * elements. You must pass the identical function that was used in the original
682 * @example $("p").unblur( myFunction );
683 * @before <p onblur="myFunction">Hello</p>
684 * @result <p>Hello</p>
688 * @param Function fn A function to unbind from the blur event on each of the matched elements.
693 * Removes all bound blur events from each of the matched elements.
695 * @example $("p").unblur();
696 * @before <p onblur="alert('Hello');">Hello</p>
697 * @result <p>Hello</p>
705 * Bind a function to the load event of each matched element.
707 * @example $("p").load( function() { alert("Hello"); } );
708 * @before <p>Hello</p>
709 * @result <p onload="alert('Hello');">Hello</p>
713 * @param Function fn A function to bind to the load event on each of the matched elements.
714 * @cat Events/Browser
718 * Trigger the load event of each matched element. This causes all of the functions
719 * that have been bound to thet load event to be executed.
721 * Marked as private: Calling load() without arguments throws exception because the ajax load
722 * does not handle it.
724 * @example $("p").load();
725 * @before <p onload="alert('Hello');">Hello</p>
726 * @result alert('Hello');
731 * @cat Events/Browser
735 * Bind a function to the load event of each matched element, which will only be executed once.
736 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
737 * only executed the first time it is triggered, and never again (unless it is re-bound).
739 * @example $("p").oneload( function() { alert("Hello"); } );
740 * @before <p onload="alert('Hello');">Hello</p>
741 * @result alert('Hello'); // Only executed for the first load
745 * @param Function fn A function to bind to the load event on each of the matched elements.
746 * @cat Events/Browser
750 * Removes a bound load event from each of the matched
751 * elements. You must pass the identical function that was used in the original
754 * @example $("p").unload( myFunction );
755 * @before <p onload="myFunction">Hello</p>
756 * @result <p>Hello</p>
760 * @param Function fn A function to unbind from the load event on each of the matched elements.
761 * @cat Events/Browser
765 * Removes all bound load events from each of the matched elements.
767 * @example $("p").unload();
768 * @before <p onload="alert('Hello');">Hello</p>
769 * @result <p>Hello</p>
773 * @cat Events/Browser
777 * Bind a function to the select event of each matched element.
779 * @example $("p").select( function() { alert("Hello"); } );
780 * @before <p>Hello</p>
781 * @result <p onselect="alert('Hello');">Hello</p>
785 * @param Function fn A function to bind to the select event on each of the matched elements.
790 * Trigger the select event of each matched element. This causes all of the functions
791 * that have been bound to thet select event to be executed.
793 * @example $("p").select();
794 * @before <p onselect="alert('Hello');">Hello</p>
795 * @result alert('Hello');
803 * Bind a function to the select event of each matched element, which will only be executed once.
804 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
805 * only executed the first time it is triggered, and never again (unless it is re-bound).
807 * @example $("p").oneselect( function() { alert("Hello"); } );
808 * @before <p onselect="alert('Hello');">Hello</p>
809 * @result alert('Hello'); // Only executed for the first select
813 * @param Function fn A function to bind to the select event on each of the matched elements.
818 * Removes a bound select event from each of the matched
819 * elements. You must pass the identical function that was used in the original
822 * @example $("p").unselect( myFunction );
823 * @before <p onselect="myFunction">Hello</p>
824 * @result <p>Hello</p>
828 * @param Function fn A function to unbind from the select event on each of the matched elements.
833 * Removes all bound select events from each of the matched elements.
835 * @example $("p").unselect();
836 * @before <p onselect="alert('Hello');">Hello</p>
837 * @result <p>Hello</p>
845 * Bind a function to the mouseup event of each matched element.
847 * @example $("p").mouseup( function() { alert("Hello"); } );
848 * @before <p>Hello</p>
849 * @result <p onmouseup="alert('Hello');">Hello</p>
853 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
858 * Trigger the mouseup event of each matched element. This causes all of the functions
859 * that have been bound to thet mouseup event to be executed.
861 * @example $("p").mouseup();
862 * @before <p onmouseup="alert('Hello');">Hello</p>
863 * @result alert('Hello');
871 * Bind a function to the mouseup event of each matched element, which will only be executed once.
872 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
873 * only executed the first time it is triggered, and never again (unless it is re-bound).
875 * @example $("p").onemouseup( function() { alert("Hello"); } );
876 * @before <p onmouseup="alert('Hello');">Hello</p>
877 * @result alert('Hello'); // Only executed for the first mouseup
881 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
886 * Removes a bound mouseup event from each of the matched
887 * elements. You must pass the identical function that was used in the original
890 * @example $("p").unmouseup( myFunction );
891 * @before <p onmouseup="myFunction">Hello</p>
892 * @result <p>Hello</p>
896 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
901 * Removes all bound mouseup events from each of the matched elements.
903 * @example $("p").unmouseup();
904 * @before <p onmouseup="alert('Hello');">Hello</p>
905 * @result <p>Hello</p>
913 * Bind a function to the unload event of each matched element.
915 * @example $("p").unload( function() { alert("Hello"); } );
916 * @before <p>Hello</p>
917 * @result <p onunload="alert('Hello');">Hello</p>
921 * @param Function fn A function to bind to the unload event on each of the matched elements.
922 * @cat Events/Browser
926 * Trigger the unload event of each matched element. This causes all of the functions
927 * that have been bound to thet unload event to be executed.
929 * @example $("p").unload();
930 * @before <p onunload="alert('Hello');">Hello</p>
931 * @result alert('Hello');
935 * @cat Events/Browser
939 * Bind a function to the unload event of each matched element, which will only be executed once.
940 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
941 * only executed the first time it is triggered, and never again (unless it is re-bound).
943 * @example $("p").oneunload( function() { alert("Hello"); } );
944 * @before <p onunload="alert('Hello');">Hello</p>
945 * @result alert('Hello'); // Only executed for the first unload
949 * @param Function fn A function to bind to the unload event on each of the matched elements.
950 * @cat Events/Browser
954 * Removes a bound unload event from each of the matched
955 * elements. You must pass the identical function that was used in the original
958 * @example $("p").ununload( myFunction );
959 * @before <p onunload="myFunction">Hello</p>
960 * @result <p>Hello</p>
964 * @param Function fn A function to unbind from the unload event on each of the matched elements.
965 * @cat Events/Browser
969 * Removes all bound unload events from each of the matched elements.
971 * @example $("p").ununload();
972 * @before <p onunload="alert('Hello');">Hello</p>
973 * @result <p>Hello</p>
977 * @cat Events/Browser
981 * Bind a function to the change event of each matched element.
983 * @example $("p").change( function() { alert("Hello"); } );
984 * @before <p>Hello</p>
985 * @result <p onchange="alert('Hello');">Hello</p>
989 * @param Function fn A function to bind to the change event on each of the matched elements.
994 * Trigger the change event of each matched element. This causes all of the functions
995 * that have been bound to thet change event to be executed.
997 * @example $("p").change();
998 * @before <p onchange="alert('Hello');">Hello</p>
999 * @result alert('Hello');
1007 * Bind a function to the change event of each matched element, which will only be executed once.
1008 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
1009 * only executed the first time it is triggered, and never again (unless it is re-bound).
1011 * @example $("p").onechange( function() { alert("Hello"); } );
1012 * @before <p onchange="alert('Hello');">Hello</p>
1013 * @result alert('Hello'); // Only executed for the first change
1017 * @param Function fn A function to bind to the change event on each of the matched elements.
1022 * Removes a bound change event from each of the matched
1023 * elements. You must pass the identical function that was used in the original
1026 * @example $("p").unchange( myFunction );
1027 * @before <p onchange="myFunction">Hello</p>
1028 * @result <p>Hello</p>
1032 * @param Function fn A function to unbind from the change event on each of the matched elements.
1037 * Removes all bound change events from each of the matched elements.
1039 * @example $("p").unchange();
1040 * @before <p onchange="alert('Hello');">Hello</p>
1041 * @result <p>Hello</p>
1049 * Bind a function to the mouseout event of each matched element.
1051 * @example $("p").mouseout( function() { alert("Hello"); } );
1052 * @before <p>Hello</p>
1053 * @result <p onmouseout="alert('Hello');">Hello</p>
1057 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1062 * Trigger the mouseout event of each matched element. This causes all of the functions
1063 * that have been bound to thet mouseout event to be executed.
1065 * @example $("p").mouseout();
1066 * @before <p onmouseout="alert('Hello');">Hello</p>
1067 * @result alert('Hello');
1075 * Bind a function to the mouseout event of each matched element, which will only be executed once.
1076 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
1077 * only executed the first time it is triggered, and never again (unless it is re-bound).
1079 * @example $("p").onemouseout( function() { alert("Hello"); } );
1080 * @before <p onmouseout="alert('Hello');">Hello</p>
1081 * @result alert('Hello'); // Only executed for the first mouseout
1085 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1090 * Removes a bound mouseout event from each of the matched
1091 * elements. You must pass the identical function that was used in the original
1094 * @example $("p").unmouseout( myFunction );
1095 * @before <p onmouseout="myFunction">Hello</p>
1096 * @result <p>Hello</p>
1100 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
1105 * Removes all bound mouseout events from each of the matched elements.
1107 * @example $("p").unmouseout();
1108 * @before <p onmouseout="alert('Hello');">Hello</p>
1109 * @result <p>Hello</p>
1117 * Bind a function to the keyup event of each matched element.
1119 * @example $("p").keyup( function() { alert("Hello"); } );
1120 * @before <p>Hello</p>
1121 * @result <p onkeyup="alert('Hello');">Hello</p>
1125 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1126 * @cat Events/Keyboard
1130 * Trigger the keyup event of each matched element. This causes all of the functions
1131 * that have been bound to thet keyup event to be executed.
1133 * @example $("p").keyup();
1134 * @before <p onkeyup="alert('Hello');">Hello</p>
1135 * @result alert('Hello');
1139 * @cat Events/Keyboard
1143 * Bind a function to the keyup event of each matched element, which will only be executed once.
1144 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1145 * only executed the first time it is triggered, and never again (unless it is re-bound).
1147 * @example $("p").onekeyup( function() { alert("Hello"); } );
1148 * @before <p onkeyup="alert('Hello');">Hello</p>
1149 * @result alert('Hello'); // Only executed for the first keyup
1153 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1154 * @cat Events/Keyboard
1158 * Removes a bound keyup event from each of the matched
1159 * elements. You must pass the identical function that was used in the original
1162 * @example $("p").unkeyup( myFunction );
1163 * @before <p onkeyup="myFunction">Hello</p>
1164 * @result <p>Hello</p>
1168 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1169 * @cat Events/Keyboard
1173 * Removes all bound keyup events from each of the matched elements.
1175 * @example $("p").unkeyup();
1176 * @before <p onkeyup="alert('Hello');">Hello</p>
1177 * @result <p>Hello</p>
1181 * @cat Events/Keyboard
1185 * Bind a function to the click event of each matched element.
1187 * @example $("p").click( function() { alert("Hello"); } );
1188 * @before <p>Hello</p>
1189 * @result <p onclick="alert('Hello');">Hello</p>
1193 * @param Function fn A function to bind to the click event on each of the matched elements.
1198 * Trigger the click event of each matched element. This causes all of the functions
1199 * that have been bound to thet click event to be executed.
1201 * @example $("p").click();
1202 * @before <p onclick="alert('Hello');">Hello</p>
1203 * @result alert('Hello');
1211 * Bind a function to the click event of each matched element, which will only be executed once.
1212 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
1213 * only executed the first time it is triggered, and never again (unless it is re-bound).
1215 * @example $("p").oneclick( function() { alert("Hello"); } );
1216 * @before <p onclick="alert('Hello');">Hello</p>
1217 * @result alert('Hello'); // Only executed for the first click
1221 * @param Function fn A function to bind to the click event on each of the matched elements.
1226 * Removes a bound click event from each of the matched
1227 * elements. You must pass the identical function that was used in the original
1230 * @example $("p").unclick( myFunction );
1231 * @before <p onclick="myFunction">Hello</p>
1232 * @result <p>Hello</p>
1236 * @param Function fn A function to unbind from the click event on each of the matched elements.
1241 * Removes all bound click events from each of the matched elements.
1243 * @example $("p").unclick();
1244 * @before <p onclick="alert('Hello');">Hello</p>
1245 * @result <p>Hello</p>
1253 * Bind a function to the resize event of each matched element.
1255 * @example $("p").resize( function() { alert("Hello"); } );
1256 * @before <p>Hello</p>
1257 * @result <p onresize="alert('Hello');">Hello</p>
1261 * @param Function fn A function to bind to the resize event on each of the matched elements.
1262 * @cat Events/Browser
1266 * Trigger the resize event of each matched element. This causes all of the functions
1267 * that have been bound to thet resize event to be executed.
1269 * @example $("p").resize();
1270 * @before <p onresize="alert('Hello');">Hello</p>
1271 * @result alert('Hello');
1275 * @cat Events/Browser
1279 * Bind a function to the resize event of each matched element, which will only be executed once.
1280 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
1281 * only executed the first time it is triggered, and never again (unless it is re-bound).
1283 * @example $("p").oneresize( function() { alert("Hello"); } );
1284 * @before <p onresize="alert('Hello');">Hello</p>
1285 * @result alert('Hello'); // Only executed for the first resize
1289 * @param Function fn A function to bind to the resize event on each of the matched elements.
1290 * @cat Events/Browser
1294 * Removes a bound resize event from each of the matched
1295 * elements. You must pass the identical function that was used in the original
1298 * @example $("p").unresize( myFunction );
1299 * @before <p onresize="myFunction">Hello</p>
1300 * @result <p>Hello</p>
1304 * @param Function fn A function to unbind from the resize event on each of the matched elements.
1305 * @cat Events/Browser
1309 * Removes all bound resize events from each of the matched elements.
1311 * @example $("p").unresize();
1312 * @before <p onresize="alert('Hello');">Hello</p>
1313 * @result <p>Hello</p>
1317 * @cat Events/Browser
1321 * Bind a function to the mousemove event of each matched element.
1323 * @example $("p").mousemove( function() { alert("Hello"); } );
1324 * @before <p>Hello</p>
1325 * @result <p onmousemove="alert('Hello');">Hello</p>
1329 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1334 * Trigger the mousemove event of each matched element. This causes all of the functions
1335 * that have been bound to thet mousemove event to be executed.
1337 * @example $("p").mousemove();
1338 * @before <p onmousemove="alert('Hello');">Hello</p>
1339 * @result alert('Hello');
1347 * Bind a function to the mousemove event of each matched element, which will only be executed once.
1348 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
1349 * only executed the first time it is triggered, and never again (unless it is re-bound).
1351 * @example $("p").onemousemove( function() { alert("Hello"); } );
1352 * @before <p onmousemove="alert('Hello');">Hello</p>
1353 * @result alert('Hello'); // Only executed for the first mousemove
1355 * @name onemousemove
1357 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1362 * Removes a bound mousemove event from each of the matched
1363 * elements. You must pass the identical function that was used in the original
1366 * @example $("p").unmousemove( myFunction );
1367 * @before <p onmousemove="myFunction">Hello</p>
1368 * @result <p>Hello</p>
1372 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
1377 * Removes all bound mousemove events from each of the matched elements.
1379 * @example $("p").unmousemove();
1380 * @before <p onmousemove="alert('Hello');">Hello</p>
1381 * @result <p>Hello</p>
1389 * Bind a function to the mousedown event of each matched element.
1391 * @example $("p").mousedown( function() { alert("Hello"); } );
1392 * @before <p>Hello</p>
1393 * @result <p onmousedown="alert('Hello');">Hello</p>
1397 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1402 * Trigger the mousedown event of each matched element. This causes all of the functions
1403 * that have been bound to thet mousedown event to be executed.
1405 * @example $("p").mousedown();
1406 * @before <p onmousedown="alert('Hello');">Hello</p>
1407 * @result alert('Hello');
1415 * Bind a function to the mousedown event of each matched element, which will only be executed once.
1416 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
1417 * only executed the first time it is triggered, and never again (unless it is re-bound).
1419 * @example $("p").onemousedown( function() { alert("Hello"); } );
1420 * @before <p onmousedown="alert('Hello');">Hello</p>
1421 * @result alert('Hello'); // Only executed for the first mousedown
1423 * @name onemousedown
1425 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1430 * Removes a bound mousedown event from each of the matched
1431 * elements. You must pass the identical function that was used in the original
1434 * @example $("p").unmousedown( myFunction );
1435 * @before <p onmousedown="myFunction">Hello</p>
1436 * @result <p>Hello</p>
1440 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
1445 * Removes all bound mousedown events from each of the matched elements.
1447 * @example $("p").unmousedown();
1448 * @before <p onmousedown="alert('Hello');">Hello</p>
1449 * @result <p>Hello</p>
1457 * Bind a function to the mouseover event of each matched element.
1459 * @example $("p").mouseover( function() { alert("Hello"); } );
1460 * @before <p>Hello</p>
1461 * @result <p onmouseover="alert('Hello');">Hello</p>
1465 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1470 * Trigger the mouseover event of each matched element. This causes all of the functions
1471 * that have been bound to thet mousedown event to be executed.
1473 * @example $("p").mouseover();
1474 * @before <p onmouseover="alert('Hello');">Hello</p>
1475 * @result alert('Hello');
1483 * Bind a function to the mouseover event of each matched element, which will only be executed once.
1484 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
1485 * only executed the first time it is triggered, and never again (unless it is re-bound).
1487 * @example $("p").onemouseover( function() { alert("Hello"); } );
1488 * @before <p onmouseover="alert('Hello');">Hello</p>
1489 * @result alert('Hello'); // Only executed for the first mouseover
1491 * @name onemouseover
1493 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
1498 * Removes a bound mouseover event from each of the matched
1499 * elements. You must pass the identical function that was used in the original
1502 * @example $("p").unmouseover( myFunction );
1503 * @before <p onmouseover="myFunction">Hello</p>
1504 * @result <p>Hello</p>
1508 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
1513 * Removes all bound mouseover events from each of the matched elements.
1515 * @example $("p").unmouseover();
1516 * @before <p onmouseover="alert('Hello');">Hello</p>
1517 * @result <p>Hello</p>
1524 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1525 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1526 "submit,keydown,keypress,keyup,error").split(",");
1528 // Go through all the event names, but make sure that
1529 // it is enclosed properly
1530 for ( var i = 0; i < e.length; i++ ) new function(){
1534 // Handle event binding
1535 jQuery.fn[o] = function(f){
1536 return f ? this.bind(o, f) : this.trigger(o);
1539 // Handle event unbinding
1540 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1542 // Finally, handle events that only fire once
1543 jQuery.fn["one"+o] = function(f){
1544 // save cloned reference to this
1545 var element = jQuery(this);
1546 var handler = function() {
1547 // unbind itself when executed
1548 element.unbind(o, handler);
1550 // apply original handler with the same arguments
1551 f.apply(this, arguments);
1553 return this.bind(o, handler);
1558 // If Mozilla is used
1559 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1560 // Use the handy event callback
1561 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1563 // If IE is used, use the excellent hack by Matthias Miller
1564 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1565 } else if ( jQuery.browser.msie ) {
1567 // Only works if you document.write() it
1568 document.write("<scr" + "ipt id=__ie_init defer=true " +
1569 "src=//:><\/script>");
1571 // Use the defer script hack
1572 var script = document.getElementById("__ie_init");
1573 if (script) // script does not exist if jQuery is loaded dynamically
1574 script.onreadystatechange = function() {
1575 if ( this.readyState != "complete" ) return;
1576 this.parentNode.removeChild( this );
1580 // Clear from memory
1583 // If Safari is used
1584 } else if ( jQuery.browser.safari ) {
1585 // Continually check to see if the document.readyState is valid
1586 jQuery.safariTimer = setInterval(function(){
1587 // loaded and complete are both valid states
1588 if ( document.readyState == "loaded" ||
1589 document.readyState == "complete" ) {
1591 // If either one are found, remove the timer
1592 clearInterval( jQuery.safariTimer );
1593 jQuery.safariTimer = null;
1595 // and execute any waiting functions
1601 // A fallback to window.onload, that will always work
1602 jQuery.event.add( window, "load", jQuery.ready );
1606 // Clean up after IE to avoid memory leaks
1607 if (jQuery.browser.msie) jQuery(window).unload(function() {
1608 var event = jQuery.event, global = event.global;
1609 for (var type in global) {
1610 var els = global[type], i = els.length;
1611 if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i);