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("<" + tagName + " />").appendTo("body");
23 display = elem.css("display");
24 if ( display === "none" )
29 elemdisplay[ 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 var bool = typeof fn === "boolean";
62 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
63 this._toggle.apply( this, arguments ) :
66 var state = bool ? fn : jQuery(this).is(":hidden");
67 jQuery(this)[ state ? "show" : "hide" ]();
70 height: "toggle", width: "toggle", opacity: "toggle"
74 fadeTo: function(speed,to,callback){
75 return this.animate({opacity: to}, speed, callback);
78 animate: function( prop, speed, easing, callback ) {
79 var optall = jQuery.speed(speed, easing, callback);
81 return this[ optall.queue === false ? "each" : "queue" ](function(){
83 var opt = jQuery.extend({}, optall), p,
84 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
88 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
89 return opt.complete.call(this);
91 if ( ( p == "height" || p == "width" ) && this.style ) {
92 // Store display property
93 opt.display = jQuery.css(this, "display");
95 // Make sure that nothing sneaks out
96 opt.overflow = this.style.overflow;
100 if ( opt.overflow != null )
101 this.style.overflow = "hidden";
103 opt.curAnim = jQuery.extend({}, prop);
105 jQuery.each( prop, function(name, val){
106 var e = new jQuery.fx( self, opt, name );
108 if ( /toggle|show|hide/.test(val) )
109 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
111 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
112 start = e.cur(true) || 0;
115 var end = parseFloat(parts[2]),
116 unit = parts[3] || "px";
118 // We need to compute starting value
119 if ( unit != "px" ) {
120 self.style[ name ] = (end || 1) + unit;
121 start = ((end || 1) / e.cur(true)) * start;
122 self.style[ name ] = start + unit;
125 // If a +=/-= token was provided, we're doing a relative animation
127 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
129 e.custom( start, end, unit );
131 e.custom( start, val, "" );
135 // For JS strict compliance
140 queue: function(type, fn){
141 if ( jQuery.isFunction(type) || jQuery.isArray(type) ) {
146 if ( !type || (typeof type === "string" && !fn) )
147 return queue( this[0], type );
149 return this.each(function(){
150 if ( jQuery.isArray(fn) )
151 queue(this, type, fn);
153 queue(this, type).push( fn );
155 if ( queue(this, type).length == 1 )
161 stop: function(clearQueue, gotoEnd){
162 var timers = jQuery.timers;
167 this.each(function(){
168 // go in reverse order so anything added to the queue during the loop is ignored
169 for ( var i = timers.length - 1; i >= 0; i-- )
170 if ( timers[i].elem == this ) {
172 // force the next step to be the last
178 // start the next in the queue if the last step wasn't forced
187 // Generate shortcuts for custom animations
189 slideDown: { height:"show" },
190 slideUp: { height: "hide" },
191 slideToggle: { height: "toggle" },
192 fadeIn: { opacity: "show" },
193 fadeOut: { opacity: "hide" }
194 }, function( name, props ){
195 jQuery.fn[ name ] = function( speed, callback ){
196 return this.animate( props, speed, callback );
200 var queue = function( elem, type, array ) {
205 var q = jQuery.data( elem, type + "queue" );
208 q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) );
214 jQuery.fn.dequeue = function(type){
217 return this.each(function(){
218 var q = queue(this, type);
229 speed: function(speed, easing, fn) {
230 var opt = typeof speed === "object" ? speed : {
231 complete: fn || !fn && easing ||
232 jQuery.isFunction( speed ) && speed,
234 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
237 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
238 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
241 opt.old = opt.complete;
242 opt.complete = function(){
243 if ( opt.queue !== false )
244 jQuery(this).dequeue();
245 if ( jQuery.isFunction( opt.old ) )
246 opt.old.call( this );
253 linear: function( p, n, firstNum, diff ) {
254 return firstNum + diff * p;
256 swing: function( p, n, firstNum, diff ) {
257 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
264 fx: function( elem, options, prop ){
265 this.options = options;
275 jQuery.fx.prototype = {
277 // Simple function for setting a style value
279 if ( this.options.step )
280 this.options.step.call( this.elem, this.now, this );
282 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
284 // Set display property to block for height/width animations
285 if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style )
286 this.elem.style.display = "block";
289 // Get the current size
290 cur: function(force){
291 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) )
292 return this.elem[ this.prop ];
294 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
295 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
298 // Start an animation from one number to another
299 custom: function(from, to, unit){
300 this.startTime = now();
303 this.unit = unit || this.unit || "px";
304 this.now = this.start;
305 this.pos = this.state = 0;
309 return self.step(gotoEnd);
314 jQuery.timers.push(t);
316 if ( t() && jQuery.timerId == null ) {
317 jQuery.timerId = setInterval(function(){
318 var timers = jQuery.timers;
320 for ( var i = 0; i < timers.length; i++ )
322 timers.splice(i--, 1);
324 if ( !timers.length ) {
325 clearInterval( jQuery.timerId );
326 jQuery.timerId = null;
332 // Simple 'show' function
334 // Remember where we started, so that we can go back to it later
335 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
336 this.options.show = true;
338 // Begin the animation
339 this.custom(0, this.cur());
341 // Make sure that we start at a small width/height to avoid any
343 if ( this.prop == "width" || this.prop == "height" )
344 this.elem.style[this.prop] = "1px";
346 // Start by showing the element
347 jQuery(this.elem).show();
350 // Simple 'hide' function
352 // Remember where we started, so that we can go back to it later
353 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
354 this.options.hide = true;
356 // Begin the animation
357 this.custom(this.cur(), 0);
360 // Each step of an animation
361 step: function(gotoEnd){
364 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
366 this.pos = this.state = 1;
369 this.options.curAnim[ this.prop ] = true;
372 for ( var i in this.options.curAnim )
373 if ( this.options.curAnim[i] !== true )
377 if ( this.options.display != null ) {
378 // Reset the overflow
379 this.elem.style.overflow = this.options.overflow;
382 this.elem.style.display = this.options.display;
383 if ( jQuery.css(this.elem, "display") == "none" )
384 this.elem.style.display = "block";
387 // Hide the element if the "hide" operation was done
388 if ( this.options.hide )
389 this.elem.style.display = "none";
391 // Reset the properties, if the item has been hidden or shown
392 if ( this.options.hide || this.options.show )
393 for ( var p in this.options.curAnim )
394 jQuery.attr(this.elem.style, p, this.options.orig[p]);
398 // Execute the complete function
399 this.options.complete.call( this.elem );
403 var n = t - this.startTime;
404 this.state = n / this.options.duration;
406 // Perform the easing function, defaults to swing
407 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
408 this.now = this.start + ((this.end - this.start) * this.pos);
410 // Perform the next step of the animation
419 jQuery.extend( jQuery.fx, {
428 opacity: function(fx){
429 jQuery.attr(fx.elem.style, "opacity", fx.now);
432 _default: function(fx){
433 if( fx.prop in fx.elem )
434 fx.elem[ fx.prop ] = fx.now;
435 else if( fx.elem.style )
436 fx.elem.style[ fx.prop ] = fx.now + fx.unit;