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 * Use unbind("click") to remove.
15 * @example $("p").toggle(function(){
16 * $(this).addClass("selected");
18 * $(this).removeClass("selected");
23 * @param Function even The function to execute on every even click.
24 * @param Function odd The function to execute on every odd click.
28 // save reference to arguments for access in closure
30 return typeof a[0] == "function" && typeof a[1] == "function" ? this.click(function(e) {
31 // Figure out which function to execute
32 this.lastToggle = this.lastToggle == 0 ? 1 : 0;
34 // Make sure that clicks stop
37 // and execute the function
38 return a[this.lastToggle].apply( this, [e] ) || false;
41 // Otherwise, execute the old toggle function
42 this._toggle.apply( this, arguments );
46 * A method for simulating hovering (moving the mouse on, and off,
47 * an object). This is a custom method which provides an 'in' to a
50 * Whenever the mouse cursor is moved over a matched
51 * element, the first specified function is fired. Whenever the mouse
52 * moves off of the element, the second specified function fires.
53 * Additionally, checks are in place to see if the mouse is still within
54 * the specified element itself (for example, an image inside of a div),
55 * and if it is, it will continue to 'hover', and not move out
56 * (a common error in using a mouseout event handler).
58 * @example $("p").hover(function(){
59 * $(this).addClass("over");
61 * $(this).addClass("out");
66 * @param Function over The function to fire whenever the mouse is moved over a matched element.
67 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
70 hover: function(f,g) {
72 // A private function for haandling mouse 'hovering'
73 function handleHover(e) {
74 // Check if mouse(over|out) are still within the same parent element
75 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
77 // Traverse up the tree
78 while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
80 // If we actually just moused on to a sub-element, ignore it
81 if ( p == this ) return false;
83 // Execute the right function
84 return (e.type == "mouseover" ? f : g).apply(this, [e]);
87 // Bind the function to the two event listeners
88 return this.mouseover(handleHover).mouseout(handleHover);
92 * Bind a function to be executed whenever the DOM is ready to be
93 * traversed and manipulated. This is probably the most important
94 * function included in the event module, as it can greatly improve
95 * the response times of your web applications.
97 * In a nutshell, this is a solid replacement for using window.onload,
98 * and attaching a function to that. By using this method, your bound Function
99 * will be called the instant the DOM is ready to be read and manipulated,
100 * which is exactly what 99.99% of all Javascript code needs to run.
102 * Please ensure you have no code in your <body> onload event handler,
103 * otherwise $(document).ready() may not fire.
105 * You can have as many $(document).ready events on your page as you like.
106 * The functions are then executed in the order they were added.
108 * @example $(document).ready(function(){ Your code here... });
112 * @param Function fn The function to be executed when the DOM is ready.
116 // If the DOM is already ready
117 if ( jQuery.isReady )
118 // Execute the function immediately
121 // Otherwise, remember the function for later
123 // Add the function to the wait list
124 jQuery.readyList.push( f );
133 * All the code that makes DOM Ready work nicely.
138 // Handle when the DOM is ready
140 // Make sure that the DOM is not already loaded
141 if ( !jQuery.isReady ) {
142 // Remember that the DOM is ready
143 jQuery.isReady = true;
145 // If there are functions bound, to execute
146 if ( jQuery.readyList ) {
147 // Execute all of them
148 for ( var i = 0; i < jQuery.readyList.length; i++ )
149 jQuery.readyList[i].apply( document );
151 // Reset the list of functions
152 jQuery.readyList = null;
154 // Remove event lisenter to avoid memory leak
155 if ( jQuery.browser.mozilla || jQuery.browser.opera )
156 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
164 * Bind a function to the scroll event of each matched element.
166 * @example $("p").scroll( function() { alert("Hello"); } );
167 * @before <p>Hello</p>
168 * @result <p onscroll="alert('Hello');">Hello</p>
172 * @param Function fn A function to bind to the scroll event on each of the matched elements.
173 * @cat Events/Browser
177 * Trigger the scroll event of each matched element. This causes all of the functions
178 * that have been bound to thet scroll event to be executed.
180 * @example $("p").scroll();
181 * @before <p onscroll="alert('Hello');">Hello</p>
182 * @result alert('Hello');
186 * @cat Events/Browser
190 * Bind a function to the scroll event of each matched element, which will only be executed once.
191 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
192 * only executed the first time it is triggered, and never again (unless it is re-bound).
194 * @example $("p").onescroll( function() { alert("Hello"); } );
195 * @before <p onscroll="alert('Hello');">Hello</p>
196 * @result alert('Hello'); // Only executed for the first scroll
200 * @param Function fn A function to bind to the scroll event on each of the matched elements.
201 * @cat Events/Browser
205 * Removes a bound scroll event from each of the matched
206 * elements. You must pass the identical function that was used in the original
209 * @example $("p").unscroll( myFunction );
210 * @before <p onscroll="myFunction">Hello</p>
211 * @result <p>Hello</p>
215 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
216 * @cat Events/Browser
220 * Removes all bound scroll events from each of the matched elements.
222 * @example $("p").unscroll();
223 * @before <p onscroll="alert('Hello');">Hello</p>
224 * @result <p>Hello</p>
228 * @cat Events/Browser
232 * Bind a function to the submit event of each matched element.
234 * @example $("#myform").submit( function() {
235 * return $("input", this).val().length > 0;
237 * @before <form id="myform"><input /></form>
238 * @desc Prevents the form submission when the input has no value entered.
242 * @param Function fn A function to bind to the submit event on each of the matched elements.
247 * Trigger the submit event of each matched element. This causes all of the functions
248 * that have been bound to thet submit event to be executed.
250 * Note: This does not execute the submit method of the form element! If you need to
251 * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
253 * @example $("form").submit();
254 * @desc Triggers all submit events registered for forms, but does not submit the form
262 * Bind a function to the submit event of each matched element, which will only be executed once.
263 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
264 * only executed the first time it is triggered, and never again (unless it is re-bound).
266 * @example $("p").onesubmit( function() { alert("Hello"); } );
267 * @before <p onsubmit="alert('Hello');">Hello</p>
268 * @result alert('Hello'); // Only executed for the first submit
272 * @param Function fn A function to bind to the submit event on each of the matched elements.
277 * Removes a bound submit event from each of the matched
278 * elements. You must pass the identical function that was used in the original
281 * @example $("p").unsubmit( myFunction );
282 * @before <p onsubmit="myFunction">Hello</p>
283 * @result <p>Hello</p>
287 * @param Function fn A function to unbind from the submit event on each of the matched elements.
292 * Removes all bound submit events from each of the matched elements.
294 * @example $("p").unsubmit();
295 * @before <p onsubmit="alert('Hello');">Hello</p>
296 * @result <p>Hello</p>
304 * Bind a function to the focus event of each matched element.
306 * @example $("p").focus( function() { alert("Hello"); } );
307 * @before <p>Hello</p>
308 * @result <p onfocus="alert('Hello');">Hello</p>
312 * @param Function fn A function to bind to the focus event on each of the matched elements.
317 * Trigger the focus event of each matched element. This causes all of the functions
318 * that have been bound to thet focus event to be executed.
320 * Note: This does not execute the focus method of the underlying elements! If you need to
321 * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
323 * @example $("p").focus();
324 * @before <p onfocus="alert('Hello');">Hello</p>
325 * @result alert('Hello');
333 * Bind a function to the focus event of each matched element, which will only be executed once.
334 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
335 * only executed the first time it is triggered, and never again (unless it is re-bound).
337 * @example $("p").onefocus( function() { alert("Hello"); } );
338 * @before <p onfocus="alert('Hello');">Hello</p>
339 * @result alert('Hello'); // Only executed for the first focus
343 * @param Function fn A function to bind to the focus event on each of the matched elements.
348 * Removes a bound focus event from each of the matched
349 * elements. You must pass the identical function that was used in the original
352 * @example $("p").unfocus( myFunction );
353 * @before <p onfocus="myFunction">Hello</p>
354 * @result <p>Hello</p>
358 * @param Function fn A function to unbind from the focus event on each of the matched elements.
363 * Removes all bound focus events from each of the matched elements.
365 * @example $("p").unfocus();
366 * @before <p onfocus="alert('Hello');">Hello</p>
367 * @result <p>Hello</p>
375 * Bind a function to the keydown event of each matched element.
377 * @example $("p").keydown( function() { alert("Hello"); } );
378 * @before <p>Hello</p>
379 * @result <p onkeydown="alert('Hello');">Hello</p>
383 * @param Function fn A function to bind to the keydown event on each of the matched elements.
384 * @cat Events/Keyboard
388 * Trigger the keydown event of each matched element. This causes all of the functions
389 * that have been bound to thet keydown event to be executed.
391 * @example $("p").keydown();
392 * @before <p onkeydown="alert('Hello');">Hello</p>
393 * @result alert('Hello');
397 * @cat Events/Keyboard
401 * Bind a function to the keydown event of each matched element, which will only be executed once.
402 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
403 * only executed the first time it is triggered, and never again (unless it is re-bound).
405 * @example $("p").onekeydown( function() { alert("Hello"); } );
406 * @before <p onkeydown="alert('Hello');">Hello</p>
407 * @result alert('Hello'); // Only executed for the first keydown
411 * @param Function fn A function to bind to the keydown event on each of the matched elements.
412 * @cat Events/Keyboard
416 * Removes a bound keydown event from each of the matched
417 * elements. You must pass the identical function that was used in the original
420 * @example $("p").unkeydown( myFunction );
421 * @before <p onkeydown="myFunction">Hello</p>
422 * @result <p>Hello</p>
426 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
427 * @cat Events/Keyboard
431 * Removes all bound keydown events from each of the matched elements.
433 * @example $("p").unkeydown();
434 * @before <p onkeydown="alert('Hello');">Hello</p>
435 * @result <p>Hello</p>
439 * @cat Events/Keyboard
443 * Bind a function to the dblclick event of each matched element.
445 * @example $("p").dblclick( function() { alert("Hello"); } );
446 * @before <p>Hello</p>
447 * @result <p ondblclick="alert('Hello');">Hello</p>
451 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
456 * Trigger the dblclick event of each matched element. This causes all of the functions
457 * that have been bound to thet dblclick event to be executed.
459 * @example $("p").dblclick();
460 * @before <p ondblclick="alert('Hello');">Hello</p>
461 * @result alert('Hello');
469 * Bind a function to the dblclick event of each matched element, which will only be executed once.
470 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
471 * only executed the first time it is triggered, and never again (unless it is re-bound).
473 * @example $("p").onedblclick( function() { alert("Hello"); } );
474 * @before <p ondblclick="alert('Hello');">Hello</p>
475 * @result alert('Hello'); // Only executed for the first dblclick
479 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
484 * Removes a bound dblclick event from each of the matched
485 * elements. You must pass the identical function that was used in the original
488 * @example $("p").undblclick( myFunction );
489 * @before <p ondblclick="myFunction">Hello</p>
490 * @result <p>Hello</p>
494 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
499 * Removes all bound dblclick events from each of the matched elements.
501 * @example $("p").undblclick();
502 * @before <p ondblclick="alert('Hello');">Hello</p>
503 * @result <p>Hello</p>
511 * Bind a function to the keypress event of each matched element.
513 * @example $("p").keypress( function() { alert("Hello"); } );
514 * @before <p>Hello</p>
515 * @result <p onkeypress="alert('Hello');">Hello</p>
519 * @param Function fn A function to bind to the keypress event on each of the matched elements.
520 * @cat Events/Keyboard
524 * Trigger the keypress event of each matched element. This causes all of the functions
525 * that have been bound to thet keypress event to be executed.
527 * @example $("p").keypress();
528 * @before <p onkeypress="alert('Hello');">Hello</p>
529 * @result alert('Hello');
533 * @cat Events/Keyboard
537 * Bind a function to the keypress event of each matched element, which will only be executed once.
538 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
539 * only executed the first time it is triggered, and never again (unless it is re-bound).
541 * @example $("p").onekeypress( function() { alert("Hello"); } );
542 * @before <p onkeypress="alert('Hello');">Hello</p>
543 * @result alert('Hello'); // Only executed for the first keypress
547 * @param Function fn A function to bind to the keypress event on each of the matched elements.
548 * @cat Events/Keyboard
552 * Removes a bound keypress event from each of the matched
553 * elements. You must pass the identical function that was used in the original
556 * @example $("p").unkeypress( myFunction );
557 * @before <p onkeypress="myFunction">Hello</p>
558 * @result <p>Hello</p>
562 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
563 * @cat Events/Keyboard
567 * Removes all bound keypress events from each of the matched elements.
569 * @example $("p").unkeypress();
570 * @before <p onkeypress="alert('Hello');">Hello</p>
571 * @result <p>Hello</p>
575 * @cat Events/Keyboard
579 * Bind a function to the error event of each matched element.
581 * @example $("p").error( function() { alert("Hello"); } );
582 * @before <p>Hello</p>
583 * @result <p onerror="alert('Hello');">Hello</p>
587 * @param Function fn A function to bind to the error event on each of the matched elements.
588 * @cat Events/Browser
592 * Trigger the error event of each matched element. This causes all of the functions
593 * that have been bound to thet error event to be executed.
595 * @example $("p").error();
596 * @before <p onerror="alert('Hello');">Hello</p>
597 * @result alert('Hello');
601 * @cat Events/Browser
605 * Bind a function to the error event of each matched element, which will only be executed once.
606 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
607 * only executed the first time it is triggered, and never again (unless it is re-bound).
609 * @example $("p").oneerror( function() { alert("Hello"); } );
610 * @before <p onerror="alert('Hello');">Hello</p>
611 * @result alert('Hello'); // Only executed for the first error
615 * @param Function fn A function to bind to the error event on each of the matched elements.
616 * @cat Events/Browser
620 * Removes a bound error event from each of the matched
621 * elements. You must pass the identical function that was used in the original
624 * @example $("p").unerror( myFunction );
625 * @before <p onerror="myFunction">Hello</p>
626 * @result <p>Hello</p>
630 * @param Function fn A function to unbind from the error event on each of the matched elements.
631 * @cat Events/Browser
635 * Removes all bound error events from each of the matched elements.
637 * @example $("p").unerror();
638 * @before <p onerror="alert('Hello');">Hello</p>
639 * @result <p>Hello</p>
643 * @cat Events/Browser
647 * Bind a function to the blur event of each matched element.
649 * @example $("p").blur( function() { alert("Hello"); } );
650 * @before <p>Hello</p>
651 * @result <p onblur="alert('Hello');">Hello</p>
655 * @param Function fn A function to bind to the blur event on each of the matched elements.
660 * Trigger the blur event of each matched element. This causes all of the functions
661 * that have been bound to thet blur event to be executed.
663 * Note: This does not execute the blur method of the underlying elements! If you need to
664 * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
666 * @example $("p").blur();
667 * @before <p onblur="alert('Hello');">Hello</p>
668 * @result alert('Hello');
676 * Bind a function to the blur event of each matched element, which will only be executed once.
677 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
678 * only executed the first time it is triggered, and never again (unless it is re-bound).
680 * @example $("p").oneblur( function() { alert("Hello"); } );
681 * @before <p onblur="alert('Hello');">Hello</p>
682 * @result alert('Hello'); // Only executed for the first blur
686 * @param Function fn A function to bind to the blur event on each of the matched elements.
691 * Removes a bound blur event from each of the matched
692 * elements. You must pass the identical function that was used in the original
695 * @example $("p").unblur( myFunction );
696 * @before <p onblur="myFunction">Hello</p>
697 * @result <p>Hello</p>
701 * @param Function fn A function to unbind from the blur event on each of the matched elements.
706 * Removes all bound blur events from each of the matched elements.
708 * @example $("p").unblur();
709 * @before <p onblur="alert('Hello');">Hello</p>
710 * @result <p>Hello</p>
718 * Bind a function to the load event of each matched element.
720 * @example $("p").load( function() { alert("Hello"); } );
721 * @before <p>Hello</p>
722 * @result <p onload="alert('Hello');">Hello</p>
726 * @param Function fn A function to bind to the load event on each of the matched elements.
727 * @cat Events/Browser
731 * Trigger the load event of each matched element. This causes all of the functions
732 * that have been bound to thet load event to be executed.
734 * Marked as private: Calling load() without arguments throws exception because the ajax load
735 * does not handle it.
737 * @example $("p").load();
738 * @before <p onload="alert('Hello');">Hello</p>
739 * @result alert('Hello');
744 * @cat Events/Browser
748 * Bind a function to the load event of each matched element, which will only be executed once.
749 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
750 * only executed the first time it is triggered, and never again (unless it is re-bound).
752 * @example $("p").oneload( function() { alert("Hello"); } );
753 * @before <p onload="alert('Hello');">Hello</p>
754 * @result alert('Hello'); // Only executed for the first load
758 * @param Function fn A function to bind to the load event on each of the matched elements.
759 * @cat Events/Browser
763 * Removes a bound load event from each of the matched
764 * elements. You must pass the identical function that was used in the original
767 * @example $("p").unload( myFunction );
768 * @before <p onload="myFunction">Hello</p>
769 * @result <p>Hello</p>
773 * @param Function fn A function to unbind from the load event on each of the matched elements.
774 * @cat Events/Browser
778 * Removes all bound load events from each of the matched elements.
780 * @example $("p").unload();
781 * @before <p onload="alert('Hello');">Hello</p>
782 * @result <p>Hello</p>
786 * @cat Events/Browser
790 * Bind a function to the select event of each matched element.
792 * @example $("p").select( function() { alert("Hello"); } );
793 * @before <p>Hello</p>
794 * @result <p onselect="alert('Hello');">Hello</p>
798 * @param Function fn A function to bind to the select event on each of the matched elements.
803 * Trigger the select event of each matched element. This causes all of the functions
804 * that have been bound to thet select event to be executed.
806 * @example $("p").select();
807 * @before <p onselect="alert('Hello');">Hello</p>
808 * @result alert('Hello');
816 * Bind a function to the select event of each matched element, which will only be executed once.
817 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
818 * only executed the first time it is triggered, and never again (unless it is re-bound).
820 * @example $("p").oneselect( function() { alert("Hello"); } );
821 * @before <p onselect="alert('Hello');">Hello</p>
822 * @result alert('Hello'); // Only executed for the first select
826 * @param Function fn A function to bind to the select event on each of the matched elements.
831 * Removes a bound select event from each of the matched
832 * elements. You must pass the identical function that was used in the original
835 * @example $("p").unselect( myFunction );
836 * @before <p onselect="myFunction">Hello</p>
837 * @result <p>Hello</p>
841 * @param Function fn A function to unbind from the select event on each of the matched elements.
846 * Removes all bound select events from each of the matched elements.
848 * @example $("p").unselect();
849 * @before <p onselect="alert('Hello');">Hello</p>
850 * @result <p>Hello</p>
858 * Bind a function to the mouseup event of each matched element.
860 * @example $("p").mouseup( function() { alert("Hello"); } );
861 * @before <p>Hello</p>
862 * @result <p onmouseup="alert('Hello');">Hello</p>
866 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
871 * Trigger the mouseup event of each matched element. This causes all of the functions
872 * that have been bound to thet mouseup event to be executed.
874 * @example $("p").mouseup();
875 * @before <p onmouseup="alert('Hello');">Hello</p>
876 * @result alert('Hello');
884 * Bind a function to the mouseup event of each matched element, which will only be executed once.
885 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
886 * only executed the first time it is triggered, and never again (unless it is re-bound).
888 * @example $("p").onemouseup( function() { alert("Hello"); } );
889 * @before <p onmouseup="alert('Hello');">Hello</p>
890 * @result alert('Hello'); // Only executed for the first mouseup
894 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
899 * Removes a bound mouseup event from each of the matched
900 * elements. You must pass the identical function that was used in the original
903 * @example $("p").unmouseup( myFunction );
904 * @before <p onmouseup="myFunction">Hello</p>
905 * @result <p>Hello</p>
909 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
914 * Removes all bound mouseup events from each of the matched elements.
916 * @example $("p").unmouseup();
917 * @before <p onmouseup="alert('Hello');">Hello</p>
918 * @result <p>Hello</p>
926 * Bind a function to the unload event of each matched element.
928 * @example $("p").unload( function() { alert("Hello"); } );
929 * @before <p>Hello</p>
930 * @result <p onunload="alert('Hello');">Hello</p>
934 * @param Function fn A function to bind to the unload event on each of the matched elements.
935 * @cat Events/Browser
939 * Trigger the unload event of each matched element. This causes all of the functions
940 * that have been bound to thet unload event to be executed.
942 * @example $("p").unload();
943 * @before <p onunload="alert('Hello');">Hello</p>
944 * @result alert('Hello');
948 * @cat Events/Browser
952 * Bind a function to the unload event of each matched element, which will only be executed once.
953 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
954 * only executed the first time it is triggered, and never again (unless it is re-bound).
956 * @example $("p").oneunload( function() { alert("Hello"); } );
957 * @before <p onunload="alert('Hello');">Hello</p>
958 * @result alert('Hello'); // Only executed for the first unload
962 * @param Function fn A function to bind to the unload event on each of the matched elements.
963 * @cat Events/Browser
967 * Removes a bound unload event from each of the matched
968 * elements. You must pass the identical function that was used in the original
971 * @example $("p").ununload( myFunction );
972 * @before <p onunload="myFunction">Hello</p>
973 * @result <p>Hello</p>
977 * @param Function fn A function to unbind from the unload event on each of the matched elements.
978 * @cat Events/Browser
982 * Removes all bound unload events from each of the matched elements.
984 * @example $("p").ununload();
985 * @before <p onunload="alert('Hello');">Hello</p>
986 * @result <p>Hello</p>
990 * @cat Events/Browser
994 * Bind a function to the change event of each matched element.
996 * @example $("p").change( function() { alert("Hello"); } );
997 * @before <p>Hello</p>
998 * @result <p onchange="alert('Hello');">Hello</p>
1002 * @param Function fn A function to bind to the change event on each of the matched elements.
1007 * Trigger the change event of each matched element. This causes all of the functions
1008 * that have been bound to thet change event to be executed.
1010 * @example $("p").change();
1011 * @before <p onchange="alert('Hello');">Hello</p>
1012 * @result alert('Hello');
1020 * Bind a function to the change event of each matched element, which will only be executed once.
1021 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
1022 * only executed the first time it is triggered, and never again (unless it is re-bound).
1024 * @example $("p").onechange( function() { alert("Hello"); } );
1025 * @before <p onchange="alert('Hello');">Hello</p>
1026 * @result alert('Hello'); // Only executed for the first change
1030 * @param Function fn A function to bind to the change event on each of the matched elements.
1035 * Removes a bound change event from each of the matched
1036 * elements. You must pass the identical function that was used in the original
1039 * @example $("p").unchange( myFunction );
1040 * @before <p onchange="myFunction">Hello</p>
1041 * @result <p>Hello</p>
1045 * @param Function fn A function to unbind from the change event on each of the matched elements.
1050 * Removes all bound change events from each of the matched elements.
1052 * @example $("p").unchange();
1053 * @before <p onchange="alert('Hello');">Hello</p>
1054 * @result <p>Hello</p>
1062 * Bind a function to the mouseout event of each matched element.
1064 * @example $("p").mouseout( function() { alert("Hello"); } );
1065 * @before <p>Hello</p>
1066 * @result <p onmouseout="alert('Hello');">Hello</p>
1070 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1075 * Trigger the mouseout event of each matched element. This causes all of the functions
1076 * that have been bound to thet mouseout event to be executed.
1078 * @example $("p").mouseout();
1079 * @before <p onmouseout="alert('Hello');">Hello</p>
1080 * @result alert('Hello');
1088 * Bind a function to the mouseout event of each matched element, which will only be executed once.
1089 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
1090 * only executed the first time it is triggered, and never again (unless it is re-bound).
1092 * @example $("p").onemouseout( function() { alert("Hello"); } );
1093 * @before <p onmouseout="alert('Hello');">Hello</p>
1094 * @result alert('Hello'); // Only executed for the first mouseout
1098 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1103 * Removes a bound mouseout event from each of the matched
1104 * elements. You must pass the identical function that was used in the original
1107 * @example $("p").unmouseout( myFunction );
1108 * @before <p onmouseout="myFunction">Hello</p>
1109 * @result <p>Hello</p>
1113 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
1118 * Removes all bound mouseout events from each of the matched elements.
1120 * @example $("p").unmouseout();
1121 * @before <p onmouseout="alert('Hello');">Hello</p>
1122 * @result <p>Hello</p>
1130 * Bind a function to the keyup event of each matched element.
1132 * @example $("p").keyup( function() { alert("Hello"); } );
1133 * @before <p>Hello</p>
1134 * @result <p onkeyup="alert('Hello');">Hello</p>
1138 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1139 * @cat Events/Keyboard
1143 * Trigger the keyup event of each matched element. This causes all of the functions
1144 * that have been bound to thet keyup event to be executed.
1146 * @example $("p").keyup();
1147 * @before <p onkeyup="alert('Hello');">Hello</p>
1148 * @result alert('Hello');
1152 * @cat Events/Keyboard
1156 * Bind a function to the keyup event of each matched element, which will only be executed once.
1157 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1158 * only executed the first time it is triggered, and never again (unless it is re-bound).
1160 * @example $("p").onekeyup( function() { alert("Hello"); } );
1161 * @before <p onkeyup="alert('Hello');">Hello</p>
1162 * @result alert('Hello'); // Only executed for the first keyup
1166 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1167 * @cat Events/Keyboard
1171 * Removes a bound keyup event from each of the matched
1172 * elements. You must pass the identical function that was used in the original
1175 * @example $("p").unkeyup( myFunction );
1176 * @before <p onkeyup="myFunction">Hello</p>
1177 * @result <p>Hello</p>
1181 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1182 * @cat Events/Keyboard
1186 * Removes all bound keyup events from each of the matched elements.
1188 * @example $("p").unkeyup();
1189 * @before <p onkeyup="alert('Hello');">Hello</p>
1190 * @result <p>Hello</p>
1194 * @cat Events/Keyboard
1198 * Bind a function to the click event of each matched element.
1200 * @example $("p").click( function() { alert("Hello"); } );
1201 * @before <p>Hello</p>
1202 * @result <p onclick="alert('Hello');">Hello</p>
1206 * @param Function fn A function to bind to the click event on each of the matched elements.
1211 * Trigger the click event of each matched element. This causes all of the functions
1212 * that have been bound to thet click event to be executed.
1214 * @example $("p").click();
1215 * @before <p onclick="alert('Hello');">Hello</p>
1216 * @result alert('Hello');
1224 * Bind a function to the click event of each matched element, which will only be executed once.
1225 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
1226 * only executed the first time it is triggered, and never again (unless it is re-bound).
1228 * @example $("p").oneclick( function() { alert("Hello"); } );
1229 * @before <p onclick="alert('Hello');">Hello</p>
1230 * @result alert('Hello'); // Only executed for the first click
1234 * @param Function fn A function to bind to the click event on each of the matched elements.
1239 * Removes a bound click event from each of the matched
1240 * elements. You must pass the identical function that was used in the original
1243 * @example $("p").unclick( myFunction );
1244 * @before <p onclick="myFunction">Hello</p>
1245 * @result <p>Hello</p>
1249 * @param Function fn A function to unbind from the click event on each of the matched elements.
1254 * Removes all bound click events from each of the matched elements.
1256 * @example $("p").unclick();
1257 * @before <p onclick="alert('Hello');">Hello</p>
1258 * @result <p>Hello</p>
1266 * Bind a function to the resize event of each matched element.
1268 * @example $("p").resize( function() { alert("Hello"); } );
1269 * @before <p>Hello</p>
1270 * @result <p onresize="alert('Hello');">Hello</p>
1274 * @param Function fn A function to bind to the resize event on each of the matched elements.
1275 * @cat Events/Browser
1279 * Trigger the resize event of each matched element. This causes all of the functions
1280 * that have been bound to thet resize event to be executed.
1282 * @example $("p").resize();
1283 * @before <p onresize="alert('Hello');">Hello</p>
1284 * @result alert('Hello');
1288 * @cat Events/Browser
1292 * Bind a function to the resize event of each matched element, which will only be executed once.
1293 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
1294 * only executed the first time it is triggered, and never again (unless it is re-bound).
1296 * @example $("p").oneresize( function() { alert("Hello"); } );
1297 * @before <p onresize="alert('Hello');">Hello</p>
1298 * @result alert('Hello'); // Only executed for the first resize
1302 * @param Function fn A function to bind to the resize event on each of the matched elements.
1303 * @cat Events/Browser
1307 * Removes a bound resize event from each of the matched
1308 * elements. You must pass the identical function that was used in the original
1311 * @example $("p").unresize( myFunction );
1312 * @before <p onresize="myFunction">Hello</p>
1313 * @result <p>Hello</p>
1317 * @param Function fn A function to unbind from the resize event on each of the matched elements.
1318 * @cat Events/Browser
1322 * Removes all bound resize events from each of the matched elements.
1324 * @example $("p").unresize();
1325 * @before <p onresize="alert('Hello');">Hello</p>
1326 * @result <p>Hello</p>
1330 * @cat Events/Browser
1334 * Bind a function to the mousemove event of each matched element.
1336 * @example $("p").mousemove( function() { alert("Hello"); } );
1337 * @before <p>Hello</p>
1338 * @result <p onmousemove="alert('Hello');">Hello</p>
1342 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1347 * Trigger the mousemove event of each matched element. This causes all of the functions
1348 * that have been bound to thet mousemove event to be executed.
1350 * @example $("p").mousemove();
1351 * @before <p onmousemove="alert('Hello');">Hello</p>
1352 * @result alert('Hello');
1360 * Bind a function to the mousemove event of each matched element, which will only be executed once.
1361 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
1362 * only executed the first time it is triggered, and never again (unless it is re-bound).
1364 * @example $("p").onemousemove( function() { alert("Hello"); } );
1365 * @before <p onmousemove="alert('Hello');">Hello</p>
1366 * @result alert('Hello'); // Only executed for the first mousemove
1368 * @name onemousemove
1370 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1375 * Removes a bound mousemove event from each of the matched
1376 * elements. You must pass the identical function that was used in the original
1379 * @example $("p").unmousemove( myFunction );
1380 * @before <p onmousemove="myFunction">Hello</p>
1381 * @result <p>Hello</p>
1385 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
1390 * Removes all bound mousemove events from each of the matched elements.
1392 * @example $("p").unmousemove();
1393 * @before <p onmousemove="alert('Hello');">Hello</p>
1394 * @result <p>Hello</p>
1402 * Bind a function to the mousedown event of each matched element.
1404 * @example $("p").mousedown( function() { alert("Hello"); } );
1405 * @before <p>Hello</p>
1406 * @result <p onmousedown="alert('Hello');">Hello</p>
1410 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1415 * Trigger the mousedown event of each matched element. This causes all of the functions
1416 * that have been bound to thet mousedown event to be executed.
1418 * @example $("p").mousedown();
1419 * @before <p onmousedown="alert('Hello');">Hello</p>
1420 * @result alert('Hello');
1428 * Bind a function to the mousedown event of each matched element, which will only be executed once.
1429 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
1430 * only executed the first time it is triggered, and never again (unless it is re-bound).
1432 * @example $("p").onemousedown( function() { alert("Hello"); } );
1433 * @before <p onmousedown="alert('Hello');">Hello</p>
1434 * @result alert('Hello'); // Only executed for the first mousedown
1436 * @name onemousedown
1438 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1443 * Removes a bound mousedown event from each of the matched
1444 * elements. You must pass the identical function that was used in the original
1447 * @example $("p").unmousedown( myFunction );
1448 * @before <p onmousedown="myFunction">Hello</p>
1449 * @result <p>Hello</p>
1453 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
1458 * Removes all bound mousedown events from each of the matched elements.
1460 * @example $("p").unmousedown();
1461 * @before <p onmousedown="alert('Hello');">Hello</p>
1462 * @result <p>Hello</p>
1470 * Bind a function to the mouseover event of each matched element.
1472 * @example $("p").mouseover( function() { alert("Hello"); } );
1473 * @before <p>Hello</p>
1474 * @result <p onmouseover="alert('Hello');">Hello</p>
1478 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1483 * Trigger the mouseover event of each matched element. This causes all of the functions
1484 * that have been bound to thet mousedown event to be executed.
1486 * @example $("p").mouseover();
1487 * @before <p onmouseover="alert('Hello');">Hello</p>
1488 * @result alert('Hello');
1496 * Bind a function to the mouseover event of each matched element, which will only be executed once.
1497 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
1498 * only executed the first time it is triggered, and never again (unless it is re-bound).
1500 * @example $("p").onemouseover( function() { alert("Hello"); } );
1501 * @before <p onmouseover="alert('Hello');">Hello</p>
1502 * @result alert('Hello'); // Only executed for the first mouseover
1504 * @name onemouseover
1506 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
1511 * Removes a bound mouseover event from each of the matched
1512 * elements. You must pass the identical function that was used in the original
1515 * @example $("p").unmouseover( myFunction );
1516 * @before <p onmouseover="myFunction">Hello</p>
1517 * @result <p>Hello</p>
1521 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
1526 * Removes all bound mouseover events from each of the matched elements.
1528 * @example $("p").unmouseover();
1529 * @before <p onmouseover="alert('Hello');">Hello</p>
1530 * @result <p>Hello</p>
1537 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1538 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
1539 "submit,keydown,keypress,keyup,error").split(",");
1541 // Go through all the event names, but make sure that
1542 // it is enclosed properly
1543 for ( var i = 0; i < e.length; i++ ) new function(){
1547 // Handle event binding
1548 jQuery.fn[o] = function(f){
1549 return f ? this.bind(o, f) : this.trigger(o);
1552 // Handle event unbinding
1553 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1555 // Finally, handle events that only fire once
1556 jQuery.fn["one"+o] = function(f){
1557 // save cloned reference to this
1558 var element = jQuery(this);
1559 var handler = function() {
1560 // unbind itself when executed
1561 element.unbind(o, handler);
1563 // apply original handler with the same arguments
1564 return f.apply(this, arguments);
1566 return this.bind(o, handler);
1571 // If Mozilla is used
1572 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1573 // Use the handy event callback
1574 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1576 // If IE is used, use the excellent hack by Matthias Miller
1577 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1578 } else if ( jQuery.browser.msie ) {
1580 // Only works if you document.write() it
1581 document.write("<scr" + "ipt id=__ie_init defer=true " +
1582 "src=//:><\/script>");
1584 // Use the defer script hack
1585 var script = document.getElementById("__ie_init");
1586 if (script) // script does not exist if jQuery is loaded dynamically
1587 script.onreadystatechange = function() {
1588 if ( this.readyState != "complete" ) return;
1589 this.parentNode.removeChild( this );
1593 // Clear from memory
1596 // If Safari is used
1597 } else if ( jQuery.browser.safari ) {
1598 // Continually check to see if the document.readyState is valid
1599 jQuery.safariTimer = setInterval(function(){
1600 // loaded and complete are both valid states
1601 if ( document.readyState == "loaded" ||
1602 document.readyState == "complete" ) {
1604 // If either one are found, remove the timer
1605 clearInterval( jQuery.safariTimer );
1606 jQuery.safariTimer = null;
1608 // and execute any waiting functions
1614 // A fallback to window.onload, that will always work
1615 jQuery.event.add( window, "load", jQuery.ready );
1619 // Clean up after IE to avoid memory leaks
1620 if (jQuery.browser.msie) jQuery(window).unload(function() {
1621 var event = jQuery.event, global = event.global;
1622 for (var type in global) {
1623 var els = global[type], i = els.length;
1624 if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i);