1 $.speed = function(s,o) {
2 if ( o && o.constructor == Function ) { o = { onComplete: o }; }
4 var ss = {"crawl":1200,"xslow":850,"slow":600,"medium":400,"fast":200,"xfast":75,"normal":400};
5 o.duration = typeof s == "number" ? s : ss[s] || 400;
7 o.oldComplete = o.onComplete;
8 o.onComplete = function(){
10 if ( o.oldComplete && o.oldComplete.constructor == Function ) {
11 $.apply( this, o.oldComplete );
20 $.dequeue = function(elem,type){
23 if ( elem.$$queue && elem.$$queue[type] ) {
25 elem.$$queue[type].shift();
28 var f = elem.$$queue[type][0];
36 $.fn.queue = function(type,fn){
42 return this.each(function(){
43 if ( !this.$$queue ) {
47 if ( !this.$$queue[type] ) {
48 this.$$queue[type] = [];
51 this.$$queue[type].push( fn );
53 if ( this.$$queue[type].length == 1 ) {
59 $.fn._hide = $.fn.hide;
61 $.fn.hide = function(a,o) {
63 return a ? this.queue(function(){
64 new $.fx.FadeSize(this,o).hide();
68 $.fn._show = $.fn.show;
70 $.fn.show = function(a,o) {
72 return a ? this.queue(function(){
73 new $.fx.FadeSize(this,o).show();
77 $.fn.slideDown = function(a,o) {
79 return this.queue(function(){
80 new $.fx.Resize(this,o).show("height");
84 $.fn.slideUp = function(a,o) {
86 return this.queue(function(){
87 new $.fx.Resize(this,o).hide("height");
91 $.fn.fadeOut = function(a,o) {
93 return a ? this.queue(function(){
94 new $.fx.Opacity(this,o,1).hide();
98 $.fn.fadeIn = function(a,o) {
100 return a ? this.queue(function(){
101 new $.fx.Opacity(this,o,1).show();
105 $.fn.fadeTo = function(a,ev,o) {
107 return a ? this.queue(function(){
108 ef = new $.fx.Opacity(this,o);
109 ef.custom(ef.cur(),parseFloat(ev));
114 $.fn.center = function(f) {
115 return this.each(function(){
116 if ( !f && this.nodeName == 'IMG' &&
117 !this.offsetWidth && !this.offsetHeight ) {
119 setTimeout(function(){
120 $(self).center(true);
124 var p = this.parentNode;
125 if ( $.css(p,"position") == 'static' ) {
126 p.style.position = 'relative';
128 s.position = 'absolute';
129 s.left = (($.css(p,"width") - $.css(this,"width"))/2) + "px";
130 s.top = (($.css(p,"height") - $.css(this,"height"))/2) + "px";
135 $.setAuto = function(e,p) {
146 * I originally wrote fx() as a clone of moo.fx and in the process
147 * of making it small in size the code became illegible to sane
148 * people. You've been warned.
151 $.fx = function(el,op,ty){
157 duration: (op && op.duration) || 400,
158 onComplete: (op && op.onComplete) || op
167 // Simple function for setting a style value
169 z.el.style[ty] = z.now+'px';
172 // Figure out the maximum number to run to
173 z.max = function(){return z.el["$$orig"+ty]||z.cur();};
175 // Get the current size
176 z.cur = function(){return $.css(z.el,ty);};
178 // Start an animation from one number to another
179 z.custom = function(from,to){
180 z.startTime = (new Date()).getTime();
184 z.timer = setInterval(function(){
189 // Simple 'show' function
196 // Simple 'hide' function
198 // Remember where we started, so that we can go back to it later
199 z.el["$$orig"+ty] = this.cur();
201 // Begin the animation
205 // Toggle between showing and hiding an element
206 z.toggle = function(){
214 // Remember the overflow of the element
215 z.oldOverflow = y.overflow;
217 // Make sure that nothing sneaks out
218 y.overflow = "hidden";
220 // Each step of an animation
221 z.step = function(firstNum, lastNum){
222 var t = (new Date()).getTime();
224 if (t > z.o.duration + z.startTime) {
226 clearInterval(z.timer);
232 // Reset the overflow
233 y.overflow = z.oldOverflow;
235 // If the element was shown, and not using a custom number,
236 // set its height and/or width to auto
237 if ( (ty == "height" || ty == "width") && z.o.auto ) {
238 $.setAuto( z.el, ty );
241 // If a callback was provided, execute it
242 if( z.o.onComplete.constructor == Function ) {
244 // Yes, this is a weird place for this, but it needs to be executed
245 // only once per cluster of effects.
246 // If the element is, effectively, hidden - hide it
247 if ( y.height == "0px" || y.width == "0px" ) {
251 $.apply( z.el, z.o.onComplete );
254 // Figure out where in the animation we are and set the number
255 var p = (t - this.startTime) / z.o.duration;
256 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
258 // Perform the next step of the animation
265 $.fx.fn = ["show","hide","toggle"];
266 $.fx.ty = ["Height","Width","Left","Top"];
269 for(var $i in $.fx.ty){(function(){
271 $.fx[c] = function(a,b){
272 return new $.fx(a,b,c.toLowerCase());
277 $.fx.Opacity = function(a,b,sv){
278 var o = new $.fx(a,b,"opacity");
279 o.cur = function(){return parseFloat(o.el.style.opacity);};
282 if (o.now == 1) { o.now = 0.9999; }
283 if (window.ActiveXObject) {
284 e.filter = "alpha(opacity=" + o.now*100 + ")";
288 o.io = o.now = (sv || o.cur());
293 $.fx.Resize = function(e,o){
295 var h = new $.fx.Height(e,o);
296 if(o) { o.onComplete = null; }
297 var w = new $.fx.Width(e,o);
298 function c(a,b,d){return (!a||a==d||b==d);}
299 for(var i in $.fx.fn){(function(){
301 z[j] = function(a,b){
302 if(c(a,b,"height")) { h[j](); }
303 if(c(a,b,"width")) { w[j](); }
308 $.fx.FadeSize = function(e,o){
310 var r = new $.fx.Resize(e,o);
311 if(o) { o.onComplete = null; }
312 var p = new $.fx.Opacity(e,o,1);
313 for(var i in $.fx.fn){(function(){
315 z[j] = function(a,b){p[j]();r[j](a,b);};