Commit 0798c6e6 authored by John Resig's avatar John Resig

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

Reorganized the different effects to be in fx.js, instead of jquery.js - and cleaned up some of the documentation.
parent 386c0bc8
...@@ -187,32 +187,32 @@ jQuery.fn.extend({ ...@@ -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({ ...@@ -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({ ...@@ -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({ ...@@ -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({ ...@@ -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) ...@@ -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);
} }
}); });
\ No newline at end of file
jQuery.fn.extend({ jQuery.fn.extend({
// overwrite the old show method /**
_show: jQuery.fn.show, * Displays each of the set of matched elements if they are hidden.
*
/** * @example $("p").show()
* Show all matched elements using a graceful animation and firing an * @before <p style="display: none">Hello</p>
* optional callback after completion. * @result [ <p style="display: block">Hello</p> ]
* *
* The height, width, and opacity of each of the matched elements * @name show
* are changed dynamically according to the specified speed. * @type jQuery
* * @cat Effects
* @example $("p").show("slow"); */
*
* @example $("p").show("slow",function(){ /**
* alert("Animation Done."); * Show all matched elements using a graceful animation and firing an
* }); * optional callback after completion.
* *
* @name show * The height, width, and opacity of each of the matched elements
* @type jQuery * are changed dynamically according to the specified speed.
* @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). *
* @param Function callback (optional) A function to be executed whenever the animation completes. * @example $("p").show("slow");
* @cat Effects *
* @see hide(String|Number,Function) * @example $("p").show("slow",function(){
*/ * alert("Animation Done.");
show: function(speed,callback){ * });
return speed ? this.animate({ *
height: "show", width: "show", opacity: "show" * @name show
}, speed, callback) : this._show(); * @type jQuery
}, * @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
// Overwrite the old hide method * @cat Effects
_hide: jQuery.fn.hide, * @see hide(String|Number,Function)
*/
/** show: function(speed,callback){
* Hide all matched elements using a graceful animation and firing an return speed ?
* optional callback after completion. this.animate({
* height: "show", width: "show", opacity: "show"
* The height, width, and opacity of each of the matched elements }, speed, callback) :
* are changed dynamically according to the specified speed.
* this.each(function(){
* @example $("p").hide("slow"); this.style.display = this.oldblock ? this.oldblock : "";
* if ( jQuery.css(this,"display") == "none" )
* @example $("p").hide("slow",function(){ this.style.display = "block";
* alert("Animation Done."); });
* }); },
*
* @name hide /**
* @type jQuery * Hides each of the set of matched elements if they are shown.
* @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). *
* @param Function callback (optional) A function to be executed whenever the animation completes. * @example $("p").hide()
* @cat Effects * @before <p>Hello</p>
* @see show(String|Number,Function) * @result [ <p style="display: none">Hello</p> ]
*/ *
hide: function(speed,callback){ * @name hide
return speed ? this.animate({ * @type jQuery
height: "hide", width: "hide", opacity: "hide" * @cat Effects
}, speed, callback) : this._hide(); */
},
/**
/** * Hide all matched elements using a graceful animation and firing an
* Reveal all matched elements by adjusting their height and firing an * optional callback after completion.
* optional callback after completion. *
* * The height, width, and opacity of each of the matched elements
* Only the height is adjusted for this animation, causing all matched * are changed dynamically according to the specified speed.
* elements to be revealed in a "sliding" manner. *
* * @example $("p").hide("slow");
* @example $("p").slideDown("slow"); *
* * @example $("p").hide("slow",function(){
* @example $("p").slideDown("slow",function(){ * alert("Animation Done.");
* alert("Animation Done."); * });
* }); *
* * @name hide
* @name slideDown * @type jQuery
* @type jQuery * @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). * @param Function callback (optional) A function to be executed whenever the animation completes.
* @param Function callback (optional) A function to be executed whenever the animation completes. * @cat Effects
* @cat Effects * @see show(String|Number,Function)
* @see slideUp(String|Number,Function) */
* @see slideToggle(String|Number,Function) hide: function(speed,callback){
*/ return speed ?
slideDown: function(speed,callback){ this.animate({
return this.animate({height: "show"}, speed, callback); height: "hide", width: "hide", opacity: "hide"
}, }, speed, callback) :
/** this.each(function(){
* Hide all matched elements by adjusting their height and firing an this.oldblock = this.oldblock || jQuery.css(this,"display");
* optional callback after completion. if ( this.oldblock == "none" )
* this.oldblock = "block";
* Only the height is adjusted for this animation, causing all matched this.style.display = "none";
* elements to be hidden in a "sliding" manner. });
* },
* @example $("p").slideUp("slow");
* // Save the old toggle function
* @example $("p").slideUp("slow",function(){ _toggle: jQuery.fn.toggle,
* alert("Animation Done.");
* }); /**
* * Toggles each of the set of matched elements. If they are shown,
* @name slideUp * toggle makes them hidden. If they are hidden, toggle
* @type jQuery * makes them shown.
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). *
* @param Function callback (optional) A function to be executed whenever the animation completes. * @example $("p").toggle()
* @cat Effects * @before <p>Hello</p><p style="display: none">Hello Again</p>
* @see slideDown(String|Number,Function) * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
* @see slideToggle(String|Number,Function) *
*/ * @name toggle
slideUp: function(speed,callback){ * @type jQuery
return this.animate({height: "hide"}, speed, callback); * @cat Effects
}, */
toggle: function( fn, fn2 ){
/** return fn ?
* Toggle the visibility of all matched elements by adjusting their height and firing an this._toggle( fn, fn2 ) :
* optional callback after completion. this.each(function(){
* jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]
* Only the height is adjusted for this animation, causing all matched .apply( jQuery(this), arguments );
* elements to be hidden in a "sliding" manner. });
* },
* @example $("p").slideToggle("slow");
* /**
* @example $("p").slideToggle("slow",function(){ * Reveal all matched elements by adjusting their height and firing an
* alert("Animation Done."); * optional callback after completion.
* }); *
* * Only the height is adjusted for this animation, causing all matched
* @name slideToggle * elements to be revealed in a "sliding" manner.
* @type jQuery *
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). * @example $("p").slideDown("slow");
* @param Function callback (optional) A function to be executed whenever the animation completes. *
* @cat Effects * @example $("p").slideDown("slow",function(){
* @see slideDown(String|Number,Function) * alert("Animation Done.");
* @see slideUp(String|Number,Function) * });
*/ *
slideToggle: function(speed, callback){ * @name slideDown
return this.each(function(){ * @type jQuery
var state = jQuery(this).is(":hidden") ? "show" : "hide"; * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
jQuery(this).animate({height: state}, speed, callback); * @param Function callback (optional) A function to be executed whenever the animation completes.
}); * @cat Effects
}, * @see slideUp(String|Number,Function)
* @see slideToggle(String|Number,Function)
/** */
* Fade in all matched elements by adjusting their opacity and firing an slideDown: function(speed,callback){
* optional callback after completion. return this.animate({height: "show"}, speed, callback);
* },
* Only the opacity is adjusted for this animation, meaning that
* all of the matched elements should already have some form of height /**
* and width associated with them. * Hide all matched elements by adjusting their height and firing an
* * optional callback after completion.
* @example $("p").fadeIn("slow"); *
* * Only the height is adjusted for this animation, causing all matched
* @example $("p").fadeIn("slow",function(){ * elements to be hidden in a "sliding" manner.
* alert("Animation Done."); *
* }); * @example $("p").slideUp("slow");
* *
* @name fadeIn * @example $("p").slideUp("slow",function(){
* @type jQuery * alert("Animation Done.");
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). * });
* @param Function callback (optional) A function to be executed whenever the animation completes. *
* @cat Effects * @name slideUp
* @see fadeOut(String|Number,Function) * @type jQuery
* @see fadeTo(String|Number,Number,Function) * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
*/ * @param Function callback (optional) A function to be executed whenever the animation completes.
fadeIn: function(speed, callback){ * @cat Effects
return this.animate({opacity: "show"}, speed, callback); * @see slideDown(String|Number,Function)
}, * @see slideToggle(String|Number,Function)
*/
/** slideUp: function(speed,callback){
* Fade out all matched elements by adjusting their opacity and firing an return this.animate({height: "hide"}, speed, callback);
* optional callback after completion. },
*
* Only the opacity is adjusted for this animation, meaning that /**
* all of the matched elements should already have some form of height * Toggle the visibility of all matched elements by adjusting their height and firing an
* and width associated with them. * optional callback after completion.
* *
* @example $("p").fadeOut("slow"); * Only the height is adjusted for this animation, causing all matched
* * elements to be hidden in a "sliding" manner.
* @example $("p").fadeOut("slow",function(){ *
* alert("Animation Done."); * @example $("p").slideToggle("slow");
* }); *
* * @example $("p").slideToggle("slow",function(){
* @name fadeOut * alert("Animation Done.");
* @type jQuery * });
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). *
* @param Function callback (optional) A function to be executed whenever the animation completes. * @name slideToggle
* @cat Effects * @type jQuery
* @see fadeIn(String|Number,Function) * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @see fadeTo(String|Number,Number,Function) * @param Function callback (optional) A function to be executed whenever the animation completes.
*/ * @cat Effects
fadeOut: function(speed, callback){ * @see slideDown(String|Number,Function)
return this.animate({opacity: "hide"}, speed, callback); * @see slideUp(String|Number,Function)
}, */
slideToggle: function(speed, callback){
/** return this.each(function(){
* Fade the opacity of all matched elements to a specified opacity and firing an var state = jQuery(this).is(":hidden") ? "show" : "hide";
* optional callback after completion. jQuery(this).animate({height: state}, speed, callback);
* });
* Only the opacity is adjusted for this animation, meaning that },
* all of the matched elements should already have some form of height
* and width associated with them. /**
* * Fade in all matched elements by adjusting their opacity and firing an
* @example $("p").fadeTo("slow", 0.5); * optional callback after completion.
* *
* @example $("p").fadeTo("slow", 0.5, function(){ * Only the opacity is adjusted for this animation, meaning that
* alert("Animation Done."); * all of the matched elements should already have some form of height
* }); * and width associated with them.
* *
* @name fadeTo * @example $("p").fadeIn("slow");
* @type jQuery *
* @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). * @example $("p").fadeIn("slow",function(){
* @param Number opacity The opacity to fade to (a number from 0 to 1). * alert("Animation Done.");
* @param Function callback (optional) A function to be executed whenever the animation completes. * });
* @cat Effects *
* @see fadeIn(String|Number,Function) * @name fadeIn
* @see fadeOut(String|Number,Function) * @type jQuery
*/ * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
fadeTo: function(speed,to,callback){ * @param Function callback (optional) A function to be executed whenever the animation completes.
return this.animate({opacity: to}, speed, callback); * @cat Effects
}, * @see fadeOut(String|Number,Function)
* @see fadeTo(String|Number,Number,Function)
/** */
* A function for making your own, custom, animations. The key aspect of fadeIn: function(speed, callback){
* this function is the object of style properties that will be animated, return this.animate({opacity: "show"}, speed, callback);
* and to what end. Each key within the object represents a style property },
* that will also be animated (for example: "height", "top", or "opacity").
* /**
* The value associated with the key represents to what end the property * Fade out all matched elements by adjusting their opacity and firing an
* will be animated. If a number is provided as the value, then the style * optional callback after completion.
* property will be transitioned from its current state to that new number. *
* Oterwise if the string "hide", "show", or "toggle" is provided, a default * Only the opacity is adjusted for this animation, meaning that
* animation will be constructed for that property. * all of the matched elements should already have some form of height
* * and width associated with them.
* @example $("p").animate({ *
* height: 'toggle', opacity: 'toggle' * @example $("p").fadeOut("slow");
* }, "slow"); *
* * @example $("p").fadeOut("slow",function(){
* @example $("p").animate({ * alert("Animation Done.");
* left: 50, opacity: 'show' * });
*
* @name fadeOut
* @type jQuery
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see fadeIn(String|Number,Function)
* @see fadeTo(String|Number,Number,Function)
*/
fadeOut: function(speed, callback){
return this.animate({opacity: "hide"}, speed, callback);
},
/**
* Fade the opacity of all matched elements to a specified opacity and firing an
* optional callback after completion.
*
* Only the opacity is adjusted for this animation, meaning that
* all of the matched elements should already have some form of height
* and width associated with them.
*
* @example $("p").fadeTo("slow", 0.5);
*
* @example $("p").fadeTo("slow", 0.5, function(){
* alert("Animation Done.");
* });
*
* @name fadeTo
* @type jQuery
* @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Number opacity The opacity to fade to (a number from 0 to 1).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see fadeIn(String|Number,Function)
* @see fadeOut(String|Number,Function)
*/
fadeTo: function(speed,to,callback){
return this.animate({opacity: to}, speed, callback);
},
/**
* A function for making your own, custom, animations. The key aspect of
* this function is the object of style properties that will be animated,
* and to what end. Each key within the object represents a style property
* that will also be animated (for example: "height", "top", or "opacity").
*
* The value associated with the key represents to what end the property
* will be animated. If a number is provided as the value, then the style
* property will be transitioned from its current state to that new number.
* Oterwise if the string "hide", "show", or "toggle" is provided, a default
* animation will be constructed for that property.
*
* @example $("p").animate({
* height: 'toggle', opacity: 'toggle'
* }, "slow");
*
* @example $("p").animate({
* left: 50, opacity: 'show'
* }, 500); * }, 500);
* *
* @example $("p").animate({ * @example $("p").animate({
* opacity: 'show' * opacity: 'show'
* }, "slow", "easein"); * }, "slow", "easein");
* @desc An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function (Only 'linear' is provided by default, with jQuery). * @desc An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function (Only 'linear' is provided by default, with jQuery).
* *
* @name animate * @name animate
* @type jQuery * @type jQuery
* @param Hash params A set of style attributes that you wish to animate, and to what end. * @param Hash params A set of style attributes that you wish to animate, and to what end.
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000). * @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param String easing (optional) The name of the easing effect that you want to use (Plugin Required). * @param String easing (optional) The name of the easing effect that you want to use (Plugin Required).
* @param Function callback (optional) A function to be executed whenever the animation completes. * @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects * @cat Effects
*/ */
animate: function( prop, speed, easing, callback ) { animate: function( prop, speed, easing, callback ) {
return this.queue(function(){ return this.queue(function(){
this.curAnim = jQuery.extend({}, prop); this.curAnim = jQuery.extend({}, prop);
var opt = jQuery.speed(speed, easing, callback); var opt = jQuery.speed(speed, easing, callback);
for ( var p in prop ) { for ( var p in prop ) {
var e = new jQuery.fx( this, opt, p ); var e = new jQuery.fx( this, opt, p );
if ( prop[p].constructor == Number ) if ( prop[p].constructor == Number )
e.custom( e.cur(), prop[p] ); e.custom( e.cur(), prop[p] );
else else
e[ prop[p] ]( prop ); e[ prop[p] ]( prop );
} }
}); });
}, },
/** /**
* *
* @private * @private
*/ */
queue: function(type,fn){ queue: function(type,fn){
if ( !fn ) { if ( !fn ) {
fn = type; fn = type;
type = "fx"; type = "fx";
} }
return this.each(function(){ return this.each(function(){
if ( !this.queue ) if ( !this.queue )
this.queue = {}; this.queue = {};
if ( !this.queue[type] ) if ( !this.queue[type] )
this.queue[type] = []; this.queue[type] = [];
this.queue[type].push( fn ); this.queue[type].push( fn );
if ( this.queue[type].length == 1 ) if ( this.queue[type].length == 1 )
fn.apply(this); fn.apply(this);
}); });
} }
}); });
jQuery.extend({ jQuery.extend({
speed: function(speed, easing, fn) { speed: function(speed, easing, fn) {
var opt = speed.constructor == Object ? speed : { var opt = speed.constructor == Object ? speed : {
complete: fn || !fn && easing || complete: fn || !fn && easing ||
speed.constructor == Function && speed, speed.constructor == Function && speed,
duration: speed, duration: speed,
easing: fn && easing || easing && easing.constructor != Function && easing easing: fn && easing || easing && easing.constructor != Function && easing
}; };
opt.duration = (opt.duration.constructor == Number ? opt.duration = (opt.duration.constructor == Number ?
opt.duration : opt.duration :
{ slow: 600, fast: 200 }[opt.duration]) || 400; { slow: 600, fast: 200 }[opt.duration]) || 400;
// Queueing // Queueing
opt.oldComplete = opt.complete; opt.oldComplete = opt.complete;
opt.complete = function(){ opt.complete = function(){
jQuery.dequeue(this, "fx"); jQuery.dequeue(this, "fx");
if ( opt.oldComplete && opt.oldComplete.constructor == Function ) if ( opt.oldComplete && opt.oldComplete.constructor == Function )
opt.oldComplete.apply( this ); opt.oldComplete.apply( this );
}; };
return opt; return opt;
},
easing: {},
queue: {},
dequeue: function(elem,type){
type = type || "fx";
if ( elem.queue && elem.queue[type] ) {
// Remove self
elem.queue[type].shift();
// Get next function
var f = elem.queue[type][0];
if ( f ) f.apply( elem );
}
}, },
/*
* I originally wrote fx() as a clone of moo.fx and in the process
* of making it small in size the code became illegible to sane
* people. You've been warned.
*/
easing: {}, fx: function( elem, options, prop ){
queue: {}, var z = this;
dequeue: function(elem,type){ // The styles
type = type || "fx"; var y = elem.style;
if ( elem.queue && elem.queue[type] ) { // Store display property
// Remove self var oldDisplay = jQuery.css(elem, 'display');
elem.queue[type].shift(); // Set display property to block for animation
y.display = "block";
// Get next function // Make sure that nothing sneaks out
var f = elem.queue[type][0]; y.overflow = "hidden";
if ( f ) f.apply( elem ); // Simple function for setting a style value
} z.a = function(){
}, if ( options.step )
options.step.apply( elem, [ z.now ] );
/*
* I originally wrote fx() as a clone of moo.fx and in the process if ( prop == "opacity" )
* of making it small in size the code became illegible to sane jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
* people. You've been warned. else if ( parseInt(z.now) ) // My hate for IE will never die
*/ y[prop] = parseInt(z.now) + "px";
};
fx: function( elem, options, prop ){
// Figure out the maximum number to run to
var z = this; z.max = function(){
return parseFloat( jQuery.css(elem,prop) );
// The styles };
var y = elem.style;
// Get the current size
// Store display property z.cur = function(){
var oldDisplay = jQuery.css(elem, 'display'); var r = parseFloat( jQuery.curCSS(elem, prop) );
// Set display property to block for animation return r && r > -10000 ? r : z.max();
y.display = "block"; };
// Make sure that nothing sneaks out
y.overflow = "hidden"; // Start an animation from one number to another
z.custom = function(from,to){
// Simple function for setting a style value z.startTime = (new Date()).getTime();
z.a = function(){ z.now = from;
if ( options.step ) z.a();
options.step.apply( elem, [ z.now ] );
z.timer = setInterval(function(){
if ( prop == "opacity" ) z.step(from, to);
jQuery.attr(y, "opacity", z.now); // Let attr handle opacity }, 13);
else if ( parseInt(z.now) ) // My hate for IE will never die };
y[prop] = parseInt(z.now) + "px";
}; // Simple 'show' function
z.show = function(){
// Figure out the maximum number to run to if ( !elem.orig ) elem.orig = {};
z.max = function(){
return parseFloat( jQuery.css(elem,prop) ); // Remember where we started, so that we can go back to it later
}; elem.orig[prop] = this.cur();
// Get the current size options.show = true;
z.cur = function(){
var r = parseFloat( jQuery.curCSS(elem, prop) ); // Begin the animation
return r && r > -10000 ? r : z.max(); z.custom(0, elem.orig[prop]);
};
// Stupid IE, look what you made me do
// Start an animation from one number to another if ( prop != "opacity" )
z.custom = function(from,to){ y[prop] = "1px";
z.startTime = (new Date()).getTime(); };
z.now = from;
z.a(); // Simple 'hide' function
z.hide = function(){
z.timer = setInterval(function(){ if ( !elem.orig ) elem.orig = {};
z.step(from, to);
}, 13); // Remember where we started, so that we can go back to it later
}; elem.orig[prop] = this.cur();
// Simple 'show' function options.hide = true;
z.show = function(){
if ( !elem.orig ) elem.orig = {}; // Begin the animation
z.custom(elem.orig[prop], 0);
// Remember where we started, so that we can go back to it later };
elem.orig[prop] = this.cur();
//Simple 'toggle' function
options.show = true; z.toggle = function() {
if ( !elem.orig ) elem.orig = {};
// Begin the animation
z.custom(0, elem.orig[prop]); // Remember where we started, so that we can go back to it later
elem.orig[prop] = this.cur();
// Stupid IE, look what you made me do
if ( prop != "opacity" ) if(oldDisplay == 'none') {
y[prop] = "1px"; options.show = true;
};
// Stupid IE, look what you made me do
// Simple 'hide' function if ( prop != "opacity" )
z.hide = function(){ y[prop] = "1px";
if ( !elem.orig ) elem.orig = {};
// Begin the animation
// Remember where we started, so that we can go back to it later z.custom(0, elem.orig[prop]);
elem.orig[prop] = this.cur(); } else {
options.hide = true;
options.hide = true;
// Begin the animation
// Begin the animation z.custom(elem.orig[prop], 0);
z.custom(elem.orig[prop], 0); }
}; };
//Simple 'toggle' function // Each step of an animation
z.toggle = function() { z.step = function(firstNum, lastNum){
if ( !elem.orig ) elem.orig = {}; var t = (new Date()).getTime();
// Remember where we started, so that we can go back to it later if (t > options.duration + z.startTime) {
elem.orig[prop] = this.cur(); // Stop the timer
clearInterval(z.timer);
if(oldDisplay == 'none') { z.timer = null;
options.show = true;
z.now = lastNum;
// Stupid IE, look what you made me do z.a();
if ( prop != "opacity" )
y[prop] = "1px"; if (elem.curAnim) elem.curAnim[ prop ] = true;
// Begin the animation var done = true;
z.custom(0, elem.orig[prop]); for ( var i in elem.curAnim )
} else { if ( elem.curAnim[i] !== true )
options.hide = true; done = false;
// Begin the animation if ( done ) {
z.custom(elem.orig[prop], 0); // Reset the overflow
} y.overflow = '';
};
// Reset the display
// Each step of an animation y.display = oldDisplay;
z.step = function(firstNum, lastNum){ if (jQuery.css(elem, 'display') == 'none')
var t = (new Date()).getTime(); y.display = 'block';
if (t > options.duration + z.startTime) { // Hide the element if the "hide" operation was done
// Stop the timer if ( options.hide )
clearInterval(z.timer); y.display = 'none';
z.timer = null;
// Reset the properties, if the item has been hidden or shown
z.now = lastNum; if ( options.hide || options.show )
z.a(); for ( var p in elem.curAnim )
if (p == "opacity")
if (elem.curAnim) elem.curAnim[ prop ] = true; jQuery.attr(y, p, elem.orig[p]);
else
var done = true; y[p] = '';
for ( var i in elem.curAnim ) }
if ( elem.curAnim[i] !== true )
done = false; // If a callback was provided, execute it
if ( done && options.complete && options.complete.constructor == Function )
if ( done ) { // Execute the complete function
// Reset the overflow options.complete.apply( elem );
y.overflow = ''; } else {
var n = t - this.startTime;
// Reset the display // Figure out where in the animation we are and set the number
y.display = oldDisplay;
if (jQuery.css(elem, 'display') == 'none')
y.display = 'block';
// Hide the element if the "hide" operation was done
if ( options.hide )
y.display = 'none';
// Reset the properties, if the item has been hidden or shown
if ( options.hide || options.show )
for ( var p in elem.curAnim )
if (p == "opacity")
jQuery.attr(y, p, elem.orig[p]);
else
y[p] = '';
}
// If a callback was provided, execute it
if ( done && options.complete && options.complete.constructor == Function )
// Execute the complete function
options.complete.apply( elem );
} else {
var n = t - this.startTime;
// Figure out where in the animation we are and set the number
var p = n / options.duration; var p = n / options.duration;
// If the easing function exists, then use it // If the easing function exists, then use it
z.now = options.easing && jQuery.easing[options.easing] ? z.now = options.easing && jQuery.easing[options.easing] ?
jQuery.easing[options.easing](p, n, firstNum, (lastNum-firstNum), options.duration) : jQuery.easing[options.easing](p, n, firstNum, (lastNum-firstNum), options.duration) :
// else use default linear easing // else use default linear easing
((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum; ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
// Perform the next step of the animation // Perform the next step of the animation
z.a(); z.a();
} }
}; };
} }
}); });
\ No newline at end of file
...@@ -742,7 +742,7 @@ jQuery.fn = jQuery.prototype = { ...@@ -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){ ...@@ -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 );
}; };
}); });
\ No newline at end of file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment