|
1 /** |
|
2 * Interface Elements for jQuery |
|
3 * FX - fold |
|
4 * |
|
5 * http://interface.eyecon.ro |
|
6 * |
|
7 * Copyright (c) 2006 Stefan Petre |
|
8 * Dual licensed under the MIT (MIT-LICENSE.txt) |
|
9 * and GPL (GPL-LICENSE.txt) licenses. |
|
10 * |
|
11 * |
|
12 */ |
|
13 |
|
14 /** |
|
15 * Applies a folding animation to element |
|
16 */ |
|
17 jQuery.fn.extend( |
|
18 { |
|
19 /** |
|
20 * @name Fold |
|
21 * @description folds the element |
|
22 * @param Mixed speed animation speed, integer for miliseconds, string ['slow' | 'normal' | 'fast'] |
|
23 * @param Integer height the height in pixels to fold element to |
|
24 * @param Function callback (optional) A function to be executed whenever the animation completes. |
|
25 * @param String easing (optional) The name of the easing effect that you want to use. |
|
26 * @type jQuery |
|
27 * @cat Plugins/Interface |
|
28 * @author Stefan Petre |
|
29 */ |
|
30 Fold : function (speed, height, callback, easing) |
|
31 { |
|
32 return this.queue('interfaceFX',function(){ |
|
33 new jQuery.fx.DoFold(this, speed, height, callback, 'fold', easing); |
|
34 }); |
|
35 }, |
|
36 |
|
37 /** |
|
38 * @name UnFold |
|
39 * @description unfolds the element |
|
40 * @param Mixed speed animation speed, integer for miliseconds, string ['slow' | 'normal' | 'fast'] |
|
41 * @param Integer height the height in pixels to unfold element to |
|
42 * @param Function callback (optional) A function to be executed whenever the animation completes. |
|
43 * @param String easing (optional) The name of the easing effect that you want to use. |
|
44 * @type jQuery |
|
45 * @cat Plugins/Interface |
|
46 * @author Stefan Petre |
|
47 */ |
|
48 UnFold : function (speed, height, callback, easing) |
|
49 { |
|
50 return this.queue('interfaceFX',function(){ |
|
51 new jQuery.fx.DoFold(this, speed, height, callback, 'unfold', easing); |
|
52 }); |
|
53 }, |
|
54 |
|
55 /** |
|
56 * @name FoldToggle |
|
57 * @description folds/unfolds the element |
|
58 * @param Mixed speed animation speed, integer for miliseconds, string ['slow' | 'normal' | 'fast'] |
|
59 * @param Integer height the height in pixels to folds/unfolds element to |
|
60 * @param Function callback (optional) A function to be executed whenever the animation completes. |
|
61 * @param String easing (optional) The name of the easing effect that you want to use. |
|
62 * @type jQuery |
|
63 * @cat Plugins/Interface |
|
64 * @author Stefan Petre |
|
65 */ |
|
66 FoldToggle : function (speed, height, callback, easing) |
|
67 { |
|
68 return this.queue('interfaceFX',function(){ |
|
69 new jQuery.fx.DoFold(this, speed, height, callback, 'toggle', easing); |
|
70 }); |
|
71 } |
|
72 } |
|
73 ); |
|
74 |
|
75 jQuery.fx.DoFold = function (e, speed, height, callback, type, easing) |
|
76 { |
|
77 if (!jQuery.fxCheckTag(e)) { |
|
78 jQuery.dequeue(e, 'interfaceFX'); |
|
79 return false; |
|
80 } |
|
81 var z = this; |
|
82 z.el = jQuery(e); |
|
83 z.easing = typeof callback == 'string' ? callback : easing||null; |
|
84 z.callback = typeof callback == 'function' ? callback : null; |
|
85 if ( type == 'toggle') { |
|
86 type = z.el.css('display') == 'none' ? 'unfold' : 'fold'; |
|
87 } |
|
88 //z.el.show(); |
|
89 z.speed = speed; |
|
90 z.height = height && height.constructor == Number ? height : 20; |
|
91 z.fx = jQuery.fx.buildWrapper(e); |
|
92 z.type = type; |
|
93 z.complete = function() |
|
94 { |
|
95 if (z.callback && z.callback.constructor == Function) { |
|
96 z.callback.apply(z.el.get(0)); |
|
97 } |
|
98 if(z.type == 'unfold'){ |
|
99 z.el.show(); |
|
100 } else { |
|
101 z.el.hide(); |
|
102 } |
|
103 jQuery.fx.destroyWrapper(z.fx.wrapper.get(0), z.fx.oldStyle); |
|
104 jQuery.dequeue(z.el.get(0), 'interfaceFX'); |
|
105 }; |
|
106 if ( z.type == 'unfold') { |
|
107 z.el.show(); |
|
108 z.fx.wrapper.css('height', z.height + 'px').css('width', '1px'); |
|
109 |
|
110 z.ef = new jQuery.fx( |
|
111 z.fx.wrapper.get(0), |
|
112 jQuery.speed ( |
|
113 z.speed, |
|
114 z.easing, |
|
115 function() |
|
116 { |
|
117 z.ef = new jQuery.fx( |
|
118 z.fx.wrapper.get(0), |
|
119 jQuery.speed( |
|
120 z.speed, |
|
121 z.easing, |
|
122 z.complete |
|
123 ), |
|
124 'height' |
|
125 ); |
|
126 z.ef.custom(z.height, z.fx.oldStyle.sizes.hb); |
|
127 } |
|
128 ), |
|
129 'width' |
|
130 ); |
|
131 z.ef.custom(0, z.fx.oldStyle.sizes.wb); |
|
132 } else { |
|
133 z.ef = new jQuery.fx( |
|
134 z.fx.wrapper.get(0), |
|
135 jQuery.speed( |
|
136 z.speed, |
|
137 z.easing, |
|
138 function() |
|
139 { |
|
140 z.ef = new jQuery.fx( |
|
141 z.fx.wrapper.get(0), |
|
142 jQuery.speed( |
|
143 z.speed, |
|
144 z.easing, |
|
145 z.complete |
|
146 ), |
|
147 'width' |
|
148 ); |
|
149 z.ef.custom(z.fx.oldStyle.sizes.wb, 0); |
|
150 } |
|
151 ), |
|
152 'height' |
|
153 ); |
|
154 z.ef.custom(z.fx.oldStyle.sizes.hb, z.height); |
|
155 } |
|
156 }; |
|
157 |