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.
\r
24 toggle: function(a,b) {
25 // If two functions are passed in, we're
26 // toggling on a click
27 return a && b ? this.click(function(e){
28 // Figure out which function to execute
29 this.last = this.last == a ? b : a;
31 // Make sure that clicks stop
34 // and execute the function
35 return this.last.apply( this, [e] ) || false;
38 // Otherwise, execute the old toggle function
43 * A method for simulating hovering (moving the mouse on, and off,
44 * an object). This is a custom method which provides an 'in' to a
47 * Whenever the mouse cursor is moved over a matched
48 * element, the first specified function is fired. Whenever the mouse
49 * moves off of the element, the second specified function fires.
50 * Additionally, checks are in place to see if the mouse is still within
51 * the specified element itself (for example, an image inside of a div),
52 * and if it is, it will continue to 'hover', and not move out
53 * (a common error in using a mouseout event handler).
55 * @example $("p").hover(function(){
56 * $(this).addClass("over");
58 * $(this).addClass("out");
63 * @param Function over The function to fire whenever the mouse is moved over a matched element.
64 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
66 hover: function(f,g) {
68 // A private function for haandling mouse 'hovering'
69 function handleHover(e) {
70 // Check if mouse(over|out) are still within the same parent element
71 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
73 // Traverse up the tree
74 while ( p && p != this ) p = p.parentNode;
76 // If we actually just moused on to a sub-element, ignore it
77 if ( p == this ) return false;
79 // Execute the right function
80 return (e.type == "mouseover" ? f : g).apply(this, [e]);
83 // Bind the function to the two event listeners
84 return this.mouseover(handleHover).mouseout(handleHover);
88 * Bind a function to be executed whenever the DOM is ready to be
89 * traversed and manipulated. This is probably the most important
90 * function included in the event module, as it can greatly improve
91 * the response times of your web applications.
93 * In a nutshell, this is a solid replacement for using window.onload,
94 * and attaching a function to that. By using this method, your bound Function
95 * will be called the instant the DOM is ready to be read and manipulated,
96 * which is exactly what 99.99% of all Javascript code needs to run.
\r
98 * Please ensure you have no code in your <body> onload event handler,
99 * otherwise $(document).ready() may not fire.
101 * @example $(document).ready(function(){ /* Your code here... */ });
105 * @param Function fn The function to be executed when the DOM is ready.
108 // If the DOM is already ready
109 if ( jQuery.isReady )
110 // Execute the function immediately
113 // Otherwise, remember the function for later
115 // Add the function to the wait list
116 jQuery.readyList.push( f );
125 * All the code that makes DOM Ready work nicely.
130 // Handle when the DOM is ready
132 // Make sure that the DOM is not already loaded
133 if ( !jQuery.isReady ) {
134 // Remember that the DOM is ready
135 jQuery.isReady = true;
137 // If there are functions bound, to execute
138 if ( jQuery.readyList ) {
139 // Execute all of them
140 for ( var i = 0; i < jQuery.readyList.length; i++ )
141 jQuery.readyList[i].apply( document );
143 // Reset the list of functions
144 jQuery.readyList = null;
153 * Bind a function to the blur event of each matched element.
155 * @example $("p").blur( function() { alert("Hello"); } );
156 * @before <p>Hello</p>
157 * @result <p onblur="alert('Hello');">Hello</p>
161 * @param Function fn A function to bind to the blur event on each of the matched elements.
165 * Trigger the blur event of each matched element. This causes all of the functions
166 * that have been bound to thet blur event to be executed.
168 * @example $("p").blur();
169 * @before <p onblur="alert('Hello');">Hello</p>
170 * @result alert('Hello');
177 * Bind a function to the blur event of each matched element, which will only be executed once.
178 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
179 * only executed the first time it is triggered, and never again (unless it is re-bound).
181 * @example $("p").oneblur( function() { alert("Hello"); } );
182 * @before <p onblur="alert('Hello');">Hello</p>
183 * @result alert('Hello'); // Only executed for the first blur
187 * @param Function fn A function to bind to the blur event on each of the matched elements.
191 * Removes a bound blur event from each of the matched
192 * elements. You must pass the identical function that was used in the original
195 * @example $("p").unblur( myFunction );
196 * @before <p onblur="myFunction">Hello</p>
197 * @result <p>Hello</p>
201 * @param Function fn A function to unbind from the blur event on each of the matched elements.
205 * Removes all bound blur events from each of the matched elements.
207 * @example $("p").unblur();
208 * @before <p onblur="alert('Hello');">Hello</p>
209 * @result <p>Hello</p>
216 * Bind a function to the focus event of each matched element.
218 * @example $("p").focus( function() { alert("Hello"); } );
219 * @before <p>Hello</p>
220 * @result <p onfocus="alert('Hello');">Hello</p>
224 * @param Function fn A function to bind to the focus event on each of the matched elements.
228 * Trigger the focus event of each matched element. This causes all of the functions
229 * that have been bound to thet focus event to be executed.
231 * @example $("p").focus();
232 * @before <p onfocus="alert('Hello');">Hello</p>
233 * @result alert('Hello');
240 * Bind a function to the focus event of each matched element, which will only be executed once.
241 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
242 * only executed the first time it is triggered, and never again (unless it is re-bound).
244 * @example $("p").onefocus( function() { alert("Hello"); } );
245 * @before <p onfocus="alert('Hello');">Hello</p>
246 * @result alert('Hello'); // Only executed for the first focus
250 * @param Function fn A function to bind to the focus event on each of the matched elements.
254 * Removes a bound focus event from each of the matched
255 * elements. You must pass the identical function that was used in the original
258 * @example $("p").unfocus( myFunction );
259 * @before <p onfocus="myFunction">Hello</p>
260 * @result <p>Hello</p>
264 * @param Function fn A function to unbind from the focus event on each of the matched elements.
268 * Removes all bound focus events from each of the matched elements.
270 * @example $("p").unfocus();
271 * @before <p onfocus="alert('Hello');">Hello</p>
272 * @result <p>Hello</p>
279 * Bind a function to the load event of each matched element.
281 * @example $("p").load( function() { alert("Hello"); } );
282 * @before <p>Hello</p>
283 * @result <p onload="alert('Hello');">Hello</p>
287 * @param Function fn A function to bind to the load event on each of the matched elements.
291 * Trigger the load event of each matched element. This causes all of the functions
292 * that have been bound to thet load event to be executed.
294 * @example $("p").load();
295 * @before <p onload="alert('Hello');">Hello</p>
296 * @result alert('Hello');
303 * Bind a function to the load event of each matched element, which will only be executed once.
304 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
305 * only executed the first time it is triggered, and never again (unless it is re-bound).
307 * @example $("p").oneload( function() { alert("Hello"); } );
308 * @before <p onload="alert('Hello');">Hello</p>
309 * @result alert('Hello'); // Only executed for the first load
313 * @param Function fn A function to bind to the load event on each of the matched elements.
317 * Removes a bound load event from each of the matched
318 * elements. You must pass the identical function that was used in the original
321 * @example $("p").unload( myFunction );
322 * @before <p onload="myFunction">Hello</p>
323 * @result <p>Hello</p>
327 * @param Function fn A function to unbind from the load event on each of the matched elements.
331 * Removes all bound load events from each of the matched elements.
333 * @example $("p").unload();
334 * @before <p onload="alert('Hello');">Hello</p>
335 * @result <p>Hello</p>
342 * Bind a function to the resize event of each matched element.
344 * @example $("p").resize( function() { alert("Hello"); } );
345 * @before <p>Hello</p>
346 * @result <p onresize="alert('Hello');">Hello</p>
350 * @param Function fn A function to bind to the resize event on each of the matched elements.
354 * Trigger the resize event of each matched element. This causes all of the functions
355 * that have been bound to thet resize event to be executed.
357 * @example $("p").resize();
358 * @before <p onresize="alert('Hello');">Hello</p>
359 * @result alert('Hello');
366 * Bind a function to the resize event of each matched element, which will only be executed once.
367 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
368 * only executed the first time it is triggered, and never again (unless it is re-bound).
370 * @example $("p").oneresize( function() { alert("Hello"); } );
371 * @before <p onresize="alert('Hello');">Hello</p>
372 * @result alert('Hello'); // Only executed for the first resize
376 * @param Function fn A function to bind to the resize event on each of the matched elements.
380 * Removes a bound resize event from each of the matched
381 * elements. You must pass the identical function that was used in the original
384 * @example $("p").unresize( myFunction );
385 * @before <p onresize="myFunction">Hello</p>
386 * @result <p>Hello</p>
390 * @param Function fn A function to unbind from the resize event on each of the matched elements.
394 * Removes all bound resize events from each of the matched elements.
396 * @example $("p").unresize();
397 * @before <p onresize="alert('Hello');">Hello</p>
398 * @result <p>Hello</p>
405 * Bind a function to the scroll event of each matched element.
407 * @example $("p").scroll( function() { alert("Hello"); } );
408 * @before <p>Hello</p>
409 * @result <p onscroll="alert('Hello');">Hello</p>
413 * @param Function fn A function to bind to the scroll event on each of the matched elements.
417 * Trigger the scroll event of each matched element. This causes all of the functions
418 * that have been bound to thet scroll event to be executed.
420 * @example $("p").scroll();
421 * @before <p onscroll="alert('Hello');">Hello</p>
422 * @result alert('Hello');
429 * Bind a function to the scroll event of each matched element, which will only be executed once.
430 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
431 * only executed the first time it is triggered, and never again (unless it is re-bound).
433 * @example $("p").onescroll( function() { alert("Hello"); } );
434 * @before <p onscroll="alert('Hello');">Hello</p>
435 * @result alert('Hello'); // Only executed for the first scroll
439 * @param Function fn A function to bind to the scroll event on each of the matched elements.
443 * Removes a bound scroll event from each of the matched
444 * elements. You must pass the identical function that was used in the original
447 * @example $("p").unscroll( myFunction );
448 * @before <p onscroll="myFunction">Hello</p>
449 * @result <p>Hello</p>
453 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
457 * Removes all bound scroll events from each of the matched elements.
459 * @example $("p").unscroll();
460 * @before <p onscroll="alert('Hello');">Hello</p>
461 * @result <p>Hello</p>
468 * Bind a function to the unload event of each matched element.
470 * @example $("p").unload( function() { alert("Hello"); } );
471 * @before <p>Hello</p>
472 * @result <p onunload="alert('Hello');">Hello</p>
476 * @param Function fn A function to bind to the unload event on each of the matched elements.
480 * Trigger the unload event of each matched element. This causes all of the functions
481 * that have been bound to thet unload event to be executed.
483 * @example $("p").unload();
484 * @before <p onunload="alert('Hello');">Hello</p>
485 * @result alert('Hello');
492 * Bind a function to the unload event of each matched element, which will only be executed once.
493 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
494 * only executed the first time it is triggered, and never again (unless it is re-bound).
496 * @example $("p").oneunload( function() { alert("Hello"); } );
497 * @before <p onunload="alert('Hello');">Hello</p>
498 * @result alert('Hello'); // Only executed for the first unload
502 * @param Function fn A function to bind to the unload event on each of the matched elements.
506 * Removes a bound unload event from each of the matched
507 * elements. You must pass the identical function that was used in the original
510 * @example $("p").ununload( myFunction );
511 * @before <p onunload="myFunction">Hello</p>
512 * @result <p>Hello</p>
516 * @param Function fn A function to unbind from the unload event on each of the matched elements.
520 * Removes all bound unload events from each of the matched elements.
522 * @example $("p").ununload();
523 * @before <p onunload="alert('Hello');">Hello</p>
524 * @result <p>Hello</p>
531 * Bind a function to the click event of each matched element.
533 * @example $("p").click( function() { alert("Hello"); } );
534 * @before <p>Hello</p>
535 * @result <p onclick="alert('Hello');">Hello</p>
539 * @param Function fn A function to bind to the click event on each of the matched elements.
543 * Trigger the click event of each matched element. This causes all of the functions
544 * that have been bound to thet click event to be executed.
546 * @example $("p").click();
547 * @before <p onclick="alert('Hello');">Hello</p>
548 * @result alert('Hello');
555 * Bind a function to the click event of each matched element, which will only be executed once.
556 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
557 * only executed the first time it is triggered, and never again (unless it is re-bound).
559 * @example $("p").oneclick( function() { alert("Hello"); } );
560 * @before <p onclick="alert('Hello');">Hello</p>
561 * @result alert('Hello'); // Only executed for the first click
565 * @param Function fn A function to bind to the click event on each of the matched elements.
569 * Removes a bound click event from each of the matched
570 * elements. You must pass the identical function that was used in the original
573 * @example $("p").unclick( myFunction );
574 * @before <p onclick="myFunction">Hello</p>
575 * @result <p>Hello</p>
579 * @param Function fn A function to unbind from the click event on each of the matched elements.
583 * Removes all bound click events from each of the matched elements.
585 * @example $("p").unclick();
586 * @before <p onclick="alert('Hello');">Hello</p>
587 * @result <p>Hello</p>
594 * Bind a function to the dblclick event of each matched element.
596 * @example $("p").dblclick( function() { alert("Hello"); } );
597 * @before <p>Hello</p>
598 * @result <p ondblclick="alert('Hello');">Hello</p>
602 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
606 * Trigger the dblclick event of each matched element. This causes all of the functions
607 * that have been bound to thet dblclick event to be executed.
609 * @example $("p").dblclick();
610 * @before <p ondblclick="alert('Hello');">Hello</p>
611 * @result alert('Hello');
618 * Bind a function to the dblclick event of each matched element, which will only be executed once.
619 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
620 * only executed the first time it is triggered, and never again (unless it is re-bound).
622 * @example $("p").onedblclick( function() { alert("Hello"); } );
623 * @before <p ondblclick="alert('Hello');">Hello</p>
624 * @result alert('Hello'); // Only executed for the first dblclick
628 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
632 * Removes a bound dblclick event from each of the matched
633 * elements. You must pass the identical function that was used in the original
636 * @example $("p").undblclick( myFunction );
637 * @before <p ondblclick="myFunction">Hello</p>
638 * @result <p>Hello</p>
642 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
646 * Removes all bound dblclick events from each of the matched elements.
648 * @example $("p").undblclick();
649 * @before <p ondblclick="alert('Hello');">Hello</p>
650 * @result <p>Hello</p>
657 * Bind a function to the mousedown event of each matched element.
659 * @example $("p").mousedown( function() { alert("Hello"); } );
660 * @before <p>Hello</p>
661 * @result <p onmousedown="alert('Hello');">Hello</p>
665 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
669 * Trigger the mousedown event of each matched element. This causes all of the functions
670 * that have been bound to thet mousedown event to be executed.
672 * @example $("p").mousedown();
673 * @before <p onmousedown="alert('Hello');">Hello</p>
674 * @result alert('Hello');
681 * Bind a function to the mousedown event of each matched element, which will only be executed once.
682 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
683 * only executed the first time it is triggered, and never again (unless it is re-bound).
685 * @example $("p").onemousedown( function() { alert("Hello"); } );
686 * @before <p onmousedown="alert('Hello');">Hello</p>
687 * @result alert('Hello'); // Only executed for the first mousedown
691 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
695 * Removes a bound mousedown event from each of the matched
696 * elements. You must pass the identical function that was used in the original
699 * @example $("p").unmousedown( myFunction );
700 * @before <p onmousedown="myFunction">Hello</p>
701 * @result <p>Hello</p>
705 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
709 * Removes all bound mousedown events from each of the matched elements.
711 * @example $("p").unmousedown();
712 * @before <p onmousedown="alert('Hello');">Hello</p>
713 * @result <p>Hello</p>
720 * Bind a function to the mouseup event of each matched element.
722 * @example $("p").mouseup( function() { alert("Hello"); } );
723 * @before <p>Hello</p>
724 * @result <p onmouseup="alert('Hello');">Hello</p>
728 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
732 * Trigger the mouseup event of each matched element. This causes all of the functions
733 * that have been bound to thet mouseup event to be executed.
735 * @example $("p").mouseup();
736 * @before <p onmouseup="alert('Hello');">Hello</p>
737 * @result alert('Hello');
744 * Bind a function to the mouseup event of each matched element, which will only be executed once.
745 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
746 * only executed the first time it is triggered, and never again (unless it is re-bound).
748 * @example $("p").onemouseup( function() { alert("Hello"); } );
749 * @before <p onmouseup="alert('Hello');">Hello</p>
750 * @result alert('Hello'); // Only executed for the first mouseup
754 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
758 * Removes a bound mouseup event from each of the matched
759 * elements. You must pass the identical function that was used in the original
762 * @example $("p").unmouseup( myFunction );
763 * @before <p onmouseup="myFunction">Hello</p>
764 * @result <p>Hello</p>
768 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
772 * Removes all bound mouseup events from each of the matched elements.
774 * @example $("p").unmouseup();
775 * @before <p onmouseup="alert('Hello');">Hello</p>
776 * @result <p>Hello</p>
783 * Bind a function to the mousemove event of each matched element.
785 * @example $("p").mousemove( function() { alert("Hello"); } );
786 * @before <p>Hello</p>
787 * @result <p onmousemove="alert('Hello');">Hello</p>
791 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
795 * Trigger the mousemove event of each matched element. This causes all of the functions
796 * that have been bound to thet mousemove event to be executed.
798 * @example $("p").mousemove();
799 * @before <p onmousemove="alert('Hello');">Hello</p>
800 * @result alert('Hello');
807 * Bind a function to the mousemove event of each matched element, which will only be executed once.
808 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
809 * only executed the first time it is triggered, and never again (unless it is re-bound).
811 * @example $("p").onemousemove( function() { alert("Hello"); } );
812 * @before <p onmousemove="alert('Hello');">Hello</p>
813 * @result alert('Hello'); // Only executed for the first mousemove
817 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
821 * Removes a bound mousemove event from each of the matched
822 * elements. You must pass the identical function that was used in the original
825 * @example $("p").unmousemove( myFunction );
826 * @before <p onmousemove="myFunction">Hello</p>
827 * @result <p>Hello</p>
831 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
835 * Removes all bound mousemove events from each of the matched elements.
837 * @example $("p").unmousemove();
838 * @before <p onmousemove="alert('Hello');">Hello</p>
839 * @result <p>Hello</p>
846 * Bind a function to the mouseover event of each matched element.
848 * @example $("p").mouseover( function() { alert("Hello"); } );
849 * @before <p>Hello</p>
850 * @result <p onmouseover="alert('Hello');">Hello</p>
854 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
858 * Trigger the mouseover event of each matched element. This causes all of the functions
859 * that have been bound to thet mouseover event to be executed.
861 * @example $("p").mouseover();
862 * @before <p onmouseover="alert('Hello');">Hello</p>
863 * @result alert('Hello');
870 * Bind a function to the mouseover event of each matched element, which will only be executed once.
871 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
872 * only executed the first time it is triggered, and never again (unless it is re-bound).
874 * @example $("p").onemouseover( function() { alert("Hello"); } );
875 * @before <p onmouseover="alert('Hello');">Hello</p>
876 * @result alert('Hello'); // Only executed for the first mouseover
880 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
884 * Removes a bound mouseover event from each of the matched
885 * elements. You must pass the identical function that was used in the original
888 * @example $("p").unmouseover( myFunction );
889 * @before <p onmouseover="myFunction">Hello</p>
890 * @result <p>Hello</p>
894 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
898 * Removes all bound mouseover events from each of the matched elements.
900 * @example $("p").unmouseover();
901 * @before <p onmouseover="alert('Hello');">Hello</p>
902 * @result <p>Hello</p>
909 * Bind a function to the mouseout event of each matched element.
911 * @example $("p").mouseout( function() { alert("Hello"); } );
912 * @before <p>Hello</p>
913 * @result <p onmouseout="alert('Hello');">Hello</p>
917 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
921 * Trigger the mouseout event of each matched element. This causes all of the functions
922 * that have been bound to thet mouseout event to be executed.
924 * @example $("p").mouseout();
925 * @before <p onmouseout="alert('Hello');">Hello</p>
926 * @result alert('Hello');
933 * Bind a function to the mouseout event of each matched element, which will only be executed once.
934 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
935 * only executed the first time it is triggered, and never again (unless it is re-bound).
937 * @example $("p").onemouseout( function() { alert("Hello"); } );
938 * @before <p onmouseout="alert('Hello');">Hello</p>
939 * @result alert('Hello'); // Only executed for the first mouseout
943 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
947 * Removes a bound mouseout event from each of the matched
948 * elements. You must pass the identical function that was used in the original
951 * @example $("p").unmouseout( myFunction );
952 * @before <p onmouseout="myFunction">Hello</p>
953 * @result <p>Hello</p>
957 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
961 * Removes all bound mouseout events from each of the matched elements.
963 * @example $("p").unmouseout();
964 * @before <p onmouseout="alert('Hello');">Hello</p>
965 * @result <p>Hello</p>
972 * Bind a function to the change event of each matched element.
974 * @example $("p").change( function() { alert("Hello"); } );
975 * @before <p>Hello</p>
976 * @result <p onchange="alert('Hello');">Hello</p>
980 * @param Function fn A function to bind to the change event on each of the matched elements.
984 * Trigger the change event of each matched element. This causes all of the functions
985 * that have been bound to thet change event to be executed.
987 * @example $("p").change();
988 * @before <p onchange="alert('Hello');">Hello</p>
989 * @result alert('Hello');
996 * Bind a function to the change event of each matched element, which will only be executed once.
997 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
998 * only executed the first time it is triggered, and never again (unless it is re-bound).
1000 * @example $("p").onechange( function() { alert("Hello"); } );
1001 * @before <p onchange="alert('Hello');">Hello</p>
1002 * @result alert('Hello'); // Only executed for the first change
1006 * @param Function fn A function to bind to the change event on each of the matched elements.
1010 * Removes a bound change event from each of the matched
1011 * elements. You must pass the identical function that was used in the original
1014 * @example $("p").unchange( myFunction );
1015 * @before <p onchange="myFunction">Hello</p>
1016 * @result <p>Hello</p>
1020 * @param Function fn A function to unbind from the change event on each of the matched elements.
1024 * Removes all bound change events from each of the matched elements.
1026 * @example $("p").unchange();
1027 * @before <p onchange="alert('Hello');">Hello</p>
1028 * @result <p>Hello</p>
1035 * Bind a function to the reset event of each matched element.
1037 * @example $("p").reset( function() { alert("Hello"); } );
1038 * @before <p>Hello</p>
1039 * @result <p onreset="alert('Hello');">Hello</p>
1043 * @param Function fn A function to bind to the reset event on each of the matched elements.
1047 * Trigger the reset event of each matched element. This causes all of the functions
1048 * that have been bound to thet reset event to be executed.
1050 * @example $("p").reset();
1051 * @before <p onreset="alert('Hello');">Hello</p>
1052 * @result alert('Hello');
1059 * Bind a function to the reset event of each matched element, which will only be executed once.
1060 * Unlike a call to the normal .reset() method, calling .onereset() causes the bound function to be
1061 * only executed the first time it is triggered, and never again (unless it is re-bound).
1063 * @example $("p").onereset( function() { alert("Hello"); } );
1064 * @before <p onreset="alert('Hello');">Hello</p>
1065 * @result alert('Hello'); // Only executed for the first reset
1069 * @param Function fn A function to bind to the reset event on each of the matched elements.
1073 * Removes a bound reset event from each of the matched
1074 * elements. You must pass the identical function that was used in the original
1077 * @example $("p").unreset( myFunction );
1078 * @before <p onreset="myFunction">Hello</p>
1079 * @result <p>Hello</p>
1083 * @param Function fn A function to unbind from the reset event on each of the matched elements.
1087 * Removes all bound reset events from each of the matched elements.
1089 * @example $("p").unreset();
1090 * @before <p onreset="alert('Hello');">Hello</p>
1091 * @result <p>Hello</p>
1098 * Bind a function to the select event of each matched element.
1100 * @example $("p").select( function() { alert("Hello"); } );
1101 * @before <p>Hello</p>
1102 * @result <p onselect="alert('Hello');">Hello</p>
1106 * @param Function fn A function to bind to the select event on each of the matched elements.
1110 * Trigger the select event of each matched element. This causes all of the functions
1111 * that have been bound to thet select event to be executed.
1113 * @example $("p").select();
1114 * @before <p onselect="alert('Hello');">Hello</p>
1115 * @result alert('Hello');
1122 * Bind a function to the select event of each matched element, which will only be executed once.
1123 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
1124 * only executed the first time it is triggered, and never again (unless it is re-bound).
1126 * @example $("p").oneselect( function() { alert("Hello"); } );
1127 * @before <p onselect="alert('Hello');">Hello</p>
1128 * @result alert('Hello'); // Only executed for the first select
1132 * @param Function fn A function to bind to the select event on each of the matched elements.
1136 * Removes a bound select event from each of the matched
1137 * elements. You must pass the identical function that was used in the original
1140 * @example $("p").unselect( myFunction );
1141 * @before <p onselect="myFunction">Hello</p>
1142 * @result <p>Hello</p>
1146 * @param Function fn A function to unbind from the select event on each of the matched elements.
1150 * Removes all bound select events from each of the matched elements.
1152 * @example $("p").unselect();
1153 * @before <p onselect="alert('Hello');">Hello</p>
1154 * @result <p>Hello</p>
1161 * Bind a function to the submit event of each matched element.
1163 * @example $("p").submit( function() { alert("Hello"); } );
1164 * @before <p>Hello</p>
1165 * @result <p onsubmit="alert('Hello');">Hello</p>
1169 * @param Function fn A function to bind to the submit event on each of the matched elements.
1173 * Trigger the submit event of each matched element. This causes all of the functions
1174 * that have been bound to thet submit event to be executed.
1176 * @example $("p").submit();
1177 * @before <p onsubmit="alert('Hello');">Hello</p>
1178 * @result alert('Hello');
1185 * Bind a function to the submit event of each matched element, which will only be executed once.
1186 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
1187 * only executed the first time it is triggered, and never again (unless it is re-bound).
1189 * @example $("p").onesubmit( function() { alert("Hello"); } );
1190 * @before <p onsubmit="alert('Hello');">Hello</p>
1191 * @result alert('Hello'); // Only executed for the first submit
1195 * @param Function fn A function to bind to the submit event on each of the matched elements.
1199 * Removes a bound submit event from each of the matched
1200 * elements. You must pass the identical function that was used in the original
1203 * @example $("p").unsubmit( myFunction );
1204 * @before <p onsubmit="myFunction">Hello</p>
1205 * @result <p>Hello</p>
1209 * @param Function fn A function to unbind from the submit event on each of the matched elements.
1213 * Removes all bound submit events from each of the matched elements.
1215 * @example $("p").unsubmit();
1216 * @before <p onsubmit="alert('Hello');">Hello</p>
1217 * @result <p>Hello</p>
1224 * Bind a function to the keydown event of each matched element.
1226 * @example $("p").keydown( function() { alert("Hello"); } );
1227 * @before <p>Hello</p>
1228 * @result <p onkeydown="alert('Hello');">Hello</p>
1232 * @param Function fn A function to bind to the keydown event on each of the matched elements.
1236 * Trigger the keydown event of each matched element. This causes all of the functions
1237 * that have been bound to thet keydown event to be executed.
1239 * @example $("p").keydown();
1240 * @before <p onkeydown="alert('Hello');">Hello</p>
1241 * @result alert('Hello');
1248 * Bind a function to the keydown event of each matched element, which will only be executed once.
1249 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
1250 * only executed the first time it is triggered, and never again (unless it is re-bound).
1252 * @example $("p").onekeydown( function() { alert("Hello"); } );
1253 * @before <p onkeydown="alert('Hello');">Hello</p>
1254 * @result alert('Hello'); // Only executed for the first keydown
1258 * @param Function fn A function to bind to the keydown event on each of the matched elements.
1262 * Removes a bound keydown event from each of the matched
1263 * elements. You must pass the identical function that was used in the original
1266 * @example $("p").unkeydown( myFunction );
1267 * @before <p onkeydown="myFunction">Hello</p>
1268 * @result <p>Hello</p>
1272 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
1276 * Removes all bound keydown events from each of the matched elements.
1278 * @example $("p").unkeydown();
1279 * @before <p onkeydown="alert('Hello');">Hello</p>
1280 * @result <p>Hello</p>
1287 * Bind a function to the keypress event of each matched element.
1289 * @example $("p").keypress( function() { alert("Hello"); } );
1290 * @before <p>Hello</p>
1291 * @result <p onkeypress="alert('Hello');">Hello</p>
1295 * @param Function fn A function to bind to the keypress event on each of the matched elements.
1299 * Trigger the keypress event of each matched element. This causes all of the functions
1300 * that have been bound to thet keypress event to be executed.
1302 * @example $("p").keypress();
1303 * @before <p onkeypress="alert('Hello');">Hello</p>
1304 * @result alert('Hello');
1311 * Bind a function to the keypress event of each matched element, which will only be executed once.
1312 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
1313 * only executed the first time it is triggered, and never again (unless it is re-bound).
1315 * @example $("p").onekeypress( function() { alert("Hello"); } );
1316 * @before <p onkeypress="alert('Hello');">Hello</p>
1317 * @result alert('Hello'); // Only executed for the first keypress
1321 * @param Function fn A function to bind to the keypress event on each of the matched elements.
1325 * Removes a bound keypress event from each of the matched
1326 * elements. You must pass the identical function that was used in the original
1329 * @example $("p").unkeypress( myFunction );
1330 * @before <p onkeypress="myFunction">Hello</p>
1331 * @result <p>Hello</p>
1335 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
1339 * Removes all bound keypress events from each of the matched elements.
1341 * @example $("p").unkeypress();
1342 * @before <p onkeypress="alert('Hello');">Hello</p>
1343 * @result <p>Hello</p>
1350 * Bind a function to the keyup event of each matched element.
1352 * @example $("p").keyup( function() { alert("Hello"); } );
1353 * @before <p>Hello</p>
1354 * @result <p onkeyup="alert('Hello');">Hello</p>
1358 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1362 * Trigger the keyup event of each matched element. This causes all of the functions
1363 * that have been bound to thet keyup event to be executed.
1365 * @example $("p").keyup();
1366 * @before <p onkeyup="alert('Hello');">Hello</p>
1367 * @result alert('Hello');
1374 * Bind a function to the keyup event of each matched element, which will only be executed once.
1375 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1376 * only executed the first time it is triggered, and never again (unless it is re-bound).
1378 * @example $("p").onekeyup( function() { alert("Hello"); } );
1379 * @before <p onkeyup="alert('Hello');">Hello</p>
1380 * @result alert('Hello'); // Only executed for the first keyup
1384 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1388 * Removes a bound keyup event from each of the matched
1389 * elements. You must pass the identical function that was used in the original
1392 * @example $("p").unkeyup( myFunction );
1393 * @before <p onkeyup="myFunction">Hello</p>
1394 * @result <p>Hello</p>
1398 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1402 * Removes all bound keyup events from each of the matched elements.
1404 * @example $("p").unkeyup();
1405 * @before <p onkeyup="alert('Hello');">Hello</p>
1406 * @result <p>Hello</p>
1413 * Bind a function to the error event of each matched element.
1415 * @example $("p").error( function() { alert("Hello"); } );
1416 * @before <p>Hello</p>
1417 * @result <p onerror="alert('Hello');">Hello</p>
1421 * @param Function fn A function to bind to the error event on each of the matched elements.
1425 * Trigger the error event of each matched element. This causes all of the functions
1426 * that have been bound to thet error event to be executed.
1428 * @example $("p").error();
1429 * @before <p onerror="alert('Hello');">Hello</p>
1430 * @result alert('Hello');
1437 * Bind a function to the error event of each matched element, which will only be executed once.
1438 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
1439 * only executed the first time it is triggered, and never again (unless it is re-bound).
1441 * @example $("p").oneerror( function() { alert("Hello"); } );
1442 * @before <p onerror="alert('Hello');">Hello</p>
1443 * @result alert('Hello'); // Only executed for the first error
1447 * @param Function fn A function to bind to the error event on each of the matched elements.
1451 * Removes a bound error event from each of the matched
1452 * elements. You must pass the identical function that was used in the original
1455 * @example $("p").unerror( myFunction );
1456 * @before <p onerror="myFunction">Hello</p>
1457 * @result <p>Hello</p>
1461 * @param Function fn A function to unbind from the error event on each of the matched elements.
1465 * Removes all bound error events from each of the matched elements.
1467 * @example $("p").unerror();
1468 * @before <p onerror="alert('Hello');">Hello</p>
1469 * @result <p>Hello</p>
1475 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1476 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1477 "submit,keydown,keypress,keyup,error").split(",");
1479 // Go through all the event names, but make sure that
1480 // it is enclosed properly
1481 for ( var i = 0; i < e.length; i++ ) new function(){
1485 // Handle event binding
1486 jQuery.fn[o] = function(f){
1487 return f ? this.bind(o, f) : this.trigger(o);
1490 // Handle event unbinding
1491 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1493 // Finally, handle events that only fire once
1494 jQuery.fn["one"+o] = function(f){
1495 // Attach the event listener
1496 return this.each(function(){
1501 jQuery.event.add( this, o, function(e){
1502 // If this function has already been executed, stop
1503 if ( count++ ) return;
1505 // And execute the bound function
1506 return f.apply(this, [e]);
1513 // If Mozilla is used
1514 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1515 // Use the handy event callback
1516 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1518 // If IE is used, use the excellent hack by Matthias Miller
1519 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1520 } else if ( jQuery.browser.msie ) {
1522 // Only works if you document.write() it
1523 document.write("<scr" + "ipt id=__ie_init defer=true " +
1524 "src=//:><\/script>");
1526 // Use the defer script hack
1527 var script = document.getElementById("__ie_init");
1528 script.onreadystatechange = function() {
1529 if ( this.readyState == "complete" )
1533 // Clear from memory
1536 // If Safari is used
1537 } else if ( jQuery.browser.safari ) {
1538 // Continually check to see if the document.readyState is valid
1539 jQuery.safariTimer = setInterval(function(){
1540 // loaded and complete are both valid states
1541 if ( document.readyState == "loaded" ||
1542 document.readyState == "complete" ) {
1544 // If either one are found, remove the timer
1545 clearInterval( jQuery.safariTimer );
1546 jQuery.safariTimer = null;
1548 // and execute any waiting functions
1554 // A fallback to window.onload, that will always work
1555 jQuery.event.add( window, "load", jQuery.ready );