3 // We're overriding the old toggle function, so
\r
4 // remember it for later
\r
5 _toggle: jQuery.fn.toggle,
\r
8 * Toggle between two function calls every other click.
\r
9 * Whenever a matched element is clicked, the first specified function
\r
10 * is fired, when clicked again, the second is fired. All subsequent
\r
11 * clicks continue to rotate through the two functions.
\r
13 * @example $("p").toggle(function(){
\r
14 * $(this).addClass("selected");
\r
16 * $(this).removeClass("selected");
\r
19 * @test var count = 0;
\r
20 * var fn1 = function() { count++; }
\r
21 * var fn2 = function() { count--; }
\r
22 * var link = $('#mark');
\r
23 * link.click().toggle(fn1, fn2).click().click().click().click().click();
\r
24 * ok( count == 1, "Check for toggle(fn, fn)" );
\r
28 * @param Function even The function to execute on every even click.
\r
29 * @param Function odd The function to execute on every odd click.
\r
32 toggle: function(a,b) {
\r
33 // If two functions are passed in, we're
\r
34 // toggling on a click
\r
35 return a && b && a.constructor == Function && b.constructor == Function ? this.click(function(e){
\r
36 // Figure out which function to execute
\r
37 this.last = this.last == a ? b : a;
\r
39 // Make sure that clicks stop
\r
42 // and execute the function
\r
43 return this.last.apply( this, [e] ) || false;
\r
46 // Otherwise, execute the old toggle function
\r
47 this._toggle.apply( this, arguments );
\r
51 * A method for simulating hovering (moving the mouse on, and off,
\r
52 * an object). This is a custom method which provides an 'in' to a
\r
55 * Whenever the mouse cursor is moved over a matched
\r
56 * element, the first specified function is fired. Whenever the mouse
\r
57 * moves off of the element, the second specified function fires.
\r
58 * Additionally, checks are in place to see if the mouse is still within
\r
59 * the specified element itself (for example, an image inside of a div),
\r
60 * and if it is, it will continue to 'hover', and not move out
\r
61 * (a common error in using a mouseout event handler).
\r
63 * @example $("p").hover(function(){
\r
64 * $(this).addClass("over");
\r
66 * $(this).addClass("out");
\r
71 * @param Function over The function to fire whenever the mouse is moved over a matched element.
\r
72 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
\r
75 hover: function(f,g) {
\r
77 // A private function for haandling mouse 'hovering'
\r
78 function handleHover(e) {
\r
79 // Check if mouse(over|out) are still within the same parent element
\r
80 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
\r
82 // Traverse up the tree
\r
83 while ( p && p != this ) try { p = p.parentNode } catch(e) { p = null; };
\r
85 // If we actually just moused on to a sub-element, ignore it
\r
86 if ( p == this ) return false;
\r
88 // Execute the right function
\r
89 return (e.type == "mouseover" ? f : g).apply(this, [e]);
\r
92 // Bind the function to the two event listeners
\r
93 return this.mouseover(handleHover).mouseout(handleHover);
\r
97 * Bind a function to be executed whenever the DOM is ready to be
\r
98 * traversed and manipulated. This is probably the most important
\r
99 * function included in the event module, as it can greatly improve
\r
100 * the response times of your web applications.
\r
102 * In a nutshell, this is a solid replacement for using window.onload,
\r
103 * and attaching a function to that. By using this method, your bound Function
\r
104 * will be called the instant the DOM is ready to be read and manipulated,
\r
105 * which is exactly what 99.99% of all Javascript code needs to run.
\r
107 * Please ensure you have no code in your <body> onload event handler,
\r
108 * otherwise $(document).ready() may not fire.
\r
110 * You can have as many $(document).ready events on your page as you like.
\r
112 * @example $(document).ready(function(){ Your code here... });
\r
116 * @param Function fn The function to be executed when the DOM is ready.
\r
119 ready: function(f) {
\r
120 // If the DOM is already ready
\r
121 if ( jQuery.isReady )
\r
122 // Execute the function immediately
\r
123 f.apply( document );
\r
125 // Otherwise, remember the function for later
\r
127 // Add the function to the wait list
\r
128 jQuery.readyList.push( f );
\r
137 * All the code that makes DOM Ready work nicely.
\r
142 // Handle when the DOM is ready
\r
143 ready: function() {
\r
144 // Make sure that the DOM is not already loaded
\r
145 if ( !jQuery.isReady ) {
\r
146 // Remember that the DOM is ready
\r
147 jQuery.isReady = true;
\r
149 // If there are functions bound, to execute
\r
150 if ( jQuery.readyList ) {
\r
151 // Execute all of them
\r
152 for ( var i = 0; i < jQuery.readyList.length; i++ )
\r
153 jQuery.readyList[i].apply( document );
\r
155 // Reset the list of functions
\r
156 jQuery.readyList = null;
\r
165 * Bind a function to the scroll event of each matched element.
\r
167 * @example $("p").scroll( function() { alert("Hello"); } );
\r
168 * @before <p>Hello</p>
\r
169 * @result <p onscroll="alert('Hello');">Hello</p>
\r
173 * @param Function fn A function to bind to the scroll event on each of the matched elements.
\r
174 * @cat Events/Browser
\r
178 * Trigger the scroll event of each matched element. This causes all of the functions
\r
179 * that have been bound to thet scroll event to be executed.
\r
181 * @example $("p").scroll();
\r
182 * @before <p onscroll="alert('Hello');">Hello</p>
\r
183 * @result alert('Hello');
\r
187 * @cat Events/Browser
\r
191 * Bind a function to the scroll event of each matched element, which will only be executed once.
\r
192 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
\r
193 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
195 * @example $("p").onescroll( function() { alert("Hello"); } );
\r
196 * @before <p onscroll="alert('Hello');">Hello</p>
\r
197 * @result alert('Hello'); // Only executed for the first scroll
\r
201 * @param Function fn A function to bind to the scroll event on each of the matched elements.
\r
202 * @cat Events/Browser
\r
206 * Removes a bound scroll event from each of the matched
\r
207 * elements. You must pass the identical function that was used in the original
\r
210 * @example $("p").unscroll( myFunction );
\r
211 * @before <p onscroll="myFunction">Hello</p>
\r
212 * @result <p>Hello</p>
\r
216 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
\r
217 * @cat Events/Browser
\r
221 * Removes all bound scroll events from each of the matched elements.
\r
223 * @example $("p").unscroll();
\r
224 * @before <p onscroll="alert('Hello');">Hello</p>
\r
225 * @result <p>Hello</p>
\r
229 * @cat Events/Browser
\r
233 * Bind a function to the submit event of each matched element.
\r
235 * @example $("p").submit( function() { alert("Hello"); } );
\r
236 * @before <p>Hello</p>
\r
237 * @result <p onsubmit="alert('Hello');">Hello</p>
\r
241 * @param Function fn A function to bind to the submit event on each of the matched elements.
\r
246 * Trigger the submit event of each matched element. This causes all of the functions
\r
247 * that have been bound to thet submit event to be executed.
\r
249 * @example $("p").submit();
\r
250 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
251 * @result alert('Hello');
\r
259 * Bind a function to the submit event of each matched element, which will only be executed once.
\r
260 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
\r
261 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
263 * @example $("p").onesubmit( function() { alert("Hello"); } );
\r
264 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
265 * @result alert('Hello'); // Only executed for the first submit
\r
269 * @param Function fn A function to bind to the submit event on each of the matched elements.
\r
274 * Removes a bound submit event from each of the matched
\r
275 * elements. You must pass the identical function that was used in the original
\r
278 * @example $("p").unsubmit( myFunction );
\r
279 * @before <p onsubmit="myFunction">Hello</p>
\r
280 * @result <p>Hello</p>
\r
284 * @param Function fn A function to unbind from the submit event on each of the matched elements.
\r
289 * Removes all bound submit events from each of the matched elements.
\r
291 * @example $("p").unsubmit();
\r
292 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
293 * @result <p>Hello</p>
\r
301 * Bind a function to the focus event of each matched element.
\r
303 * @example $("p").focus( function() { alert("Hello"); } );
\r
304 * @before <p>Hello</p>
\r
305 * @result <p onfocus="alert('Hello');">Hello</p>
\r
309 * @param Function fn A function to bind to the focus event on each of the matched elements.
\r
314 * Trigger the focus event of each matched element. This causes all of the functions
\r
315 * that have been bound to thet focus event to be executed.
\r
317 * @example $("p").focus();
\r
318 * @before <p onfocus="alert('Hello');">Hello</p>
\r
319 * @result alert('Hello');
\r
327 * Bind a function to the focus event of each matched element, which will only be executed once.
\r
328 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
\r
329 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
331 * @example $("p").onefocus( function() { alert("Hello"); } );
\r
332 * @before <p onfocus="alert('Hello');">Hello</p>
\r
333 * @result alert('Hello'); // Only executed for the first focus
\r
337 * @param Function fn A function to bind to the focus event on each of the matched elements.
\r
342 * Removes a bound focus event from each of the matched
\r
343 * elements. You must pass the identical function that was used in the original
\r
346 * @example $("p").unfocus( myFunction );
\r
347 * @before <p onfocus="myFunction">Hello</p>
\r
348 * @result <p>Hello</p>
\r
352 * @param Function fn A function to unbind from the focus event on each of the matched elements.
\r
357 * Removes all bound focus events from each of the matched elements.
\r
359 * @example $("p").unfocus();
\r
360 * @before <p onfocus="alert('Hello');">Hello</p>
\r
361 * @result <p>Hello</p>
\r
369 * Bind a function to the keydown event of each matched element.
\r
371 * @example $("p").keydown( function() { alert("Hello"); } );
\r
372 * @before <p>Hello</p>
\r
373 * @result <p onkeydown="alert('Hello');">Hello</p>
\r
377 * @param Function fn A function to bind to the keydown event on each of the matched elements.
\r
378 * @cat Events/Keyboard
\r
382 * Trigger the keydown event of each matched element. This causes all of the functions
\r
383 * that have been bound to thet keydown event to be executed.
\r
385 * @example $("p").keydown();
\r
386 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
387 * @result alert('Hello');
\r
391 * @cat Events/Keyboard
\r
395 * Bind a function to the keydown event of each matched element, which will only be executed once.
\r
396 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
\r
397 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
399 * @example $("p").onekeydown( function() { alert("Hello"); } );
\r
400 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
401 * @result alert('Hello'); // Only executed for the first keydown
\r
405 * @param Function fn A function to bind to the keydown event on each of the matched elements.
\r
406 * @cat Events/Keyboard
\r
410 * Removes a bound keydown event from each of the matched
\r
411 * elements. You must pass the identical function that was used in the original
\r
414 * @example $("p").unkeydown( myFunction );
\r
415 * @before <p onkeydown="myFunction">Hello</p>
\r
416 * @result <p>Hello</p>
\r
420 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
\r
421 * @cat Events/Keyboard
\r
425 * Removes all bound keydown events from each of the matched elements.
\r
427 * @example $("p").unkeydown();
\r
428 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
429 * @result <p>Hello</p>
\r
433 * @cat Events/Keyboard
\r
437 * Bind a function to the dblclick event of each matched element.
\r
439 * @example $("p").dblclick( function() { alert("Hello"); } );
\r
440 * @before <p>Hello</p>
\r
441 * @result <p ondblclick="alert('Hello');">Hello</p>
\r
445 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
\r
446 * @cat Events/Mouse
\r
450 * Trigger the dblclick event of each matched element. This causes all of the functions
\r
451 * that have been bound to thet dblclick event to be executed.
\r
453 * @example $("p").dblclick();
\r
454 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
455 * @result alert('Hello');
\r
459 * @cat Events/Mouse
\r
463 * Bind a function to the dblclick event of each matched element, which will only be executed once.
\r
464 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
\r
465 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
467 * @example $("p").onedblclick( function() { alert("Hello"); } );
\r
468 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
469 * @result alert('Hello'); // Only executed for the first dblclick
\r
471 * @name onedblclick
\r
473 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
\r
474 * @cat Events/Mouse
\r
478 * Removes a bound dblclick event from each of the matched
\r
479 * elements. You must pass the identical function that was used in the original
\r
482 * @example $("p").undblclick( myFunction );
\r
483 * @before <p ondblclick="myFunction">Hello</p>
\r
484 * @result <p>Hello</p>
\r
488 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
\r
489 * @cat Events/Mouse
\r
493 * Removes all bound dblclick events from each of the matched elements.
\r
495 * @example $("p").undblclick();
\r
496 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
497 * @result <p>Hello</p>
\r
501 * @cat Events/Mouse
\r
505 * Bind a function to the keypress event of each matched element.
\r
507 * @example $("p").keypress( function() { alert("Hello"); } );
\r
508 * @before <p>Hello</p>
\r
509 * @result <p onkeypress="alert('Hello');">Hello</p>
\r
513 * @param Function fn A function to bind to the keypress event on each of the matched elements.
\r
514 * @cat Events/Keyboard
\r
518 * Trigger the keypress event of each matched element. This causes all of the functions
\r
519 * that have been bound to thet keypress event to be executed.
\r
521 * @example $("p").keypress();
\r
522 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
523 * @result alert('Hello');
\r
527 * @cat Events/Keyboard
\r
531 * Bind a function to the keypress event of each matched element, which will only be executed once.
\r
532 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
\r
533 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
535 * @example $("p").onekeypress( function() { alert("Hello"); } );
\r
536 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
537 * @result alert('Hello'); // Only executed for the first keypress
\r
539 * @name onekeypress
\r
541 * @param Function fn A function to bind to the keypress event on each of the matched elements.
\r
542 * @cat Events/Keyboard
\r
546 * Removes a bound keypress event from each of the matched
\r
547 * elements. You must pass the identical function that was used in the original
\r
550 * @example $("p").unkeypress( myFunction );
\r
551 * @before <p onkeypress="myFunction">Hello</p>
\r
552 * @result <p>Hello</p>
\r
556 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
\r
557 * @cat Events/Keyboard
\r
561 * Removes all bound keypress events from each of the matched elements.
\r
563 * @example $("p").unkeypress();
\r
564 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
565 * @result <p>Hello</p>
\r
569 * @cat Events/Keyboard
\r
573 * Bind a function to the error event of each matched element.
\r
575 * @example $("p").error( function() { alert("Hello"); } );
\r
576 * @before <p>Hello</p>
\r
577 * @result <p onerror="alert('Hello');">Hello</p>
\r
581 * @param Function fn A function to bind to the error event on each of the matched elements.
\r
582 * @cat Events/Browser
\r
586 * Trigger the error event of each matched element. This causes all of the functions
\r
587 * that have been bound to thet error event to be executed.
\r
589 * @example $("p").error();
\r
590 * @before <p onerror="alert('Hello');">Hello</p>
\r
591 * @result alert('Hello');
\r
595 * @cat Events/Browser
\r
599 * Bind a function to the error event of each matched element, which will only be executed once.
\r
600 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
\r
601 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
603 * @example $("p").oneerror( function() { alert("Hello"); } );
\r
604 * @before <p onerror="alert('Hello');">Hello</p>
\r
605 * @result alert('Hello'); // Only executed for the first error
\r
609 * @param Function fn A function to bind to the error event on each of the matched elements.
\r
610 * @cat Events/Browser
\r
614 * Removes a bound error event from each of the matched
\r
615 * elements. You must pass the identical function that was used in the original
\r
618 * @example $("p").unerror( myFunction );
\r
619 * @before <p onerror="myFunction">Hello</p>
\r
620 * @result <p>Hello</p>
\r
624 * @param Function fn A function to unbind from the error event on each of the matched elements.
\r
625 * @cat Events/Browser
\r
629 * Removes all bound error events from each of the matched elements.
\r
631 * @example $("p").unerror();
\r
632 * @before <p onerror="alert('Hello');">Hello</p>
\r
633 * @result <p>Hello</p>
\r
637 * @cat Events/Browser
\r
641 * Bind a function to the blur event of each matched element.
\r
643 * @example $("p").blur( function() { alert("Hello"); } );
\r
644 * @before <p>Hello</p>
\r
645 * @result <p onblur="alert('Hello');">Hello</p>
\r
649 * @param Function fn A function to bind to the blur event on each of the matched elements.
\r
654 * Trigger the blur event of each matched element. This causes all of the functions
\r
655 * that have been bound to thet blur event to be executed.
\r
657 * @example $("p").blur();
\r
658 * @before <p onblur="alert('Hello');">Hello</p>
\r
659 * @result alert('Hello');
\r
667 * Bind a function to the blur event of each matched element, which will only be executed once.
\r
668 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
\r
669 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
671 * @example $("p").oneblur( function() { alert("Hello"); } );
\r
672 * @before <p onblur="alert('Hello');">Hello</p>
\r
673 * @result alert('Hello'); // Only executed for the first blur
\r
677 * @param Function fn A function to bind to the blur event on each of the matched elements.
\r
682 * Removes a bound blur event from each of the matched
\r
683 * elements. You must pass the identical function that was used in the original
\r
686 * @example $("p").unblur( myFunction );
\r
687 * @before <p onblur="myFunction">Hello</p>
\r
688 * @result <p>Hello</p>
\r
692 * @param Function fn A function to unbind from the blur event on each of the matched elements.
\r
697 * Removes all bound blur events from each of the matched elements.
\r
699 * @example $("p").unblur();
\r
700 * @before <p onblur="alert('Hello');">Hello</p>
\r
701 * @result <p>Hello</p>
\r
709 * Bind a function to the load event of each matched element.
\r
711 * @example $("p").load( function() { alert("Hello"); } );
\r
712 * @before <p>Hello</p>
\r
713 * @result <p onload="alert('Hello');">Hello</p>
\r
717 * @param Function fn A function to bind to the load event on each of the matched elements.
\r
718 * @cat Events/Browser
\r
722 * Trigger the load event of each matched element. This causes all of the functions
\r
723 * that have been bound to thet load event to be executed.
\r
725 * Marked as private: Calling load() without arguments throws exception because the ajax load
\r
726 * does not handle it.
\r
728 * @example $("p").load();
\r
729 * @before <p onload="alert('Hello');">Hello</p>
\r
730 * @result alert('Hello');
\r
735 * @cat Events/Browser
\r
739 * Bind a function to the load event of each matched element, which will only be executed once.
\r
740 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
\r
741 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
743 * @example $("p").oneload( function() { alert("Hello"); } );
\r
744 * @before <p onload="alert('Hello');">Hello</p>
\r
745 * @result alert('Hello'); // Only executed for the first load
\r
749 * @param Function fn A function to bind to the load event on each of the matched elements.
\r
750 * @cat Events/Browser
\r
754 * Removes a bound load event from each of the matched
\r
755 * elements. You must pass the identical function that was used in the original
\r
758 * @example $("p").unload( myFunction );
\r
759 * @before <p onload="myFunction">Hello</p>
\r
760 * @result <p>Hello</p>
\r
764 * @param Function fn A function to unbind from the load event on each of the matched elements.
\r
765 * @cat Events/Browser
\r
769 * Removes all bound load events from each of the matched elements.
\r
771 * @example $("p").unload();
\r
772 * @before <p onload="alert('Hello');">Hello</p>
\r
773 * @result <p>Hello</p>
\r
777 * @cat Events/Browser
\r
781 * Bind a function to the select event of each matched element.
\r
783 * @example $("p").select( function() { alert("Hello"); } );
\r
784 * @before <p>Hello</p>
\r
785 * @result <p onselect="alert('Hello');">Hello</p>
\r
789 * @param Function fn A function to bind to the select event on each of the matched elements.
\r
794 * Trigger the select event of each matched element. This causes all of the functions
\r
795 * that have been bound to thet select event to be executed.
\r
797 * @example $("p").select();
\r
798 * @before <p onselect="alert('Hello');">Hello</p>
\r
799 * @result alert('Hello');
\r
807 * Bind a function to the select event of each matched element, which will only be executed once.
\r
808 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
\r
809 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
811 * @example $("p").oneselect( function() { alert("Hello"); } );
\r
812 * @before <p onselect="alert('Hello');">Hello</p>
\r
813 * @result alert('Hello'); // Only executed for the first select
\r
817 * @param Function fn A function to bind to the select event on each of the matched elements.
\r
822 * Removes a bound select event from each of the matched
\r
823 * elements. You must pass the identical function that was used in the original
\r
826 * @example $("p").unselect( myFunction );
\r
827 * @before <p onselect="myFunction">Hello</p>
\r
828 * @result <p>Hello</p>
\r
832 * @param Function fn A function to unbind from the select event on each of the matched elements.
\r
837 * Removes all bound select events from each of the matched elements.
\r
839 * @example $("p").unselect();
\r
840 * @before <p onselect="alert('Hello');">Hello</p>
\r
841 * @result <p>Hello</p>
\r
849 * Bind a function to the mouseup event of each matched element.
\r
851 * @example $("p").mouseup( function() { alert("Hello"); } );
\r
852 * @before <p>Hello</p>
\r
853 * @result <p onmouseup="alert('Hello');">Hello</p>
\r
857 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
\r
858 * @cat Events/Mouse
\r
862 * Trigger the mouseup event of each matched element. This causes all of the functions
\r
863 * that have been bound to thet mouseup event to be executed.
\r
865 * @example $("p").mouseup();
\r
866 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
867 * @result alert('Hello');
\r
871 * @cat Events/Mouse
\r
875 * Bind a function to the mouseup event of each matched element, which will only be executed once.
\r
876 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
\r
877 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
879 * @example $("p").onemouseup( function() { alert("Hello"); } );
\r
880 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
881 * @result alert('Hello'); // Only executed for the first mouseup
\r
885 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
\r
886 * @cat Events/Mouse
\r
890 * Removes a bound mouseup event from each of the matched
\r
891 * elements. You must pass the identical function that was used in the original
\r
894 * @example $("p").unmouseup( myFunction );
\r
895 * @before <p onmouseup="myFunction">Hello</p>
\r
896 * @result <p>Hello</p>
\r
900 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
\r
901 * @cat Events/Mouse
\r
905 * Removes all bound mouseup events from each of the matched elements.
\r
907 * @example $("p").unmouseup();
\r
908 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
909 * @result <p>Hello</p>
\r
913 * @cat Events/Mouse
\r
917 * Bind a function to the unload event of each matched element.
\r
919 * @example $("p").unload( function() { alert("Hello"); } );
\r
920 * @before <p>Hello</p>
\r
921 * @result <p onunload="alert('Hello');">Hello</p>
\r
925 * @param Function fn A function to bind to the unload event on each of the matched elements.
\r
926 * @cat Events/Browser
\r
930 * Trigger the unload event of each matched element. This causes all of the functions
\r
931 * that have been bound to thet unload event to be executed.
\r
933 * @example $("p").unload();
\r
934 * @before <p onunload="alert('Hello');">Hello</p>
\r
935 * @result alert('Hello');
\r
939 * @cat Events/Browser
\r
943 * Bind a function to the unload event of each matched element, which will only be executed once.
\r
944 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
\r
945 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
947 * @example $("p").oneunload( function() { alert("Hello"); } );
\r
948 * @before <p onunload="alert('Hello');">Hello</p>
\r
949 * @result alert('Hello'); // Only executed for the first unload
\r
953 * @param Function fn A function to bind to the unload event on each of the matched elements.
\r
954 * @cat Events/Browser
\r
958 * Removes a bound unload event from each of the matched
\r
959 * elements. You must pass the identical function that was used in the original
\r
962 * @example $("p").ununload( myFunction );
\r
963 * @before <p onunload="myFunction">Hello</p>
\r
964 * @result <p>Hello</p>
\r
968 * @param Function fn A function to unbind from the unload event on each of the matched elements.
\r
969 * @cat Events/Browser
\r
973 * Removes all bound unload events from each of the matched elements.
\r
975 * @example $("p").ununload();
\r
976 * @before <p onunload="alert('Hello');">Hello</p>
\r
977 * @result <p>Hello</p>
\r
981 * @cat Events/Browser
\r
985 * Bind a function to the change event of each matched element.
\r
987 * @example $("p").change( function() { alert("Hello"); } );
\r
988 * @before <p>Hello</p>
\r
989 * @result <p onchange="alert('Hello');">Hello</p>
\r
993 * @param Function fn A function to bind to the change event on each of the matched elements.
\r
998 * Trigger the change event of each matched element. This causes all of the functions
\r
999 * that have been bound to thet change event to be executed.
\r
1001 * @example $("p").change();
\r
1002 * @before <p onchange="alert('Hello');">Hello</p>
\r
1003 * @result alert('Hello');
\r
1007 * @cat Events/Form
\r
1011 * Bind a function to the change event of each matched element, which will only be executed once.
\r
1012 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
\r
1013 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1015 * @example $("p").onechange( function() { alert("Hello"); } );
\r
1016 * @before <p onchange="alert('Hello');">Hello</p>
\r
1017 * @result alert('Hello'); // Only executed for the first change
\r
1021 * @param Function fn A function to bind to the change event on each of the matched elements.
\r
1022 * @cat Events/Form
\r
1026 * Removes a bound change event from each of the matched
\r
1027 * elements. You must pass the identical function that was used in the original
\r
1030 * @example $("p").unchange( myFunction );
\r
1031 * @before <p onchange="myFunction">Hello</p>
\r
1032 * @result <p>Hello</p>
\r
1036 * @param Function fn A function to unbind from the change event on each of the matched elements.
\r
1037 * @cat Events/Form
\r
1041 * Removes all bound change events from each of the matched elements.
\r
1043 * @example $("p").unchange();
\r
1044 * @before <p onchange="alert('Hello');">Hello</p>
\r
1045 * @result <p>Hello</p>
\r
1049 * @cat Events/Form
\r
1053 * Bind a function to the mouseout event of each matched element.
\r
1055 * @example $("p").mouseout( function() { alert("Hello"); } );
\r
1056 * @before <p>Hello</p>
\r
1057 * @result <p onmouseout="alert('Hello');">Hello</p>
\r
1061 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
\r
1062 * @cat Events/Mouse
\r
1066 * Trigger the mouseout event of each matched element. This causes all of the functions
\r
1067 * that have been bound to thet mouseout event to be executed.
\r
1069 * @example $("p").mouseout();
\r
1070 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1071 * @result alert('Hello');
\r
1075 * @cat Events/Mouse
\r
1079 * Bind a function to the mouseout event of each matched element, which will only be executed once.
\r
1080 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
\r
1081 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1083 * @example $("p").onemouseout( function() { alert("Hello"); } );
\r
1084 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1085 * @result alert('Hello'); // Only executed for the first mouseout
\r
1087 * @name onemouseout
\r
1089 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
\r
1090 * @cat Events/Mouse
\r
1094 * Removes a bound mouseout event from each of the matched
\r
1095 * elements. You must pass the identical function that was used in the original
\r
1098 * @example $("p").unmouseout( myFunction );
\r
1099 * @before <p onmouseout="myFunction">Hello</p>
\r
1100 * @result <p>Hello</p>
\r
1102 * @name unmouseout
\r
1104 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
\r
1105 * @cat Events/Mouse
\r
1109 * Removes all bound mouseout events from each of the matched elements.
\r
1111 * @example $("p").unmouseout();
\r
1112 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1113 * @result <p>Hello</p>
\r
1115 * @name unmouseout
\r
1117 * @cat Events/Mouse
\r
1121 * Bind a function to the keyup event of each matched element.
\r
1123 * @example $("p").keyup( function() { alert("Hello"); } );
\r
1124 * @before <p>Hello</p>
\r
1125 * @result <p onkeyup="alert('Hello');">Hello</p>
\r
1129 * @param Function fn A function to bind to the keyup event on each of the matched elements.
\r
1130 * @cat Events/Keyboard
\r
1134 * Trigger the keyup event of each matched element. This causes all of the functions
\r
1135 * that have been bound to thet keyup event to be executed.
\r
1137 * @example $("p").keyup();
\r
1138 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1139 * @result alert('Hello');
\r
1143 * @cat Events/Keyboard
\r
1147 * Bind a function to the keyup event of each matched element, which will only be executed once.
\r
1148 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
\r
1149 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1151 * @example $("p").onekeyup( function() { alert("Hello"); } );
\r
1152 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1153 * @result alert('Hello'); // Only executed for the first keyup
\r
1157 * @param Function fn A function to bind to the keyup event on each of the matched elements.
\r
1158 * @cat Events/Keyboard
\r
1162 * Removes a bound keyup event from each of the matched
\r
1163 * elements. You must pass the identical function that was used in the original
\r
1166 * @example $("p").unkeyup( myFunction );
\r
1167 * @before <p onkeyup="myFunction">Hello</p>
\r
1168 * @result <p>Hello</p>
\r
1172 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
\r
1173 * @cat Events/Keyboard
\r
1177 * Removes all bound keyup events from each of the matched elements.
\r
1179 * @example $("p").unkeyup();
\r
1180 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1181 * @result <p>Hello</p>
\r
1185 * @cat Events/Keyboard
\r
1189 * Bind a function to the click event of each matched element.
\r
1191 * @example $("p").click( function() { alert("Hello"); } );
\r
1192 * @before <p>Hello</p>
\r
1193 * @result <p onclick="alert('Hello');">Hello</p>
\r
1197 * @param Function fn A function to bind to the click event on each of the matched elements.
\r
1198 * @cat Events/Mouse
\r
1202 * Trigger the click event of each matched element. This causes all of the functions
\r
1203 * that have been bound to thet click event to be executed.
\r
1205 * @example $("p").click();
\r
1206 * @before <p onclick="alert('Hello');">Hello</p>
\r
1207 * @result alert('Hello');
\r
1211 * @cat Events/Mouse
\r
1215 * Bind a function to the click event of each matched element, which will only be executed once.
\r
1216 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
\r
1217 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1219 * @example $("p").oneclick( function() { alert("Hello"); } );
\r
1220 * @before <p onclick="alert('Hello');">Hello</p>
\r
1221 * @result alert('Hello'); // Only executed for the first click
\r
1225 * @param Function fn A function to bind to the click event on each of the matched elements.
\r
1226 * @cat Events/Mouse
\r
1230 * Removes a bound click event from each of the matched
\r
1231 * elements. You must pass the identical function that was used in the original
\r
1234 * @example $("p").unclick( myFunction );
\r
1235 * @before <p onclick="myFunction">Hello</p>
\r
1236 * @result <p>Hello</p>
\r
1240 * @param Function fn A function to unbind from the click event on each of the matched elements.
\r
1241 * @cat Events/Mouse
\r
1245 * Removes all bound click events from each of the matched elements.
\r
1247 * @example $("p").unclick();
\r
1248 * @before <p onclick="alert('Hello');">Hello</p>
\r
1249 * @result <p>Hello</p>
\r
1253 * @cat Events/Mouse
\r
1257 * Bind a function to the resize event of each matched element.
\r
1259 * @example $("p").resize( function() { alert("Hello"); } );
\r
1260 * @before <p>Hello</p>
\r
1261 * @result <p onresize="alert('Hello');">Hello</p>
\r
1265 * @param Function fn A function to bind to the resize event on each of the matched elements.
\r
1266 * @cat Events/Browser
\r
1270 * Trigger the resize event of each matched element. This causes all of the functions
\r
1271 * that have been bound to thet resize event to be executed.
\r
1273 * @example $("p").resize();
\r
1274 * @before <p onresize="alert('Hello');">Hello</p>
\r
1275 * @result alert('Hello');
\r
1279 * @cat Events/Browser
\r
1283 * Bind a function to the resize event of each matched element, which will only be executed once.
\r
1284 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
\r
1285 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1287 * @example $("p").oneresize( function() { alert("Hello"); } );
\r
1288 * @before <p onresize="alert('Hello');">Hello</p>
\r
1289 * @result alert('Hello'); // Only executed for the first resize
\r
1293 * @param Function fn A function to bind to the resize event on each of the matched elements.
\r
1294 * @cat Events/Browser
\r
1298 * Removes a bound resize event from each of the matched
\r
1299 * elements. You must pass the identical function that was used in the original
\r
1302 * @example $("p").unresize( myFunction );
\r
1303 * @before <p onresize="myFunction">Hello</p>
\r
1304 * @result <p>Hello</p>
\r
1308 * @param Function fn A function to unbind from the resize event on each of the matched elements.
\r
1309 * @cat Events/Browser
\r
1313 * Removes all bound resize events from each of the matched elements.
\r
1315 * @example $("p").unresize();
\r
1316 * @before <p onresize="alert('Hello');">Hello</p>
\r
1317 * @result <p>Hello</p>
\r
1321 * @cat Events/Browser
\r
1325 * Bind a function to the mousemove event of each matched element.
\r
1327 * @example $("p").mousemove( function() { alert("Hello"); } );
\r
1328 * @before <p>Hello</p>
\r
1329 * @result <p onmousemove="alert('Hello');">Hello</p>
\r
1333 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
\r
1334 * @cat Events/Mouse
\r
1338 * Trigger the mousemove event of each matched element. This causes all of the functions
\r
1339 * that have been bound to thet mousemove event to be executed.
\r
1341 * @example $("p").mousemove();
\r
1342 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1343 * @result alert('Hello');
\r
1347 * @cat Events/Mouse
\r
1351 * Bind a function to the mousemove event of each matched element, which will only be executed once.
\r
1352 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
\r
1353 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1355 * @example $("p").onemousemove( function() { alert("Hello"); } );
\r
1356 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1357 * @result alert('Hello'); // Only executed for the first mousemove
\r
1359 * @name onemousemove
\r
1361 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
\r
1362 * @cat Events/Mouse
\r
1366 * Removes a bound mousemove event from each of the matched
\r
1367 * elements. You must pass the identical function that was used in the original
\r
1370 * @example $("p").unmousemove( myFunction );
\r
1371 * @before <p onmousemove="myFunction">Hello</p>
\r
1372 * @result <p>Hello</p>
\r
1374 * @name unmousemove
\r
1376 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
\r
1377 * @cat Events/Mouse
\r
1381 * Removes all bound mousemove events from each of the matched elements.
\r
1383 * @example $("p").unmousemove();
\r
1384 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1385 * @result <p>Hello</p>
\r
1387 * @name unmousemove
\r
1389 * @cat Events/Mouse
\r
1393 * Bind a function to the mousedown event of each matched element.
\r
1395 * @example $("p").mousedown( function() { alert("Hello"); } );
\r
1396 * @before <p>Hello</p>
\r
1397 * @result <p onmousedown="alert('Hello');">Hello</p>
\r
1401 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1402 * @cat Events/Mouse
\r
1406 * Trigger the mousedown event of each matched element. This causes all of the functions
\r
1407 * that have been bound to thet mousedown event to be executed.
\r
1409 * @example $("p").mousedown();
\r
1410 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1411 * @result alert('Hello');
\r
1415 * @cat Events/Mouse
\r
1419 * Bind a function to the mousedown event of each matched element, which will only be executed once.
\r
1420 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
\r
1421 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1423 * @example $("p").onemousedown( function() { alert("Hello"); } );
\r
1424 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1425 * @result alert('Hello'); // Only executed for the first mousedown
\r
1427 * @name onemousedown
\r
1429 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1430 * @cat Events/Mouse
\r
1434 * Removes a bound mousedown event from each of the matched
\r
1435 * elements. You must pass the identical function that was used in the original
\r
1438 * @example $("p").unmousedown( myFunction );
\r
1439 * @before <p onmousedown="myFunction">Hello</p>
\r
1440 * @result <p>Hello</p>
\r
1442 * @name unmousedown
\r
1444 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
\r
1445 * @cat Events/Mouse
\r
1449 * Removes all bound mousedown events from each of the matched elements.
\r
1451 * @example $("p").unmousedown();
\r
1452 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1453 * @result <p>Hello</p>
\r
1455 * @name unmousedown
\r
1457 * @cat Events/Mouse
\r
1461 * Bind a function to the mouseover event of each matched element.
\r
1463 * @example $("p").mouseover( function() { alert("Hello"); } );
\r
1464 * @before <p>Hello</p>
\r
1465 * @result <p onmouseover="alert('Hello');">Hello</p>
\r
1469 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1470 * @cat Events/Mouse
\r
1474 * Trigger the mouseover event of each matched element. This causes all of the functions
\r
1475 * that have been bound to thet mousedown event to be executed.
\r
1477 * @example $("p").mouseover();
\r
1478 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1479 * @result alert('Hello');
\r
1483 * @cat Events/Mouse
\r
1487 * Bind a function to the mouseover event of each matched element, which will only be executed once.
\r
1488 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
\r
1489 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1491 * @example $("p").onemouseover( function() { alert("Hello"); } );
\r
1492 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1493 * @result alert('Hello'); // Only executed for the first mouseover
\r
1495 * @name onemouseover
\r
1497 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
\r
1498 * @cat Events/Mouse
\r
1502 * Removes a bound mouseover event from each of the matched
\r
1503 * elements. You must pass the identical function that was used in the original
\r
1506 * @example $("p").unmouseover( myFunction );
\r
1507 * @before <p onmouseover="myFunction">Hello</p>
\r
1508 * @result <p>Hello</p>
\r
1510 * @name unmouseover
\r
1512 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
\r
1513 * @cat Events/Mouse
\r
1517 * Removes all bound mouseover events from each of the matched elements.
\r
1519 * @example $("p").unmouseover();
\r
1520 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1521 * @result <p>Hello</p>
\r
1523 * @name unmouseover
\r
1525 * @cat Events/Mouse
\r
1529 * @test var count;
\r
1531 * var e = ("blur,focus,resize,scroll,unload,click,dblclick," +
\r
1532 * "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
\r
1533 * "submit,keydown,keypress,keyup,error").split(",");
\r
1534 * var handler1 = function(event) {
\r
1537 * var handler2 = function(event) {
\r
1540 * for( var i=0; i < e.length; i++) {
\r
1541 * var event = e[i];
\r
1544 * $(document)[event](handler1);
\r
1545 * $(document)[event](handler2);
\r
1546 * $(document)["one"+event](handler1);
\r
1548 * // call event two times
\r
1549 * $(document)[event]();
\r
1550 * $(document)[event]();
\r
1552 * // unbind events
\r
1553 * $(document)["un"+event](handler1);
\r
1554 * // call once more
\r
1555 * $(document)[event]();
\r
1557 * // remove all handlers
\r
1558 * $(document)["un"+event]();
\r
1560 * // call once more
\r
1561 * $(document)[event]();
\r
1564 * ok( count == 6, 'Checking event ' + event);
\r
1568 * @name eventTesting
\r
1572 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
\r
1573 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
\r
1574 "submit,keydown,keypress,keyup,error").split(",");
\r
1576 // Go through all the event names, but make sure that
\r
1577 // it is enclosed properly
\r
1578 for ( var i = 0; i < e.length; i++ ) new function(){
\r
1582 // Handle event binding
\r
1583 jQuery.fn[o] = function(f){
\r
1584 return f ? this.bind(o, f) : this.trigger(o);
\r
1587 // Handle event unbinding
\r
1588 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
\r
1590 // Finally, handle events that only fire once
\r
1591 jQuery.fn["one"+o] = function(f){
\r
1592 // Attach the event listener
\r
1593 return this.each(function(){
\r
1598 jQuery.event.add( this, o, function(e){
\r
1599 // If this function has already been executed, stop
\r
1600 if ( count++ ) return;
\r
1602 // And execute the bound function
\r
1603 return f.apply(this, [e]);
\r
1610 // If Mozilla is used
\r
1611 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
\r
1612 // Use the handy event callback
\r
1613 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
\r
1615 // If IE is used, use the excellent hack by Matthias Miller
\r
1616 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
\r
1617 } else if ( jQuery.browser.msie ) {
\r
1619 // Only works if you document.write() it
\r
1620 document.write("<scr" + "ipt id=__ie_init defer=true " +
\r
1621 "src=//:><\/script>");
\r
1623 // Use the defer script hack
\r
1624 var script = document.getElementById("__ie_init");
\r
1625 script.onreadystatechange = function() {
\r
1626 if ( this.readyState != "complete" ) return;
\r
1627 this.parentNode.removeChild( this );
\r
1631 // Clear from memory
\r
1634 // If Safari is used
\r
1635 } else if ( jQuery.browser.safari ) {
\r
1636 // Continually check to see if the document.readyState is valid
\r
1637 jQuery.safariTimer = setInterval(function(){
\r
1638 // loaded and complete are both valid states
\r
1639 if ( document.readyState == "loaded" ||
\r
1640 document.readyState == "complete" ) {
\r
1642 // If either one are found, remove the timer
\r
1643 clearInterval( jQuery.safariTimer );
\r
1644 jQuery.safariTimer = null;
\r
1646 // and execute any waiting functions
\r
1652 // A fallback to window.onload, that will always work
\r
1653 jQuery.event.add( window, "load", jQuery.ready );
\r
1657 // Clean up after IE to avoid memory leaks
\r
1658 if ($.browser.msie) $(window).unload(function() {
\r
1659 var event = jQuery.event, global = event.global;
\r
1660 for (var type in global) {
\r
1661 var els = global[type], i = els.length;
\r
1662 if (i>0) do event.remove(els[i-1], type); while (--i);
\r