Reorganized the different effects to be in fx.js, instead of jquery.js - and cleaned up some of the documentation.

This commit is contained in:
John Resig 2007-01-07 21:43:38 +00:00
parent 386c0bc8a6
commit 0798c6e64e
3 changed files with 564 additions and 512 deletions

View file

@ -187,32 +187,32 @@ jQuery.fn.extend({
* data as the second paramter (and the handler function as the third), see * data as the second paramter (and the handler function as the third), see
* second example. * second example.
* *
* @example $("p").bind( "click", function() { * @example $("p").bind("click", function(){
* alert( $(this).text() ); * alert( $(this).text() );
* } ) * });
* @before <p>Hello</p> * @before <p>Hello</p>
* @result alert("Hello") * @result alert("Hello")
* *
* @example var handler = function(event) { * @example function handler(event) {
* alert(event.data.foo); * alert(event.data.foo);
* }; * }
* $("p").bind( "click", {foo: "bar"}, handler) * $("p").bind("click", {foo: "bar"}, handler)
* @result alert("bar") * @result alert("bar")
* @desc Pass some additional data to the event handler. * @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 * @desc Cancel a default action and prevent it from bubbling by returning false
* from your function. * from your function.
* *
* @example $("form").bind( "submit", function(event) { * @example $("form").bind("submit", function(event){
* event.preventDefault(); * event.preventDefault();
* } ); * });
* @desc Cancel only the default action by using the preventDefault method. * @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(); * event.stopPropagation();
* } ) * });
* @desc Stop only an event from bubbling by using the stopPropagation method. * @desc Stop only an event from bubbling by using the stopPropagation method.
* *
* @name bind * @name bind
@ -241,9 +241,9 @@ jQuery.fn.extend({
* data as the second paramter (and the handler function as the third), see * data as the second paramter (and the handler function as the third), see
* second example. * second example.
* *
* @example $("p").one( "click", function() { * @example $("p").one("click", function(){
* alert( $(this).text() ); * alert( $(this).text() );
* } ) * });
* @before <p>Hello</p> * @before <p>Hello</p>
* @result alert("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. * Toggle between two function calls every other click.
* Whenever a matched element is clicked, the first specified function * Whenever a matched element is clicked, the first specified function
@ -341,9 +337,10 @@ jQuery.fn.extend({
* @cat Events * @cat Events
*/ */
toggle: function() { toggle: function() {
// save reference to arguments for access in closure // Save reference to arguments for access in closure
var a = arguments; 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 // Figure out which function to execute
this.lastToggle = this.lastToggle == 0 ? 1 : 0; this.lastToggle = this.lastToggle == 0 ? 1 : 0;
@ -352,10 +349,7 @@ jQuery.fn.extend({
// and execute the function // and execute the function
return a[this.lastToggle].apply( this, [e] ) || false; return a[this.lastToggle].apply( this, [e] ) || false;
}) : });
// Otherwise, execute the old toggle function
this._toggle.apply( this, arguments );
}, },
/** /**
@ -881,4 +875,4 @@ if (jQuery.browser.msie)
jQuery.event.remove(els[i-1], type); jQuery.event.remove(els[i-1], type);
while (--i); while (--i);
} }
}); });

File diff suppressed because it is too large Load diff

View file

@ -742,7 +742,7 @@ jQuery.fn = jQuery.prototype = {
* @example $("p").find("span").end(); * @example $("p").find("span").end();
* @before <p><span>Hello</span>, how are you?</p> * @before <p><span>Hello</span>, how are you?</p>
* @result [ <p>...</p> ] * @result [ <p>...</p> ]
* desc Selects all paragraphs, finds span elements inside these, and reverts the * @desc Selects all paragraphs, finds span elements inside these, and reverts the
* selection back to the paragraphs. * selection back to the paragraphs.
* *
* @name end * @name end
@ -2112,4 +2112,4 @@ jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
jQuery.fn[ n ] = function(num,fn) { jQuery.fn[ n ] = function(num,fn) {
return this.filter( ":" + n + "(" + num + ")", fn ); return this.filter( ":" + n + "(" + num + ")", fn );
}; };
}); });