X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fevent%2Fevent.js;h=9b5d46ea3edc4f95f331169ba10e076011fe47a7;hb=c6e6e72561979ab80aaf5ce1ab63d3dd010382a3;hp=9b3788b4e695f23874462f49a9bd4e82e94697a1;hpb=c330527318775d32c87954f640c53066e7a732d9;p=jquery.git diff --git a/src/event/event.js b/src/event/event.js index 9b3788b..9b5d46e 100644 --- a/src/event/event.js +++ b/src/event/event.js @@ -187,32 +187,32 @@ jQuery.fn.extend({ * data as the second paramter (and the handler function as the third), see * second example. * - * @example $("p").bind( "click", function() { + * @example $("p").bind("click", function(){ * alert( $(this).text() ); - * } ) + * }); * @before

Hello

* @result alert("Hello") * - * @example var handler = function(event) { + * @example function handler(event) { * alert(event.data.foo); - * }; - * $("p").bind( "click", {foo: "bar"}, handler) + * } + * $("p").bind("click", {foo: "bar"}, handler) * @result alert("bar") * @desc Pass some additional data to the event handler. * - * @example $("form").bind( "submit", function() { return false; } ) + * @example $("form").bind("submit", function() { return false; }) * @desc Cancel a default action and prevent it from bubbling by returning false * from your function. * - * @example $("form").bind( "submit", function(event) { + * @example $("form").bind("submit", function(event){ * event.preventDefault(); - * } ); + * }); * @desc Cancel only the default action by using the preventDefault method. * * - * @example $("form").bind( "submit", function(event) { + * @example $("form").bind("submit", function(event){ * event.stopPropagation(); - * } ) + * }); * @desc Stop only an event from bubbling by using the stopPropagation method. * * @name bind @@ -241,9 +241,9 @@ jQuery.fn.extend({ * data as the second paramter (and the handler function as the third), see * second example. * - * @example $("p").one( "click", function() { + * @example $("p").one("click", function(){ * alert( $(this).text() ); - * } ) + * }); * @before

Hello

* @result alert("Hello") * @@ -316,10 +316,6 @@ jQuery.fn.extend({ }); }, - // We're overriding the old toggle function, so - // remember it for later - _toggle: jQuery.fn.toggle, - /** * Toggle between two function calls every other click. * Whenever a matched element is clicked, the first specified function @@ -341,9 +337,10 @@ jQuery.fn.extend({ * @cat Events */ toggle: function() { - // save reference to arguments for access in closure + // Save reference to arguments for access in closure var a = arguments; - return typeof a[0] == "function" && typeof a[1] == "function" ? this.click(function(e) { + + return this.click(function(e) { // Figure out which function to execute this.lastToggle = this.lastToggle == 0 ? 1 : 0; @@ -352,10 +349,7 @@ jQuery.fn.extend({ // and execute the function return a[this.lastToggle].apply( this, [e] ) || false; - }) : - - // Otherwise, execute the old toggle function - this._toggle.apply( this, arguments ); + }); }, /** @@ -414,6 +408,10 @@ jQuery.fn.extend({ * and attaching a function to that. By using this method, your bound Function * will be called the instant the DOM is ready to be read and manipulated, * which is exactly what 99.99% of all Javascript code needs to run. + * + * There is one argument passed to the ready event handler: A reference to + * the jQuery function. You can name that argument whatever you like, and + * can therefore stick with the $ alias without risc of naming collisions. * * Please ensure you have no code in your <body> onload event handler, * otherwise $(document).ready() may not fire. @@ -423,21 +421,30 @@ jQuery.fn.extend({ * * @example $(document).ready(function(){ Your code here... }); * + * @example jQuery(function($) { + * // Your code using failsafe $ alias here... + * }); + * @desc Uses both the shortcut for $(document).ready() and the argument + * to write failsafe jQuery code using the $ alias, without relying on the + * global alias. + * * @name ready * @type jQuery * @param Function fn The function to be executed when the DOM is ready. * @cat Events + * @see $.noConflict() + * @see $(Function) */ ready: function(f) { // If the DOM is already ready if ( jQuery.isReady ) // Execute the function immediately - f.apply( document ); + f.apply( document, [jQuery] ); // Otherwise, remember the function for later else { // Add the function to the wait list - jQuery.readyList.push( f ); + jQuery.readyList.push( function() { return f.apply(this, [jQuery]) } ); } return this; @@ -486,7 +493,7 @@ new function(){ * @name scroll * @type jQuery * @param Function fn A function to bind to the scroll event on each of the matched elements. - * @cat Events/Browser + * @cat Events */ /** @@ -501,7 +508,7 @@ new function(){ * @name submit * @type jQuery * @param Function fn A function to bind to the submit event on each of the matched elements. - * @cat Events/Form + * @cat Events */ /** @@ -516,7 +523,7 @@ new function(){ * * @name submit * @type jQuery - * @cat Events/Form + * @cat Events */ /** @@ -529,7 +536,7 @@ new function(){ * @name focus * @type jQuery * @param Function fn A function to bind to the focus event on each of the matched elements. - * @cat Events/UI + * @cat Events */ /** @@ -545,7 +552,7 @@ new function(){ * * @name focus * @type jQuery - * @cat Events/UI + * @cat Events */ /** @@ -558,7 +565,7 @@ new function(){ * @name keydown * @type jQuery * @param Function fn A function to bind to the keydown event on each of the matched elements. - * @cat Events/Keyboard + * @cat Events */ /** @@ -571,7 +578,7 @@ new function(){ * @name dblclick * @type jQuery * @param Function fn A function to bind to the dblclick event on each of the matched elements. - * @cat Events/Mouse + * @cat Events */ /** @@ -584,7 +591,7 @@ new function(){ * @name keypress * @type jQuery * @param Function fn A function to bind to the keypress event on each of the matched elements. - * @cat Events/Keyboard + * @cat Events */ /** @@ -597,7 +604,7 @@ new function(){ * @name error * @type jQuery * @param Function fn A function to bind to the error event on each of the matched elements. - * @cat Events/Browser + * @cat Events */ /** @@ -610,7 +617,7 @@ new function(){ * @name blur * @type jQuery * @param Function fn A function to bind to the blur event on each of the matched elements. - * @cat Events/UI + * @cat Events */ /** @@ -626,7 +633,7 @@ new function(){ * * @name blur * @type jQuery - * @cat Events/UI + * @cat Events */ /** @@ -639,7 +646,7 @@ new function(){ * @name load * @type jQuery * @param Function fn A function to bind to the load event on each of the matched elements. - * @cat Events/Browser + * @cat Events */ /** @@ -652,7 +659,7 @@ new function(){ * @name select * @type jQuery * @param Function fn A function to bind to the select event on each of the matched elements. - * @cat Events/Form + * @cat Events */ /** @@ -665,7 +672,7 @@ new function(){ * * @name select * @type jQuery - * @cat Events/Form + * @cat Events */ /** @@ -678,7 +685,7 @@ new function(){ * @name mouseup * @type jQuery * @param Function fn A function to bind to the mouseup event on each of the matched elements. - * @cat Events/Mouse + * @cat Events */ /** @@ -691,7 +698,7 @@ new function(){ * @name unload * @type jQuery * @param Function fn A function to bind to the unload event on each of the matched elements. - * @cat Events/Browser + * @cat Events */ /** @@ -704,7 +711,7 @@ new function(){ * @name change * @type jQuery * @param Function fn A function to bind to the change event on each of the matched elements. - * @cat Events/Form + * @cat Events */ /** @@ -717,7 +724,7 @@ new function(){ * @name mouseout * @type jQuery * @param Function fn A function to bind to the mouseout event on each of the matched elements. - * @cat Events/Mouse + * @cat Events */ /** @@ -730,7 +737,7 @@ new function(){ * @name keyup * @type jQuery * @param Function fn A function to bind to the keyup event on each of the matched elements. - * @cat Events/Keyboard + * @cat Events */ /** @@ -743,7 +750,7 @@ new function(){ * @name click * @type jQuery * @param Function fn A function to bind to the click event on each of the matched elements. - * @cat Events/Mouse + * @cat Events */ /** @@ -756,7 +763,7 @@ new function(){ * * @name click * @type jQuery - * @cat Events/Mouse + * @cat Events */ /** @@ -769,7 +776,7 @@ new function(){ * @name resize * @type jQuery * @param Function fn A function to bind to the resize event on each of the matched elements. - * @cat Events/Browser + * @cat Events */ /** @@ -782,7 +789,7 @@ new function(){ * @name mousemove * @type jQuery * @param Function fn A function to bind to the mousemove event on each of the matched elements. - * @cat Events/Mouse + * @cat Events */ /** @@ -795,7 +802,7 @@ new function(){ * @name mousedown * @type jQuery * @param Function fn A function to bind to the mousedown event on each of the matched elements. - * @cat Events/Mouse + * @cat Events */ /** @@ -808,7 +815,7 @@ new function(){ * @name mouseover * @type jQuery * @param Function fn A function to bind to the mousedown event on each of the matched elements. - * @cat Events/Mouse + * @cat Events */ jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + @@ -881,4 +888,4 @@ if (jQuery.browser.msie) jQuery.event.remove(els[i-1], type); while (--i); } - }); \ No newline at end of file + });