Improved docs for blur() and focus(), mentioning the difference between calling the...
[jquery.git] / src / event / event.js
index 7a61773..fd4385c 100644 (file)
@@ -16,13 +16,6 @@ jQuery.fn.extend({
         *   $(this).removeClass("selected");
         * });
         * 
-        * @test var count = 0;
-        * var fn1 = function() { count++; }
-        * var fn2 = function() { count--; }
-        * var link = $('#mark');
-        * link.click().toggle(fn1, fn2).click().click().click().click().click();
-        * ok( count == 1, "Check for toggle(fn, fn)" );
-        *
         * @name toggle
         * @type jQuery
         * @param Function even The function to execute on every even click.
@@ -108,6 +101,7 @@ jQuery.fn.extend({
         * otherwise $(document).ready() may not fire.
         *
         * You can have as many $(document).ready events on your page as you like.
+        * The functions are then executed in the order they were added.
         *
         * @example $(document).ready(function(){ Your code here... });
         *
@@ -235,9 +229,11 @@ new function(){
                /**
                 * Bind a function to the submit event of each matched element.
                 *
-                * @example $("p").submit( function() { alert("Hello"); } );
-                * @before <p>Hello</p>
-                * @result <p onsubmit="alert('Hello');">Hello</p>
+                * @example $("#myform").submit( function() {
+                *   return $("input", this).val().length > 0;
+                * } );
+                * @before <form id="myform"><input /></form>
+                * @desc Prevents the form submission when the input has no value entered.
                 *
                 * @name submit
                 * @type jQuery
@@ -249,9 +245,11 @@ new function(){
                 * Trigger the submit event of each matched element. This causes all of the functions
                 * that have been bound to thet submit event to be executed.
                 *
-                * @example $("p").submit();
-                * @before <p onsubmit="alert('Hello');">Hello</p>
-                * @result alert('Hello');
+                * Note: This does not execute the submit method of the form element! If you need to
+                * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
+                *
+                * @example $("form").submit();
+                * @desc Triggers all submit events registered for forms, but does not submit the form
                 *
                 * @name submit
                 * @type jQuery
@@ -317,6 +315,9 @@ new function(){
                 * Trigger the focus event of each matched element. This causes all of the functions
                 * that have been bound to thet focus event to be executed.
                 *
+                * Note: This does not execute the focus method of the underlying elements! If you need to
+                * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
+                *
                 * @example $("p").focus();
                 * @before <p onfocus="alert('Hello');">Hello</p>
                 * @result alert('Hello');
@@ -657,6 +658,9 @@ new function(){
                 * Trigger the blur event of each matched element. This causes all of the functions
                 * that have been bound to thet blur event to be executed.
                 *
+                * Note: This does not execute the blur method of the underlying elements! If you need to
+                * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
+                *
                 * @example $("p").blur();
                 * @before <p onblur="alert('Hello');">Hello</p>
                 * @result alert('Hello');
@@ -1527,53 +1531,9 @@ new function(){
                 * @type jQuery
                 * @cat Events/Mouse
                 */
-                
-                /**
-                 * @test var count;
-                 * // ignore load
-                 * var e = ("blur,focus,resize,scroll,unload,click,dblclick," +
-                 *             "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," + 
-                 *             "submit,keydown,keypress,keyup,error").split(",");
-                 * var handler1 = function(event) {
-                 *     count++;
-                 * };
-                 * var handler2 = function(event) {
-                 *     count++;
-                 * };
-                 * for( var i=0; i < e.length; i++) {
-                 *     var event = e[i];
-                 *     count = 0;
-                 *     // bind handler
-                 *     $(document)[event](handler1);
-                 *             $(document)[event](handler2);
-                 *     $(document)["one"+event](handler1);
-                 *     
-                 *     // call event two times
-                 *     $(document)[event]();
-                 *     $(document)[event]();
-                 *     
-                 *     // unbind events
-                 *     $(document)["un"+event](handler1);
-                 *     // call once more
-                 *     $(document)[event]();
-                 *
-                 *     // remove all handlers
-                 *             $(document)["un"+event]();
-                 *
-                 *     // call once more
-                 *     $(document)[event]();
-                 *     
-                 *     // assert count
-                 *     ok( count == 6, 'Checking event ' + event);
-                 * }
-                 *
-                 * @private
-                 * @name eventTesting
-                 * @cat Events
-                 */
 
        var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
-               "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," + 
+               "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + 
                "submit,keydown,keypress,keyup,error").split(",");
 
        // Go through all the event names, but make sure that
@@ -1597,8 +1557,9 @@ new function(){
                        var handler = function() {
                                // unbind itself when executed
                                element.unbind(o, handler);
+                               element = null;
                                // apply original handler with the same arguments
-                               f.apply(this, arguments);
+                               return f.apply(this, arguments);
                        };
                        return this.bind(o, handler);
                };
@@ -1620,11 +1581,12 @@ new function(){
        
                // Use the defer script hack
                var script = document.getElementById("__ie_init");
-               script.onreadystatechange = function() {
-                       if ( this.readyState != "complete" ) return;
-                       this.parentNode.removeChild( this );
-                       jQuery.ready();
-               };
+               if (script) // script does not exist if jQuery is loaded dynamically
+                       script.onreadystatechange = function() {
+                               if ( this.readyState != "complete" ) return;
+                               this.parentNode.removeChild( this );
+                               jQuery.ready();
+                       };
        
                // Clear from memory
                script = null;