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 = this; };
\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
158 // Remove event lisenter to avoid memory leak
\r
159 if ( jQuery.browser.mozilla || jQuery.browser.opera )
\r
160 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
\r
168 * Bind a function to the scroll event of each matched element.
\r
170 * @example $("p").scroll( function() { alert("Hello"); } );
\r
171 * @before <p>Hello</p>
\r
172 * @result <p onscroll="alert('Hello');">Hello</p>
\r
176 * @param Function fn A function to bind to the scroll event on each of the matched elements.
\r
177 * @cat Events/Browser
\r
181 * Trigger the scroll event of each matched element. This causes all of the functions
\r
182 * that have been bound to thet scroll event to be executed.
\r
184 * @example $("p").scroll();
\r
185 * @before <p onscroll="alert('Hello');">Hello</p>
\r
186 * @result alert('Hello');
\r
190 * @cat Events/Browser
\r
194 * Bind a function to the scroll event of each matched element, which will only be executed once.
\r
195 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
\r
196 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
198 * @example $("p").onescroll( function() { alert("Hello"); } );
\r
199 * @before <p onscroll="alert('Hello');">Hello</p>
\r
200 * @result alert('Hello'); // Only executed for the first scroll
\r
204 * @param Function fn A function to bind to the scroll event on each of the matched elements.
\r
205 * @cat Events/Browser
\r
209 * Removes a bound scroll event from each of the matched
\r
210 * elements. You must pass the identical function that was used in the original
\r
213 * @example $("p").unscroll( myFunction );
\r
214 * @before <p onscroll="myFunction">Hello</p>
\r
215 * @result <p>Hello</p>
\r
219 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
\r
220 * @cat Events/Browser
\r
224 * Removes all bound scroll events from each of the matched elements.
\r
226 * @example $("p").unscroll();
\r
227 * @before <p onscroll="alert('Hello');">Hello</p>
\r
228 * @result <p>Hello</p>
\r
232 * @cat Events/Browser
\r
236 * Bind a function to the submit event of each matched element.
\r
238 * @example $("p").submit( function() { alert("Hello"); } );
\r
239 * @before <p>Hello</p>
\r
240 * @result <p onsubmit="alert('Hello');">Hello</p>
\r
244 * @param Function fn A function to bind to the submit event on each of the matched elements.
\r
249 * Trigger the submit event of each matched element. This causes all of the functions
\r
250 * that have been bound to thet submit event to be executed.
\r
252 * @example $("p").submit();
\r
253 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
254 * @result alert('Hello');
\r
262 * Bind a function to the submit event of each matched element, which will only be executed once.
\r
263 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
\r
264 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
266 * @example $("p").onesubmit( function() { alert("Hello"); } );
\r
267 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
268 * @result alert('Hello'); // Only executed for the first submit
\r
272 * @param Function fn A function to bind to the submit event on each of the matched elements.
\r
277 * Removes a bound submit event from each of the matched
\r
278 * elements. You must pass the identical function that was used in the original
\r
281 * @example $("p").unsubmit( myFunction );
\r
282 * @before <p onsubmit="myFunction">Hello</p>
\r
283 * @result <p>Hello</p>
\r
287 * @param Function fn A function to unbind from the submit event on each of the matched elements.
\r
292 * Removes all bound submit events from each of the matched elements.
\r
294 * @example $("p").unsubmit();
\r
295 * @before <p onsubmit="alert('Hello');">Hello</p>
\r
296 * @result <p>Hello</p>
\r
304 * Bind a function to the focus event of each matched element.
\r
306 * @example $("p").focus( function() { alert("Hello"); } );
\r
307 * @before <p>Hello</p>
\r
308 * @result <p onfocus="alert('Hello');">Hello</p>
\r
312 * @param Function fn A function to bind to the focus event on each of the matched elements.
\r
317 * Trigger the focus event of each matched element. This causes all of the functions
\r
318 * that have been bound to thet focus event to be executed.
\r
320 * @example $("p").focus();
\r
321 * @before <p onfocus="alert('Hello');">Hello</p>
\r
322 * @result alert('Hello');
\r
330 * Bind a function to the focus event of each matched element, which will only be executed once.
\r
331 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
\r
332 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
334 * @example $("p").onefocus( function() { alert("Hello"); } );
\r
335 * @before <p onfocus="alert('Hello');">Hello</p>
\r
336 * @result alert('Hello'); // Only executed for the first focus
\r
340 * @param Function fn A function to bind to the focus event on each of the matched elements.
\r
345 * Removes a bound focus event from each of the matched
\r
346 * elements. You must pass the identical function that was used in the original
\r
349 * @example $("p").unfocus( myFunction );
\r
350 * @before <p onfocus="myFunction">Hello</p>
\r
351 * @result <p>Hello</p>
\r
355 * @param Function fn A function to unbind from the focus event on each of the matched elements.
\r
360 * Removes all bound focus events from each of the matched elements.
\r
362 * @example $("p").unfocus();
\r
363 * @before <p onfocus="alert('Hello');">Hello</p>
\r
364 * @result <p>Hello</p>
\r
372 * Bind a function to the keydown event of each matched element.
\r
374 * @example $("p").keydown( function() { alert("Hello"); } );
\r
375 * @before <p>Hello</p>
\r
376 * @result <p onkeydown="alert('Hello');">Hello</p>
\r
380 * @param Function fn A function to bind to the keydown event on each of the matched elements.
\r
381 * @cat Events/Keyboard
\r
385 * Trigger the keydown event of each matched element. This causes all of the functions
\r
386 * that have been bound to thet keydown event to be executed.
\r
388 * @example $("p").keydown();
\r
389 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
390 * @result alert('Hello');
\r
394 * @cat Events/Keyboard
\r
398 * Bind a function to the keydown event of each matched element, which will only be executed once.
\r
399 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
\r
400 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
402 * @example $("p").onekeydown( function() { alert("Hello"); } );
\r
403 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
404 * @result alert('Hello'); // Only executed for the first keydown
\r
408 * @param Function fn A function to bind to the keydown event on each of the matched elements.
\r
409 * @cat Events/Keyboard
\r
413 * Removes a bound keydown event from each of the matched
\r
414 * elements. You must pass the identical function that was used in the original
\r
417 * @example $("p").unkeydown( myFunction );
\r
418 * @before <p onkeydown="myFunction">Hello</p>
\r
419 * @result <p>Hello</p>
\r
423 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
\r
424 * @cat Events/Keyboard
\r
428 * Removes all bound keydown events from each of the matched elements.
\r
430 * @example $("p").unkeydown();
\r
431 * @before <p onkeydown="alert('Hello');">Hello</p>
\r
432 * @result <p>Hello</p>
\r
436 * @cat Events/Keyboard
\r
440 * Bind a function to the dblclick event of each matched element.
\r
442 * @example $("p").dblclick( function() { alert("Hello"); } );
\r
443 * @before <p>Hello</p>
\r
444 * @result <p ondblclick="alert('Hello');">Hello</p>
\r
448 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
\r
449 * @cat Events/Mouse
\r
453 * Trigger the dblclick event of each matched element. This causes all of the functions
\r
454 * that have been bound to thet dblclick event to be executed.
\r
456 * @example $("p").dblclick();
\r
457 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
458 * @result alert('Hello');
\r
462 * @cat Events/Mouse
\r
466 * Bind a function to the dblclick event of each matched element, which will only be executed once.
\r
467 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
\r
468 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
470 * @example $("p").onedblclick( function() { alert("Hello"); } );
\r
471 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
472 * @result alert('Hello'); // Only executed for the first dblclick
\r
474 * @name onedblclick
\r
476 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
\r
477 * @cat Events/Mouse
\r
481 * Removes a bound dblclick event from each of the matched
\r
482 * elements. You must pass the identical function that was used in the original
\r
485 * @example $("p").undblclick( myFunction );
\r
486 * @before <p ondblclick="myFunction">Hello</p>
\r
487 * @result <p>Hello</p>
\r
491 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
\r
492 * @cat Events/Mouse
\r
496 * Removes all bound dblclick events from each of the matched elements.
\r
498 * @example $("p").undblclick();
\r
499 * @before <p ondblclick="alert('Hello');">Hello</p>
\r
500 * @result <p>Hello</p>
\r
504 * @cat Events/Mouse
\r
508 * Bind a function to the keypress event of each matched element.
\r
510 * @example $("p").keypress( function() { alert("Hello"); } );
\r
511 * @before <p>Hello</p>
\r
512 * @result <p onkeypress="alert('Hello');">Hello</p>
\r
516 * @param Function fn A function to bind to the keypress event on each of the matched elements.
\r
517 * @cat Events/Keyboard
\r
521 * Trigger the keypress event of each matched element. This causes all of the functions
\r
522 * that have been bound to thet keypress event to be executed.
\r
524 * @example $("p").keypress();
\r
525 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
526 * @result alert('Hello');
\r
530 * @cat Events/Keyboard
\r
534 * Bind a function to the keypress event of each matched element, which will only be executed once.
\r
535 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
\r
536 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
538 * @example $("p").onekeypress( function() { alert("Hello"); } );
\r
539 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
540 * @result alert('Hello'); // Only executed for the first keypress
\r
542 * @name onekeypress
\r
544 * @param Function fn A function to bind to the keypress event on each of the matched elements.
\r
545 * @cat Events/Keyboard
\r
549 * Removes a bound keypress event from each of the matched
\r
550 * elements. You must pass the identical function that was used in the original
\r
553 * @example $("p").unkeypress( myFunction );
\r
554 * @before <p onkeypress="myFunction">Hello</p>
\r
555 * @result <p>Hello</p>
\r
559 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
\r
560 * @cat Events/Keyboard
\r
564 * Removes all bound keypress events from each of the matched elements.
\r
566 * @example $("p").unkeypress();
\r
567 * @before <p onkeypress="alert('Hello');">Hello</p>
\r
568 * @result <p>Hello</p>
\r
572 * @cat Events/Keyboard
\r
576 * Bind a function to the error event of each matched element.
\r
578 * @example $("p").error( function() { alert("Hello"); } );
\r
579 * @before <p>Hello</p>
\r
580 * @result <p onerror="alert('Hello');">Hello</p>
\r
584 * @param Function fn A function to bind to the error event on each of the matched elements.
\r
585 * @cat Events/Browser
\r
589 * Trigger the error event of each matched element. This causes all of the functions
\r
590 * that have been bound to thet error event to be executed.
\r
592 * @example $("p").error();
\r
593 * @before <p onerror="alert('Hello');">Hello</p>
\r
594 * @result alert('Hello');
\r
598 * @cat Events/Browser
\r
602 * Bind a function to the error event of each matched element, which will only be executed once.
\r
603 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
\r
604 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
606 * @example $("p").oneerror( function() { alert("Hello"); } );
\r
607 * @before <p onerror="alert('Hello');">Hello</p>
\r
608 * @result alert('Hello'); // Only executed for the first error
\r
612 * @param Function fn A function to bind to the error event on each of the matched elements.
\r
613 * @cat Events/Browser
\r
617 * Removes a bound error event from each of the matched
\r
618 * elements. You must pass the identical function that was used in the original
\r
621 * @example $("p").unerror( myFunction );
\r
622 * @before <p onerror="myFunction">Hello</p>
\r
623 * @result <p>Hello</p>
\r
627 * @param Function fn A function to unbind from the error event on each of the matched elements.
\r
628 * @cat Events/Browser
\r
632 * Removes all bound error events from each of the matched elements.
\r
634 * @example $("p").unerror();
\r
635 * @before <p onerror="alert('Hello');">Hello</p>
\r
636 * @result <p>Hello</p>
\r
640 * @cat Events/Browser
\r
644 * Bind a function to the blur event of each matched element.
\r
646 * @example $("p").blur( function() { alert("Hello"); } );
\r
647 * @before <p>Hello</p>
\r
648 * @result <p onblur="alert('Hello');">Hello</p>
\r
652 * @param Function fn A function to bind to the blur event on each of the matched elements.
\r
657 * Trigger the blur event of each matched element. This causes all of the functions
\r
658 * that have been bound to thet blur event to be executed.
\r
660 * @example $("p").blur();
\r
661 * @before <p onblur="alert('Hello');">Hello</p>
\r
662 * @result alert('Hello');
\r
670 * Bind a function to the blur event of each matched element, which will only be executed once.
\r
671 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
\r
672 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
674 * @example $("p").oneblur( function() { alert("Hello"); } );
\r
675 * @before <p onblur="alert('Hello');">Hello</p>
\r
676 * @result alert('Hello'); // Only executed for the first blur
\r
680 * @param Function fn A function to bind to the blur event on each of the matched elements.
\r
685 * Removes a bound blur event from each of the matched
\r
686 * elements. You must pass the identical function that was used in the original
\r
689 * @example $("p").unblur( myFunction );
\r
690 * @before <p onblur="myFunction">Hello</p>
\r
691 * @result <p>Hello</p>
\r
695 * @param Function fn A function to unbind from the blur event on each of the matched elements.
\r
700 * Removes all bound blur events from each of the matched elements.
\r
702 * @example $("p").unblur();
\r
703 * @before <p onblur="alert('Hello');">Hello</p>
\r
704 * @result <p>Hello</p>
\r
712 * Bind a function to the load event of each matched element.
\r
714 * @example $("p").load( function() { alert("Hello"); } );
\r
715 * @before <p>Hello</p>
\r
716 * @result <p onload="alert('Hello');">Hello</p>
\r
720 * @param Function fn A function to bind to the load event on each of the matched elements.
\r
721 * @cat Events/Browser
\r
725 * Trigger the load event of each matched element. This causes all of the functions
\r
726 * that have been bound to thet load event to be executed.
\r
728 * Marked as private: Calling load() without arguments throws exception because the ajax load
\r
729 * does not handle it.
\r
731 * @example $("p").load();
\r
732 * @before <p onload="alert('Hello');">Hello</p>
\r
733 * @result alert('Hello');
\r
738 * @cat Events/Browser
\r
742 * Bind a function to the load event of each matched element, which will only be executed once.
\r
743 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
\r
744 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
746 * @example $("p").oneload( function() { alert("Hello"); } );
\r
747 * @before <p onload="alert('Hello');">Hello</p>
\r
748 * @result alert('Hello'); // Only executed for the first load
\r
752 * @param Function fn A function to bind to the load event on each of the matched elements.
\r
753 * @cat Events/Browser
\r
757 * Removes a bound load event from each of the matched
\r
758 * elements. You must pass the identical function that was used in the original
\r
761 * @example $("p").unload( myFunction );
\r
762 * @before <p onload="myFunction">Hello</p>
\r
763 * @result <p>Hello</p>
\r
767 * @param Function fn A function to unbind from the load event on each of the matched elements.
\r
768 * @cat Events/Browser
\r
772 * Removes all bound load events from each of the matched elements.
\r
774 * @example $("p").unload();
\r
775 * @before <p onload="alert('Hello');">Hello</p>
\r
776 * @result <p>Hello</p>
\r
780 * @cat Events/Browser
\r
784 * Bind a function to the select event of each matched element.
\r
786 * @example $("p").select( function() { alert("Hello"); } );
\r
787 * @before <p>Hello</p>
\r
788 * @result <p onselect="alert('Hello');">Hello</p>
\r
792 * @param Function fn A function to bind to the select event on each of the matched elements.
\r
797 * Trigger the select event of each matched element. This causes all of the functions
\r
798 * that have been bound to thet select event to be executed.
\r
800 * @example $("p").select();
\r
801 * @before <p onselect="alert('Hello');">Hello</p>
\r
802 * @result alert('Hello');
\r
810 * Bind a function to the select event of each matched element, which will only be executed once.
\r
811 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
\r
812 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
814 * @example $("p").oneselect( function() { alert("Hello"); } );
\r
815 * @before <p onselect="alert('Hello');">Hello</p>
\r
816 * @result alert('Hello'); // Only executed for the first select
\r
820 * @param Function fn A function to bind to the select event on each of the matched elements.
\r
825 * Removes a bound select event from each of the matched
\r
826 * elements. You must pass the identical function that was used in the original
\r
829 * @example $("p").unselect( myFunction );
\r
830 * @before <p onselect="myFunction">Hello</p>
\r
831 * @result <p>Hello</p>
\r
835 * @param Function fn A function to unbind from the select event on each of the matched elements.
\r
840 * Removes all bound select events from each of the matched elements.
\r
842 * @example $("p").unselect();
\r
843 * @before <p onselect="alert('Hello');">Hello</p>
\r
844 * @result <p>Hello</p>
\r
852 * Bind a function to the mouseup event of each matched element.
\r
854 * @example $("p").mouseup( function() { alert("Hello"); } );
\r
855 * @before <p>Hello</p>
\r
856 * @result <p onmouseup="alert('Hello');">Hello</p>
\r
860 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
\r
861 * @cat Events/Mouse
\r
865 * Trigger the mouseup event of each matched element. This causes all of the functions
\r
866 * that have been bound to thet mouseup event to be executed.
\r
868 * @example $("p").mouseup();
\r
869 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
870 * @result alert('Hello');
\r
874 * @cat Events/Mouse
\r
878 * Bind a function to the mouseup event of each matched element, which will only be executed once.
\r
879 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
\r
880 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
882 * @example $("p").onemouseup( function() { alert("Hello"); } );
\r
883 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
884 * @result alert('Hello'); // Only executed for the first mouseup
\r
888 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
\r
889 * @cat Events/Mouse
\r
893 * Removes a bound mouseup event from each of the matched
\r
894 * elements. You must pass the identical function that was used in the original
\r
897 * @example $("p").unmouseup( myFunction );
\r
898 * @before <p onmouseup="myFunction">Hello</p>
\r
899 * @result <p>Hello</p>
\r
903 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
\r
904 * @cat Events/Mouse
\r
908 * Removes all bound mouseup events from each of the matched elements.
\r
910 * @example $("p").unmouseup();
\r
911 * @before <p onmouseup="alert('Hello');">Hello</p>
\r
912 * @result <p>Hello</p>
\r
916 * @cat Events/Mouse
\r
920 * Bind a function to the unload event of each matched element.
\r
922 * @example $("p").unload( function() { alert("Hello"); } );
\r
923 * @before <p>Hello</p>
\r
924 * @result <p onunload="alert('Hello');">Hello</p>
\r
928 * @param Function fn A function to bind to the unload event on each of the matched elements.
\r
929 * @cat Events/Browser
\r
933 * Trigger the unload event of each matched element. This causes all of the functions
\r
934 * that have been bound to thet unload event to be executed.
\r
936 * @example $("p").unload();
\r
937 * @before <p onunload="alert('Hello');">Hello</p>
\r
938 * @result alert('Hello');
\r
942 * @cat Events/Browser
\r
946 * Bind a function to the unload event of each matched element, which will only be executed once.
\r
947 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
\r
948 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
950 * @example $("p").oneunload( function() { alert("Hello"); } );
\r
951 * @before <p onunload="alert('Hello');">Hello</p>
\r
952 * @result alert('Hello'); // Only executed for the first unload
\r
956 * @param Function fn A function to bind to the unload event on each of the matched elements.
\r
957 * @cat Events/Browser
\r
961 * Removes a bound unload event from each of the matched
\r
962 * elements. You must pass the identical function that was used in the original
\r
965 * @example $("p").ununload( myFunction );
\r
966 * @before <p onunload="myFunction">Hello</p>
\r
967 * @result <p>Hello</p>
\r
971 * @param Function fn A function to unbind from the unload event on each of the matched elements.
\r
972 * @cat Events/Browser
\r
976 * Removes all bound unload events from each of the matched elements.
\r
978 * @example $("p").ununload();
\r
979 * @before <p onunload="alert('Hello');">Hello</p>
\r
980 * @result <p>Hello</p>
\r
984 * @cat Events/Browser
\r
988 * Bind a function to the change event of each matched element.
\r
990 * @example $("p").change( function() { alert("Hello"); } );
\r
991 * @before <p>Hello</p>
\r
992 * @result <p onchange="alert('Hello');">Hello</p>
\r
996 * @param Function fn A function to bind to the change event on each of the matched elements.
\r
1001 * Trigger the change event of each matched element. This causes all of the functions
\r
1002 * that have been bound to thet change event to be executed.
\r
1004 * @example $("p").change();
\r
1005 * @before <p onchange="alert('Hello');">Hello</p>
\r
1006 * @result alert('Hello');
\r
1010 * @cat Events/Form
\r
1014 * Bind a function to the change event of each matched element, which will only be executed once.
\r
1015 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
\r
1016 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1018 * @example $("p").onechange( function() { alert("Hello"); } );
\r
1019 * @before <p onchange="alert('Hello');">Hello</p>
\r
1020 * @result alert('Hello'); // Only executed for the first change
\r
1024 * @param Function fn A function to bind to the change event on each of the matched elements.
\r
1025 * @cat Events/Form
\r
1029 * Removes a bound change event from each of the matched
\r
1030 * elements. You must pass the identical function that was used in the original
\r
1033 * @example $("p").unchange( myFunction );
\r
1034 * @before <p onchange="myFunction">Hello</p>
\r
1035 * @result <p>Hello</p>
\r
1039 * @param Function fn A function to unbind from the change event on each of the matched elements.
\r
1040 * @cat Events/Form
\r
1044 * Removes all bound change events from each of the matched elements.
\r
1046 * @example $("p").unchange();
\r
1047 * @before <p onchange="alert('Hello');">Hello</p>
\r
1048 * @result <p>Hello</p>
\r
1052 * @cat Events/Form
\r
1056 * Bind a function to the mouseout event of each matched element.
\r
1058 * @example $("p").mouseout( function() { alert("Hello"); } );
\r
1059 * @before <p>Hello</p>
\r
1060 * @result <p onmouseout="alert('Hello');">Hello</p>
\r
1064 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
\r
1065 * @cat Events/Mouse
\r
1069 * Trigger the mouseout event of each matched element. This causes all of the functions
\r
1070 * that have been bound to thet mouseout event to be executed.
\r
1072 * @example $("p").mouseout();
\r
1073 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1074 * @result alert('Hello');
\r
1078 * @cat Events/Mouse
\r
1082 * Bind a function to the mouseout event of each matched element, which will only be executed once.
\r
1083 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
\r
1084 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1086 * @example $("p").onemouseout( function() { alert("Hello"); } );
\r
1087 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1088 * @result alert('Hello'); // Only executed for the first mouseout
\r
1090 * @name onemouseout
\r
1092 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
\r
1093 * @cat Events/Mouse
\r
1097 * Removes a bound mouseout event from each of the matched
\r
1098 * elements. You must pass the identical function that was used in the original
\r
1101 * @example $("p").unmouseout( myFunction );
\r
1102 * @before <p onmouseout="myFunction">Hello</p>
\r
1103 * @result <p>Hello</p>
\r
1105 * @name unmouseout
\r
1107 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
\r
1108 * @cat Events/Mouse
\r
1112 * Removes all bound mouseout events from each of the matched elements.
\r
1114 * @example $("p").unmouseout();
\r
1115 * @before <p onmouseout="alert('Hello');">Hello</p>
\r
1116 * @result <p>Hello</p>
\r
1118 * @name unmouseout
\r
1120 * @cat Events/Mouse
\r
1124 * Bind a function to the keyup event of each matched element.
\r
1126 * @example $("p").keyup( function() { alert("Hello"); } );
\r
1127 * @before <p>Hello</p>
\r
1128 * @result <p onkeyup="alert('Hello');">Hello</p>
\r
1132 * @param Function fn A function to bind to the keyup event on each of the matched elements.
\r
1133 * @cat Events/Keyboard
\r
1137 * Trigger the keyup event of each matched element. This causes all of the functions
\r
1138 * that have been bound to thet keyup event to be executed.
\r
1140 * @example $("p").keyup();
\r
1141 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1142 * @result alert('Hello');
\r
1146 * @cat Events/Keyboard
\r
1150 * Bind a function to the keyup event of each matched element, which will only be executed once.
\r
1151 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
\r
1152 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1154 * @example $("p").onekeyup( function() { alert("Hello"); } );
\r
1155 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1156 * @result alert('Hello'); // Only executed for the first keyup
\r
1160 * @param Function fn A function to bind to the keyup event on each of the matched elements.
\r
1161 * @cat Events/Keyboard
\r
1165 * Removes a bound keyup event from each of the matched
\r
1166 * elements. You must pass the identical function that was used in the original
\r
1169 * @example $("p").unkeyup( myFunction );
\r
1170 * @before <p onkeyup="myFunction">Hello</p>
\r
1171 * @result <p>Hello</p>
\r
1175 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
\r
1176 * @cat Events/Keyboard
\r
1180 * Removes all bound keyup events from each of the matched elements.
\r
1182 * @example $("p").unkeyup();
\r
1183 * @before <p onkeyup="alert('Hello');">Hello</p>
\r
1184 * @result <p>Hello</p>
\r
1188 * @cat Events/Keyboard
\r
1192 * Bind a function to the click event of each matched element.
\r
1194 * @example $("p").click( function() { alert("Hello"); } );
\r
1195 * @before <p>Hello</p>
\r
1196 * @result <p onclick="alert('Hello');">Hello</p>
\r
1200 * @param Function fn A function to bind to the click event on each of the matched elements.
\r
1201 * @cat Events/Mouse
\r
1205 * Trigger the click event of each matched element. This causes all of the functions
\r
1206 * that have been bound to thet click event to be executed.
\r
1208 * @example $("p").click();
\r
1209 * @before <p onclick="alert('Hello');">Hello</p>
\r
1210 * @result alert('Hello');
\r
1214 * @cat Events/Mouse
\r
1218 * Bind a function to the click event of each matched element, which will only be executed once.
\r
1219 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
\r
1220 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1222 * @example $("p").oneclick( function() { alert("Hello"); } );
\r
1223 * @before <p onclick="alert('Hello');">Hello</p>
\r
1224 * @result alert('Hello'); // Only executed for the first click
\r
1228 * @param Function fn A function to bind to the click event on each of the matched elements.
\r
1229 * @cat Events/Mouse
\r
1233 * Removes a bound click event from each of the matched
\r
1234 * elements. You must pass the identical function that was used in the original
\r
1237 * @example $("p").unclick( myFunction );
\r
1238 * @before <p onclick="myFunction">Hello</p>
\r
1239 * @result <p>Hello</p>
\r
1243 * @param Function fn A function to unbind from the click event on each of the matched elements.
\r
1244 * @cat Events/Mouse
\r
1248 * Removes all bound click events from each of the matched elements.
\r
1250 * @example $("p").unclick();
\r
1251 * @before <p onclick="alert('Hello');">Hello</p>
\r
1252 * @result <p>Hello</p>
\r
1256 * @cat Events/Mouse
\r
1260 * Bind a function to the resize event of each matched element.
\r
1262 * @example $("p").resize( function() { alert("Hello"); } );
\r
1263 * @before <p>Hello</p>
\r
1264 * @result <p onresize="alert('Hello');">Hello</p>
\r
1268 * @param Function fn A function to bind to the resize event on each of the matched elements.
\r
1269 * @cat Events/Browser
\r
1273 * Trigger the resize event of each matched element. This causes all of the functions
\r
1274 * that have been bound to thet resize event to be executed.
\r
1276 * @example $("p").resize();
\r
1277 * @before <p onresize="alert('Hello');">Hello</p>
\r
1278 * @result alert('Hello');
\r
1282 * @cat Events/Browser
\r
1286 * Bind a function to the resize event of each matched element, which will only be executed once.
\r
1287 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
\r
1288 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1290 * @example $("p").oneresize( function() { alert("Hello"); } );
\r
1291 * @before <p onresize="alert('Hello');">Hello</p>
\r
1292 * @result alert('Hello'); // Only executed for the first resize
\r
1296 * @param Function fn A function to bind to the resize event on each of the matched elements.
\r
1297 * @cat Events/Browser
\r
1301 * Removes a bound resize event from each of the matched
\r
1302 * elements. You must pass the identical function that was used in the original
\r
1305 * @example $("p").unresize( myFunction );
\r
1306 * @before <p onresize="myFunction">Hello</p>
\r
1307 * @result <p>Hello</p>
\r
1311 * @param Function fn A function to unbind from the resize event on each of the matched elements.
\r
1312 * @cat Events/Browser
\r
1316 * Removes all bound resize events from each of the matched elements.
\r
1318 * @example $("p").unresize();
\r
1319 * @before <p onresize="alert('Hello');">Hello</p>
\r
1320 * @result <p>Hello</p>
\r
1324 * @cat Events/Browser
\r
1328 * Bind a function to the mousemove event of each matched element.
\r
1330 * @example $("p").mousemove( function() { alert("Hello"); } );
\r
1331 * @before <p>Hello</p>
\r
1332 * @result <p onmousemove="alert('Hello');">Hello</p>
\r
1336 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
\r
1337 * @cat Events/Mouse
\r
1341 * Trigger the mousemove event of each matched element. This causes all of the functions
\r
1342 * that have been bound to thet mousemove event to be executed.
\r
1344 * @example $("p").mousemove();
\r
1345 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1346 * @result alert('Hello');
\r
1350 * @cat Events/Mouse
\r
1354 * Bind a function to the mousemove event of each matched element, which will only be executed once.
\r
1355 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
\r
1356 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1358 * @example $("p").onemousemove( function() { alert("Hello"); } );
\r
1359 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1360 * @result alert('Hello'); // Only executed for the first mousemove
\r
1362 * @name onemousemove
\r
1364 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
\r
1365 * @cat Events/Mouse
\r
1369 * Removes a bound mousemove event from each of the matched
\r
1370 * elements. You must pass the identical function that was used in the original
\r
1373 * @example $("p").unmousemove( myFunction );
\r
1374 * @before <p onmousemove="myFunction">Hello</p>
\r
1375 * @result <p>Hello</p>
\r
1377 * @name unmousemove
\r
1379 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
\r
1380 * @cat Events/Mouse
\r
1384 * Removes all bound mousemove events from each of the matched elements.
\r
1386 * @example $("p").unmousemove();
\r
1387 * @before <p onmousemove="alert('Hello');">Hello</p>
\r
1388 * @result <p>Hello</p>
\r
1390 * @name unmousemove
\r
1392 * @cat Events/Mouse
\r
1396 * Bind a function to the mousedown event of each matched element.
\r
1398 * @example $("p").mousedown( function() { alert("Hello"); } );
\r
1399 * @before <p>Hello</p>
\r
1400 * @result <p onmousedown="alert('Hello');">Hello</p>
\r
1404 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1405 * @cat Events/Mouse
\r
1409 * Trigger the mousedown event of each matched element. This causes all of the functions
\r
1410 * that have been bound to thet mousedown event to be executed.
\r
1412 * @example $("p").mousedown();
\r
1413 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1414 * @result alert('Hello');
\r
1418 * @cat Events/Mouse
\r
1422 * Bind a function to the mousedown event of each matched element, which will only be executed once.
\r
1423 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
\r
1424 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1426 * @example $("p").onemousedown( function() { alert("Hello"); } );
\r
1427 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1428 * @result alert('Hello'); // Only executed for the first mousedown
\r
1430 * @name onemousedown
\r
1432 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1433 * @cat Events/Mouse
\r
1437 * Removes a bound mousedown event from each of the matched
\r
1438 * elements. You must pass the identical function that was used in the original
\r
1441 * @example $("p").unmousedown( myFunction );
\r
1442 * @before <p onmousedown="myFunction">Hello</p>
\r
1443 * @result <p>Hello</p>
\r
1445 * @name unmousedown
\r
1447 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
\r
1448 * @cat Events/Mouse
\r
1452 * Removes all bound mousedown events from each of the matched elements.
\r
1454 * @example $("p").unmousedown();
\r
1455 * @before <p onmousedown="alert('Hello');">Hello</p>
\r
1456 * @result <p>Hello</p>
\r
1458 * @name unmousedown
\r
1460 * @cat Events/Mouse
\r
1464 * Bind a function to the mouseover event of each matched element.
\r
1466 * @example $("p").mouseover( function() { alert("Hello"); } );
\r
1467 * @before <p>Hello</p>
\r
1468 * @result <p onmouseover="alert('Hello');">Hello</p>
\r
1472 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
\r
1473 * @cat Events/Mouse
\r
1477 * Trigger the mouseover event of each matched element. This causes all of the functions
\r
1478 * that have been bound to thet mousedown event to be executed.
\r
1480 * @example $("p").mouseover();
\r
1481 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1482 * @result alert('Hello');
\r
1486 * @cat Events/Mouse
\r
1490 * Bind a function to the mouseover event of each matched element, which will only be executed once.
\r
1491 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
\r
1492 * only executed the first time it is triggered, and never again (unless it is re-bound).
\r
1494 * @example $("p").onemouseover( function() { alert("Hello"); } );
\r
1495 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1496 * @result alert('Hello'); // Only executed for the first mouseover
\r
1498 * @name onemouseover
\r
1500 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
\r
1501 * @cat Events/Mouse
\r
1505 * Removes a bound mouseover event from each of the matched
\r
1506 * elements. You must pass the identical function that was used in the original
\r
1509 * @example $("p").unmouseover( myFunction );
\r
1510 * @before <p onmouseover="myFunction">Hello</p>
\r
1511 * @result <p>Hello</p>
\r
1513 * @name unmouseover
\r
1515 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
\r
1516 * @cat Events/Mouse
\r
1520 * Removes all bound mouseover events from each of the matched elements.
\r
1522 * @example $("p").unmouseover();
\r
1523 * @before <p onmouseover="alert('Hello');">Hello</p>
\r
1524 * @result <p>Hello</p>
\r
1526 * @name unmouseover
\r
1528 * @cat Events/Mouse
\r
1532 * @test var count;
\r
1534 * var e = ("blur,focus,resize,scroll,unload,click,dblclick," +
\r
1535 * "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
\r
1536 * "submit,keydown,keypress,keyup,error").split(",");
\r
1537 * var handler1 = function(event) {
\r
1540 * var handler2 = function(event) {
\r
1543 * for( var i=0; i < e.length; i++) {
\r
1544 * var event = e[i];
\r
1547 * $(document)[event](handler1);
\r
1548 * $(document)[event](handler2);
\r
1549 * $(document)["one"+event](handler1);
\r
1551 * // call event two times
\r
1552 * $(document)[event]();
\r
1553 * $(document)[event]();
\r
1555 * // unbind events
\r
1556 * $(document)["un"+event](handler1);
\r
1557 * // call once more
\r
1558 * $(document)[event]();
\r
1560 * // remove all handlers
\r
1561 * $(document)["un"+event]();
\r
1563 * // call once more
\r
1564 * $(document)[event]();
\r
1567 * ok( count == 6, 'Checking event ' + event);
\r
1571 * @name eventTesting
\r
1575 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
\r
1576 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
\r
1577 "submit,keydown,keypress,keyup,error").split(",");
\r
1579 // Go through all the event names, but make sure that
\r
1580 // it is enclosed properly
\r
1581 for ( var i = 0; i < e.length; i++ ) new function(){
\r
1585 // Handle event binding
\r
1586 jQuery.fn[o] = function(f){
\r
1587 return f ? this.bind(o, f) : this.trigger(o);
\r
1590 // Handle event unbinding
\r
1591 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
\r
1593 // Finally, handle events that only fire once
\r
1594 jQuery.fn["one"+o] = function(f){
\r
1595 // Attach the event listener
\r
1596 return this.each(function(){
\r
1601 jQuery.event.add( this, o, function(e){
\r
1602 // If this function has already been executed, stop
\r
1603 if ( count++ ) return;
\r
1605 // And execute the bound function
\r
1606 return f.apply(this, [e]);
\r
1613 // If Mozilla is used
\r
1614 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
\r
1615 // Use the handy event callback
\r
1616 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
\r
1618 // If IE is used, use the excellent hack by Matthias Miller
\r
1619 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
\r
1620 } else if ( jQuery.browser.msie ) {
\r
1622 // Only works if you document.write() it
\r
1623 document.write("<scr" + "ipt id=__ie_init defer=true " +
\r
1624 "src=//:><\/script>");
\r
1626 // Use the defer script hack
\r
1627 var script = document.getElementById("__ie_init");
\r
1628 script.onreadystatechange = function() {
\r
1629 if ( this.readyState != "complete" ) return;
\r
1630 this.parentNode.removeChild( this );
\r
1634 // Clear from memory
\r
1637 // If Safari is used
\r
1638 } else if ( jQuery.browser.safari ) {
\r
1639 // Continually check to see if the document.readyState is valid
\r
1640 jQuery.safariTimer = setInterval(function(){
\r
1641 // loaded and complete are both valid states
\r
1642 if ( document.readyState == "loaded" ||
\r
1643 document.readyState == "complete" ) {
\r
1645 // If either one are found, remove the timer
\r
1646 clearInterval( jQuery.safariTimer );
\r
1647 jQuery.safariTimer = null;
\r
1649 // and execute any waiting functions
\r
1655 // A fallback to window.onload, that will always work
\r
1656 jQuery.event.add( window, "load", jQuery.ready );
\r
1660 // Clean up after IE to avoid memory leaks
\r
1661 if (jQuery.browser.msie) jQuery(window).unload(function() {
\r
1662 var event = jQuery.event, global = event.global;
\r
1663 for (var type in global) {
\r
1664 var els = global[type], i = els.length;
\r
1665 if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i);
\r