2 * jQuery UI Effects 1.9.0
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
= [],
251 // more than 1 argument specified - assume ( red, green, blue, alpha )
252 if ( green
!== undefined ) {
253 red
= [ red
, green
, blue
, alpha
];
257 if ( type
=== "string" ) {
258 return this.parse( stringParse( red
) || colors
._default
);
261 if ( type
=== "array" ) {
262 each( spaces
.rgba
.props
, function( key
, prop
) {
263 rgba
[ prop
.idx
] = clamp( red
[ prop
.idx
], prop
);
268 if ( type
=== "object" ) {
269 if ( red
instanceof color
) {
270 each( spaces
, function( spaceName
, space
) {
271 if ( red
[ space
.cache
] ) {
272 inst
[ space
.cache
] = red
[ space
.cache
].slice();
276 each( spaces
, function( spaceName
, space
) {
277 var cache
= space
.cache
;
278 each( space
.props
, function( key
, prop
) {
280 // if the cache doesn't exist, and we know how to convert
281 if ( !inst
[ cache
] && space
.to
) {
283 // if the value was null, we don't need to copy it
284 // if the key was alpha, we don't need to copy it either
285 if ( key
=== "alpha" || red
[ key
] == null ) {
288 inst
[ cache
] = space
.to( inst
._rgba
);
291 // this is the only case where we allow nulls for ALL properties.
292 // call clamp with alwaysAllowEmpty
293 inst
[ cache
][ prop
.idx
] = clamp( red
[ key
], prop
, true );
296 // everything defined but alpha?
297 if ( inst
[ cache
] && $.inArray( null, inst
[ cache
].slice( 0, 3 ) ) < 0 ) {
298 // use the default of 1
299 inst
[ cache
][ 3 ] = 1;
301 inst
._rgba
= space
.from( inst
[ cache
] );
309 is: function( compare
) {
310 var is
= color( compare
),
314 each( spaces
, function( _
, space
) {
316 isCache
= is
[ space
.cache
];
318 localCache
= inst
[ space
.cache
] || space
.to
&& space
.to( inst
._rgba
) || [];
319 each( space
.props
, function( _
, prop
) {
320 if ( isCache
[ prop
.idx
] != null ) {
321 same
= ( isCache
[ prop
.idx
] === localCache
[ prop
.idx
] );
333 each( spaces
, function( spaceName
, space
) {
334 if ( inst
[ space
.cache
] ) {
335 used
.push( spaceName
);
340 transition: function( other
, distance
) {
341 var end
= color( other
),
342 spaceName
= end
._space(),
343 space
= spaces
[ spaceName
],
344 startColor
= this.alpha() === 0 ? color( "transparent" ) : this,
345 start
= startColor
[ space
.cache
] || space
.to( startColor
._rgba
),
346 result
= start
.slice();
348 end
= end
[ space
.cache
];
349 each( space
.props
, function( key
, prop
) {
350 var index
= prop
.idx
,
351 startValue
= start
[ index
],
352 endValue
= end
[ index
],
353 type
= propTypes
[ prop
.type
] || {};
355 // if null, don't override start value
356 if ( endValue
=== null ) {
360 if ( startValue
=== null ) {
361 result
[ index
] = endValue
;
364 if ( endValue
- startValue
> type
.mod
/ 2 ) {
365 startValue
+= type
.mod
;
366 } else if ( startValue
- endValue
> type
.mod
/ 2 ) {
367 startValue
-= type
.mod
;
370 result
[ index
] = clamp( ( endValue
- startValue
) * distance
+ startValue
, prop
);
373 return this[ spaceName
]( result
);
375 blend: function( opaque
) {
376 // if we are already opaque - return ourself
377 if ( this._rgba
[ 3 ] === 1 ) {
381 var rgb
= this._rgba
.slice(),
383 blend
= color( opaque
)._rgba
;
385 return color( jQuery
.map( rgb
, function( v
, i
) {
386 return ( 1 - a
) * blend
[ i
] + a
* v
;
389 toRgbaString: function() {
390 var prefix
= "rgba(",
391 rgba
= jQuery
.map( this._rgba
, function( v
, i
) {
392 return v
== null ? ( i
> 2 ? 1 : 0 ) : v
;
395 if ( rgba
[ 3 ] === 1 ) {
400 return prefix
+ rgba
.join() + ")";
402 toHslaString: function() {
403 var prefix
= "hsla(",
404 hsla
= jQuery
.map( this.hsla(), function( v
, i
) {
411 v
= Math
.round( v
* 100 ) + "%";
416 if ( hsla
[ 3 ] === 1 ) {
420 return prefix
+ hsla
.join() + ")";
422 toHexString: function( includeAlpha
) {
423 var rgba
= this._rgba
.slice(),
426 if ( includeAlpha
) {
427 rgba
.push( ~~( alpha
* 255 ) );
430 return "#" + jQuery
.map( rgba
, function( v
, i
) {
432 // default to 0 when nulls exist
433 v
= ( v
|| 0 ).toString( 16 );
434 return v
.length
=== 1 ? "0" + v
: v
;
437 toString: function() {
438 return this._rgba
[ 3 ] === 0 ? "transparent" : this.toRgbaString();
441 color
.fn
.parse
.prototype = color
.fn
;
443 // hsla conversions adapted from:
444 // https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
446 function hue2rgb( p
, q
, h
) {
449 return p
+ (q
- p
) * h
* 6;
455 return p
+ (q
- p
) * ((2/3) - h
) * 6;
460 spaces
.hsla
.to = function ( rgba
) {
461 if ( rgba
[ 0 ] == null || rgba
[ 1 ] == null || rgba
[ 2 ] == null ) {
462 return [ null, null, null, rgba
[ 3 ] ];
464 var r
= rgba
[ 0 ] / 255,
468 max
= Math
.max( r
, g
, b
),
469 min
= Math
.min( r
, g
, b
),
477 } else if ( r
=== max
) {
478 h
= ( 60 * ( g
- b
) / diff
) + 360;
479 } else if ( g
=== max
) {
480 h
= ( 60 * ( b
- r
) / diff
) + 120;
482 h
= ( 60 * ( r
- g
) / diff
) + 240;
485 if ( l
=== 0 || l
=== 1 ) {
487 } else if ( l
<= 0.5 ) {
490 s
= diff
/ ( 2 - add
);
492 return [ Math
.round(h
) % 360, s
, l
, a
== null ? 1 : a
];
495 spaces
.hsla
.from = function ( hsla
) {
496 if ( hsla
[ 0 ] == null || hsla
[ 1 ] == null || hsla
[ 2 ] == null ) {
497 return [ null, null, null, hsla
[ 3 ] ];
499 var h
= hsla
[ 0 ] / 360,
503 q
= l
<= 0.5 ? l
* ( 1 + s
) : l
+ s
- l
* s
,
508 Math
.round( hue2rgb( p
, q
, h
+ ( 1 / 3 ) ) * 255 ),
509 Math
.round( hue2rgb( p
, q
, h
) * 255 ),
510 Math
.round( hue2rgb( p
, q
, h
- ( 1 / 3 ) ) * 255 ),
516 each( spaces
, function( spaceName
, space
) {
517 var props
= space
.props
,
522 // makes rgba() and hsla()
523 color
.fn
[ spaceName
] = function( value
) {
525 // generate a cache for this space if it doesn't exist
526 if ( to
&& !this[ cache
] ) {
527 this[ cache
] = to( this._rgba
);
529 if ( value
=== undefined ) {
530 return this[ cache
].slice();
534 type
= jQuery
.type( value
),
535 arr
= ( type
=== "array" || type
=== "object" ) ? value
: arguments
,
536 local
= this[ cache
].slice();
538 each( props
, function( key
, prop
) {
539 var val
= arr
[ type
=== "object" ? key
: prop
.idx
];
541 val
= local
[ prop
.idx
];
543 local
[ prop
.idx
] = clamp( val
, prop
);
547 ret
= color( from( local
) );
548 ret
[ cache
] = local
;
551 return color( local
);
555 // makes red() green() blue() alpha() hue() saturation() lightness()
556 each( props
, function( key
, prop
) {
557 // alpha is included in more than one space
558 if ( color
.fn
[ key
] ) {
561 color
.fn
[ key
] = function( value
) {
562 var vtype
= jQuery
.type( value
),
563 fn
= ( key
=== "alpha" ? ( this._hsla
? "hsla" : "rgba" ) : spaceName
),
564 local
= this[ fn
](),
565 cur
= local
[ prop
.idx
],
568 if ( vtype
=== "undefined" ) {
572 if ( vtype
=== "function" ) {
573 value
= value
.call( this, cur
);
574 vtype
= jQuery
.type( value
);
576 if ( value
== null && prop
.empty
) {
579 if ( vtype
=== "string" ) {
580 match
= rplusequals
.exec( value
);
582 value
= cur
+ parseFloat( match
[ 2 ] ) * ( match
[ 1 ] === "+" ? 1 : -1 );
585 local
[ prop
.idx
] = value
;
586 return this[ fn
]( local
);
591 // add .fx.step functions
592 each( stepHooks
, function( i
, hook
) {
593 jQuery
.cssHooks
[ hook
] = {
594 set: function( elem
, value
) {
596 backgroundColor
= "";
598 if ( jQuery
.type( value
) !== "string" || ( parsed
= stringParse( value
) ) ) {
599 value
= color( parsed
|| value
);
600 if ( !support
.rgba
&& value
._rgba
[ 3 ] !== 1 ) {
601 curElem
= hook
=== "backgroundColor" ? elem
.parentNode
: elem
;
603 (backgroundColor
=== "" || backgroundColor
=== "transparent") &&
604 curElem
&& curElem
.style
607 backgroundColor
= jQuery
.css( curElem
, "backgroundColor" );
608 curElem
= curElem
.parentNode
;
613 value
= value
.blend( backgroundColor
&& backgroundColor
!== "transparent" ?
618 value
= value
.toRgbaString();
621 elem
.style
[ hook
] = value
;
623 // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
627 jQuery
.fx
.step
[ hook
] = function( fx
) {
628 if ( !fx
.colorInit
) {
629 fx
.start
= color( fx
.elem
, hook
);
630 fx
.end
= color( fx
.end
);
633 jQuery
.cssHooks
[ hook
].set( fx
.elem
, fx
.start
.transition( fx
.end
, fx
.pos
) );
637 jQuery
.cssHooks
.borderColor
= {
638 expand: function( value
) {
641 each( [ "Top", "Right", "Bottom", "Left" ], function( i
, part
) {
642 expanded
[ "border" + part
+ "Color" ] = value
;
648 // Basic color names only.
649 // Usage of any of the other color names requires adding yourself or including
650 // jquery.color.svg-names.js.
651 colors
= jQuery
.Color
.names
= {
652 // 4.1. Basic color keywords
670 // 4.2.3. "transparent" color keyword
671 transparent
: [ null, null, null, 0 ],
680 /******************************************************************************/
681 /****************************** CLASS ANIMATIONS ******************************/
682 /******************************************************************************/
685 var classAnimationActions
= [ "add", "remove", "toggle" ],
698 $.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ], function( _
, prop
) {
699 $.fx
.step
[ prop
] = function( fx
) {
700 if ( fx
.end
!== "none" && !fx
.setAttr
|| fx
.pos
=== 1 && !fx
.setAttr
) {
701 jQuery
.style( fx
.elem
, prop
, fx
.end
);
707 function getElementStyles() {
708 var style
= this.ownerDocument
.defaultView
?
709 this.ownerDocument
.defaultView
.getComputedStyle( this, null ) :
716 // webkit enumerates style porperties
717 if ( style
&& style
.length
&& style
[ 0 ] && style
[ style
[ 0 ] ] ) {
721 if ( typeof style
[ key
] === "string" ) {
722 newStyle
[ $.camelCase( key
) ] = style
[ key
];
726 for ( key
in style
) {
727 if ( typeof style
[ key
] === "string" ) {
728 newStyle
[ key
] = style
[ key
];
737 function styleDifference( oldStyle
, newStyle
) {
741 for ( name
in newStyle
) {
742 value
= newStyle
[ name
];
743 if ( oldStyle
[ name
] !== value
) {
744 if ( !shorthandStyles
[ name
] ) {
745 if ( $.fx
.step
[ name
] || !isNaN( parseFloat( value
) ) ) {
746 diff
[ name
] = value
;
755 $.effects
.animateClass = function( value
, duration
, easing
, callback
) {
756 var o
= $.speed( duration
, easing
, callback
);
758 return this.queue( function() {
759 var animated
= $( this ),
760 baseClass
= animated
.attr( "class" ) || "",
762 allAnimations
= o
.children
? animated
.find( "*" ).andSelf() : animated
;
764 // map the animated objects to store the original styles.
765 allAnimations
= allAnimations
.map(function() {
769 start
: getElementStyles
.call( this )
773 // apply class change
774 applyClassChange = function() {
775 $.each( classAnimationActions
, function(i
, action
) {
776 if ( value
[ action
] ) {
777 animated
[ action
+ "Class" ]( value
[ action
] );
783 // map all animated objects again - calculate new styles and diff
784 allAnimations
= allAnimations
.map(function() {
785 this.end
= getElementStyles
.call( this.el
[ 0 ] );
786 this.diff
= styleDifference( this.start
, this.end
);
790 // apply original class
791 animated
.attr( "class", baseClass
);
793 // map all animated objects again - this time collecting a promise
794 allAnimations
= allAnimations
.map(function() {
795 var styleInfo
= this,
797 opts
= jQuery
.extend({}, o
, {
799 complete: function() {
800 dfd
.resolve( styleInfo
);
804 this.el
.animate( this.diff
, opts
);
805 return dfd
.promise();
808 // once all animations have completed:
809 $.when
.apply( $, allAnimations
.get() ).done(function() {
811 // set the final class
814 // for each animated element,
815 // clear all css properties that were animated
816 $.each( arguments
, function() {
818 $.each( this.diff
, function(key
) {
823 // this is guarnteed to be there if you use jQuery.speed()
824 // it also handles dequeuing the next anim...
825 o
.complete
.call( animated
[ 0 ] );
831 _addClass
: $.fn
.addClass
,
832 addClass: function( classNames
, speed
, easing
, callback
) {
834 $.effects
.animateClass
.call( this,
835 { add
: classNames
}, speed
, easing
, callback
) :
836 this._addClass( classNames
);
839 _removeClass
: $.fn
.removeClass
,
840 removeClass: function( classNames
, speed
, easing
, callback
) {
842 $.effects
.animateClass
.call( this,
843 { remove
: classNames
}, speed
, easing
, callback
) :
844 this._removeClass( classNames
);
847 _toggleClass
: $.fn
.toggleClass
,
848 toggleClass: function( classNames
, force
, speed
, easing
, callback
) {
849 if ( typeof force
=== "boolean" || force
=== undefined ) {
851 // without speed parameter
852 return this._toggleClass( classNames
, force
);
854 return $.effects
.animateClass
.call( this,
855 (force
? { add
: classNames
} : { remove
: classNames
}),
856 speed
, easing
, callback
);
859 // without force parameter
860 return $.effects
.animateClass
.call( this,
861 { toggle
: classNames
}, force
, speed
, easing
);
865 switchClass: function( remove
, add
, speed
, easing
, callback
) {
866 return $.effects
.animateClass
.call( this, {
869 }, speed
, easing
, callback
);
875 /******************************************************************************/
876 /*********************************** EFFECTS **********************************/
877 /******************************************************************************/
881 $.extend( $.effects
, {
884 // Saves a set of properties in a data storage
885 save: function( element
, set ) {
886 for( var i
=0; i
< set.length
; i
++ ) {
887 if ( set[ i
] !== null ) {
888 element
.data( dataSpace
+ set[ i
], element
[ 0 ].style
[ set[ i
] ] );
893 // Restores a set of previously saved properties from a data storage
894 restore: function( element
, set ) {
896 for( i
=0; i
< set.length
; i
++ ) {
897 if ( set[ i
] !== null ) {
898 val
= element
.data( dataSpace
+ set[ i
] );
899 // support: jQuery 1.6.2
900 // http://bugs.jquery.com/ticket/9917
901 // jQuery 1.6.2 incorrectly returns undefined for any falsy value.
902 // We can't differentiate between "" and 0 here, so we just assume
903 // empty string since it's likely to be a more common value...
904 if ( val
=== undefined ) {
907 element
.css( set[ i
], val
);
912 setMode: function( el
, mode
) {
913 if (mode
=== "toggle") {
914 mode
= el
.is( ":hidden" ) ? "show" : "hide";
919 // Translates a [top,left] array into a baseline value
920 // this should be a little more flexible in the future to handle a string & hash
921 getBaseline: function( origin
, original
) {
923 switch ( origin
[ 0 ] ) {
924 case "top": y
= 0; break;
925 case "middle": y
= 0.5; break;
926 case "bottom": y
= 1; break;
927 default: y
= origin
[ 0 ] / original
.height
;
929 switch ( origin
[ 1 ] ) {
930 case "left": x
= 0; break;
931 case "center": x
= 0.5; break;
932 case "right": x
= 1; break;
933 default: x
= origin
[ 1 ] / original
.width
;
941 // Wraps the element around a wrapper that copies position properties
942 createWrapper: function( element
) {
944 // if the element is already wrapped, return it
945 if ( element
.parent().is( ".ui-effects-wrapper" )) {
946 return element
.parent();
951 width
: element
.outerWidth(true),
952 height
: element
.outerHeight(true),
953 "float": element
.css( "float" )
955 wrapper
= $( "<div></div>" )
956 .addClass( "ui-effects-wrapper" )
959 background
: "transparent",
964 // Store the size in case width/height are defined in % - Fixes #5245
966 width
: element
.width(),
967 height
: element
.height()
969 active
= document
.activeElement
;
972 // Firefox incorrectly exposes anonymous content
973 // https://bugzilla.mozilla.org/show_bug.cgi?id=561664
977 active
= document
.body
;
980 element
.wrap( wrapper
);
982 // Fixes #7595 - Elements lose focus when wrapped.
983 if ( element
[ 0 ] === active
|| $.contains( element
[ 0 ], active
) ) {
987 wrapper
= element
.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
989 // transfer positioning properties to the wrapper
990 if ( element
.css( "position" ) === "static" ) {
991 wrapper
.css({ position
: "relative" });
992 element
.css({ position
: "relative" });
995 position
: element
.css( "position" ),
996 zIndex
: element
.css( "z-index" )
998 $.each([ "top", "left", "bottom", "right" ], function(i
, pos
) {
999 props
[ pos
] = element
.css( pos
);
1000 if ( isNaN( parseInt( props
[ pos
], 10 ) ) ) {
1001 props
[ pos
] = "auto";
1005 position
: "relative",
1014 return wrapper
.css( props
).show();
1017 removeWrapper: function( element
) {
1018 var active
= document
.activeElement
;
1020 if ( element
.parent().is( ".ui-effects-wrapper" ) ) {
1021 element
.parent().replaceWith( element
);
1023 // Fixes #7595 - Elements lose focus when wrapped.
1024 if ( element
[ 0 ] === active
|| $.contains( element
[ 0 ], active
) ) {
1025 $( active
).focus();
1033 setTransition: function( element
, list
, factor
, value
) {
1034 value
= value
|| {};
1035 $.each( list
, function( i
, x
) {
1036 var unit
= element
.cssUnit( x
);
1037 if ( unit
[ 0 ] > 0 ) {
1038 value
[ x
] = unit
[ 0 ] * factor
+ unit
[ 1 ];
1045 // return an effect options object for the given parameters:
1046 function _normalizeArguments( effect
, options
, speed
, callback
) {
1048 // allow passing all optinos as the first parameter
1049 if ( $.isPlainObject( effect
) ) {
1051 effect
= effect
.effect
;
1054 // convert to an object
1055 effect
= { effect
: effect
};
1058 if ( options
=== undefined ) {
1062 // catch (effect, callback)
1063 if ( $.isFunction( options
) ) {
1069 // catch (effect, speed, ?)
1070 if ( typeof options
=== "number" || $.fx
.speeds
[ options
] ) {
1076 // catch (effect, options, callback)
1077 if ( $.isFunction( speed
) ) {
1082 // add options to effect
1084 $.extend( effect
, options
);
1087 speed
= speed
|| options
.duration
;
1088 effect
.duration
= $.fx
.off
? 0 :
1089 typeof speed
=== "number" ? speed
:
1090 speed
in $.fx
.speeds
? $.fx
.speeds
[ speed
] :
1091 $.fx
.speeds
._default
;
1093 effect
.complete
= callback
|| options
.complete
;
1098 function standardSpeed( speed
) {
1099 // valid standard speeds
1100 if ( !speed
|| typeof speed
=== "number" || $.fx
.speeds
[ speed
] ) {
1104 // invalid strings - treat as "normal" speed
1105 if ( typeof speed
=== "string" && !$.effects
.effect
[ speed
] ) {
1106 // TODO: remove in 2.0 (#7115)
1107 if ( backCompat
&& $.effects
[ speed
] ) {
1117 effect: function( effect
, options
, speed
, callback
) {
1118 var args
= _normalizeArguments
.apply( this, arguments
),
1121 effectMethod
= $.effects
.effect
[ args
.effect
],
1123 // DEPRECATED: remove in 2.0 (#7115)
1124 oldEffectMethod
= !effectMethod
&& backCompat
&& $.effects
[ args
.effect
];
1126 if ( $.fx
.off
|| !( effectMethod
|| oldEffectMethod
) ) {
1127 // delegate to the original method (e.g., .show()) if possible
1129 return this[ mode
]( args
.duration
, args
.complete
);
1131 return this.each( function() {
1132 if ( args
.complete
) {
1133 args
.complete
.call( this );
1139 function run( next
) {
1140 var elem
= $( this ),
1141 complete
= args
.complete
,
1145 if ( $.isFunction( complete
) ) {
1146 complete
.call( elem
[0] );
1148 if ( $.isFunction( next
) ) {
1153 // if the element is hiddden and mode is hide,
1154 // or element is visible and mode is show
1155 if ( elem
.is( ":hidden" ) ? mode
=== "hide" : mode
=== "show" ) {
1158 effectMethod
.call( elem
[0], args
, done
);
1162 // TODO: remove this check in 2.0, effectMethod will always be true
1163 if ( effectMethod
) {
1164 return queue
=== false ? this.each( run
) : this.queue( queue
|| "fx", run
);
1166 // DEPRECATED: remove in 2.0 (#7115)
1167 return oldEffectMethod
.call(this, {
1169 duration
: args
.duration
,
1170 callback
: args
.complete
,
1177 show: function( speed
) {
1178 if ( standardSpeed( speed
) ) {
1179 return this._show
.apply( this, arguments
);
1181 var args
= _normalizeArguments
.apply( this, arguments
);
1183 return this.effect
.call( this, args
);
1188 hide: function( speed
) {
1189 if ( standardSpeed( speed
) ) {
1190 return this._hide
.apply( this, arguments
);
1192 var args
= _normalizeArguments
.apply( this, arguments
);
1194 return this.effect
.call( this, args
);
1198 // jQuery core overloads toggle and creates _toggle
1199 __toggle
: $.fn
.toggle
,
1200 toggle: function( speed
) {
1201 if ( standardSpeed( speed
) || typeof speed
=== "boolean" || $.isFunction( speed
) ) {
1202 return this.__toggle
.apply( this, arguments
);
1204 var args
= _normalizeArguments
.apply( this, arguments
);
1205 args
.mode
= "toggle";
1206 return this.effect
.call( this, args
);
1211 cssUnit: function(key
) {
1212 var style
= this.css( key
),
1215 $.each( [ "em", "px", "%", "pt" ], function( i
, unit
) {
1216 if ( style
.indexOf( unit
) > 0 ) {
1217 val
= [ parseFloat( style
), unit
];
1226 /******************************************************************************/
1227 /*********************************** EASING ***********************************/
1228 /******************************************************************************/
1232 // based on easing equations from Robert Penner (http://www.robertpenner.com/easing)
1234 var baseEasings
= {};
1236 $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i
, name
) {
1237 baseEasings
[ name
] = function( p
) {
1238 return Math
.pow( p
, i
+ 2 );
1242 $.extend( baseEasings
, {
1243 Sine: function ( p
) {
1244 return 1 - Math
.cos( p
* Math
.PI
/ 2 );
1246 Circ: function ( p
) {
1247 return 1 - Math
.sqrt( 1 - p
* p
);
1249 Elastic: function( p
) {
1250 return p
=== 0 || p
=== 1 ? p
:
1251 -Math
.pow( 2, 8 * (p
- 1) ) * Math
.sin( ( (p
- 1) * 80 - 7.5 ) * Math
.PI
/ 15 );
1253 Back: function( p
) {
1254 return p
* p
* ( 3 * p
- 2 );
1256 Bounce: function ( p
) {
1260 while ( p
< ( ( pow2
= Math
.pow( 2, --bounce
) ) - 1 ) / 11 ) {}
1261 return 1 / Math
.pow( 4, 3 - bounce
) - 7.5625 * Math
.pow( ( pow2
* 3 - 2 ) / 22 - p
, 2 );
1265 $.each( baseEasings
, function( name
, easeIn
) {
1266 $.easing
[ "easeIn" + name
] = easeIn
;
1267 $.easing
[ "easeOut" + name
] = function( p
) {
1268 return 1 - easeIn( 1 - p
);
1270 $.easing
[ "easeInOut" + name
] = function( p
) {
1272 easeIn( p
* 2 ) / 2 :
1273 1 - easeIn( p
* -2 + 2 ) / 2;