4 show: function(speed,callback){
7 height: "show", width: "show", opacity: "show"
10 for ( var i = 0, l = this.length; i < l; i++ ){
11 var old = jQuery.data(this[i], "olddisplay");
13 this[i].style.display = old || "";
15 if ( jQuery.css(this[i], "display") === "none" ) {
16 var tagName = this[i].tagName, display;
18 if ( elemdisplay[ tagName ] ) {
19 display = elemdisplay[ tagName ];
21 var elem = jQuery("<" + this[i].tagName + " />").appendTo("body");
23 display = elem.css("display");
24 if ( display === "none" )
29 elemdisplay[ this[i].tagName ] = display;
32 this[i].style.display = jQuery.data(this[i], "olddisplay", display);
40 hide: function(speed,callback){
43 height: "hide", width: "hide", opacity: "hide"
46 for ( var i = 0, l = this.length; i < l; i++ ){
47 var old = jQuery.data(this[i], "olddisplay");
48 if ( !old && old !== "none" )
49 jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
50 this[i].style.display = "none";
56 // Save the old toggle function
57 _toggle: jQuery.fn.toggle,
59 toggle: function( fn, fn2 ){
60 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
61 this._toggle.apply( this, arguments ) :
64 height: "toggle", width: "toggle", opacity: "toggle"
67 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
71 fadeTo: function(speed,to,callback){
72 return this.animate({opacity: to}, speed, callback);
75 animate: function( prop, speed, easing, callback ) {
76 var optall = jQuery.speed(speed, easing, callback);
78 return this[ optall.queue === false ? "each" : "queue" ](function(){
80 var opt = jQuery.extend({}, optall), p,
81 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
85 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
86 return opt.complete.call(this);
88 if ( ( p == "height" || p == "width" ) && this.style ) {
89 // Store display property
90 opt.display = jQuery.css(this, "display");
92 // Make sure that nothing sneaks out
93 opt.overflow = this.style.overflow;
97 if ( opt.overflow != null )
98 this.style.overflow = "hidden";
100 opt.curAnim = jQuery.extend({}, prop);
102 jQuery.each( prop, function(name, val){
103 var e = new jQuery.fx( self, opt, name );
105 if ( /toggle|show|hide/.test(val) )
106 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
108 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
109 start = e.cur(true) || 0;
112 var end = parseFloat(parts[2]),
113 unit = parts[3] || "px";
115 // We need to compute starting value
116 if ( unit != "px" ) {
117 self.style[ name ] = (end || 1) + unit;
118 start = ((end || 1) / e.cur(true)) * start;
119 self.style[ name ] = start + unit;
122 // If a +=/-= token was provided, we're doing a relative animation
124 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
126 e.custom( start, end, unit );
128 e.custom( start, val, "" );
132 // For JS strict compliance
137 queue: function(type, fn){
138 if ( jQuery.isFunction(type) || jQuery.isArray(type) ) {
143 if ( !type || (typeof type === "string" && !fn) )
144 return queue( this[0], type );
146 return this.each(function(){
147 if ( jQuery.isArray(fn) )
148 queue(this, type, fn);
150 queue(this, type).push( fn );
152 if ( queue(this, type).length == 1 )
158 stop: function(clearQueue, gotoEnd){
159 var timers = jQuery.timers;
164 this.each(function(){
165 // go in reverse order so anything added to the queue during the loop is ignored
166 for ( var i = timers.length - 1; i >= 0; i-- )
167 if ( timers[i].elem == this ) {
169 // force the next step to be the last
175 // start the next in the queue if the last step wasn't forced
184 // Generate shortcuts for custom animations
186 slideDown: { height:"show" },
187 slideUp: { height: "hide" },
188 slideToggle: { height: "toggle" },
189 fadeIn: { opacity: "show" },
190 fadeOut: { opacity: "hide" }
191 }, function( name, props ){
192 jQuery.fn[ name ] = function( speed, callback ){
193 return this.animate( props, speed, callback );
197 var queue = function( elem, type, array ) {
202 var q = jQuery.data( elem, type + "queue" );
205 q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) );
211 jQuery.fn.dequeue = function(type){
214 return this.each(function(){
215 var q = queue(this, type);
226 speed: function(speed, easing, fn) {
227 var opt = typeof speed === "object" ? speed : {
228 complete: fn || !fn && easing ||
229 jQuery.isFunction( speed ) && speed,
231 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
234 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
235 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
238 opt.old = opt.complete;
239 opt.complete = function(){
240 if ( opt.queue !== false )
241 jQuery(this).dequeue();
242 if ( jQuery.isFunction( opt.old ) )
243 opt.old.call( this );
250 linear: function( p, n, firstNum, diff ) {
251 return firstNum + diff * p;
253 swing: function( p, n, firstNum, diff ) {
254 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
261 fx: function( elem, options, prop ){
262 this.options = options;
272 jQuery.fx.prototype = {
274 // Simple function for setting a style value
276 if ( this.options.step )
277 this.options.step.call( this.elem, this.now, this );
279 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
281 // Set display property to block for height/width animations
282 if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style )
283 this.elem.style.display = "block";
286 // Get the current size
287 cur: function(force){
288 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) )
289 return this.elem[ this.prop ];
291 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
292 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
295 // Start an animation from one number to another
296 custom: function(from, to, unit){
297 this.startTime = now();
300 this.unit = unit || this.unit || "px";
301 this.now = this.start;
302 this.pos = this.state = 0;
306 return self.step(gotoEnd);
311 jQuery.timers.push(t);
313 if ( t() && jQuery.timerId == null ) {
314 jQuery.timerId = setInterval(function(){
315 var timers = jQuery.timers;
317 for ( var i = 0; i < timers.length; i++ )
319 timers.splice(i--, 1);
321 if ( !timers.length ) {
322 clearInterval( jQuery.timerId );
323 jQuery.timerId = null;
329 // Simple 'show' function
331 // Remember where we started, so that we can go back to it later
332 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
333 this.options.show = true;
335 // Begin the animation
336 this.custom(0, this.cur());
338 // Make sure that we start at a small width/height to avoid any
340 if ( this.prop == "width" || this.prop == "height" )
341 this.elem.style[this.prop] = "1px";
343 // Start by showing the element
344 jQuery(this.elem).show();
347 // Simple 'hide' function
349 // Remember where we started, so that we can go back to it later
350 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
351 this.options.hide = true;
353 // Begin the animation
354 this.custom(this.cur(), 0);
357 // Each step of an animation
358 step: function(gotoEnd){
361 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
363 this.pos = this.state = 1;
366 this.options.curAnim[ this.prop ] = true;
369 for ( var i in this.options.curAnim )
370 if ( this.options.curAnim[i] !== true )
374 if ( this.options.display != null ) {
375 // Reset the overflow
376 this.elem.style.overflow = this.options.overflow;
379 this.elem.style.display = this.options.display;
380 if ( jQuery.css(this.elem, "display") == "none" )
381 this.elem.style.display = "block";
384 // Hide the element if the "hide" operation was done
385 if ( this.options.hide )
386 this.elem.style.display = "none";
388 // Reset the properties, if the item has been hidden or shown
389 if ( this.options.hide || this.options.show )
390 for ( var p in this.options.curAnim )
391 jQuery.attr(this.elem.style, p, this.options.orig[p]);
395 // Execute the complete function
396 this.options.complete.call( this.elem );
400 var n = t - this.startTime;
401 this.state = n / this.options.duration;
403 // Perform the easing function, defaults to swing
404 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
405 this.now = this.start + ((this.end - this.start) * this.pos);
407 // Perform the next step of the animation
416 jQuery.extend( jQuery.fx, {
425 opacity: function(fx){
426 jQuery.attr(fx.elem.style, "opacity", fx.now);
429 _default: function(fx){
430 if( fx.prop in fx.elem )
431 fx.elem[ fx.prop ] = fx.now;
432 else if( fx.elem.style )
433 fx.elem.style[ fx.prop ] = fx.now + fx.unit;