author | Dan |
Mon, 01 Oct 2007 23:48:24 -0400 | |
changeset 158 | f7e83b6db3be |
parent 81 | d7fc25acd3f3 |
permissions | -rw-r--r-- |
1 | 1 |
// Make an HTML element fly in from the top or bottom. |
2 |
// Includes inertia! |
|
3 |
||
4 |
// vB, don't even try. It's GPL like the rest of Enano. I know you're jealous. >:) |
|
5 |
||
6 |
var fly_in_cache = new Object(); |
|
7 |
var FI_TOP = 1; |
|
8 |
var FI_BOTTOM = 2; |
|
9 |
var FI_IN = 1; |
|
10 |
var FI_OUT = 2; |
|
11 |
var FI_UP = 1; |
|
12 |
var FI_DOWN = 2; |
|
13 |
||
39
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
14 |
/** |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
15 |
* You can thank Robert Penner for the math used here. Ported from an ActionScript class. |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
16 |
* License: Modified BSD license <http://www.robertpenner.com/easing_terms_of_use.html> |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
17 |
*/ |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
18 |
|
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
19 |
// Effects code - don't bother changing these formulas |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
20 |
var Back = { |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
21 |
easeOut: function(t, b, c, d, s) |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
22 |
{ |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
23 |
if (s == undefined) s = 1.70158; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
24 |
return c * ( ( t=t/d-1 ) * t * ( ( s + 1 ) * t + s) + 1) + b; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
25 |
}, |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
26 |
easeIn: function (t, b, c, d, s) |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
27 |
{ |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
28 |
if (s == undefined) s = 1.70158; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
29 |
return c * ( t/=d ) * t * ( ( s + 1 ) * t - s) + b; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
30 |
}, |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
31 |
easeInOut: function (t, b, c, d, s) |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
32 |
{ |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
33 |
if (s == undefined) s = 1.70158; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
34 |
if ((t /= d/2) < 1) |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
35 |
{ |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
36 |
return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
37 |
} |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
38 |
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
39 |
} |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
40 |
} |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
41 |
|
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
42 |
// This should be set to the class name of the effect you want. |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
43 |
var GlideEffect = Back; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
44 |
|
1 | 45 |
// Placeholder functions, to make organization a little easier :-) |
46 |
||
47 |
function fly_in_top(element, nofade, height_taken_care_of) |
|
48 |
{ |
|
49 |
return fly_core(element, nofade, FI_TOP, FI_IN, height_taken_care_of); |
|
50 |
} |
|
51 |
||
52 |
function fly_in_bottom(element, nofade, height_taken_care_of) |
|
53 |
{ |
|
54 |
return fly_core(element, nofade, FI_BOTTOM, FI_IN, height_taken_care_of); |
|
55 |
} |
|
56 |
||
57 |
function fly_out_top(element, nofade, height_taken_care_of) |
|
58 |
{ |
|
59 |
return fly_core(element, nofade, FI_TOP, FI_OUT, height_taken_care_of); |
|
60 |
} |
|
61 |
||
62 |
function fly_out_bottom(element, nofade, height_taken_care_of) |
|
63 |
{ |
|
64 |
return fly_core(element, nofade, FI_BOTTOM, FI_OUT, height_taken_care_of); |
|
65 |
} |
|
66 |
||
67 |
function fly_core(element, nofade, origin, direction, height_taken_care_of) |
|
68 |
{ |
|
69 |
if ( !element || typeof(element) != 'object' ) |
|
70 |
return false; |
|
71 |
// target dimensions |
|
72 |
var top, left; |
|
73 |
// initial dimensions |
|
74 |
var topi, lefti; |
|
75 |
// current dimensions |
|
76 |
var topc, leftc; |
|
77 |
// screen dimensions |
|
78 |
var w = getWidth(); |
|
79 |
var h = getHeight(); |
|
80 |
var y = parseInt ( getScrollOffset() ); |
|
81 |
// temp vars |
|
82 |
var dim, off, diff, dist, ratio, opac_factor; |
|
83 |
// setup element |
|
84 |
element.style.position = 'absolute'; |
|
85 |
||
86 |
dim = [ $(element).Height(), $(element).Width() ]; |
|
87 |
off = [ $(element).Top(), $(element).Left() ]; |
|
88 |
||
89 |
if ( height_taken_care_of ) |
|
90 |
{ |
|
91 |
top = off[0]; |
|
92 |
left = off[1]; |
|
93 |
} |
|
94 |
else |
|
95 |
{ |
|
96 |
top = Math.round(( h / 2 ) - ( dim[0] / 2 )) + y; // - ( h / 4 )); |
|
97 |
left = Math.round(( w / 2 ) - ( dim[1] / 2 )); |
|
98 |
} |
|
99 |
||
100 |
// you can change this around to get it to fly in from corners or be on the left/right side |
|
101 |
lefti = left; |
|
102 |
||
103 |
// calculate first frame Y position |
|
104 |
if ( origin == FI_TOP && direction == FI_IN ) |
|
105 |
{ |
|
106 |
topi = 0 - dim[0] + y; |
|
107 |
} |
|
108 |
else if ( origin == FI_TOP && direction == FI_OUT ) |
|
109 |
{ |
|
110 |
topi = top; |
|
111 |
top = 0 - dim[0] + y; |
|
112 |
} |
|
113 |
else if ( origin == FI_BOTTOM && direction == FI_IN ) |
|
114 |
{ |
|
115 |
topi = h + y; |
|
116 |
} |
|
117 |
else if ( origin == FI_BOTTOM && direction == FI_OUT ) |
|
118 |
{ |
|
119 |
topi = top; |
|
120 |
top = h + y; |
|
121 |
} |
|
122 |
||
123 |
var abs_dir = ( ( origin == FI_TOP && direction == FI_IN ) || ( origin == FI_BOTTOM && direction == FI_OUT ) ) ? FI_DOWN : FI_UP; |
|
124 |
||
39
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
125 |
var diff_top = top - topi; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
126 |
var diff_left = left - lefti; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
127 |
|
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
128 |
var frames = 100; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
129 |
var timeout = 0; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
130 |
var timerstep = 8; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
131 |
|
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
132 |
// cache element so it can be changed from within setTimeout() |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
133 |
var rand_seed = Math.floor(Math.random() * 1000000); |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
134 |
fly_in_cache[rand_seed] = element; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
135 |
|
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
136 |
for ( var i = 0; i < frames; i++ ) |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
137 |
{ |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
138 |
topc = GlideEffect.easeInOut(i, topi, diff_top, frames); |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
139 |
leftc = GlideEffect.easeInOut(i, lefti, diff_left, frames); |
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
39
diff
changeset
|
140 |
var code = 'var o = fly_in_cache['+rand_seed+']; o.style.top=\''+topc+'px\';'; |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
39
diff
changeset
|
141 |
if ( !height_taken_care_of ) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
39
diff
changeset
|
142 |
code += ' o.style.left=\''+leftc+'px\''; |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
39
diff
changeset
|
143 |
code += ';'; |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
39
diff
changeset
|
144 |
setTimeout(code, timeout); |
39
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
145 |
timeout += timerstep; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
146 |
|
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
147 |
var ratio = i / frames; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
148 |
|
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
149 |
if ( !nofade ) |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
150 |
{ |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
151 |
// handle fade |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
152 |
var opac_factor = ratio * 100; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
153 |
if ( direction == FI_OUT ) |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
154 |
opac_factor = 100 - opac_factor; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
155 |
setTimeout('var o = fly_in_cache['+rand_seed+']; domObjChangeOpac('+opac_factor+', o);', timeout); |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
156 |
} |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
157 |
|
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
158 |
} |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
159 |
|
81
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
parents:
74
diff
changeset
|
160 |
// old framestepper code removed from here in Loch Ness |
1 | 161 |
|
39
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
162 |
timeout += timerstep; |
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
parents:
1
diff
changeset
|
163 |
return timeout; |
1 | 164 |
} |
165 |
||
166 |
function abs(i) |
|
167 |
{ |
|
168 |
if ( isNaN(i) ) |
|
169 |
return i; |
|
170 |
return ( i < 0 ) ? ( 0 - i ) : i; |
|
171 |
} |
|
172 |