1 // overwrite the old show method
2 $.fn._show = $.fn.show;
5 * The effects module overloads the show method to now allow
6 * for a speed to the show operation. What actually happens is
7 * that the height, width, and opacity to the matched elements
8 * are changed dynamically. The only three current speeds are
9 * "slow", "normal", and "fast". For example:
10 * $("p").show("slow");
11 * Note: You should not run the show method on things
12 * that are already shown. This can be circumvented by doing this:
13 * $("p:hidden").show("slow");
15 $.fn.show = function(speed,callback){
16 return speed ? this.animate({
17 height: "show", width: "show", opacity: "show"
18 }, speed, callback) : this._show();
21 // We're overwriting the old hide method
22 $.fn._hide = $.fn.hide;
26 * The hide function behaves very similary to the show function,
27 * but is just the opposite.
28 * $("p:visible").hide("slow");
30 $.fn.hide = function(speed,callback){
31 return speed ? this.animate({
35 }, speed, callback) : this._hide();
39 * This function increases the height and opacity for all matched
40 * elements. This is very similar to 'show', but does not change
41 * the width - creating a neat sliding effect.
42 * $("p:hidden").slideDown("slow");
44 $.fn.slideDown = function(speed,callback){
45 return this.animate({height: "show"}, speed, callback);
49 * Just like slideDown, only it hides all matched elements.
50 * $("p:visible").slideUp("slow");
52 $.fn.slideUp = function(speed,callback){
53 return this.animate({height: "hide"}, speed, callback);
57 * Adjusts the opacity of all matched elements from a hidden,
58 * to a fully visible, state.
59 * $("p:hidden").fadeIn("slow");
61 $.fn.fadeIn = function(speed,callback){
62 return this.animate({opacity: "show"}, speed, callback);
66 * Same as fadeIn, but transitions from a visible, to a hidden state.
67 * $("p:visible").fadeOut("slow");
69 $.fn.fadeOut = function(speed,callback){
70 return this.animate({opacity: "hide"}, speed, callback);
76 $.fn.fadeTo = function(speed,to,callback){
77 return this.animate({opacity: to}, speed, callback);
83 $.fn.animate = function(prop,speed,callback) {
84 return this.queue(function(){
86 for ( var p in prop ) {
87 var e = new fx( this, $.speed(speed,callback,i++), p );
88 if ( prop[p].constructor == Number )
89 e.custom( e.cur(), prop[p] );
96 $.speed = function(s,o,i) {
99 if ( o.constructor == Function )
102 var ss = {"slow":600,"fast":200};
103 o.duration = s.constructor == Number ? s : ss[s] || 400;
106 o.oldComplete = o.complete;
107 o.complete = function(){
108 $.dequeue(this, "fx");
109 if ( o.oldComplete && o.oldComplete.constructor == Function )
110 o.oldComplete.apply( this );
121 $.dequeue = function(elem,type){
124 if ( elem.queue && elem.queue[type] ) {
126 elem.queue[type].shift();
129 var f = elem.queue[type][0];
136 $.fn.queue = function(type,fn){
142 return this.each(function(){
146 if ( !this.queue[type] )
147 this.queue[type] = [];
149 this.queue[type].push( fn );
151 if ( this.queue[type].length == 1 )
156 $.setAuto = function(e,p) {
166 * I originally wrote fx() as a clone of moo.fx and in the process
167 * of making it small in size the code became illegible to sane
168 * people. You've been warned.
171 $.fx = function( elem, options, prop ){
177 duration: options.duration || 400,
178 complete: options.complete
187 // Simple function for setting a style value
189 if ( prop == "opacity" ) {
190 if (z.now == 1) z.now = 0.9999;
191 if (window.ActiveXObject)
192 y.filter = "alpha(opacity=" + z.now*100 + ")";
195 y[prop] = z.now+"px";
198 // Figure out the maximum number to run to
200 return z.el["orig"+prop] || z.cur();
203 // Get the current size
205 return parseFloat( $.css(z.el,prop) );
208 // Start an animation from one number to another
209 z.custom = function(from,to){
210 z.startTime = (new Date()).getTime();
214 z.timer = setInterval(function(){
219 // Simple 'show' function
226 // Simple 'hide' function
228 // Remember where we started, so that we can go back to it later
229 z.el["orig"+prop] = this.cur();
231 // Begin the animation
235 // IE has trouble with opacity if it doesn't have layout
236 if ( $.browser == "msie" && !z.el.currentStyle.hasLayout )
239 // Remember the overflow of the element
240 z.oldOverflow = y.overflow;
242 // Make sure that nothing sneaks out
243 y.overflow = "hidden";
245 // Each step of an animation
246 z.step = function(firstNum, lastNum){
247 var t = (new Date()).getTime();
249 if (t > z.o.duration + z.startTime) {
251 clearInterval(z.timer);
257 // Reset the overflow
258 y.overflow = z.oldOverflow;
260 // If the element was shown, and not using a custom number,
261 // set its height and/or width to auto
262 if ( (prop == "height" || prop == "width") && z.o.auto )
263 $.setAuto( z.el, prop );
265 // If a callback was provided, execute it
266 if( z.o.complete.constructor == Function ) {
268 // Yes, this is a weird place for this, but it needs to be executed
269 // only once per cluster of effects.
270 // If the element is, effectively, hidden - hide it
271 if ( y.height == "0px" || y.width == "0px" )
274 // Execute the complete function
275 z.o.complete.apply( z.el );
278 // Figure out where in the animation we are and set the number
279 var p = (t - this.startTime) / z.o.duration;
280 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
282 // Perform the next step of the animation