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 * @example $(document).ready(function(){ Your code here... });
\r
114 * @param Function fn The function to be executed when the DOM is ready.
\r
117 ready: function(f) {
\r
118 // If the DOM is already ready
\r
119 if ( jQuery.isReady )
\r
120 // Execute the function immediately
\r
121 f.apply( document );
\r
123 // Otherwise, remember the function for later
\r
125 // Add the function to the wait list
\r
126 jQuery.readyList.push( f );
\r
135 * All the code that makes DOM Ready work nicely.
\r
140 // Handle when the DOM is ready
\r
141 ready: function() {
\r
142 // Make sure that the DOM is not already loaded
\r
143 if ( !jQuery.isReady ) {
\r
144 // Remember that the DOM is ready
\r
145 jQuery.isReady = true;
\r
147 // If there are functions bound, to execute
\r
148 if ( jQuery.readyList ) {
\r
149 // Execute all of them
\r
150 for ( var i = 0; i < jQuery.readyList.length; i++ )
\r
151 jQuery.readyList[i].apply( document );
\r
153 // Reset the list of functions
\r
154 jQuery.readyList = null;
\r
163 * Bind a function to the scroll event of each matched element.
\r
165 * @example $("p").scroll( function() { alert("Hello"); } );
\r
166 * @before <p>Hello</p>
\r
167 * @result <p onscroll="alert('Hello');">Hello</p>
\r
171 * @param Function fn A function to bind to the scroll event on each of the matched elements.
\r
172 * @cat Events/Browser
\r
176 * Trigger the scroll event of each matched element. This causes all of the functions
\r
177 * that have been bound to thet scroll event to be executed.
\r
179 * @example $("p").scroll();
\r
180 * @before <p onscroll="alert('Hello');">Hello</p>
\r
181 * @result alert('Hello');
\r
185 * @cat Events/Browser
\r
189 * Bind a function to the scroll event of each matched element, which will only be executed once.
\r
190 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
\r
191 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
193 * @example $("p").onescroll( function() { alert("Hello"); } );
\r
194 * @before <p onscroll="alert('Hello');">Hello</p>
\r
195 * @result alert('Hello'); // Only executed for the first scroll
\r
199 * @param Function fn A function to bind to the scroll event on each of the matched elements.
\r
200 * @cat Events/Browser
\r
204 * Removes a bound scroll event from each of the matched
\r
205 * elements. You must pass the identical function that was used in the original
\r
208 * @example $("p").unscroll( myFunction );
\r
209 * @before <p onscroll="myFunction">Hello</p>
\r
210 * @result <p>Hello</p>
\r
214 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
\r
215 * @cat Events/Browser
\r
219 * Removes all bound scroll events from each of the matched elements.
\r
221 * @example $("p").unscroll();
\r
222 * @before <p onscroll="alert('Hello');">Hello</p>
\r
223 * @result <p>Hello</p>
\r
227 * @cat Events/Browser
\r
231 * Bind a function to the submit event of each matched element.
\r
233 * @example $("p").submit( function() { alert("Hello"); } );
\r
234 * @before <p>Hello</p>
\r
235 * @result <p onsubmit="alert('Hello');">Hello</p>
\r
239 * @param Function fn A function to bind to the submit event on each of the matched elements.
\r
244 * Trigger the submit event of each matched element. This causes all of the functions
\r
245 * that have been bound to thet submit event to be executed.
\r
247 * @example $("p").submit();
\r
248 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
249 * @result alert('Hello');
\r
257 * Bind a function to the submit event of each matched element, which will only be executed once.
\r
258 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
\r
259 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
261 * @example $("p").onesubmit( function() { alert("Hello"); } );
\r
262 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
263 * @result alert('Hello'); // Only executed for the first submit
\r
267 * @param Function fn A function to bind to the submit event on each of the matched elements.
\r
272 * Removes a bound submit event from each of the matched
\r
273 * elements. You must pass the identical function that was used in the original
\r
276 * @example $("p").unsubmit( myFunction );
\r
277 * @before <p onsubmit="myFunction">Hello</p>
\r
278 * @result <p>Hello</p>
\r
282 * @param Function fn A function to unbind from the submit event on each of the matched elements.
\r
287 * Removes all bound submit events from each of the matched elements.
\r
289 * @example $("p").unsubmit();
\r
290 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
291 * @result <p>Hello</p>
\r
299 * Bind a function to the focus event of each matched element.
\r
301 * @example $("p").focus( function() { alert("Hello"); } );
\r
302 * @before <p>Hello</p>
\r
303 * @result <p onfocus="alert('Hello');">Hello</p>
\r
307 * @param Function fn A function to bind to the focus event on each of the matched elements.
\r
312 * Trigger the focus event of each matched element. This causes all of the functions
\r
313 * that have been bound to thet focus event to be executed.
\r
315 * @example $("p").focus();
\r
316 * @before <p onfocus="alert('Hello');">Hello</p>
\r
317 * @result alert('Hello');
\r
325 * Bind a function to the focus event of each matched element, which will only be executed once.
\r
326 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
\r
327 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
329 * @example $("p").onefocus( function() { alert("Hello"); } );
\r
330 * @before <p onfocus="alert('Hello');">Hello</p>
\r
331 * @result alert('Hello'); // Only executed for the first focus
\r
335 * @param Function fn A function to bind to the focus event on each of the matched elements.
\r
340 * Removes a bound focus event from each of the matched
\r
341 * elements. You must pass the identical function that was used in the original
\r
344 * @example $("p").unfocus( myFunction );
\r
345 * @before <p onfocus="myFunction">Hello</p>
\r
346 * @result <p>Hello</p>
\r
350 * @param Function fn A function to unbind from the focus event on each of the matched elements.
\r
355 * Removes all bound focus events from each of the matched elements.
\r
357 * @example $("p").unfocus();
\r
358 * @before <p onfocus="alert('Hello');">Hello</p>
\r
359 * @result <p>Hello</p>
\r
367 * Bind a function to the keydown event of each matched element.
\r
369 * @example $("p").keydown( function() { alert("Hello"); } );
\r
370 * @before <p>Hello</p>
\r
371 * @result <p onkeydown="alert('Hello');">Hello</p>
\r
375 * @param Function fn A function to bind to the keydown event on each of the matched elements.
\r
376 * @cat Events/Keyboard
\r
380 * Trigger the keydown event of each matched element. This causes all of the functions
\r
381 * that have been bound to thet keydown event to be executed.
\r
383 * @example $("p").keydown();
\r
384 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
385 * @result alert('Hello');
\r
389 * @cat Events/Keyboard
\r
393 * Bind a function to the keydown event of each matched element, which will only be executed once.
\r
394 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
\r
395 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
397 * @example $("p").onekeydown( function() { alert("Hello"); } );
\r
398 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
399 * @result alert('Hello'); // Only executed for the first keydown
\r
403 * @param Function fn A function to bind to the keydown event on each of the matched elements.
\r
404 * @cat Events/Keyboard
\r
408 * Removes a bound keydown event from each of the matched
\r
409 * elements. You must pass the identical function that was used in the original
\r
412 * @example $("p").unkeydown( myFunction );
\r
413 * @before <p onkeydown="myFunction">Hello</p>
\r
414 * @result <p>Hello</p>
\r
418 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
\r
419 * @cat Events/Keyboard
\r
423 * Removes all bound keydown events from each of the matched elements.
\r
425 * @example $("p").unkeydown();
\r
426 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
427 * @result <p>Hello</p>
\r
431 * @cat Events/Keyboard
\r
435 * Bind a function to the dblclick event of each matched element.
\r
437 * @example $("p").dblclick( function() { alert("Hello"); } );
\r
438 * @before <p>Hello</p>
\r
439 * @result <p ondblclick="alert('Hello');">Hello</p>
\r
443 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
\r
444 * @cat Events/Mouse
\r
448 * Trigger the dblclick event of each matched element. This causes all of the functions
\r
449 * that have been bound to thet dblclick event to be executed.
\r
451 * @example $("p").dblclick();
\r
452 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
453 * @result alert('Hello');
\r
457 * @cat Events/Mouse
\r
461 * Bind a function to the dblclick event of each matched element, which will only be executed once.
\r
462 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
\r
463 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
465 * @example $("p").onedblclick( function() { alert("Hello"); } );
\r
466 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
467 * @result alert('Hello'); // Only executed for the first dblclick
\r
469 * @name onedblclick
\r
471 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
\r
472 * @cat Events/Mouse
\r
476 * Removes a bound dblclick event from each of the matched
\r
477 * elements. You must pass the identical function that was used in the original
\r
480 * @example $("p").undblclick( myFunction );
\r
481 * @before <p ondblclick="myFunction">Hello</p>
\r
482 * @result <p>Hello</p>
\r
486 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
\r
487 * @cat Events/Mouse
\r
491 * Removes all bound dblclick events from each of the matched elements.
\r
493 * @example $("p").undblclick();
\r
494 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
495 * @result <p>Hello</p>
\r
499 * @cat Events/Mouse
\r
503 * Bind a function to the keypress event of each matched element.
\r
505 * @example $("p").keypress( function() { alert("Hello"); } );
\r
506 * @before <p>Hello</p>
\r
507 * @result <p onkeypress="alert('Hello');">Hello</p>
\r
511 * @param Function fn A function to bind to the keypress event on each of the matched elements.
\r
512 * @cat Events/Keyboard
\r
516 * Trigger the keypress event of each matched element. This causes all of the functions
\r
517 * that have been bound to thet keypress event to be executed.
\r
519 * @example $("p").keypress();
\r
520 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
521 * @result alert('Hello');
\r
525 * @cat Events/Keyboard
\r
529 * Bind a function to the keypress event of each matched element, which will only be executed once.
\r
530 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
\r
531 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
533 * @example $("p").onekeypress( function() { alert("Hello"); } );
\r
534 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
535 * @result alert('Hello'); // Only executed for the first keypress
\r
537 * @name onekeypress
\r
539 * @param Function fn A function to bind to the keypress event on each of the matched elements.
\r
540 * @cat Events/Keyboard
\r
544 * Removes a bound keypress event from each of the matched
\r
545 * elements. You must pass the identical function that was used in the original
\r
548 * @example $("p").unkeypress( myFunction );
\r
549 * @before <p onkeypress="myFunction">Hello</p>
\r
550 * @result <p>Hello</p>
\r
554 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
\r
555 * @cat Events/Keyboard
\r
559 * Removes all bound keypress events from each of the matched elements.
\r
561 * @example $("p").unkeypress();
\r
562 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
563 * @result <p>Hello</p>
\r
567 * @cat Events/Keyboard
\r
571 * Bind a function to the error event of each matched element.
\r
573 * @example $("p").error( function() { alert("Hello"); } );
\r
574 * @before <p>Hello</p>
\r
575 * @result <p onerror="alert('Hello');">Hello</p>
\r
579 * @param Function fn A function to bind to the error event on each of the matched elements.
\r
580 * @cat Events/Browser
\r
584 * Trigger the error event of each matched element. This causes all of the functions
\r
585 * that have been bound to thet error event to be executed.
\r
587 * @example $("p").error();
\r
588 * @before <p onerror="alert('Hello');">Hello</p>
\r
589 * @result alert('Hello');
\r
593 * @cat Events/Browser
\r
597 * Bind a function to the error event of each matched element, which will only be executed once.
\r
598 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
\r
599 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
601 * @example $("p").oneerror( function() { alert("Hello"); } );
\r
602 * @before <p onerror="alert('Hello');">Hello</p>
\r
603 * @result alert('Hello'); // Only executed for the first error
\r
607 * @param Function fn A function to bind to the error event on each of the matched elements.
\r
608 * @cat Events/Browser
\r
612 * Removes a bound error event from each of the matched
\r
613 * elements. You must pass the identical function that was used in the original
\r
616 * @example $("p").unerror( myFunction );
\r
617 * @before <p onerror="myFunction">Hello</p>
\r
618 * @result <p>Hello</p>
\r
622 * @param Function fn A function to unbind from the error event on each of the matched elements.
\r
623 * @cat Events/Browser
\r
627 * Removes all bound error events from each of the matched elements.
\r
629 * @example $("p").unerror();
\r
630 * @before <p onerror="alert('Hello');">Hello</p>
\r
631 * @result <p>Hello</p>
\r
635 * @cat Events/Browser
\r
639 * Bind a function to the blur event of each matched element.
\r
641 * @example $("p").blur( function() { alert("Hello"); } );
\r
642 * @before <p>Hello</p>
\r
643 * @result <p onblur="alert('Hello');">Hello</p>
\r
647 * @param Function fn A function to bind to the blur event on each of the matched elements.
\r
652 * Trigger the blur event of each matched element. This causes all of the functions
\r
653 * that have been bound to thet blur event to be executed.
\r
655 * @example $("p").blur();
\r
656 * @before <p onblur="alert('Hello');">Hello</p>
\r
657 * @result alert('Hello');
\r
665 * Bind a function to the blur event of each matched element, which will only be executed once.
\r
666 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
\r
667 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
669 * @example $("p").oneblur( function() { alert("Hello"); } );
\r
670 * @before <p onblur="alert('Hello');">Hello</p>
\r
671 * @result alert('Hello'); // Only executed for the first blur
\r
675 * @param Function fn A function to bind to the blur event on each of the matched elements.
\r
680 * Removes a bound blur event from each of the matched
\r
681 * elements. You must pass the identical function that was used in the original
\r
684 * @example $("p").unblur( myFunction );
\r
685 * @before <p onblur="myFunction">Hello</p>
\r
686 * @result <p>Hello</p>
\r
690 * @param Function fn A function to unbind from the blur event on each of the matched elements.
\r
695 * Removes all bound blur events from each of the matched elements.
\r
697 * @example $("p").unblur();
\r
698 * @before <p onblur="alert('Hello');">Hello</p>
\r
699 * @result <p>Hello</p>
\r
707 * Bind a function to the load event of each matched element.
\r
709 * @example $("p").load( function() { alert("Hello"); } );
\r
710 * @before <p>Hello</p>
\r
711 * @result <p onload="alert('Hello');">Hello</p>
\r
715 * @param Function fn A function to bind to the load event on each of the matched elements.
\r
716 * @cat Events/Browser
\r
720 * Trigger the load event of each matched element. This causes all of the functions
\r
721 * that have been bound to thet load event to be executed.
\r
723 * Marked as private: Calling load() without arguments throws exception because the ajax load
\r
724 * does not handle it.
\r
726 * @example $("p").load();
\r
727 * @before <p onload="alert('Hello');">Hello</p>
\r
728 * @result alert('Hello');
\r
733 * @cat Events/Browser
\r
737 * Bind a function to the load event of each matched element, which will only be executed once.
\r
738 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
\r
739 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
741 * @example $("p").oneload( function() { alert("Hello"); } );
\r
742 * @before <p onload="alert('Hello');">Hello</p>
\r
743 * @result alert('Hello'); // Only executed for the first load
\r
747 * @param Function fn A function to bind to the load event on each of the matched elements.
\r
748 * @cat Events/Browser
\r
752 * Removes a bound load event from each of the matched
\r
753 * elements. You must pass the identical function that was used in the original
\r
756 * @example $("p").unload( myFunction );
\r
757 * @before <p onload="myFunction">Hello</p>
\r
758 * @result <p>Hello</p>
\r
762 * @param Function fn A function to unbind from the load event on each of the matched elements.
\r
763 * @cat Events/Browser
\r
767 * Removes all bound load events from each of the matched elements.
\r
769 * @example $("p").unload();
\r
770 * @before <p onload="alert('Hello');">Hello</p>
\r
771 * @result <p>Hello</p>
\r
775 * @cat Events/Browser
\r
779 * Bind a function to the select event of each matched element.
\r
781 * @example $("p").select( function() { alert("Hello"); } );
\r
782 * @before <p>Hello</p>
\r
783 * @result <p onselect="alert('Hello');">Hello</p>
\r
787 * @param Function fn A function to bind to the select event on each of the matched elements.
\r
792 * Trigger the select event of each matched element. This causes all of the functions
\r
793 * that have been bound to thet select event to be executed.
\r
795 * @example $("p").select();
\r
796 * @before <p onselect="alert('Hello');">Hello</p>
\r
797 * @result alert('Hello');
\r
805 * Bind a function to the select event of each matched element, which will only be executed once.
\r
806 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
\r
807 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
809 * @example $("p").oneselect( function() { alert("Hello"); } );
\r
810 * @before <p onselect="alert('Hello');">Hello</p>
\r
811 * @result alert('Hello'); // Only executed for the first select
\r
815 * @param Function fn A function to bind to the select event on each of the matched elements.
\r
820 * Removes a bound select event from each of the matched
\r
821 * elements. You must pass the identical function that was used in the original
\r
824 * @example $("p").unselect( myFunction );
\r
825 * @before <p onselect="myFunction">Hello</p>
\r
826 * @result <p>Hello</p>
\r
830 * @param Function fn A function to unbind from the select event on each of the matched elements.
\r
835 * Removes all bound select events from each of the matched elements.
\r
837 * @example $("p").unselect();
\r
838 * @before <p onselect="alert('Hello');">Hello</p>
\r
839 * @result <p>Hello</p>
\r
847 * Bind a function to the mouseup event of each matched element.
\r
849 * @example $("p").mouseup( function() { alert("Hello"); } );
\r
850 * @before <p>Hello</p>
\r
851 * @result <p onmouseup="alert('Hello');">Hello</p>
\r
855 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
\r
856 * @cat Events/Mouse
\r
860 * Trigger the mouseup event of each matched element. This causes all of the functions
\r
861 * that have been bound to thet mouseup event to be executed.
\r
863 * @example $("p").mouseup();
\r
864 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
865 * @result alert('Hello');
\r
869 * @cat Events/Mouse
\r
873 * Bind a function to the mouseup event of each matched element, which will only be executed once.
\r
874 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
\r
875 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
877 * @example $("p").onemouseup( function() { alert("Hello"); } );
\r
878 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
879 * @result alert('Hello'); // Only executed for the first mouseup
\r
883 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
\r
884 * @cat Events/Mouse
\r
888 * Removes a bound mouseup event from each of the matched
\r
889 * elements. You must pass the identical function that was used in the original
\r
892 * @example $("p").unmouseup( myFunction );
\r
893 * @before <p onmouseup="myFunction">Hello</p>
\r
894 * @result <p>Hello</p>
\r
898 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
\r
899 * @cat Events/Mouse
\r
903 * Removes all bound mouseup events from each of the matched elements.
\r
905 * @example $("p").unmouseup();
\r
906 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
907 * @result <p>Hello</p>
\r
911 * @cat Events/Mouse
\r
915 * Bind a function to the unload event of each matched element.
\r
917 * @example $("p").unload( function() { alert("Hello"); } );
\r
918 * @before <p>Hello</p>
\r
919 * @result <p onunload="alert('Hello');">Hello</p>
\r
923 * @param Function fn A function to bind to the unload event on each of the matched elements.
\r
924 * @cat Events/Browser
\r
928 * Trigger the unload event of each matched element. This causes all of the functions
\r
929 * that have been bound to thet unload event to be executed.
\r
931 * @example $("p").unload();
\r
932 * @before <p onunload="alert('Hello');">Hello</p>
\r
933 * @result alert('Hello');
\r
937 * @cat Events/Browser
\r
941 * Bind a function to the unload event of each matched element, which will only be executed once.
\r
942 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
\r
943 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
945 * @example $("p").oneunload( function() { alert("Hello"); } );
\r
946 * @before <p onunload="alert('Hello');">Hello</p>
\r
947 * @result alert('Hello'); // Only executed for the first unload
\r
951 * @param Function fn A function to bind to the unload event on each of the matched elements.
\r
952 * @cat Events/Browser
\r
956 * Removes a bound unload event from each of the matched
\r
957 * elements. You must pass the identical function that was used in the original
\r
960 * @example $("p").ununload( myFunction );
\r
961 * @before <p onunload="myFunction">Hello</p>
\r
962 * @result <p>Hello</p>
\r
966 * @param Function fn A function to unbind from the unload event on each of the matched elements.
\r
967 * @cat Events/Browser
\r
971 * Removes all bound unload events from each of the matched elements.
\r
973 * @example $("p").ununload();
\r
974 * @before <p onunload="alert('Hello');">Hello</p>
\r
975 * @result <p>Hello</p>
\r
979 * @cat Events/Browser
\r
983 * Bind a function to the change event of each matched element.
\r
985 * @example $("p").change( function() { alert("Hello"); } );
\r
986 * @before <p>Hello</p>
\r
987 * @result <p onchange="alert('Hello');">Hello</p>
\r
991 * @param Function fn A function to bind to the change event on each of the matched elements.
\r
996 * Trigger the change event of each matched element. This causes all of the functions
\r
997 * that have been bound to thet change event to be executed.
\r
999 * @example $("p").change();
\r
1000 * @before <p onchange="alert('Hello');">Hello</p>
\r
1001 * @result alert('Hello');
\r
1005 * @cat Events/Form
\r
1009 * Bind a function to the change event of each matched element, which will only be executed once.
\r
1010 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
\r
1011 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1013 * @example $("p").onechange( function() { alert("Hello"); } );
\r
1014 * @before <p onchange="alert('Hello');">Hello</p>
\r
1015 * @result alert('Hello'); // Only executed for the first change
\r
1019 * @param Function fn A function to bind to the change event on each of the matched elements.
\r
1020 * @cat Events/Form
\r
1024 * Removes a bound change event from each of the matched
\r
1025 * elements. You must pass the identical function that was used in the original
\r
1028 * @example $("p").unchange( myFunction );
\r
1029 * @before <p onchange="myFunction">Hello</p>
\r
1030 * @result <p>Hello</p>
\r
1034 * @param Function fn A function to unbind from the change event on each of the matched elements.
\r
1035 * @cat Events/Form
\r
1039 * Removes all bound change events from each of the matched elements.
\r
1041 * @example $("p").unchange();
\r
1042 * @before <p onchange="alert('Hello');">Hello</p>
\r
1043 * @result <p>Hello</p>
\r
1047 * @cat Events/Form
\r
1051 * Bind a function to the mouseout event of each matched element.
\r
1053 * @example $("p").mouseout( function() { alert("Hello"); } );
\r
1054 * @before <p>Hello</p>
\r
1055 * @result <p onmouseout="alert('Hello');">Hello</p>
\r
1059 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
\r
1060 * @cat Events/Mouse
\r
1064 * Trigger the mouseout event of each matched element. This causes all of the functions
\r
1065 * that have been bound to thet mouseout event to be executed.
\r
1067 * @example $("p").mouseout();
\r
1068 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1069 * @result alert('Hello');
\r
1073 * @cat Events/Mouse
\r
1077 * Bind a function to the mouseout event of each matched element, which will only be executed once.
\r
1078 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
\r
1079 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1081 * @example $("p").onemouseout( function() { alert("Hello"); } );
\r
1082 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1083 * @result alert('Hello'); // Only executed for the first mouseout
\r
1085 * @name onemouseout
\r
1087 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
\r
1088 * @cat Events/Mouse
\r
1092 * Removes a bound mouseout event from each of the matched
\r
1093 * elements. You must pass the identical function that was used in the original
\r
1096 * @example $("p").unmouseout( myFunction );
\r
1097 * @before <p onmouseout="myFunction">Hello</p>
\r
1098 * @result <p>Hello</p>
\r
1100 * @name unmouseout
\r
1102 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
\r
1103 * @cat Events/Mouse
\r
1107 * Removes all bound mouseout events from each of the matched elements.
\r
1109 * @example $("p").unmouseout();
\r
1110 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1111 * @result <p>Hello</p>
\r
1113 * @name unmouseout
\r
1115 * @cat Events/Mouse
\r
1119 * Bind a function to the keyup event of each matched element.
\r
1121 * @example $("p").keyup( function() { alert("Hello"); } );
\r
1122 * @before <p>Hello</p>
\r
1123 * @result <p onkeyup="alert('Hello');">Hello</p>
\r
1127 * @param Function fn A function to bind to the keyup event on each of the matched elements.
\r
1128 * @cat Events/Keyboard
\r
1132 * Trigger the keyup event of each matched element. This causes all of the functions
\r
1133 * that have been bound to thet keyup event to be executed.
\r
1135 * @example $("p").keyup();
\r
1136 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1137 * @result alert('Hello');
\r
1141 * @cat Events/Keyboard
\r
1145 * Bind a function to the keyup event of each matched element, which will only be executed once.
\r
1146 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
\r
1147 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1149 * @example $("p").onekeyup( function() { alert("Hello"); } );
\r
1150 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1151 * @result alert('Hello'); // Only executed for the first keyup
\r
1155 * @param Function fn A function to bind to the keyup event on each of the matched elements.
\r
1156 * @cat Events/Keyboard
\r
1160 * Removes a bound keyup event from each of the matched
\r
1161 * elements. You must pass the identical function that was used in the original
\r
1164 * @example $("p").unkeyup( myFunction );
\r
1165 * @before <p onkeyup="myFunction">Hello</p>
\r
1166 * @result <p>Hello</p>
\r
1170 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
\r
1171 * @cat Events/Keyboard
\r
1175 * Removes all bound keyup events from each of the matched elements.
\r
1177 * @example $("p").unkeyup();
\r
1178 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1179 * @result <p>Hello</p>
\r
1183 * @cat Events/Keyboard
\r
1187 * Bind a function to the click event of each matched element.
\r
1189 * @example $("p").click( function() { alert("Hello"); } );
\r
1190 * @before <p>Hello</p>
\r
1191 * @result <p onclick="alert('Hello');">Hello</p>
\r
1195 * @param Function fn A function to bind to the click event on each of the matched elements.
\r
1196 * @cat Events/Mouse
\r
1200 * Trigger the click event of each matched element. This causes all of the functions
\r
1201 * that have been bound to thet click event to be executed.
\r
1203 * @example $("p").click();
\r
1204 * @before <p onclick="alert('Hello');">Hello</p>
\r
1205 * @result alert('Hello');
\r
1209 * @cat Events/Mouse
\r
1213 * Bind a function to the click event of each matched element, which will only be executed once.
\r
1214 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
\r
1215 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1217 * @example $("p").oneclick( function() { alert("Hello"); } );
\r
1218 * @before <p onclick="alert('Hello');">Hello</p>
\r
1219 * @result alert('Hello'); // Only executed for the first click
\r
1223 * @param Function fn A function to bind to the click event on each of the matched elements.
\r
1224 * @cat Events/Mouse
\r
1228 * Removes a bound click event from each of the matched
\r
1229 * elements. You must pass the identical function that was used in the original
\r
1232 * @example $("p").unclick( myFunction );
\r
1233 * @before <p onclick="myFunction">Hello</p>
\r
1234 * @result <p>Hello</p>
\r
1238 * @param Function fn A function to unbind from the click event on each of the matched elements.
\r
1239 * @cat Events/Mouse
\r
1243 * Removes all bound click events from each of the matched elements.
\r
1245 * @example $("p").unclick();
\r
1246 * @before <p onclick="alert('Hello');">Hello</p>
\r
1247 * @result <p>Hello</p>
\r
1251 * @cat Events/Mouse
\r
1255 * Bind a function to the resize event of each matched element.
\r
1257 * @example $("p").resize( function() { alert("Hello"); } );
\r
1258 * @before <p>Hello</p>
\r
1259 * @result <p onresize="alert('Hello');">Hello</p>
\r
1263 * @param Function fn A function to bind to the resize event on each of the matched elements.
\r
1264 * @cat Events/Browser
\r
1268 * Trigger the resize event of each matched element. This causes all of the functions
\r
1269 * that have been bound to thet resize event to be executed.
\r
1271 * @example $("p").resize();
\r
1272 * @before <p onresize="alert('Hello');">Hello</p>
\r
1273 * @result alert('Hello');
\r
1277 * @cat Events/Browser
\r
1281 * Bind a function to the resize event of each matched element, which will only be executed once.
\r
1282 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
\r
1283 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1285 * @example $("p").oneresize( function() { alert("Hello"); } );
\r
1286 * @before <p onresize="alert('Hello');">Hello</p>
\r
1287 * @result alert('Hello'); // Only executed for the first resize
\r
1291 * @param Function fn A function to bind to the resize event on each of the matched elements.
\r
1292 * @cat Events/Browser
\r
1296 * Removes a bound resize event from each of the matched
\r
1297 * elements. You must pass the identical function that was used in the original
\r
1300 * @example $("p").unresize( myFunction );
\r
1301 * @before <p onresize="myFunction">Hello</p>
\r
1302 * @result <p>Hello</p>
\r
1306 * @param Function fn A function to unbind from the resize event on each of the matched elements.
\r
1307 * @cat Events/Browser
\r
1311 * Removes all bound resize events from each of the matched elements.
\r
1313 * @example $("p").unresize();
\r
1314 * @before <p onresize="alert('Hello');">Hello</p>
\r
1315 * @result <p>Hello</p>
\r
1319 * @cat Events/Browser
\r
1323 * Bind a function to the mousemove event of each matched element.
\r
1325 * @example $("p").mousemove( function() { alert("Hello"); } );
\r
1326 * @before <p>Hello</p>
\r
1327 * @result <p onmousemove="alert('Hello');">Hello</p>
\r
1331 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
\r
1332 * @cat Events/Mouse
\r
1336 * Trigger the mousemove event of each matched element. This causes all of the functions
\r
1337 * that have been bound to thet mousemove event to be executed.
\r
1339 * @example $("p").mousemove();
\r
1340 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1341 * @result alert('Hello');
\r
1345 * @cat Events/Mouse
\r
1349 * Bind a function to the mousemove event of each matched element, which will only be executed once.
\r
1350 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
\r
1351 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1353 * @example $("p").onemousemove( function() { alert("Hello"); } );
\r
1354 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1355 * @result alert('Hello'); // Only executed for the first mousemove
\r
1357 * @name onemousemove
\r
1359 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
\r
1360 * @cat Events/Mouse
\r
1364 * Removes a bound mousemove event from each of the matched
\r
1365 * elements. You must pass the identical function that was used in the original
\r
1368 * @example $("p").unmousemove( myFunction );
\r
1369 * @before <p onmousemove="myFunction">Hello</p>
\r
1370 * @result <p>Hello</p>
\r
1372 * @name unmousemove
\r
1374 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
\r
1375 * @cat Events/Mouse
\r
1379 * Removes all bound mousemove events from each of the matched elements.
\r
1381 * @example $("p").unmousemove();
\r
1382 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1383 * @result <p>Hello</p>
\r
1385 * @name unmousemove
\r
1387 * @cat Events/Mouse
\r
1391 * Bind a function to the mousedown event of each matched element.
\r
1393 * @example $("p").mousedown( function() { alert("Hello"); } );
\r
1394 * @before <p>Hello</p>
\r
1395 * @result <p onmousedown="alert('Hello');">Hello</p>
\r
1399 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1400 * @cat Events/Mouse
\r
1404 * Trigger the mousedown event of each matched element. This causes all of the functions
\r
1405 * that have been bound to thet mousedown event to be executed.
\r
1407 * @example $("p").mousedown();
\r
1408 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1409 * @result alert('Hello');
\r
1413 * @cat Events/Mouse
\r
1417 * Bind a function to the mousedown event of each matched element, which will only be executed once.
\r
1418 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
\r
1419 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1421 * @example $("p").onemousedown( function() { alert("Hello"); } );
\r
1422 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1423 * @result alert('Hello'); // Only executed for the first mousedown
\r
1425 * @name onemousedown
\r
1427 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1428 * @cat Events/Mouse
\r
1432 * Removes a bound mousedown event from each of the matched
\r
1433 * elements. You must pass the identical function that was used in the original
\r
1436 * @example $("p").unmousedown( myFunction );
\r
1437 * @before <p onmousedown="myFunction">Hello</p>
\r
1438 * @result <p>Hello</p>
\r
1440 * @name unmousedown
\r
1442 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
\r
1443 * @cat Events/Mouse
\r
1447 * Removes all bound mousedown events from each of the matched elements.
\r
1449 * @example $("p").unmousedown();
\r
1450 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1451 * @result <p>Hello</p>
\r
1453 * @name unmousedown
\r
1455 * @cat Events/Mouse
\r
1459 * Bind a function to the mouseover event of each matched element.
\r
1461 * @example $("p").mouseover( function() { alert("Hello"); } );
\r
1462 * @before <p>Hello</p>
\r
1463 * @result <p onmouseover="alert('Hello');">Hello</p>
\r
1467 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1468 * @cat Events/Mouse
\r
1472 * Trigger the mouseover event of each matched element. This causes all of the functions
\r
1473 * that have been bound to thet mousedown event to be executed.
\r
1475 * @example $("p").mouseover();
\r
1476 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1477 * @result alert('Hello');
\r
1481 * @cat Events/Mouse
\r
1485 * Bind a function to the mouseover event of each matched element, which will only be executed once.
\r
1486 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
\r
1487 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1489 * @example $("p").onemouseover( function() { alert("Hello"); } );
\r
1490 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1491 * @result alert('Hello'); // Only executed for the first mouseover
\r
1493 * @name onemouseover
\r
1495 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
\r
1496 * @cat Events/Mouse
\r
1500 * Removes a bound mouseover event from each of the matched
\r
1501 * elements. You must pass the identical function that was used in the original
\r
1504 * @example $("p").unmouseover( myFunction );
\r
1505 * @before <p onmouseover="myFunction">Hello</p>
\r
1506 * @result <p>Hello</p>
\r
1508 * @name unmouseover
\r
1510 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
\r
1511 * @cat Events/Mouse
\r
1515 * Removes all bound mouseover events from each of the matched elements.
\r
1517 * @example $("p").unmouseover();
\r
1518 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1519 * @result <p>Hello</p>
\r
1521 * @name unmouseover
\r
1523 * @cat Events/Mouse
\r
1527 * @test var count;
\r
1529 * var e = ("blur,focus,resize,scroll,unload,click,dblclick," +
\r
1530 * "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
\r
1531 * "submit,keydown,keypress,keyup,error").split(",");
\r
1532 * var handler1 = function(event) {
\r
1535 * var handler2 = function(event) {
\r
1538 * for( var i=0; i < e.length; i++) {
\r
1539 * var event = e[i];
\r
1542 * $(document)[event](handler1);
\r
1543 * $(document)[event](handler2);
\r
1544 * $(document)["one"+event](handler1);
\r
1546 * // call event two times
\r
1547 * $(document)[event]();
\r
1548 * $(document)[event]();
\r
1550 * // unbind events
\r
1551 * $(document)["un"+event](handler1);
\r
1552 * // call once more
\r
1553 * $(document)[event]();
\r
1555 * // remove all handlers
\r
1556 * $(document)["un"+event]();
\r
1558 * // call once more
\r
1559 * $(document)[event]();
\r
1562 * ok( count == 6, 'Checking event ' + event);
\r
1566 * @name eventTesting
\r
1570 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
\r
1571 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
\r
1572 "submit,keydown,keypress,keyup,error").split(",");
\r
1574 // Go through all the event names, but make sure that
\r
1575 // it is enclosed properly
\r
1576 for ( var i = 0; i < e.length; i++ ) new function(){
\r
1580 // Handle event binding
\r
1581 jQuery.fn[o] = function(f){
\r
1582 return f ? this.bind(o, f) : this.trigger(o);
\r
1585 // Handle event unbinding
\r
1586 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
\r
1588 // Finally, handle events that only fire once
\r
1589 jQuery.fn["one"+o] = function(f){
\r
1590 // Attach the event listener
\r
1591 return this.each(function(){
\r
1596 jQuery.event.add( this, o, function(e){
\r
1597 // If this function has already been executed, stop
\r
1598 if ( count++ ) return;
\r
1600 // And execute the bound function
\r
1601 return f.apply(this, [e]);
\r
1608 // If Mozilla is used
\r
1609 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
\r
1610 // Use the handy event callback
\r
1611 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
\r
1613 // If IE is used, use the excellent hack by Matthias Miller
\r
1614 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
\r
1615 } else if ( jQuery.browser.msie ) {
\r
1617 // Only works if you document.write() it
\r
1618 document.write("<scr" + "ipt id=__ie_init defer=true " +
\r
1619 "src=//:><\/script>");
\r
1621 // Use the defer script hack
\r
1622 var script = document.getElementById("__ie_init");
\r
1623 script.onreadystatechange = function() {
\r
1624 if ( this.readyState != "complete" ) return;
\r
1625 this.parentNode.removeChild( this );
\r
1629 // Clear from memory
\r
1632 // If Safari is used
\r
1633 } else if ( jQuery.browser.safari ) {
\r
1634 // Continually check to see if the document.readyState is valid
\r
1635 jQuery.safariTimer = setInterval(function(){
\r
1636 // loaded and complete are both valid states
\r
1637 if ( document.readyState == "loaded" ||
\r
1638 document.readyState == "complete" ) {
\r
1640 // If either one are found, remove the timer
\r
1641 clearInterval( jQuery.safariTimer );
\r
1642 jQuery.safariTimer = null;
\r
1644 // and execute any waiting functions
\r
1650 // A fallback to window.onload, that will always work
\r
1651 jQuery.event.add( window, "load", jQuery.ready );
\r
1655 // Clean up after IE to avoid memory leaks
\r
1656 if ($.browser.msie) $(window).unload(function() {
\r
1657 var event = jQuery.event, global = event.global;
\r
1658 for (var type in global) {
\r
1659 var els = global[type], i = els.length;
\r
1660 if (i>0) do event.remove(els[i-1], type); while (--i);
\r