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");
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 * @example $("p").load();
724 * @before <p onload="alert('Hello');">Hello</p>
725 * @result alert('Hello');
729 * @cat Events/Browser
733 * Bind a function to the load event of each matched element, which will only be executed once.
734 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
735 * only executed the first time it is triggered, and never again (unless it is re-bound).
737 * @example $("p").oneload( function() { alert("Hello"); } );
738 * @before <p onload="alert('Hello');">Hello</p>
739 * @result alert('Hello'); // Only executed for the first load
743 * @param Function fn A function to bind to the load event on each of the matched elements.
744 * @cat Events/Browser
748 * Removes a bound load event from each of the matched
749 * elements. You must pass the identical function that was used in the original
752 * @example $("p").unload( myFunction );
753 * @before <p onload="myFunction">Hello</p>
754 * @result <p>Hello</p>
758 * @param Function fn A function to unbind from the load event on each of the matched elements.
759 * @cat Events/Browser
763 * Removes all bound load events from each of the matched elements.
765 * @example $("p").unload();
766 * @before <p onload="alert('Hello');">Hello</p>
767 * @result <p>Hello</p>
771 * @cat Events/Browser
775 * Bind a function to the select event of each matched element.
777 * @example $("p").select( function() { alert("Hello"); } );
778 * @before <p>Hello</p>
779 * @result <p onselect="alert('Hello');">Hello</p>
783 * @param Function fn A function to bind to the select event on each of the matched elements.
788 * Trigger the select event of each matched element. This causes all of the functions
789 * that have been bound to thet select event to be executed.
791 * @example $("p").select();
792 * @before <p onselect="alert('Hello');">Hello</p>
793 * @result alert('Hello');
801 * Bind a function to the select event of each matched element, which will only be executed once.
802 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
803 * only executed the first time it is triggered, and never again (unless it is re-bound).
805 * @example $("p").oneselect( function() { alert("Hello"); } );
806 * @before <p onselect="alert('Hello');">Hello</p>
807 * @result alert('Hello'); // Only executed for the first select
811 * @param Function fn A function to bind to the select event on each of the matched elements.
816 * Removes a bound select event from each of the matched
817 * elements. You must pass the identical function that was used in the original
820 * @example $("p").unselect( myFunction );
821 * @before <p onselect="myFunction">Hello</p>
822 * @result <p>Hello</p>
826 * @param Function fn A function to unbind from the select event on each of the matched elements.
831 * Removes all bound select events from each of the matched elements.
833 * @example $("p").unselect();
834 * @before <p onselect="alert('Hello');">Hello</p>
835 * @result <p>Hello</p>
843 * Bind a function to the mouseup event of each matched element.
845 * @example $("p").mouseup( function() { alert("Hello"); } );
846 * @before <p>Hello</p>
847 * @result <p onmouseup="alert('Hello');">Hello</p>
851 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
856 * Trigger the mouseup event of each matched element. This causes all of the functions
857 * that have been bound to thet mouseup event to be executed.
859 * @example $("p").mouseup();
860 * @before <p onmouseup="alert('Hello');">Hello</p>
861 * @result alert('Hello');
869 * Bind a function to the mouseup event of each matched element, which will only be executed once.
870 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
871 * only executed the first time it is triggered, and never again (unless it is re-bound).
873 * @example $("p").onemouseup( function() { alert("Hello"); } );
874 * @before <p onmouseup="alert('Hello');">Hello</p>
875 * @result alert('Hello'); // Only executed for the first mouseup
879 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
884 * Removes a bound mouseup event from each of the matched
885 * elements. You must pass the identical function that was used in the original
888 * @example $("p").unmouseup( myFunction );
889 * @before <p onmouseup="myFunction">Hello</p>
890 * @result <p>Hello</p>
894 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
899 * Removes all bound mouseup events from each of the matched elements.
901 * @example $("p").unmouseup();
902 * @before <p onmouseup="alert('Hello');">Hello</p>
903 * @result <p>Hello</p>
911 * Bind a function to the unload event of each matched element.
913 * @example $("p").unload( function() { alert("Hello"); } );
914 * @before <p>Hello</p>
915 * @result <p onunload="alert('Hello');">Hello</p>
919 * @param Function fn A function to bind to the unload event on each of the matched elements.
920 * @cat Events/Browser
924 * Trigger the unload event of each matched element. This causes all of the functions
925 * that have been bound to thet unload event to be executed.
927 * @example $("p").unload();
928 * @before <p onunload="alert('Hello');">Hello</p>
929 * @result alert('Hello');
933 * @cat Events/Browser
937 * Bind a function to the unload event of each matched element, which will only be executed once.
938 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
939 * only executed the first time it is triggered, and never again (unless it is re-bound).
941 * @example $("p").oneunload( function() { alert("Hello"); } );
942 * @before <p onunload="alert('Hello');">Hello</p>
943 * @result alert('Hello'); // Only executed for the first unload
947 * @param Function fn A function to bind to the unload event on each of the matched elements.
948 * @cat Events/Browser
952 * Removes a bound unload event from each of the matched
953 * elements. You must pass the identical function that was used in the original
956 * @example $("p").ununload( myFunction );
957 * @before <p onunload="myFunction">Hello</p>
958 * @result <p>Hello</p>
962 * @param Function fn A function to unbind from the unload event on each of the matched elements.
963 * @cat Events/Browser
967 * Removes all bound unload events from each of the matched elements.
969 * @example $("p").ununload();
970 * @before <p onunload="alert('Hello');">Hello</p>
971 * @result <p>Hello</p>
975 * @cat Events/Browser
979 * Bind a function to the change event of each matched element.
981 * @example $("p").change( function() { alert("Hello"); } );
982 * @before <p>Hello</p>
983 * @result <p onchange="alert('Hello');">Hello</p>
987 * @param Function fn A function to bind to the change event on each of the matched elements.
992 * Trigger the change event of each matched element. This causes all of the functions
993 * that have been bound to thet change event to be executed.
995 * @example $("p").change();
996 * @before <p onchange="alert('Hello');">Hello</p>
997 * @result alert('Hello');
1005 * Bind a function to the change event of each matched element, which will only be executed once.
1006 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
1007 * only executed the first time it is triggered, and never again (unless it is re-bound).
1009 * @example $("p").onechange( function() { alert("Hello"); } );
1010 * @before <p onchange="alert('Hello');">Hello</p>
1011 * @result alert('Hello'); // Only executed for the first change
1015 * @param Function fn A function to bind to the change event on each of the matched elements.
1020 * Removes a bound change event from each of the matched
1021 * elements. You must pass the identical function that was used in the original
1024 * @example $("p").unchange( myFunction );
1025 * @before <p onchange="myFunction">Hello</p>
1026 * @result <p>Hello</p>
1030 * @param Function fn A function to unbind from the change event on each of the matched elements.
1035 * Removes all bound change events from each of the matched elements.
1037 * @example $("p").unchange();
1038 * @before <p onchange="alert('Hello');">Hello</p>
1039 * @result <p>Hello</p>
1047 * Bind a function to the mouseout event of each matched element.
1049 * @example $("p").mouseout( function() { alert("Hello"); } );
1050 * @before <p>Hello</p>
1051 * @result <p onmouseout="alert('Hello');">Hello</p>
1055 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1060 * Trigger the mouseout event of each matched element. This causes all of the functions
1061 * that have been bound to thet mouseout event to be executed.
1063 * @example $("p").mouseout();
1064 * @before <p onmouseout="alert('Hello');">Hello</p>
1065 * @result alert('Hello');
1073 * Bind a function to the mouseout event of each matched element, which will only be executed once.
1074 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
1075 * only executed the first time it is triggered, and never again (unless it is re-bound).
1077 * @example $("p").onemouseout( function() { alert("Hello"); } );
1078 * @before <p onmouseout="alert('Hello');">Hello</p>
1079 * @result alert('Hello'); // Only executed for the first mouseout
1083 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1088 * Removes a bound mouseout event from each of the matched
1089 * elements. You must pass the identical function that was used in the original
1092 * @example $("p").unmouseout( myFunction );
1093 * @before <p onmouseout="myFunction">Hello</p>
1094 * @result <p>Hello</p>
1098 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
1103 * Removes all bound mouseout events from each of the matched elements.
1105 * @example $("p").unmouseout();
1106 * @before <p onmouseout="alert('Hello');">Hello</p>
1107 * @result <p>Hello</p>
1115 * Bind a function to the keyup event of each matched element.
1117 * @example $("p").keyup( function() { alert("Hello"); } );
1118 * @before <p>Hello</p>
1119 * @result <p onkeyup="alert('Hello');">Hello</p>
1123 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1124 * @cat Events/Keyboard
1128 * Trigger the keyup event of each matched element. This causes all of the functions
1129 * that have been bound to thet keyup event to be executed.
1131 * @example $("p").keyup();
1132 * @before <p onkeyup="alert('Hello');">Hello</p>
1133 * @result alert('Hello');
1137 * @cat Events/Keyboard
1141 * Bind a function to the keyup event of each matched element, which will only be executed once.
1142 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1143 * only executed the first time it is triggered, and never again (unless it is re-bound).
1145 * @example $("p").onekeyup( function() { alert("Hello"); } );
1146 * @before <p onkeyup="alert('Hello');">Hello</p>
1147 * @result alert('Hello'); // Only executed for the first keyup
1151 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1152 * @cat Events/Keyboard
1156 * Removes a bound keyup event from each of the matched
1157 * elements. You must pass the identical function that was used in the original
1160 * @example $("p").unkeyup( myFunction );
1161 * @before <p onkeyup="myFunction">Hello</p>
1162 * @result <p>Hello</p>
1166 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1167 * @cat Events/Keyboard
1171 * Removes all bound keyup events from each of the matched elements.
1173 * @example $("p").unkeyup();
1174 * @before <p onkeyup="alert('Hello');">Hello</p>
1175 * @result <p>Hello</p>
1179 * @cat Events/Keyboard
1183 * Bind a function to the click event of each matched element.
1185 * @example $("p").click( function() { alert("Hello"); } );
1186 * @before <p>Hello</p>
1187 * @result <p onclick="alert('Hello');">Hello</p>
1191 * @param Function fn A function to bind to the click event on each of the matched elements.
1196 * Trigger the click event of each matched element. This causes all of the functions
1197 * that have been bound to thet click event to be executed.
1199 * @example $("p").click();
1200 * @before <p onclick="alert('Hello');">Hello</p>
1201 * @result alert('Hello');
1209 * Bind a function to the click event of each matched element, which will only be executed once.
1210 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
1211 * only executed the first time it is triggered, and never again (unless it is re-bound).
1213 * @example $("p").oneclick( function() { alert("Hello"); } );
1214 * @before <p onclick="alert('Hello');">Hello</p>
1215 * @result alert('Hello'); // Only executed for the first click
1219 * @param Function fn A function to bind to the click event on each of the matched elements.
1224 * Removes a bound click event from each of the matched
1225 * elements. You must pass the identical function that was used in the original
1228 * @example $("p").unclick( myFunction );
1229 * @before <p onclick="myFunction">Hello</p>
1230 * @result <p>Hello</p>
1234 * @param Function fn A function to unbind from the click event on each of the matched elements.
1239 * Removes all bound click events from each of the matched elements.
1241 * @example $("p").unclick();
1242 * @before <p onclick="alert('Hello');">Hello</p>
1243 * @result <p>Hello</p>
1251 * Bind a function to the resize event of each matched element.
1253 * @example $("p").resize( function() { alert("Hello"); } );
1254 * @before <p>Hello</p>
1255 * @result <p onresize="alert('Hello');">Hello</p>
1259 * @param Function fn A function to bind to the resize event on each of the matched elements.
1260 * @cat Events/Browser
1264 * Trigger the resize event of each matched element. This causes all of the functions
1265 * that have been bound to thet resize event to be executed.
1267 * @example $("p").resize();
1268 * @before <p onresize="alert('Hello');">Hello</p>
1269 * @result alert('Hello');
1273 * @cat Events/Browser
1277 * Bind a function to the resize event of each matched element, which will only be executed once.
1278 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
1279 * only executed the first time it is triggered, and never again (unless it is re-bound).
1281 * @example $("p").oneresize( function() { alert("Hello"); } );
1282 * @before <p onresize="alert('Hello');">Hello</p>
1283 * @result alert('Hello'); // Only executed for the first resize
1287 * @param Function fn A function to bind to the resize event on each of the matched elements.
1288 * @cat Events/Browser
1292 * Removes a bound resize event from each of the matched
1293 * elements. You must pass the identical function that was used in the original
1296 * @example $("p").unresize( myFunction );
1297 * @before <p onresize="myFunction">Hello</p>
1298 * @result <p>Hello</p>
1302 * @param Function fn A function to unbind from the resize event on each of the matched elements.
1303 * @cat Events/Browser
1307 * Removes all bound resize events from each of the matched elements.
1309 * @example $("p").unresize();
1310 * @before <p onresize="alert('Hello');">Hello</p>
1311 * @result <p>Hello</p>
1315 * @cat Events/Browser
1319 * Bind a function to the mousemove event of each matched element.
1321 * @example $("p").mousemove( function() { alert("Hello"); } );
1322 * @before <p>Hello</p>
1323 * @result <p onmousemove="alert('Hello');">Hello</p>
1327 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1332 * Trigger the mousemove event of each matched element. This causes all of the functions
1333 * that have been bound to thet mousemove event to be executed.
1335 * @example $("p").mousemove();
1336 * @before <p onmousemove="alert('Hello');">Hello</p>
1337 * @result alert('Hello');
1345 * Bind a function to the mousemove event of each matched element, which will only be executed once.
1346 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
1347 * only executed the first time it is triggered, and never again (unless it is re-bound).
1349 * @example $("p").onemousemove( function() { alert("Hello"); } );
1350 * @before <p onmousemove="alert('Hello');">Hello</p>
1351 * @result alert('Hello'); // Only executed for the first mousemove
1353 * @name onemousemove
1355 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1360 * Removes a bound mousemove event from each of the matched
1361 * elements. You must pass the identical function that was used in the original
1364 * @example $("p").unmousemove( myFunction );
1365 * @before <p onmousemove="myFunction">Hello</p>
1366 * @result <p>Hello</p>
1370 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
1375 * Removes all bound mousemove events from each of the matched elements.
1377 * @example $("p").unmousemove();
1378 * @before <p onmousemove="alert('Hello');">Hello</p>
1379 * @result <p>Hello</p>
1387 * Bind a function to the mousedown event of each matched element.
1389 * @example $("p").mousedown( function() { alert("Hello"); } );
1390 * @before <p>Hello</p>
1391 * @result <p onmousedown="alert('Hello');">Hello</p>
1395 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1400 * Trigger the mousedown event of each matched element. This causes all of the functions
1401 * that have been bound to thet mousedown event to be executed.
1403 * @example $("p").mousedown();
1404 * @before <p onmousedown="alert('Hello');">Hello</p>
1405 * @result alert('Hello');
1413 * Bind a function to the mousedown event of each matched element, which will only be executed once.
1414 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
1415 * only executed the first time it is triggered, and never again (unless it is re-bound).
1417 * @example $("p").onemousedown( function() { alert("Hello"); } );
1418 * @before <p onmousedown="alert('Hello');">Hello</p>
1419 * @result alert('Hello'); // Only executed for the first mousedown
1421 * @name onemousedown
1423 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1428 * Removes a bound mousedown event from each of the matched
1429 * elements. You must pass the identical function that was used in the original
1432 * @example $("p").unmousedown( myFunction );
1433 * @before <p onmousedown="myFunction">Hello</p>
1434 * @result <p>Hello</p>
1438 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
1443 * Removes all bound mousedown events from each of the matched elements.
1445 * @example $("p").unmousedown();
1446 * @before <p onmousedown="alert('Hello');">Hello</p>
1447 * @result <p>Hello</p>
1456 * var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1457 * "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1458 * "submit,keydown,keypress,keyup,error").split(",");
1459 * var handler1 = function(event) {
1462 * var handler2 = function(event) {
1465 * for( var i=0; i < e.length; i++) {
1469 * $(document)[event](handler1);
1470 * $(document)[event](handler2);
1471 * $(document)["one"+event](handler1);
1473 * // call event two times
1474 * $(document)[event]();
1475 * $(document)[event]();
1478 * $(document)["un"+event](handler1);
1480 * $(document)[event]();
1482 * // remove all handlers
1483 * $(document)["un"+event]();
1486 * $(document)[event]();
1489 * @test ok( count == 6, 'Checking event ' + event);
1493 * @name eventTesting
1496 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1497 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1498 "submit,keydown,keypress,keyup,error").split(",");
1500 // Go through all the event names, but make sure that
1501 // it is enclosed properly
1502 for ( var i = 0; i < e.length; i++ ) new function(){
1506 // Handle event binding
1507 jQuery.fn[o] = function(f){
1508 return f ? this.bind(o, f) : this.trigger(o);
1511 // Handle event unbinding
1512 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1514 // Finally, handle events that only fire once
1515 jQuery.fn["one"+o] = function(f){
1516 // Attach the event listener
1517 return this.each(function(){
1522 jQuery.event.add( this, o, function(e){
1523 // If this function has already been executed, stop
1524 if ( count++ ) return;
1526 // And execute the bound function
1527 return f.apply(this, [e]);
1534 // If Mozilla is used
1535 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1536 // Use the handy event callback
1537 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1539 // If IE is used, use the excellent hack by Matthias Miller
1540 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1541 } else if ( jQuery.browser.msie ) {
1543 // Only works if you document.write() it
1544 document.write("<scr" + "ipt id=__ie_init defer=true " +
1545 "src=//:><\/script>");
1547 // Use the defer script hack
1548 var script = document.getElementById("__ie_init");
1549 script.onreadystatechange = function() {
1550 if ( this.readyState != "complete" ) return;
1551 this.parentNode.removeChild( this );
1555 // Clear from memory
1558 // If Safari is used
1559 } else if ( jQuery.browser.safari ) {
1560 // Continually check to see if the document.readyState is valid
1561 jQuery.safariTimer = setInterval(function(){
1562 // loaded and complete are both valid states
1563 if ( document.readyState == "loaded" ||
1564 document.readyState == "complete" ) {
1566 // If either one are found, remove the timer
1567 clearInterval( jQuery.safariTimer );
1568 jQuery.safariTimer = null;
1570 // and execute any waiting functions
1576 // A fallback to window.onload, that will always work
1577 jQuery.event.add( window, "load", jQuery.ready );