X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent%2Fevent.js;h=852b3135233eb017011376ef2060d0376eeeae84;hb=65a88fae8919e5da774dcc45c9b42220f875b697;hp=921e524276caabc18a9523b9002cd2153dc98523;hpb=7cc550727c4e0bcd93c5d435f0799f568fc74dfa;p=jquery.git diff --git a/src/event/event.js b/src/event/event.js index 921e524..852b313 100644 --- a/src/event/event.js +++ b/src/event/event.js @@ -10,6 +10,8 @@ jQuery.fn.extend({ * is fired, when clicked again, the second is fired. All subsequent * clicks continue to rotate through the two functions. * + * Use unbind("click") to remove. + * * @example $("p").toggle(function(){ * $(this).addClass("selected"); * },function(){ @@ -22,18 +24,18 @@ jQuery.fn.extend({ * @param Function odd The function to execute on every odd click. * @cat Events */ - toggle: function(a,b) { - // If two functions are passed in, we're - // toggling on a click - return a && b && a.constructor == Function && b.constructor == Function ? this.click(function(e){ + toggle: function() { + // save reference to arguments for access in closure + var a = arguments; + return typeof a[0] == "function" && typeof a[1] == "function" ? this.click(function(e) { // Figure out which function to execute - this.last = this.last == a ? b : a; + this.lastToggle = this.lastToggle == 0 ? 1 : 0; // Make sure that clicks stop e.preventDefault(); // and execute the function - return this.last.apply( this, [e] ) || false; + return a[this.lastToggle].apply( this, [e] ) || false; }) : // Otherwise, execute the old toggle function @@ -101,6 +103,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... }); * @@ -228,9 +231,11 @@ new function(){ /** * Bind a function to the submit event of each matched element. * - * @example $("p").submit( function() { alert("Hello"); } ); - * @before

Hello

- * @result

Hello

+ * @example $("#myform").submit( function() { + * return $("input", this).val().length > 0; + * } ); + * @before
+ * @desc Prevents the form submission when the input has no value entered. * * @name submit * @type jQuery @@ -242,9 +247,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

Hello

- * @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 @@ -310,6 +317,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

Hello

* @result alert('Hello'); @@ -650,6 +660,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

Hello

* @result alert('Hello'); @@ -1522,7 +1535,7 @@ new function(){ */ 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 @@ -1548,7 +1561,7 @@ new function(){ 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); };