Skip to content

Commit d0c613d

Browse files
committed
Effect: Give puff-effect and size-effect its own files. Previously, they were into scale-effect file.
1 parent 670f650 commit d0c613d

File tree

5 files changed

+284
-240
lines changed

5 files changed

+284
-240
lines changed

build/effect.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,23 @@
2323
"highlight": {
2424
"description": "Highlights the background of an element in a defined color for a custom duration."
2525
},
26+
"puff": {
27+
"dependencies": [ "effect-scale" ],
28+
"description": "Creates a puff effect by scaling the element up and hiding it at the same time."
29+
},
2630
"pulsate": {
2731
"description": "Pulsates an element n times by changing the opacity to zero and back."
2832
},
2933
"scale": {
34+
"dependencies": [ "effect-size" ],
3035
"description": "Grows or shrinks an element and its content. Restores an elemnt to its original size."
3136
},
3237
"shake": {
3338
"description": "Shakes an element horizontally or vertically n times."
3439
},
40+
"size": {
41+
"description": "Resize an element to a specified width and height."
42+
},
3543
"slide": {
3644
"description": "Slides an element in and out of the viewport."
3745
}

demos/effect/default.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
<script src="../../ui/jquery.ui.effect-fade.js"></script>
1515
<script src="../../ui/jquery.ui.effect-fold.js"></script>
1616
<script src="../../ui/jquery.ui.effect-highlight.js"></script>
17+
<script src="../../ui/jquery.ui.effect-puff.js"></script>
1718
<script src="../../ui/jquery.ui.effect-pulsate.js"></script>
1819
<script src="../../ui/jquery.ui.effect-scale.js"></script>
1920
<script src="../../ui/jquery.ui.effect-shake.js"></script>
21+
<script src="../../ui/jquery.ui.effect-size.js"></script>
2022
<script src="../../ui/jquery.ui.effect-slide.js"></script>
2123
<script src="../../ui/jquery.ui.effect-transfer.js"></script>
2224
<link rel="stylesheet" href="../demos.css">

ui/jquery.ui.effect-puff.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*!
2+
* jQuery UI Effects Puff @VERSION
3+
* http://jqueryui.com
4+
*
5+
* Copyright 2013 jQuery Foundation and other contributors
6+
* Released under the MIT license.
7+
* http://jquery.org/license
8+
*
9+
* http://api.jqueryui.com/puff-effect/
10+
*
11+
* Depends:
12+
* jquery.ui.effect.js
13+
* jquery.ui.effect-scale.js
14+
*/
15+
(function( $, undefined ) {
16+
17+
$.effects.effect.puff = function( o, done ) {
18+
var elem = $( this ),
19+
mode = $.effects.setMode( elem, o.mode || "hide" ),
20+
hide = mode === "hide",
21+
percent = parseInt( o.percent, 10 ) || 150,
22+
factor = percent / 100,
23+
original = {
24+
height: elem.height(),
25+
width: elem.width(),
26+
outerHeight: elem.outerHeight(),
27+
outerWidth: elem.outerWidth()
28+
};
29+
30+
$.extend( o, {
31+
effect: "scale",
32+
queue: false,
33+
fade: true,
34+
mode: mode,
35+
complete: done,
36+
percent: hide ? percent : 100,
37+
from: hide ?
38+
original :
39+
{
40+
height: original.height * factor,
41+
width: original.width * factor,
42+
outerHeight: original.outerHeight * factor,
43+
outerWidth: original.outerWidth * factor
44+
}
45+
});
46+
47+
elem.effect( o );
48+
};
49+
50+
})(jQuery);

ui/jquery.ui.effect-scale.js

Lines changed: 1 addition & 240 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,10 @@
1010
*
1111
* Depends:
1212
* jquery.ui.effect.js
13+
* jquery.ui.effect-size.js
1314
*/
1415
(function( $, undefined ) {
1516

16-
$.effects.effect.puff = function( o, done ) {
17-
var elem = $( this ),
18-
mode = $.effects.setMode( elem, o.mode || "hide" ),
19-
hide = mode === "hide",
20-
percent = parseInt( o.percent, 10 ) || 150,
21-
factor = percent / 100,
22-
original = {
23-
height: elem.height(),
24-
width: elem.width(),
25-
outerHeight: elem.outerHeight(),
26-
outerWidth: elem.outerWidth()
27-
};
28-
29-
$.extend( o, {
30-
effect: "scale",
31-
queue: false,
32-
fade: true,
33-
mode: mode,
34-
complete: done,
35-
percent: hide ? percent : 100,
36-
from: hide ?
37-
original :
38-
{
39-
height: original.height * factor,
40-
width: original.width * factor,
41-
outerHeight: original.outerHeight * factor,
42-
outerWidth: original.outerWidth * factor
43-
}
44-
});
45-
46-
elem.effect( o );
47-
};
48-
4917
$.effects.effect.scale = function( o, done ) {
5018

5119
// Create element
@@ -108,211 +76,4 @@ $.effects.effect.scale = function( o, done ) {
10876

10977
};
11078

111-
$.effects.effect.size = function( o, done ) {
112-
113-
// Create element
114-
var original, baseline, factor,
115-
el = $( this ),
116-
props0 = [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ],
117-
118-
// Always restore
119-
props1 = [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ],
120-
121-
// Copy for children
122-
props2 = [ "width", "height", "overflow" ],
123-
cProps = [ "fontSize" ],
124-
vProps = [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ],
125-
hProps = [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ],
126-
127-
// Set options
128-
mode = $.effects.setMode( el, o.mode || "effect" ),
129-
restore = o.restore || mode !== "effect",
130-
scale = o.scale || "both",
131-
origin = o.origin || [ "middle", "center" ],
132-
position = el.css( "position" ),
133-
props = restore ? props0 : props1,
134-
zero = {
135-
height: 0,
136-
width: 0,
137-
outerHeight: 0,
138-
outerWidth: 0
139-
};
140-
141-
if ( mode === "show" ) {
142-
el.show();
143-
}
144-
original = {
145-
height: el.height(),
146-
width: el.width(),
147-
outerHeight: el.outerHeight(),
148-
outerWidth: el.outerWidth()
149-
};
150-
151-
if ( o.mode === "toggle" && mode === "show" ) {
152-
el.from = o.to || zero;
153-
el.to = o.from || original;
154-
} else {
155-
el.from = o.from || ( mode === "show" ? zero : original );
156-
el.to = o.to || ( mode === "hide" ? zero : original );
157-
}
158-
159-
// Set scaling factor
160-
factor = {
161-
from: {
162-
y: el.from.height / original.height,
163-
x: el.from.width / original.width
164-
},
165-
to: {
166-
y: el.to.height / original.height,
167-
x: el.to.width / original.width
168-
}
169-
};
170-
171-
// Scale the css box
172-
if ( scale === "box" || scale === "both" ) {
173-
174-
// Vertical props scaling
175-
if ( factor.from.y !== factor.to.y ) {
176-
props = props.concat( vProps );
177-
el.from = $.effects.setTransition( el, vProps, factor.from.y, el.from );
178-
el.to = $.effects.setTransition( el, vProps, factor.to.y, el.to );
179-
}
180-
181-
// Horizontal props scaling
182-
if ( factor.from.x !== factor.to.x ) {
183-
props = props.concat( hProps );
184-
el.from = $.effects.setTransition( el, hProps, factor.from.x, el.from );
185-
el.to = $.effects.setTransition( el, hProps, factor.to.x, el.to );
186-
}
187-
}
188-
189-
// Scale the content
190-
if ( scale === "content" || scale === "both" ) {
191-
192-
// Vertical props scaling
193-
if ( factor.from.y !== factor.to.y ) {
194-
props = props.concat( cProps ).concat( props2 );
195-
el.from = $.effects.setTransition( el, cProps, factor.from.y, el.from );
196-
el.to = $.effects.setTransition( el, cProps, factor.to.y, el.to );
197-
}
198-
}
199-
200-
$.effects.save( el, props );
201-
el.show();
202-
$.effects.createWrapper( el );
203-
el.css( "overflow", "hidden" ).css( el.from );
204-
205-
// Adjust
206-
if (origin) { // Calculate baseline shifts
207-
baseline = $.effects.getBaseline( origin, original );
208-
el.from.top = ( original.outerHeight - el.outerHeight() ) * baseline.y;
209-
el.from.left = ( original.outerWidth - el.outerWidth() ) * baseline.x;
210-
el.to.top = ( original.outerHeight - el.to.outerHeight ) * baseline.y;
211-
el.to.left = ( original.outerWidth - el.to.outerWidth ) * baseline.x;
212-
}
213-
el.css( el.from ); // set top & left
214-
215-
// Animate
216-
if ( scale === "content" || scale === "both" ) { // Scale the children
217-
218-
// Add margins/font-size
219-
vProps = vProps.concat([ "marginTop", "marginBottom" ]).concat(cProps);
220-
hProps = hProps.concat([ "marginLeft", "marginRight" ]);
221-
props2 = props0.concat(vProps).concat(hProps);
222-
223-
el.find( "*[width]" ).each( function(){
224-
var child = $( this ),
225-
c_original = {
226-
height: child.height(),
227-
width: child.width(),
228-
outerHeight: child.outerHeight(),
229-
outerWidth: child.outerWidth()
230-
};
231-
if (restore) {
232-
$.effects.save(child, props2);
233-
}
234-
235-
child.from = {
236-
height: c_original.height * factor.from.y,
237-
width: c_original.width * factor.from.x,
238-
outerHeight: c_original.outerHeight * factor.from.y,
239-
outerWidth: c_original.outerWidth * factor.from.x
240-
};
241-
child.to = {
242-
height: c_original.height * factor.to.y,
243-
width: c_original.width * factor.to.x,
244-
outerHeight: c_original.height * factor.to.y,
245-
outerWidth: c_original.width * factor.to.x
246-
};
247-
248-
// Vertical props scaling
249-
if ( factor.from.y !== factor.to.y ) {
250-
child.from = $.effects.setTransition( child, vProps, factor.from.y, child.from );
251-
child.to = $.effects.setTransition( child, vProps, factor.to.y, child.to );
252-
}
253-
254-
// Horizontal props scaling
255-
if ( factor.from.x !== factor.to.x ) {
256-
child.from = $.effects.setTransition( child, hProps, factor.from.x, child.from );
257-
child.to = $.effects.setTransition( child, hProps, factor.to.x, child.to );
258-
}
259-
260-
// Animate children
261-
child.css( child.from );
262-
child.animate( child.to, o.duration, o.easing, function() {
263-
264-
// Restore children
265-
if ( restore ) {
266-
$.effects.restore( child, props2 );
267-
}
268-
});
269-
});
270-
}
271-
272-
// Animate
273-
el.animate( el.to, {
274-
queue: false,
275-
duration: o.duration,
276-
easing: o.easing,
277-
complete: function() {
278-
if ( el.to.opacity === 0 ) {
279-
el.css( "opacity", el.from.opacity );
280-
}
281-
if( mode === "hide" ) {
282-
el.hide();
283-
}
284-
$.effects.restore( el, props );
285-
if ( !restore ) {
286-
287-
// we need to calculate our new positioning based on the scaling
288-
if ( position === "static" ) {
289-
el.css({
290-
position: "relative",
291-
top: el.to.top,
292-
left: el.to.left
293-
});
294-
} else {
295-
$.each([ "top", "left" ], function( idx, pos ) {
296-
el.css( pos, function( _, str ) {
297-
var val = parseInt( str, 10 ),
298-
toRef = idx ? el.to.left : el.to.top;
299-
300-
// if original was "auto", recalculate the new value from wrapper
301-
if ( str === "auto" ) {
302-
return toRef + "px";
303-
}
304-
305-
return val + toRef + "px";
306-
});
307-
});
308-
}
309-
}
310-
311-
$.effects.removeWrapper( el );
312-
done();
313-
}
314-
});
315-
316-
};
317-
31879
})(jQuery);

0 commit comments

Comments
 (0)