2 show: function(speed,callback){
5 height: "show", width: "show", opacity: "show"
8 this.filter(":hidden").each(function(){
9 this.style.display = this.oldblock || "";
10 if ( jQuery.css(this,"display") == "none" ) {
11 var elem = jQuery("<" + this.tagName + " />").appendTo("body");
12 this.style.display = elem.css("display");
13 // handle an edge condition where css is - div { display:none; } or similar
14 if (this.style.display == "none")
15 this.style.display = "block";
21 hide: function(speed,callback){
24 height: "hide", width: "hide", opacity: "hide"
27 this.filter(":visible").each(function(){
28 this.oldblock = this.oldblock || jQuery.css(this,"display");
29 this.style.display = "none";
33 // Save the old toggle function
34 _toggle: jQuery.fn.toggle,
36 toggle: function( fn, fn2 ){
37 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
38 this._toggle.apply( this, arguments ) :
41 height: "toggle", width: "toggle", opacity: "toggle"
44 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
48 fadeTo: function(speed,to,callback){
49 return this.animate({opacity: to}, speed, callback);
52 animate: function( prop, speed, easing, callback ) {
53 var optall = jQuery.speed(speed, easing, callback);
55 return this[ optall.queue === false ? "each" : "queue" ](function(){
57 var opt = jQuery.extend({}, optall), p,
58 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
62 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
63 return opt.complete.call(this);
65 if ( ( p == "height" || p == "width" ) && this.style ) {
66 // Store display property
67 opt.display = jQuery.css(this, "display");
69 // Make sure that nothing sneaks out
70 opt.overflow = this.style.overflow;
74 if ( opt.overflow != null )
75 this.style.overflow = "hidden";
77 opt.curAnim = jQuery.extend({}, prop);
79 jQuery.each( prop, function(name, val){
80 var e = new jQuery.fx( self, opt, name );
82 if ( /toggle|show|hide/.test(val) )
83 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
85 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
86 start = e.cur(true) || 0;
89 var end = parseFloat(parts[2]),
90 unit = parts[3] || "px";
92 // We need to compute starting value
94 self.style[ name ] = (end || 1) + unit;
95 start = ((end || 1) / e.cur(true)) * start;
96 self.style[ name ] = start + unit;
99 // If a +=/-= token was provided, we're doing a relative animation
101 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
103 e.custom( start, end, unit );
105 e.custom( start, val, "" );
109 // For JS strict compliance
114 queue: function(type, fn){
115 if ( jQuery.isFunction(type) || jQuery.isArray(type) ) {
120 if ( !type || (typeof type === "string" && !fn) )
121 return queue( this[0], type );
123 return this.each(function(){
124 if ( jQuery.isArray(fn) )
125 queue(this, type, fn);
127 queue(this, type).push( fn );
129 if ( queue(this, type).length == 1 )
135 stop: function(clearQueue, gotoEnd){
136 var timers = jQuery.timers;
141 this.each(function(){
142 // go in reverse order so anything added to the queue during the loop is ignored
143 for ( var i = timers.length - 1; i >= 0; i-- )
144 if ( timers[i].elem == this ) {
146 // force the next step to be the last
152 // start the next in the queue if the last step wasn't forced
161 // Generate shortcuts for custom animations
163 slideDown: { height:"show" },
164 slideUp: { height: "hide" },
165 slideToggle: { height: "toggle" },
166 fadeIn: { opacity: "show" },
167 fadeOut: { opacity: "hide" }
168 }, function( name, props ){
169 jQuery.fn[ name ] = function( speed, callback ){
170 return this.animate( props, speed, callback );
174 var queue = function( elem, type, array ) {
179 var q = jQuery.data( elem, type + "queue" );
182 q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) );
188 jQuery.fn.dequeue = function(type){
191 return this.each(function(){
192 var q = queue(this, type);
203 speed: function(speed, easing, fn) {
204 var opt = typeof speed === "object" ? speed : {
205 complete: fn || !fn && easing ||
206 jQuery.isFunction( speed ) && speed,
208 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
211 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
212 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
215 opt.old = opt.complete;
216 opt.complete = function(){
217 if ( opt.queue !== false )
218 jQuery(this).dequeue();
219 if ( jQuery.isFunction( opt.old ) )
220 opt.old.call( this );
227 linear: function( p, n, firstNum, diff ) {
228 return firstNum + diff * p;
230 swing: function( p, n, firstNum, diff ) {
231 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
238 fx: function( elem, options, prop ){
239 this.options = options;
249 jQuery.fx.prototype = {
251 // Simple function for setting a style value
253 if ( this.options.step )
254 this.options.step.call( this.elem, this.now, this );
256 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
258 // Set display property to block for height/width animations
259 if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style )
260 this.elem.style.display = "block";
263 // Get the current size
264 cur: function(force){
265 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) )
266 return this.elem[ this.prop ];
268 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
269 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
272 // Start an animation from one number to another
273 custom: function(from, to, unit){
274 this.startTime = now();
277 this.unit = unit || this.unit || "px";
278 this.now = this.start;
279 this.pos = this.state = 0;
283 return self.step(gotoEnd);
288 jQuery.timers.push(t);
290 if ( t() && jQuery.timerId == null ) {
291 jQuery.timerId = setInterval(function(){
292 var timers = jQuery.timers;
294 for ( var i = 0; i < timers.length; i++ )
296 timers.splice(i--, 1);
298 if ( !timers.length ) {
299 clearInterval( jQuery.timerId );
300 jQuery.timerId = null;
306 // Simple 'show' function
308 // Remember where we started, so that we can go back to it later
309 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
310 this.options.show = true;
312 // Begin the animation
313 this.custom(0, this.cur());
315 // Make sure that we start at a small width/height to avoid any
317 if ( this.prop == "width" || this.prop == "height" )
318 this.elem.style[this.prop] = "1px";
320 // Start by showing the element
321 jQuery(this.elem).show();
324 // Simple 'hide' function
326 // Remember where we started, so that we can go back to it later
327 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
328 this.options.hide = true;
330 // Begin the animation
331 this.custom(this.cur(), 0);
334 // Each step of an animation
335 step: function(gotoEnd){
338 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
340 this.pos = this.state = 1;
343 this.options.curAnim[ this.prop ] = true;
346 for ( var i in this.options.curAnim )
347 if ( this.options.curAnim[i] !== true )
351 if ( this.options.display != null ) {
352 // Reset the overflow
353 this.elem.style.overflow = this.options.overflow;
356 this.elem.style.display = this.options.display;
357 if ( jQuery.css(this.elem, "display") == "none" )
358 this.elem.style.display = "block";
361 // Hide the element if the "hide" operation was done
362 if ( this.options.hide )
363 this.elem.style.display = "none";
365 // Reset the properties, if the item has been hidden or shown
366 if ( this.options.hide || this.options.show )
367 for ( var p in this.options.curAnim )
368 jQuery.attr(this.elem.style, p, this.options.orig[p]);
372 // Execute the complete function
373 this.options.complete.call( this.elem );
377 var n = t - this.startTime;
378 this.state = n / this.options.duration;
380 // Perform the easing function, defaults to swing
381 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
382 this.now = this.start + ((this.end - this.start) * this.pos);
384 // Perform the next step of the animation
393 jQuery.extend( jQuery.fx, {
402 opacity: function(fx){
403 jQuery.attr(fx.elem.style, "opacity", fx.now);
406 _default: function(fx){
407 if( fx.prop in fx.elem )
408 fx.elem[ fx.prop ] = fx.now;
409 else if( fx.elem.style )
410 fx.elem.style[ fx.prop ] = fx.now + fx.unit;