Fixed a bunch of endline issues.
[jquery.git] / src / event / event.js
index bbf52a9..86a93d4 100644 (file)
@@ -15,6 +15,13 @@ jQuery.fn.extend({
         * },function(){
         *   $(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
@@ -64,7 +71,7 @@ jQuery.fn.extend({
         * @param Function over The function to fire whenever the mouse is moved over a matched element.
         * @param Function out The function to fire whenever the mouse is moved off of a matched element.
         * @cat Events
-        */\r
+        */
        hover: function(f,g) {
                
                // A private function for haandling mouse 'hovering'
@@ -73,7 +80,7 @@ jQuery.fn.extend({
                        var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
        
                        // Traverse up the tree
-                       while ( p && p != this ) p = p.parentNode;
+                       while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
                        
                        // If we actually just moused on to a sub-element, ignore it
                        if ( p == this ) return false;
@@ -100,6 +107,8 @@ jQuery.fn.extend({
         * Please ensure you have no code in your <body> onload event handler, 
         * otherwise $(document).ready() may not fire.
         *
+        * You can have as many $(document).ready events on your page as you like.
+        *
         * @example $(document).ready(function(){ Your code here... });
         *
         * @name ready
@@ -146,6 +155,9 @@ jQuery.extend({
                                // Reset the list of functions
                                jQuery.readyList = null;
                        }
+                       // Remove event lisenter to avoid memory leak
+                       if ( jQuery.browser.mozilla || jQuery.browser.opera )
+                               document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
                }
        }
 });
@@ -713,11 +725,15 @@ new function(){
                 * Trigger the load event of each matched element. This causes all of the functions
                 * that have been bound to thet load event to be executed.
                 *
+                * Marked as private: Calling load() without arguments throws exception because the ajax load
+                * does not handle it.
+                *
                 * @example $("p").load();
                 * @before <p onload="alert('Hello');">Hello</p>
                 * @result alert('Hello');
                 *
                 * @name load
+                * @private
                 * @type jQuery
                 * @cat Events/Browser
                 */
@@ -1443,6 +1459,118 @@ new function(){
                 * @type jQuery
                 * @cat Events/Mouse
                 */
+                
+               /**
+                * Bind a function to the mouseover event of each matched element.
+                *
+                * @example $("p").mouseover( function() { alert("Hello"); } );
+                * @before <p>Hello</p>
+                * @result <p onmouseover="alert('Hello');">Hello</p>
+                *
+                * @name mouseover
+                * @type jQuery
+                * @param Function fn A function to bind to the mousedown event on each of the matched elements.
+                * @cat Events/Mouse
+                */
+
+               /**
+                * Trigger the mouseover event of each matched element. This causes all of the functions
+                * that have been bound to thet mousedown event to be executed.
+                *
+                * @example $("p").mouseover();
+                * @before <p onmouseover="alert('Hello');">Hello</p>
+                * @result alert('Hello');
+                *
+                * @name mouseover
+                * @type jQuery
+                * @cat Events/Mouse
+                */
+
+               /**
+                * Bind a function to the mouseover event of each matched element, which will only be executed once.
+                * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
+                * only executed the first time it is triggered, and never again (unless it is re-bound).
+                *
+                * @example $("p").onemouseover( function() { alert("Hello"); } );
+                * @before <p onmouseover="alert('Hello');">Hello</p>
+                * @result alert('Hello'); // Only executed for the first mouseover
+                *
+                * @name onemouseover
+                * @type jQuery
+                * @param Function fn A function to bind to the mouseover event on each of the matched elements.
+                * @cat Events/Mouse
+                */
+
+               /**
+                * Removes a bound mouseover event from each of the matched
+                * elements. You must pass the identical function that was used in the original 
+                * bind method.
+                *
+                * @example $("p").unmouseover( myFunction );
+                * @before <p onmouseover="myFunction">Hello</p>
+                * @result <p>Hello</p>
+                *
+                * @name unmouseover
+                * @type jQuery
+                * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
+                * @cat Events/Mouse
+                */
+
+               /**
+                * Removes all bound mouseover events from each of the matched elements.
+                *
+                * @example $("p").unmouseover();
+                * @before <p onmouseover="alert('Hello');">Hello</p>
+                * @result <p>Hello</p>
+                *
+                * @name unmouseover
+                * @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," + 
@@ -1528,3 +1656,12 @@ new function(){
        jQuery.event.add( window, "load", jQuery.ready );
        
 };
+
+// Clean up after IE to avoid memory leaks
+if (jQuery.browser.msie) jQuery(window).unload(function() {
+       var event = jQuery.event, global = event.global;
+       for (var type in global) {
+               var els = global[type], i = els.length;
+               if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i);
+       }
+});