2 * jQuery UI Effects 1.9.2
5 * Copyright 2012 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 ;(jQuery.effects || (function($, undefined) {
13 var backCompat = $.uiBackCompat !== false,
14 // prefix used for storing data on .data()
15 dataSpace = "ui-effects-";
22 * jQuery Color Animations v2.0.0
25 * Copyright 2012 jQuery Foundation and other contributors
26 * Released under the MIT license.
27 * http://jquery.org/license
29 * Date: Mon Aug 13 13:41:02 2012 -0500
31 (function( jQuery, undefined ) {
33 var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor".split(" "),
35 // plusequals test for += 100 -= 100
36 rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
37 // a set of RE's that can match strings and generate color tuples.
39 re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
40 parse: function( execResult ) {
49 re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
50 parse: function( execResult ) {
52 execResult[ 1 ] * 2.55,
53 execResult[ 2 ] * 2.55,
54 execResult[ 3 ] * 2.55,
59 // this regex ignores A-F because it's compared against an already lowercased string
60 re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
61 parse: function( execResult ) {
63 parseInt( execResult[ 1 ], 16 ),
64 parseInt( execResult[ 2 ], 16 ),
65 parseInt( execResult[ 3 ], 16 )
69 // this regex ignores A-F because it's compared against an already lowercased string
70 re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
71 parse: function( execResult ) {
73 parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
74 parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
75 parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
79 re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
81 parse: function( execResult ) {
84 execResult[ 2 ] / 100,
85 execResult[ 3 ] / 100,
92 color = jQuery.Color = function( color, green, blue, alpha ) {
93 return new jQuery.Color.fn.parse( color, green, blue, alpha );
143 support = color.support = {},
145 // element for support tests
146 supportElem = jQuery( "<p>" )[ 0 ],
148 // colors = jQuery.Color.names
151 // local aliases of functions called often
154 // determine rgba support immediately
155 supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
156 support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
158 // define cache name and alpha properties
159 // for rgba and hsla spaces
160 each( spaces, function( spaceName, space ) {
161 space.cache = "_" + spaceName;
162 space.props.alpha = {
169 function clamp( value, prop, allowEmpty ) {
170 var type = propTypes[ prop.type ] || {};
172 if ( value == null ) {
173 return (allowEmpty || !prop.def) ? null : prop.def;
176 // ~~ is an short way of doing floor for positive numbers
177 value = type.floor ? ~~value : parseFloat( value );
179 // IE will pass in empty strings as value for alpha,
180 // which will hit this case
181 if ( isNaN( value ) ) {
186 // we add mod before modding to make sure that negatives values
187 // get converted properly: -10 -> 350
188 return (value + type.mod) % type.mod;
191 // for now all property types without mod have min and max
192 return 0 > value ? 0 : type.max < value ? type.max : value;
195 function stringParse( string ) {
197 rgba = inst._rgba = [];
199 string = string.toLowerCase();
201 each( stringParsers, function( i, parser ) {
203 match = parser.re.exec( string ),
204 values = match && parser.parse( match ),
205 spaceName = parser.space || "rgba";
208 parsed = inst[ spaceName ]( values );
210 // if this was an rgba parse the assignment might happen twice
212 inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
213 rgba = inst._rgba = parsed._rgba;
215 // exit each( stringParsers ) here because we matched
220 // Found a stringParser that handled it
223 // if this came from a parsed string, force "transparent" when alpha is 0
224 // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
225 if ( rgba.join() === "0,0,0,0" ) {
226 jQuery.extend( rgba, colors.transparent );
232 return colors[ string ];
235 color.fn = jQuery.extend( color.prototype, {
236 parse: function( red, green, blue, alpha ) {
237 if ( red === undefined ) {
238 this._rgba = [ null, null, null, null ];
241 if ( red.jquery || red.nodeType ) {
242 red = jQuery( red ).css( green );
247 type = jQuery.type( red ),
248 rgba = this._rgba = [];
250 // more than 1 argument specified - assume ( red, green, blue, alpha )
251 if ( green !== undefined ) {
252 red = [ red, green, blue, alpha ];
256 if ( type === "string" ) {
257 return this.parse( stringParse( red ) || colors._default );
260 if ( type === "array" ) {
261 each( spaces.rgba.props, function( key, prop ) {
262 rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
267 if ( type === "object" ) {
268 if ( red instanceof color ) {
269 each( spaces, function( spaceName, space ) {
270 if ( red[ space.cache ] ) {
271 inst[ space.cache ] = red[ space.cache ].slice();
275 each( spaces, function( spaceName, space ) {
276 var cache = space.cache;
277 each( space.props, function( key, prop ) {
279 // if the cache doesn't exist, and we know how to convert
280 if ( !inst[ cache ] && space.to ) {
282 // if the value was null, we don't need to copy it
283 // if the key was alpha, we don't need to copy it either
284 if ( key === "alpha" || red[ key ] == null ) {
287 inst[ cache ] = space.to( inst._rgba );
290 // this is the only case where we allow nulls for ALL properties.
291 // call clamp with alwaysAllowEmpty
292 inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
295 // everything defined but alpha?
296 if ( inst[ cache ] && $.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
297 // use the default of 1
298 inst[ cache ][ 3 ] = 1;
300 inst._rgba = space.from( inst[ cache ] );
308 is: function( compare ) {
309 var is = color( compare ),
313 each( spaces, function( _, space ) {
315 isCache = is[ space.cache ];
317 localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
318 each( space.props, function( _, prop ) {
319 if ( isCache[ prop.idx ] != null ) {
320 same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
332 each( spaces, function( spaceName, space ) {
333 if ( inst[ space.cache ] ) {
334 used.push( spaceName );
339 transition: function( other, distance ) {
340 var end = color( other ),
341 spaceName = end._space(),
342 space = spaces[ spaceName ],
343 startColor = this.alpha() === 0 ? color( "transparent" ) : this,
344 start = startColor[ space.cache ] || space.to( startColor._rgba ),
345 result = start.slice();
347 end = end[ space.cache ];
348 each( space.props, function( key, prop ) {
349 var index = prop.idx,
350 startValue = start[ index ],
351 endValue = end[ index ],
352 type = propTypes[ prop.type ] || {};
354 // if null, don't override start value
355 if ( endValue === null ) {
359 if ( startValue === null ) {
360 result[ index ] = endValue;
363 if ( endValue - startValue > type.mod / 2 ) {
364 startValue += type.mod;
365 } else if ( startValue - endValue > type.mod / 2 ) {
366 startValue -= type.mod;
369 result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
372 return this[ spaceName ]( result );
374 blend: function( opaque ) {
375 // if we are already opaque - return ourself
376 if ( this._rgba[ 3 ] === 1 ) {
380 var rgb = this._rgba.slice(),
382 blend = color( opaque )._rgba;
384 return color( jQuery.map( rgb, function( v, i ) {
385 return ( 1 - a ) * blend[ i ] + a * v;
388 toRgbaString: function() {
389 var prefix = "rgba(",
390 rgba = jQuery.map( this._rgba, function( v, i ) {
391 return v == null ? ( i > 2 ? 1 : 0 ) : v;
394 if ( rgba[ 3 ] === 1 ) {
399 return prefix + rgba.join() + ")";
401 toHslaString: function() {
402 var prefix = "hsla(",
403 hsla = jQuery.map( this.hsla(), function( v, i ) {
410 v = Math.round( v * 100 ) + "%";
415 if ( hsla[ 3 ] === 1 ) {
419 return prefix + hsla.join() + ")";
421 toHexString: function( includeAlpha ) {
422 var rgba = this._rgba.slice(),
425 if ( includeAlpha ) {
426 rgba.push( ~~( alpha * 255 ) );
429 return "#" + jQuery.map( rgba, function( v ) {
431 // default to 0 when nulls exist
432 v = ( v || 0 ).toString( 16 );
433 return v.length === 1 ? "0" + v : v;
436 toString: function() {
437 return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
440 color.fn.parse.prototype = color.fn;
442 // hsla conversions adapted from:
443 // https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
445 function hue2rgb( p, q, h ) {
448 return p + (q - p) * h * 6;
454 return p + (q - p) * ((2/3) - h) * 6;
459 spaces.hsla.to = function ( rgba ) {
460 if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
461 return [ null, null, null, rgba[ 3 ] ];
463 var r = rgba[ 0 ] / 255,
467 max = Math.max( r, g, b ),
468 min = Math.min( r, g, b ),
476 } else if ( r === max ) {
477 h = ( 60 * ( g - b ) / diff ) + 360;
478 } else if ( g === max ) {
479 h = ( 60 * ( b - r ) / diff ) + 120;
481 h = ( 60 * ( r - g ) / diff ) + 240;
484 if ( l === 0 || l === 1 ) {
486 } else if ( l <= 0.5 ) {
489 s = diff / ( 2 - add );
491 return [ Math.round(h) % 360, s, l, a == null ? 1 : a ];
494 spaces.hsla.from = function ( hsla ) {
495 if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
496 return [ null, null, null, hsla[ 3 ] ];
498 var h = hsla[ 0 ] / 360,
502 q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
506 Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
507 Math.round( hue2rgb( p, q, h ) * 255 ),
508 Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
514 each( spaces, function( spaceName, space ) {
515 var props = space.props,
520 // makes rgba() and hsla()
521 color.fn[ spaceName ] = function( value ) {
523 // generate a cache for this space if it doesn't exist
524 if ( to && !this[ cache ] ) {
525 this[ cache ] = to( this._rgba );
527 if ( value === undefined ) {
528 return this[ cache ].slice();
532 type = jQuery.type( value ),
533 arr = ( type === "array" || type === "object" ) ? value : arguments,
534 local = this[ cache ].slice();
536 each( props, function( key, prop ) {
537 var val = arr[ type === "object" ? key : prop.idx ];
539 val = local[ prop.idx ];
541 local[ prop.idx ] = clamp( val, prop );
545 ret = color( from( local ) );
546 ret[ cache ] = local;
549 return color( local );
553 // makes red() green() blue() alpha() hue() saturation() lightness()
554 each( props, function( key, prop ) {
555 // alpha is included in more than one space
556 if ( color.fn[ key ] ) {
559 color.fn[ key ] = function( value ) {
560 var vtype = jQuery.type( value ),
561 fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ),
562 local = this[ fn ](),
563 cur = local[ prop.idx ],
566 if ( vtype === "undefined" ) {
570 if ( vtype === "function" ) {
571 value = value.call( this, cur );
572 vtype = jQuery.type( value );
574 if ( value == null && prop.empty ) {
577 if ( vtype === "string" ) {
578 match = rplusequals.exec( value );
580 value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
583 local[ prop.idx ] = value;
584 return this[ fn ]( local );
589 // add .fx.step functions
590 each( stepHooks, function( i, hook ) {
591 jQuery.cssHooks[ hook ] = {
592 set: function( elem, value ) {
594 backgroundColor = "";
596 if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) {
597 value = color( parsed || value );
598 if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
599 curElem = hook === "backgroundColor" ? elem.parentNode : elem;
601 (backgroundColor === "" || backgroundColor === "transparent") &&
602 curElem && curElem.style
605 backgroundColor = jQuery.css( curElem, "backgroundColor" );
606 curElem = curElem.parentNode;
611 value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
616 value = value.toRgbaString();
619 elem.style[ hook ] = value;
621 // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
625 jQuery.fx.step[ hook ] = function( fx ) {
626 if ( !fx.colorInit ) {
627 fx.start = color( fx.elem, hook );
628 fx.end = color( fx.end );
631 jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
635 jQuery.cssHooks.borderColor = {
636 expand: function( value ) {
639 each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
640 expanded[ "border" + part + "Color" ] = value;
646 // Basic color names only.
647 // Usage of any of the other color names requires adding yourself or including
648 // jquery.color.svg-names.js.
649 colors = jQuery.Color.names = {
650 // 4.1. Basic color keywords
668 // 4.2.3. "transparent" color keyword
669 transparent: [ null, null, null, 0 ],
678 /******************************************************************************/
679 /****************************** CLASS ANIMATIONS ******************************/
680 /******************************************************************************/
683 var classAnimationActions = [ "add", "remove", "toggle" ],
696 $.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ], function( _, prop ) {
697 $.fx.step[ prop ] = function( fx ) {
698 if ( fx.end !== "none" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) {
699 jQuery.style( fx.elem, prop, fx.end );
705 function getElementStyles() {
706 var style = this.ownerDocument.defaultView ?
707 this.ownerDocument.defaultView.getComputedStyle( this, null ) :
713 // webkit enumerates style porperties
714 if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {
718 if ( typeof style[ key ] === "string" ) {
719 newStyle[ $.camelCase( key ) ] = style[ key ];
723 for ( key in style ) {
724 if ( typeof style[ key ] === "string" ) {
725 newStyle[ key ] = style[ key ];
734 function styleDifference( oldStyle, newStyle ) {
738 for ( name in newStyle ) {
739 value = newStyle[ name ];
740 if ( oldStyle[ name ] !== value ) {
741 if ( !shorthandStyles[ name ] ) {
742 if ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) {
743 diff[ name ] = value;
752 $.effects.animateClass = function( value, duration, easing, callback ) {
753 var o = $.speed( duration, easing, callback );
755 return this.queue( function() {
756 var animated = $( this ),
757 baseClass = animated.attr( "class" ) || "",
759 allAnimations = o.children ? animated.find( "*" ).andSelf() : animated;
761 // map the animated objects to store the original styles.
762 allAnimations = allAnimations.map(function() {
766 start: getElementStyles.call( this )
770 // apply class change
771 applyClassChange = function() {
772 $.each( classAnimationActions, function(i, action) {
773 if ( value[ action ] ) {
774 animated[ action + "Class" ]( value[ action ] );
780 // map all animated objects again - calculate new styles and diff
781 allAnimations = allAnimations.map(function() {
782 this.end = getElementStyles.call( this.el[ 0 ] );
783 this.diff = styleDifference( this.start, this.end );
787 // apply original class
788 animated.attr( "class", baseClass );
790 // map all animated objects again - this time collecting a promise
791 allAnimations = allAnimations.map(function() {
792 var styleInfo = this,
794 opts = jQuery.extend({}, o, {
796 complete: function() {
797 dfd.resolve( styleInfo );
801 this.el.animate( this.diff, opts );
802 return dfd.promise();
805 // once all animations have completed:
806 $.when.apply( $, allAnimations.get() ).done(function() {
808 // set the final class
811 // for each animated element,
812 // clear all css properties that were animated
813 $.each( arguments, function() {
815 $.each( this.diff, function(key) {
820 // this is guarnteed to be there if you use jQuery.speed()
821 // it also handles dequeuing the next anim...
822 o.complete.call( animated[ 0 ] );
828 _addClass: $.fn.addClass,
829 addClass: function( classNames, speed, easing, callback ) {
831 $.effects.animateClass.call( this,
832 { add: classNames }, speed, easing, callback ) :
833 this._addClass( classNames );
836 _removeClass: $.fn.removeClass,
837 removeClass: function( classNames, speed, easing, callback ) {
839 $.effects.animateClass.call( this,
840 { remove: classNames }, speed, easing, callback ) :
841 this._removeClass( classNames );
844 _toggleClass: $.fn.toggleClass,
845 toggleClass: function( classNames, force, speed, easing, callback ) {
846 if ( typeof force === "boolean" || force === undefined ) {
848 // without speed parameter
849 return this._toggleClass( classNames, force );
851 return $.effects.animateClass.call( this,
852 (force ? { add: classNames } : { remove: classNames }),
853 speed, easing, callback );
856 // without force parameter
857 return $.effects.animateClass.call( this,
858 { toggle: classNames }, force, speed, easing );
862 switchClass: function( remove, add, speed, easing, callback) {
863 return $.effects.animateClass.call( this, {
866 }, speed, easing, callback );
872 /******************************************************************************/
873 /*********************************** EFFECTS **********************************/
874 /******************************************************************************/
878 $.extend( $.effects, {
881 // Saves a set of properties in a data storage
882 save: function( element, set ) {
883 for( var i=0; i < set.length; i++ ) {
884 if ( set[ i ] !== null ) {
885 element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
890 // Restores a set of previously saved properties from a data storage
891 restore: function( element, set ) {
893 for( i=0; i < set.length; i++ ) {
894 if ( set[ i ] !== null ) {
895 val = element.data( dataSpace + set[ i ] );
896 // support: jQuery 1.6.2
897 // http://bugs.jquery.com/ticket/9917
898 // jQuery 1.6.2 incorrectly returns undefined for any falsy value.
899 // We can't differentiate between "" and 0 here, so we just assume
900 // empty string since it's likely to be a more common value...
901 if ( val === undefined ) {
904 element.css( set[ i ], val );
909 setMode: function( el, mode ) {
910 if (mode === "toggle") {
911 mode = el.is( ":hidden" ) ? "show" : "hide";
916 // Translates a [top,left] array into a baseline value
917 // this should be a little more flexible in the future to handle a string & hash
918 getBaseline: function( origin, original ) {
920 switch ( origin[ 0 ] ) {
921 case "top": y = 0; break;
922 case "middle": y = 0.5; break;
923 case "bottom": y = 1; break;
924 default: y = origin[ 0 ] / original.height;
926 switch ( origin[ 1 ] ) {
927 case "left": x = 0; break;
928 case "center": x = 0.5; break;
929 case "right": x = 1; break;
930 default: x = origin[ 1 ] / original.width;
938 // Wraps the element around a wrapper that copies position properties
939 createWrapper: function( element ) {
941 // if the element is already wrapped, return it
942 if ( element.parent().is( ".ui-effects-wrapper" )) {
943 return element.parent();
948 width: element.outerWidth(true),
949 height: element.outerHeight(true),
950 "float": element.css( "float" )
952 wrapper = $( "<div></div>" )
953 .addClass( "ui-effects-wrapper" )
956 background: "transparent",
961 // Store the size in case width/height are defined in % - Fixes #5245
963 width: element.width(),
964 height: element.height()
966 active = document.activeElement;
969 // Firefox incorrectly exposes anonymous content
970 // https://bugzilla.mozilla.org/show_bug.cgi?id=561664
974 active = document.body;
977 element.wrap( wrapper );
979 // Fixes #7595 - Elements lose focus when wrapped.
980 if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
984 wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
986 // transfer positioning properties to the wrapper
987 if ( element.css( "position" ) === "static" ) {
988 wrapper.css({ position: "relative" });
989 element.css({ position: "relative" });
992 position: element.css( "position" ),
993 zIndex: element.css( "z-index" )
995 $.each([ "top", "left", "bottom", "right" ], function(i, pos) {
996 props[ pos ] = element.css( pos );
997 if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
998 props[ pos ] = "auto";
1002 position: "relative",
1011 return wrapper.css( props ).show();
1014 removeWrapper: function( element ) {
1015 var active = document.activeElement;
1017 if ( element.parent().is( ".ui-effects-wrapper" ) ) {
1018 element.parent().replaceWith( element );
1020 // Fixes #7595 - Elements lose focus when wrapped.
1021 if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
1022 $( active ).focus();
1030 setTransition: function( element, list, factor, value ) {
1031 value = value || {};
1032 $.each( list, function( i, x ) {
1033 var unit = element.cssUnit( x );
1034 if ( unit[ 0 ] > 0 ) {
1035 value[ x ] = unit[ 0 ] * factor + unit[ 1 ];
1042 // return an effect options object for the given parameters:
1043 function _normalizeArguments( effect, options, speed, callback ) {
1045 // allow passing all options as the first parameter
1046 if ( $.isPlainObject( effect ) ) {
1048 effect = effect.effect;
1051 // convert to an object
1052 effect = { effect: effect };
1054 // catch (effect, null, ...)
1055 if ( options == null ) {
1059 // catch (effect, callback)
1060 if ( $.isFunction( options ) ) {
1066 // catch (effect, speed, ?)
1067 if ( typeof options === "number" || $.fx.speeds[ options ] ) {
1073 // catch (effect, options, callback)
1074 if ( $.isFunction( speed ) ) {
1079 // add options to effect
1081 $.extend( effect, options );
1084 speed = speed || options.duration;
1085 effect.duration = $.fx.off ? 0 :
1086 typeof speed === "number" ? speed :
1087 speed in $.fx.speeds ? $.fx.speeds[ speed ] :
1088 $.fx.speeds._default;
1090 effect.complete = callback || options.complete;
1095 function standardSpeed( speed ) {
1096 // valid standard speeds
1097 if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) {
1101 // invalid strings - treat as "normal" speed
1102 if ( typeof speed === "string" && !$.effects.effect[ speed ] ) {
1103 // TODO: remove in 2.0 (#7115)
1104 if ( backCompat && $.effects[ speed ] ) {
1114 effect: function( /* effect, options, speed, callback */ ) {
1115 var args = _normalizeArguments.apply( this, arguments ),
1118 effectMethod = $.effects.effect[ args.effect ],
1120 // DEPRECATED: remove in 2.0 (#7115)
1121 oldEffectMethod = !effectMethod && backCompat && $.effects[ args.effect ];
1123 if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) {
1124 // delegate to the original method (e.g., .show()) if possible
1126 return this[ mode ]( args.duration, args.complete );
1128 return this.each( function() {
1129 if ( args.complete ) {
1130 args.complete.call( this );
1136 function run( next ) {
1137 var elem = $( this ),
1138 complete = args.complete,
1142 if ( $.isFunction( complete ) ) {
1143 complete.call( elem[0] );
1145 if ( $.isFunction( next ) ) {
1150 // if the element is hiddden and mode is hide,
1151 // or element is visible and mode is show
1152 if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
1155 effectMethod.call( elem[0], args, done );
1159 // TODO: remove this check in 2.0, effectMethod will always be true
1160 if ( effectMethod ) {
1161 return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
1163 // DEPRECATED: remove in 2.0 (#7115)
1164 return oldEffectMethod.call(this, {
1166 duration: args.duration,
1167 callback: args.complete,
1174 show: function( speed ) {
1175 if ( standardSpeed( speed ) ) {
1176 return this._show.apply( this, arguments );
1178 var args = _normalizeArguments.apply( this, arguments );
1180 return this.effect.call( this, args );
1185 hide: function( speed ) {
1186 if ( standardSpeed( speed ) ) {
1187 return this._hide.apply( this, arguments );
1189 var args = _normalizeArguments.apply( this, arguments );
1191 return this.effect.call( this, args );
1195 // jQuery core overloads toggle and creates _toggle
1196 __toggle: $.fn.toggle,
1197 toggle: function( speed ) {
1198 if ( standardSpeed( speed ) || typeof speed === "boolean" || $.isFunction( speed ) ) {
1199 return this.__toggle.apply( this, arguments );
1201 var args = _normalizeArguments.apply( this, arguments );
1202 args.mode = "toggle";
1203 return this.effect.call( this, args );
1208 cssUnit: function(key) {
1209 var style = this.css( key ),
1212 $.each( [ "em", "px", "%", "pt" ], function( i, unit ) {
1213 if ( style.indexOf( unit ) > 0 ) {
1214 val = [ parseFloat( style ), unit ];
1223 /******************************************************************************/
1224 /*********************************** EASING ***********************************/
1225 /******************************************************************************/
1229 // based on easing equations from Robert Penner (http://www.robertpenner.com/easing)
1231 var baseEasings = {};
1233 $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) {
1234 baseEasings[ name ] = function( p ) {
1235 return Math.pow( p, i + 2 );
1239 $.extend( baseEasings, {
1240 Sine: function ( p ) {
1241 return 1 - Math.cos( p * Math.PI / 2 );
1243 Circ: function ( p ) {
1244 return 1 - Math.sqrt( 1 - p * p );
1246 Elastic: function( p ) {
1247 return p === 0 || p === 1 ? p :
1248 -Math.pow( 2, 8 * (p - 1) ) * Math.sin( ( (p - 1) * 80 - 7.5 ) * Math.PI / 15 );
1250 Back: function( p ) {
1251 return p * p * ( 3 * p - 2 );
1253 Bounce: function ( p ) {
1257 while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
1258 return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
1262 $.each( baseEasings, function( name, easeIn ) {
1263 $.easing[ "easeIn" + name ] = easeIn;
1264 $.easing[ "easeOut" + name ] = function( p ) {
1265 return 1 - easeIn( 1 - p );
1267 $.easing[ "easeInOut" + name ] = function( p ) {
1269 easeIn( p * 2 ) / 2 :
1270 1 - easeIn( p * -2 + 2 ) / 2;