jquery-ui/ui/effect-fold.js

89 lines
2.1 KiB
JavaScript
Raw Normal View History

/*!
* jQuery UI Effects Fold @VERSION
2012-07-04 13:08:08 +00:00
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
2012-08-09 14:13:24 +00:00
* Released under the MIT license.
* http://jquery.org/license
*/
//>>label: Fold Effect
//>>group: Effects
//>>description: Folds an element first horizontally and then vertically.
//>>docs: http://api.jqueryui.com/fold-effect/
//>>demos: http://jqueryui.com/effect/
( function( factory ) {
if ( typeof define === "function" && define.amd ) {
2008-05-23 09:26:18 +00:00
// AMD. Register as an anonymous module.
define( [
"jquery",
"./effect"
], factory );
} else {
// Browser globals
factory( jQuery );
}
}( function( $ ) {
return $.effects.define( "fold", "hide", function( options, done ) {
2008-05-23 09:26:18 +00:00
// Create element
var element = $( this ),
mode = options.mode,
2011-06-21 06:15:42 +00:00
show = mode === "show",
hide = mode === "hide",
size = options.size || 15,
2011-06-21 06:15:42 +00:00
percent = /([0-9]+)%/.exec( size ),
horizFirst = !!options.horizFirst,
ref = horizFirst ? [ "right", "bottom" ] : [ "bottom", "right" ],
duration = options.duration / 2,
placeholder = $.effects.createPlaceholder( element ),
start = element.cssClip(),
animation1 = { clip: $.extend( {}, start ) },
animation2 = { clip: $.extend( {}, start ) },
distance = [ start[ ref[ 0 ] ], start[ ref[ 1 ] ] ],
queuelen = element.queue().length;
if ( percent ) {
2011-06-21 06:15:42 +00:00
size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ hide ? 0 : 1 ];
}
animation1.clip[ ref[ 0 ] ] = size;
animation2.clip[ ref[ 0 ] ] = size;
animation2.clip[ ref[ 1 ] ] = 0;
2011-06-21 06:15:42 +00:00
if ( show ) {
element.cssClip( animation2.clip );
if ( placeholder ) {
placeholder.css( $.effects.clipToBox( animation2 ) );
}
animation2.clip = start;
}
// Animate
element
.queue( function( next ) {
if ( placeholder ) {
placeholder
.animate( $.effects.clipToBox( animation1 ), duration, options.easing )
.animate( $.effects.clipToBox( animation2 ), duration, options.easing );
2011-06-21 06:15:42 +00:00
}
next();
} )
.animate( animation1, duration, options.easing )
.animate( animation2, duration, options.easing )
.queue( done );
$.effects.unshift( element, queuelen, 4 );
} );
} ) );