2 * jQuery UI Effects 1.11.2
5 * Copyright 2014 jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/category/effects-core/
11 (function( factory ) {
12 if ( typeof define === "function" && define.amd ) {
14 // AMD. Register as an anonymous module.
15 define( [ "jquery" ], factory );
23 var dataSpace = "ui-effects-",
25 // Create a local jQuery because jQuery Color relies on it and the
26 // global may not exist with AMD and a custom build (#10199)
34 * jQuery Color Animations v2.1.2
35 * https://github.com/jquery/jquery-color
37 * Copyright 2014 jQuery Foundation and other contributors
38 * Released under the MIT license.
39 * http://jquery.org/license
41 * Date: Wed Jan 16 08:47:09 2013 -0600
43 (function( jQuery, undefined ) {
45 var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
47 // plusequals test for += 100 -= 100
48 rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
49 // a set of RE's that can match strings and generate color tuples.
51 re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
52 parse: function( execResult ) {
61 re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
62 parse: function( execResult ) {
64 execResult[ 1 ] * 2.55,
65 execResult[ 2 ] * 2.55,
66 execResult[ 3 ] * 2.55,
71 // this regex ignores A-F because it's compared against an already lowercased string
72 re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
73 parse: function( execResult ) {
75 parseInt( execResult[ 1 ], 16 ),
76 parseInt( execResult[ 2 ], 16 ),
77 parseInt( execResult[ 3 ], 16 )
81 // this regex ignores A-F because it's compared against an already lowercased string
82 re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
83 parse: function( execResult ) {
85 parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
86 parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
87 parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
91 re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
93 parse: function( execResult ) {
96 execResult[ 2 ] / 100,
97 execResult[ 3 ] / 100,
104 color = jQuery.Color = function( color, green, blue, alpha ) {
105 return new jQuery.Color.fn.parse( color, green, blue, alpha );
155 support = color.support = {},
157 // element for support tests
158 supportElem = jQuery( "<p>" )[ 0 ],
160 // colors = jQuery.Color.names
163 // local aliases of functions called often
166 // determine rgba support immediately
167 supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
168 support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
170 // define cache name and alpha properties
171 // for rgba and hsla spaces
172 each( spaces, function( spaceName, space ) {
173 space.cache = "_" + spaceName;
174 space.props.alpha = {
181 function clamp( value, prop, allowEmpty ) {
182 var type = propTypes[ prop.type ] || {};
184 if ( value == null ) {
185 return (allowEmpty || !prop.def) ? null : prop.def;
188 // ~~ is an short way of doing floor for positive numbers
189 value = type.floor ? ~~value : parseFloat( value );
191 // IE will pass in empty strings as value for alpha,
192 // which will hit this case
193 if ( isNaN( value ) ) {
198 // we add mod before modding to make sure that negatives values
199 // get converted properly: -10 -> 350
200 return (value + type.mod) % type.mod;
203 // for now all property types without mod have min and max
204 return 0 > value ? 0 : type.max < value ? type.max : value;
207 function stringParse( string ) {
209 rgba = inst._rgba = [];
211 string = string.toLowerCase();
213 each( stringParsers, function( i, parser ) {
215 match = parser.re.exec( string ),
216 values = match && parser.parse( match ),
217 spaceName = parser.space || "rgba";
220 parsed = inst[ spaceName ]( values );
222 // if this was an rgba parse the assignment might happen twice
224 inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
225 rgba = inst._rgba = parsed._rgba;
227 // exit each( stringParsers ) here because we matched
232 // Found a stringParser that handled it
235 // if this came from a parsed string, force "transparent" when alpha is 0
236 // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
237 if ( rgba.join() === "0,0,0,0" ) {
238 jQuery.extend( rgba, colors.transparent );
244 return colors[ string ];
247 color.fn = jQuery.extend( color.prototype, {
248 parse: function( red, green, blue, alpha ) {
249 if ( red === undefined ) {
250 this._rgba = [ null, null, null, null ];
253 if ( red.jquery || red.nodeType ) {
254 red = jQuery( red ).css( green );
259 type = jQuery.type( red ),
260 rgba = this._rgba = [];
262 // more than 1 argument specified - assume ( red, green, blue, alpha )
263 if ( green !== undefined ) {
264 red = [ red, green, blue, alpha ];
268 if ( type === "string" ) {
269 return this.parse( stringParse( red ) || colors._default );
272 if ( type === "array" ) {
273 each( spaces.rgba.props, function( key, prop ) {
274 rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
279 if ( type === "object" ) {
280 if ( red instanceof color ) {
281 each( spaces, function( spaceName, space ) {
282 if ( red[ space.cache ] ) {
283 inst[ space.cache ] = red[ space.cache ].slice();
287 each( spaces, function( spaceName, space ) {
288 var cache = space.cache;
289 each( space.props, function( key, prop ) {
291 // if the cache doesn't exist, and we know how to convert
292 if ( !inst[ cache ] && space.to ) {
294 // if the value was null, we don't need to copy it
295 // if the key was alpha, we don't need to copy it either
296 if ( key === "alpha" || red[ key ] == null ) {
299 inst[ cache ] = space.to( inst._rgba );
302 // this is the only case where we allow nulls for ALL properties.
303 // call clamp with alwaysAllowEmpty
304 inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
307 // everything defined but alpha?
308 if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
309 // use the default of 1
310 inst[ cache ][ 3 ] = 1;
312 inst._rgba = space.from( inst[ cache ] );
320 is: function( compare ) {
321 var is = color( compare ),
325 each( spaces, function( _, space ) {
327 isCache = is[ space.cache ];
329 localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
330 each( space.props, function( _, prop ) {
331 if ( isCache[ prop.idx ] != null ) {
332 same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
344 each( spaces, function( spaceName, space ) {
345 if ( inst[ space.cache ] ) {
346 used.push( spaceName );
351 transition: function( other, distance ) {
352 var end = color( other ),
353 spaceName = end._space(),
354 space = spaces[ spaceName ],
355 startColor = this.alpha() === 0 ? color( "transparent" ) : this,
356 start = startColor[ space.cache ] || space.to( startColor._rgba ),
357 result = start.slice();
359 end = end[ space.cache ];
360 each( space.props, function( key, prop ) {
361 var index = prop.idx,
362 startValue = start[ index ],
363 endValue = end[ index ],
364 type = propTypes[ prop.type ] || {};
366 // if null, don't override start value
367 if ( endValue === null ) {
371 if ( startValue === null ) {
372 result[ index ] = endValue;
375 if ( endValue - startValue > type.mod / 2 ) {
376 startValue += type.mod;
377 } else if ( startValue - endValue > type.mod / 2 ) {
378 startValue -= type.mod;
381 result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
384 return this[ spaceName ]( result );
386 blend: function( opaque ) {
387 // if we are already opaque - return ourself
388 if ( this._rgba[ 3 ] === 1 ) {
392 var rgb = this._rgba.slice(),
394 blend = color( opaque )._rgba;
396 return color( jQuery.map( rgb, function( v, i ) {
397 return ( 1 - a ) * blend[ i ] + a * v;
400 toRgbaString: function() {
401 var prefix = "rgba(",
402 rgba = jQuery.map( this._rgba, function( v, i ) {
403 return v == null ? ( i > 2 ? 1 : 0 ) : v;
406 if ( rgba[ 3 ] === 1 ) {
411 return prefix + rgba.join() + ")";
413 toHslaString: function() {
414 var prefix = "hsla(",
415 hsla = jQuery.map( this.hsla(), function( v, i ) {
422 v = Math.round( v * 100 ) + "%";
427 if ( hsla[ 3 ] === 1 ) {
431 return prefix + hsla.join() + ")";
433 toHexString: function( includeAlpha ) {
434 var rgba = this._rgba.slice(),
437 if ( includeAlpha ) {
438 rgba.push( ~~( alpha * 255 ) );
441 return "#" + jQuery.map( rgba, function( v ) {
443 // default to 0 when nulls exist
444 v = ( v || 0 ).toString( 16 );
445 return v.length === 1 ? "0" + v : v;
448 toString: function() {
449 return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
452 color.fn.parse.prototype = color.fn;
454 // hsla conversions adapted from:
455 // https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
457 function hue2rgb( p, q, h ) {
460 return p + ( q - p ) * h * 6;
466 return p + ( q - p ) * ( ( 2 / 3 ) - h ) * 6;
471 spaces.hsla.to = function( rgba ) {
472 if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
473 return [ null, null, null, rgba[ 3 ] ];
475 var r = rgba[ 0 ] / 255,
479 max = Math.max( r, g, b ),
480 min = Math.min( r, g, b ),
488 } else if ( r === max ) {
489 h = ( 60 * ( g - b ) / diff ) + 360;
490 } else if ( g === max ) {
491 h = ( 60 * ( b - r ) / diff ) + 120;
493 h = ( 60 * ( r - g ) / diff ) + 240;
496 // chroma (diff) == 0 means greyscale which, by definition, saturation = 0%
497 // otherwise, saturation is based on the ratio of chroma (diff) to lightness (add)
500 } else if ( l <= 0.5 ) {
503 s = diff / ( 2 - add );
505 return [ Math.round(h) % 360, s, l, a == null ? 1 : a ];
508 spaces.hsla.from = function( hsla ) {
509 if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
510 return [ null, null, null, hsla[ 3 ] ];
512 var h = hsla[ 0 ] / 360,
516 q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
520 Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
521 Math.round( hue2rgb( p, q, h ) * 255 ),
522 Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
527 each( spaces, function( spaceName, space ) {
528 var props = space.props,
533 // makes rgba() and hsla()
534 color.fn[ spaceName ] = function( value ) {
536 // generate a cache for this space if it doesn't exist
537 if ( to && !this[ cache ] ) {
538 this[ cache ] = to( this._rgba );
540 if ( value === undefined ) {
541 return this[ cache ].slice();
545 type = jQuery.type( value ),
546 arr = ( type === "array" || type === "object" ) ? value : arguments,
547 local = this[ cache ].slice();
549 each( props, function( key, prop ) {
550 var val = arr[ type === "object" ? key : prop.idx ];
552 val = local[ prop.idx ];
554 local[ prop.idx ] = clamp( val, prop );
558 ret = color( from( local ) );
559 ret[ cache ] = local;
562 return color( local );
566 // makes red() green() blue() alpha() hue() saturation() lightness()
567 each( props, function( key, prop ) {
568 // alpha is included in more than one space
569 if ( color.fn[ key ] ) {
572 color.fn[ key ] = function( value ) {
573 var vtype = jQuery.type( value ),
574 fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ),
575 local = this[ fn ](),
576 cur = local[ prop.idx ],
579 if ( vtype === "undefined" ) {
583 if ( vtype === "function" ) {
584 value = value.call( this, cur );
585 vtype = jQuery.type( value );
587 if ( value == null && prop.empty ) {
590 if ( vtype === "string" ) {
591 match = rplusequals.exec( value );
593 value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
596 local[ prop.idx ] = value;
597 return this[ fn ]( local );
602 // add cssHook and .fx.step function for each named hook.
603 // accept a space separated string of properties
604 color.hook = function( hook ) {
605 var hooks = hook.split( " " );
606 each( hooks, function( i, hook ) {
607 jQuery.cssHooks[ hook ] = {
608 set: function( elem, value ) {
610 backgroundColor = "";
612 if ( value !== "transparent" && ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) ) {
613 value = color( parsed || value );
614 if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
615 curElem = hook === "backgroundColor" ? elem.parentNode : elem;
617 (backgroundColor === "" || backgroundColor === "transparent") &&
618 curElem && curElem.style
621 backgroundColor = jQuery.css( curElem, "backgroundColor" );
622 curElem = curElem.parentNode;
627 value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
632 value = value.toRgbaString();
635 elem.style[ hook ] = value;
637 // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
641 jQuery.fx.step[ hook ] = function( fx ) {
642 if ( !fx.colorInit ) {
643 fx.start = color( fx.elem, hook );
644 fx.end = color( fx.end );
647 jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
653 color.hook( stepHooks );
655 jQuery.cssHooks.borderColor = {
656 expand: function( value ) {
659 each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
660 expanded[ "border" + part + "Color" ] = value;
666 // Basic color names only.
667 // Usage of any of the other color names requires adding yourself or including
668 // jquery.color.svg-names.js.
669 colors = jQuery.Color.names = {
670 // 4.1. Basic color keywords
688 // 4.2.3. "transparent" color keyword
689 transparent: [ null, null, null, 0 ],
696 /******************************************************************************/
697 /****************************** CLASS ANIMATIONS ******************************/
698 /******************************************************************************/
701 var classAnimationActions = [ "add", "remove", "toggle" ],
714 $.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ], function( _, prop ) {
715 $.fx.step[ prop ] = function( fx ) {
716 if ( fx.end !== "none" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) {
717 jQuery.style( fx.elem, prop, fx.end );
723 function getElementStyles( elem ) {
725 style = elem.ownerDocument.defaultView ?
726 elem.ownerDocument.defaultView.getComputedStyle( elem, null ) :
730 if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {
734 if ( typeof style[ key ] === "string" ) {
735 styles[ $.camelCase( key ) ] = style[ key ];
738 // support: Opera, IE <9
740 for ( key in style ) {
741 if ( typeof style[ key ] === "string" ) {
742 styles[ key ] = style[ key ];
750 function styleDifference( oldStyle, newStyle ) {
754 for ( name in newStyle ) {
755 value = newStyle[ name ];
756 if ( oldStyle[ name ] !== value ) {
757 if ( !shorthandStyles[ name ] ) {
758 if ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) {
759 diff[ name ] = value;
768 // support: jQuery <1.8
769 if ( !$.fn.addBack ) {
770 $.fn.addBack = function( selector ) {
771 return this.add( selector == null ?
772 this.prevObject : this.prevObject.filter( selector )
777 $.effects.animateClass = function( value, duration, easing, callback ) {
778 var o = $.speed( duration, easing, callback );
780 return this.queue( function() {
781 var animated = $( this ),
782 baseClass = animated.attr( "class" ) || "",
784 allAnimations = o.children ? animated.find( "*" ).addBack() : animated;
786 // map the animated objects to store the original styles.
787 allAnimations = allAnimations.map(function() {
791 start: getElementStyles( this )
795 // apply class change
796 applyClassChange = function() {
797 $.each( classAnimationActions, function(i, action) {
798 if ( value[ action ] ) {
799 animated[ action + "Class" ]( value[ action ] );
805 // map all animated objects again - calculate new styles and diff
806 allAnimations = allAnimations.map(function() {
807 this.end = getElementStyles( this.el[ 0 ] );
808 this.diff = styleDifference( this.start, this.end );
812 // apply original class
813 animated.attr( "class", baseClass );
815 // map all animated objects again - this time collecting a promise
816 allAnimations = allAnimations.map(function() {
817 var styleInfo = this,
819 opts = $.extend({}, o, {
821 complete: function() {
822 dfd.resolve( styleInfo );
826 this.el.animate( this.diff, opts );
827 return dfd.promise();
830 // once all animations have completed:
831 $.when.apply( $, allAnimations.get() ).done(function() {
833 // set the final class
836 // for each animated element,
837 // clear all css properties that were animated
838 $.each( arguments, function() {
840 $.each( this.diff, function(key) {
845 // this is guarnteed to be there if you use jQuery.speed()
846 // it also handles dequeuing the next anim...
847 o.complete.call( animated[ 0 ] );
853 addClass: (function( orig ) {
854 return function( classNames, speed, easing, callback ) {
856 $.effects.animateClass.call( this,
857 { add: classNames }, speed, easing, callback ) :
858 orig.apply( this, arguments );
862 removeClass: (function( orig ) {
863 return function( classNames, speed, easing, callback ) {
864 return arguments.length > 1 ?
865 $.effects.animateClass.call( this,
866 { remove: classNames }, speed, easing, callback ) :
867 orig.apply( this, arguments );
869 })( $.fn.removeClass ),
871 toggleClass: (function( orig ) {
872 return function( classNames, force, speed, easing, callback ) {
873 if ( typeof force === "boolean" || force === undefined ) {
875 // without speed parameter
876 return orig.apply( this, arguments );
878 return $.effects.animateClass.call( this,
879 (force ? { add: classNames } : { remove: classNames }),
880 speed, easing, callback );
883 // without force parameter
884 return $.effects.animateClass.call( this,
885 { toggle: classNames }, force, speed, easing );
888 })( $.fn.toggleClass ),
890 switchClass: function( remove, add, speed, easing, callback) {
891 return $.effects.animateClass.call( this, {
894 }, speed, easing, callback );
900 /******************************************************************************/
901 /*********************************** EFFECTS **********************************/
902 /******************************************************************************/
906 $.extend( $.effects, {
909 // Saves a set of properties in a data storage
910 save: function( element, set ) {
911 for ( var i = 0; i < set.length; i++ ) {
912 if ( set[ i ] !== null ) {
913 element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
918 // Restores a set of previously saved properties from a data storage
919 restore: function( element, set ) {
921 for ( i = 0; i < set.length; i++ ) {
922 if ( set[ i ] !== null ) {
923 val = element.data( dataSpace + set[ i ] );
924 // support: jQuery 1.6.2
925 // http://bugs.jquery.com/ticket/9917
926 // jQuery 1.6.2 incorrectly returns undefined for any falsy value.
927 // We can't differentiate between "" and 0 here, so we just assume
928 // empty string since it's likely to be a more common value...
929 if ( val === undefined ) {
932 element.css( set[ i ], val );
937 setMode: function( el, mode ) {
938 if (mode === "toggle") {
939 mode = el.is( ":hidden" ) ? "show" : "hide";
944 // Translates a [top,left] array into a baseline value
945 // this should be a little more flexible in the future to handle a string & hash
946 getBaseline: function( origin, original ) {
948 switch ( origin[ 0 ] ) {
949 case "top": y = 0; break;
950 case "middle": y = 0.5; break;
951 case "bottom": y = 1; break;
952 default: y = origin[ 0 ] / original.height;
954 switch ( origin[ 1 ] ) {
955 case "left": x = 0; break;
956 case "center": x = 0.5; break;
957 case "right": x = 1; break;
958 default: x = origin[ 1 ] / original.width;
966 // Wraps the element around a wrapper that copies position properties
967 createWrapper: function( element ) {
969 // if the element is already wrapped, return it
970 if ( element.parent().is( ".ui-effects-wrapper" )) {
971 return element.parent();
976 width: element.outerWidth(true),
977 height: element.outerHeight(true),
978 "float": element.css( "float" )
980 wrapper = $( "<div></div>" )
981 .addClass( "ui-effects-wrapper" )
984 background: "transparent",
989 // Store the size in case width/height are defined in % - Fixes #5245
991 width: element.width(),
992 height: element.height()
994 active = document.activeElement;
997 // Firefox incorrectly exposes anonymous content
998 // https://bugzilla.mozilla.org/show_bug.cgi?id=561664
1002 active = document.body;
1005 element.wrap( wrapper );
1007 // Fixes #7595 - Elements lose focus when wrapped.
1008 if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
1009 $( active ).focus();
1012 wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
1014 // transfer positioning properties to the wrapper
1015 if ( element.css( "position" ) === "static" ) {
1016 wrapper.css({ position: "relative" });
1017 element.css({ position: "relative" });
1020 position: element.css( "position" ),
1021 zIndex: element.css( "z-index" )
1023 $.each([ "top", "left", "bottom", "right" ], function(i, pos) {
1024 props[ pos ] = element.css( pos );
1025 if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
1026 props[ pos ] = "auto";
1030 position: "relative",
1039 return wrapper.css( props ).show();
1042 removeWrapper: function( element ) {
1043 var active = document.activeElement;
1045 if ( element.parent().is( ".ui-effects-wrapper" ) ) {
1046 element.parent().replaceWith( element );
1048 // Fixes #7595 - Elements lose focus when wrapped.
1049 if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
1050 $( active ).focus();
1057 setTransition: function( element, list, factor, value ) {
1058 value = value || {};
1059 $.each( list, function( i, x ) {
1060 var unit = element.cssUnit( x );
1061 if ( unit[ 0 ] > 0 ) {
1062 value[ x ] = unit[ 0 ] * factor + unit[ 1 ];
1069 // return an effect options object for the given parameters:
1070 function _normalizeArguments( effect, options, speed, callback ) {
1072 // allow passing all options as the first parameter
1073 if ( $.isPlainObject( effect ) ) {
1075 effect = effect.effect;
1078 // convert to an object
1079 effect = { effect: effect };
1081 // catch (effect, null, ...)
1082 if ( options == null ) {
1086 // catch (effect, callback)
1087 if ( $.isFunction( options ) ) {
1093 // catch (effect, speed, ?)
1094 if ( typeof options === "number" || $.fx.speeds[ options ] ) {
1100 // catch (effect, options, callback)
1101 if ( $.isFunction( speed ) ) {
1106 // add options to effect
1108 $.extend( effect, options );
1111 speed = speed || options.duration;
1112 effect.duration = $.fx.off ? 0 :
1113 typeof speed === "number" ? speed :
1114 speed in $.fx.speeds ? $.fx.speeds[ speed ] :
1115 $.fx.speeds._default;
1117 effect.complete = callback || options.complete;
1122 function standardAnimationOption( option ) {
1123 // Valid standard speeds (nothing, number, named speed)
1124 if ( !option || typeof option === "number" || $.fx.speeds[ option ] ) {
1128 // Invalid strings - treat as "normal" speed
1129 if ( typeof option === "string" && !$.effects.effect[ option ] ) {
1133 // Complete callback
1134 if ( $.isFunction( option ) ) {
1138 // Options hash (but not naming an effect)
1139 if ( typeof option === "object" && !option.effect ) {
1143 // Didn't match any standard API
1148 effect: function( /* effect, options, speed, callback */ ) {
1149 var args = _normalizeArguments.apply( this, arguments ),
1152 effectMethod = $.effects.effect[ args.effect ];
1154 if ( $.fx.off || !effectMethod ) {
1155 // delegate to the original method (e.g., .show()) if possible
1157 return this[ mode ]( args.duration, args.complete );
1159 return this.each( function() {
1160 if ( args.complete ) {
1161 args.complete.call( this );
1167 function run( next ) {
1168 var elem = $( this ),
1169 complete = args.complete,
1173 if ( $.isFunction( complete ) ) {
1174 complete.call( elem[0] );
1176 if ( $.isFunction( next ) ) {
1181 // If the element already has the correct final state, delegate to
1182 // the core methods so the internal tracking of "olddisplay" works.
1183 if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
1187 effectMethod.call( elem[0], args, done );
1191 return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
1194 show: (function( orig ) {
1195 return function( option ) {
1196 if ( standardAnimationOption( option ) ) {
1197 return orig.apply( this, arguments );
1199 var args = _normalizeArguments.apply( this, arguments );
1201 return this.effect.call( this, args );
1206 hide: (function( orig ) {
1207 return function( option ) {
1208 if ( standardAnimationOption( option ) ) {
1209 return orig.apply( this, arguments );
1211 var args = _normalizeArguments.apply( this, arguments );
1213 return this.effect.call( this, args );
1218 toggle: (function( orig ) {
1219 return function( option ) {
1220 if ( standardAnimationOption( option ) || typeof option === "boolean" ) {
1221 return orig.apply( this, arguments );
1223 var args = _normalizeArguments.apply( this, arguments );
1224 args.mode = "toggle";
1225 return this.effect.call( this, args );
1231 cssUnit: function(key) {
1232 var style = this.css( key ),
1235 $.each( [ "em", "px", "%", "pt" ], function( i, unit ) {
1236 if ( style.indexOf( unit ) > 0 ) {
1237 val = [ parseFloat( style ), unit ];
1246 /******************************************************************************/
1247 /*********************************** EASING ***********************************/
1248 /******************************************************************************/
1252 // based on easing equations from Robert Penner (http://www.robertpenner.com/easing)
1254 var baseEasings = {};
1256 $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) {
1257 baseEasings[ name ] = function( p ) {
1258 return Math.pow( p, i + 2 );
1262 $.extend( baseEasings, {
1263 Sine: function( p ) {
1264 return 1 - Math.cos( p * Math.PI / 2 );
1266 Circ: function( p ) {
1267 return 1 - Math.sqrt( 1 - p * p );
1269 Elastic: function( p ) {
1270 return p === 0 || p === 1 ? p :
1271 -Math.pow( 2, 8 * (p - 1) ) * Math.sin( ( (p - 1) * 80 - 7.5 ) * Math.PI / 15 );
1273 Back: function( p ) {
1274 return p * p * ( 3 * p - 2 );
1276 Bounce: function( p ) {
1280 while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
1281 return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
1285 $.each( baseEasings, function( name, easeIn ) {
1286 $.easing[ "easeIn" + name ] = easeIn;
1287 $.easing[ "easeOut" + name ] = function( p ) {
1288 return 1 - easeIn( 1 - p );
1290 $.easing[ "easeInOut" + name ] = function( p ) {
1292 easeIn( p * 2 ) / 2 :
1293 1 - easeIn( p * -2 + 2 ) / 2;