2008-06-06 20:08:52 +00:00
|
|
|
/*
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Effects Scale @VERSION
|
2008-06-06 20:08:52 +00:00
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2008-11-20 04:10:34 +00:00
|
|
|
*
|
2008-06-06 20:08:52 +00:00
|
|
|
* http://docs.jquery.com/UI/Effects/Scale
|
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.effects.core.js
|
2008-06-06 20:08:52 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2008-06-06 19:47:31 +00:00
|
|
|
|
2011-03-15 13:00:45 +00:00
|
|
|
$.effects.effect.puff = function( o ) {
|
2011-03-07 00:34:18 +00:00
|
|
|
return this.queue( function() {
|
|
|
|
var elem = $( this ),
|
|
|
|
mode = $.effects.setMode( elem, o.mode || 'hide' ),
|
|
|
|
percent = parseInt( o.percent, 10 ) || 150,
|
2009-06-15 02:21:44 +00:00
|
|
|
factor = percent / 100,
|
2011-03-07 00:34:18 +00:00
|
|
|
original = {
|
|
|
|
height: elem.height(),
|
|
|
|
width: elem.width()
|
|
|
|
};
|
2009-06-15 02:21:44 +00:00
|
|
|
|
2011-03-03 02:10:09 +00:00
|
|
|
$.extend(o, {
|
|
|
|
effect: 'scale',
|
2011-05-01 11:24:22 +00:00
|
|
|
queue: false,
|
2009-06-15 02:21:44 +00:00
|
|
|
fade: true,
|
|
|
|
mode: mode,
|
|
|
|
percent: mode == 'hide' ? percent : 100,
|
|
|
|
from: mode == 'hide'
|
|
|
|
? original
|
|
|
|
: {
|
|
|
|
height: original.height * factor,
|
|
|
|
width: original.width * factor
|
|
|
|
}
|
|
|
|
});
|
2011-03-07 00:34:18 +00:00
|
|
|
|
2011-05-01 11:24:22 +00:00
|
|
|
elem.effect( o );
|
2008-06-06 19:47:31 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2011-03-15 13:00:45 +00:00
|
|
|
$.effects.effect.scale = function( o ) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-05-01 11:24:22 +00:00
|
|
|
return this[ o.queue === false ? "each" : "queue" ]( function() {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Create element
|
2011-03-07 00:34:18 +00:00
|
|
|
var el = $( this ),
|
|
|
|
options = $.extend( true, {}, o ),
|
|
|
|
mode = $.effects.setMode( el, o.mode || 'effect' ),
|
|
|
|
percent = parseInt( o.percent, 10 ) || ( parseInt( o.percent, 10 ) == 0 ? 0 : ( mode == 'hide' ? 0 : 100 ) ),
|
|
|
|
direction = o.direction || 'both',
|
|
|
|
origin = o.origin,
|
|
|
|
original = {
|
|
|
|
height: el.height(),
|
2011-05-20 01:25:34 +00:00
|
|
|
width: el.width(),
|
|
|
|
outerHeight: el.outerHeight(),
|
|
|
|
outerWidth: el.outerWidth()
|
2011-03-07 00:34:18 +00:00
|
|
|
},
|
|
|
|
factor = {
|
|
|
|
y: direction != 'horizontal' ? (percent / 100) : 1,
|
|
|
|
x: direction != 'vertical' ? (percent / 100) : 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// We are going to pass this effect to the size effect:
|
|
|
|
options.effect = "size";
|
2011-05-01 11:24:22 +00:00
|
|
|
options.queue = false;
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
// Set default origin and restore for show/hide
|
|
|
|
if ( mode != 'effect' ) {
|
2008-06-26 15:58:38 +00:00
|
|
|
options.origin = origin || ['middle','center'];
|
2008-06-06 19:47:31 +00:00
|
|
|
options.restore = true;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-07 00:34:18 +00:00
|
|
|
options.from = o.from || ( mode == 'show' ? { height: 0, width: 0 } : original );
|
|
|
|
options.to = {
|
|
|
|
height: original.height * factor.y,
|
2011-05-20 01:25:34 +00:00
|
|
|
width: original.width * factor.x,
|
|
|
|
outerHeight: original.outerHeight * factor.y,
|
|
|
|
outerWidth: original.outerWidth * factor.x
|
2011-03-07 00:34:18 +00:00
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-07 00:34:18 +00:00
|
|
|
if ( options.fade ) { // Fade option to support puff
|
|
|
|
if ( mode == 'show' ) {
|
|
|
|
options.from.opacity = 0;
|
|
|
|
options.to.opacity = 1;
|
|
|
|
}
|
|
|
|
if ( mode == 'hide' ) {
|
|
|
|
options.from.opacity = 1;
|
|
|
|
options.to.opacity = 0;
|
|
|
|
}
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Animate
|
2011-05-01 11:24:22 +00:00
|
|
|
el.effect(options);
|
2008-06-06 19:47:31 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
2008-05-31 17:18:24 +00:00
|
|
|
|
2011-03-15 13:00:45 +00:00
|
|
|
$.effects.effect.size = function( o ) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-05-01 11:24:22 +00:00
|
|
|
return this[ o.queue === false ? "each" : "queue" ]( function() {
|
2008-06-06 19:47:31 +00:00
|
|
|
// Create element
|
2011-03-07 00:34:18 +00:00
|
|
|
var el = $( this ),
|
|
|
|
props = [ 'position', 'top', 'bottom', 'left', 'right', 'width', 'height', 'overflow', 'opacity' ],
|
|
|
|
|
|
|
|
// Always restore
|
|
|
|
props1 = [ 'position', 'top', 'bottom', 'left', 'right', 'overflow', 'opacity' ],
|
|
|
|
|
|
|
|
// Copy for children
|
|
|
|
props2 = [ 'width', 'height', 'overflow' ],
|
|
|
|
cProps = [ 'fontSize' ],
|
|
|
|
vProps = [ 'borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom' ],
|
|
|
|
hProps = [ 'borderLeftWidth', 'borderRightWidth', 'paddingLeft', 'paddingRight' ],
|
|
|
|
|
|
|
|
// Set options
|
|
|
|
mode = $.effects.setMode( el, o.mode || 'effect' ),
|
2011-06-10 01:36:48 +00:00
|
|
|
restore = o.restore || mode !== "effect",
|
2011-03-07 00:34:18 +00:00
|
|
|
scale = o.scale || 'both',
|
|
|
|
origin = o.origin,
|
2011-05-18 23:13:37 +00:00
|
|
|
original, baseline, factor;
|
|
|
|
|
|
|
|
if ( mode === "show" ) {
|
|
|
|
el.show();
|
|
|
|
}
|
|
|
|
original = {
|
|
|
|
height: el.height(),
|
2011-05-20 01:25:34 +00:00
|
|
|
width: el.width(),
|
|
|
|
outerHeight: el.outerHeight(),
|
|
|
|
outerWidth: el.outerWidth()
|
2011-05-18 23:13:37 +00:00
|
|
|
};
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
el.from = o.from || original;
|
|
|
|
el.to = o.to || original;
|
|
|
|
|
|
|
|
// Set scaling factor
|
|
|
|
factor = {
|
|
|
|
from: {
|
|
|
|
y: el.from.height / original.height,
|
|
|
|
x: el.from.width / original.width
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
y: el.to.height / original.height,
|
|
|
|
x: el.to.width / original.width
|
|
|
|
}
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
// Scale the css box
|
|
|
|
if ( scale == 'box' || scale == 'both' ) {
|
|
|
|
|
|
|
|
// Vertical props scaling
|
2011-05-18 23:13:37 +00:00
|
|
|
if ( factor.from.y !== factor.to.y ) {
|
2011-03-07 00:34:18 +00:00
|
|
|
props = props.concat( vProps );
|
|
|
|
el.from = $.effects.setTransition( el, vProps, factor.from.y, el.from );
|
|
|
|
el.to = $.effects.setTransition( el, vProps, factor.to.y, el.to );
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
// Horizontal props scaling
|
2011-05-18 23:13:37 +00:00
|
|
|
if ( factor.from.x !== factor.to.x ) {
|
2011-03-07 00:34:18 +00:00
|
|
|
props = props.concat( hProps );
|
|
|
|
el.from = $.effects.setTransition( el, hProps, factor.from.x, el.from );
|
|
|
|
el.to = $.effects.setTransition( el, hProps, factor.to.x, el.to );
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
// Scale the content
|
|
|
|
if ( scale == 'content' || scale == 'both' ) {
|
|
|
|
|
|
|
|
// Vertical props scaling
|
2011-05-18 23:13:37 +00:00
|
|
|
if ( factor.from.y !== factor.to.y ) {
|
2011-03-07 00:34:18 +00:00
|
|
|
props = props.concat( cProps );
|
|
|
|
el.from = $.effects.setTransition( el, cProps, factor.from.y, el.from );
|
|
|
|
el.to = $.effects.setTransition( el, cProps, factor.to.y, el.to );
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
$.effects.save( el, restore ? props : props1 );
|
|
|
|
el.show();
|
|
|
|
$.effects.createWrapper( el );
|
|
|
|
el.css( 'overflow', 'hidden' ).css( el.from );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-05-20 01:25:34 +00:00
|
|
|
// Adjust
|
|
|
|
if (origin) { // Calculate baseline shifts
|
|
|
|
baseline = $.effects.getBaseline( origin, original );
|
|
|
|
el.from.top = ( original.outerHeight - el.outerHeight() ) * baseline.y;
|
|
|
|
el.from.left = ( original.outerWidth - el.outerWidth() ) * baseline.x;
|
|
|
|
el.to.top = ( original.outerHeight - el.to.outerHeight ) * baseline.y;
|
|
|
|
el.to.left = ( original.outerWidth - el.to.outerWidth ) * baseline.x;
|
|
|
|
}
|
|
|
|
el.css( el.from ); // set top & left
|
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Animate
|
2011-03-07 00:34:18 +00:00
|
|
|
if ( scale == 'content' || scale == 'both' ) { // Scale the children
|
|
|
|
|
|
|
|
// Add margins/font-size
|
|
|
|
vProps = vProps.concat([ 'marginTop', 'marginBottom' ]).concat(cProps);
|
|
|
|
hProps = hProps.concat([ 'marginLeft', 'marginRight' ]);
|
|
|
|
props2 = props.concat(vProps).concat(hProps);
|
|
|
|
|
|
|
|
el.find( "*[width]" ).each( function(){
|
|
|
|
var child = $( this ),
|
|
|
|
c_original = {
|
|
|
|
height: child.height(),
|
|
|
|
width: child.width()
|
|
|
|
};
|
2008-06-06 19:47:31 +00:00
|
|
|
if (restore) $.effects.save(child, props2);
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
child.from = {
|
|
|
|
height: c_original.height * factor.from.y,
|
|
|
|
width: c_original.width * factor.from.x
|
|
|
|
};
|
|
|
|
child.to = {
|
|
|
|
height: c_original.height * factor.to.y,
|
|
|
|
width: c_original.width * factor.to.x
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
// Vertical props scaling
|
|
|
|
if ( factor.from.y != factor.to.y ) {
|
|
|
|
child.from = $.effects.setTransition( child, vProps, factor.from.y, child.from );
|
|
|
|
child.to = $.effects.setTransition( child, vProps, factor.to.y, child.to );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Horizontal props scaling
|
|
|
|
if ( factor.from.x != factor.to.x ) {
|
|
|
|
child.from = $.effects.setTransition( child, hProps, factor.from.x, child.from );
|
|
|
|
child.to = $.effects.setTransition( child, hProps, factor.to.x, child.to );
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2011-03-07 00:34:18 +00:00
|
|
|
|
|
|
|
// Animate children
|
|
|
|
child.css( child.from );
|
|
|
|
child.animate( child.to, o.duration, o.easing, function() {
|
|
|
|
|
|
|
|
// Restore children
|
|
|
|
if (restore) $.effects.restore( child, props2 );
|
|
|
|
});
|
2008-06-06 19:47:31 +00:00
|
|
|
});
|
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Animate
|
2011-03-07 00:34:18 +00:00
|
|
|
el.animate( el.to, {
|
|
|
|
queue: false,
|
|
|
|
duration: o.duration,
|
|
|
|
easing: o.easing,
|
|
|
|
complete: function() {
|
|
|
|
if ( el.to.opacity === 0 ) {
|
|
|
|
el.css( 'opacity', el.from.opacity );
|
|
|
|
}
|
|
|
|
if( mode == 'hide' ) {
|
|
|
|
el.hide();
|
|
|
|
}
|
|
|
|
$.effects.restore( el, restore ? props : props1 );
|
|
|
|
$.effects.removeWrapper( el );
|
|
|
|
$.isFunction( o.complete ) && o.complete.apply( this, arguments ); // Callback
|
|
|
|
el.dequeue();
|
2009-07-09 04:00:35 +00:00
|
|
|
}
|
2011-03-07 00:34:18 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
});
|
2008-05-31 17:18:24 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery);
|