Skip to content

Commit f1a44a3

Browse files
committed
Effects Core: Upgrading jQuery Color to 2.1.1
1 parent 67b5bc7 commit f1a44a3

File tree

1 file changed

+58
-50
lines changed

1 file changed

+58
-50
lines changed

ui/jquery.ui.effect.js

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ $.effects = {
1919
};
2020

2121
/*!
22-
* jQuery Color Animations v2.0.0
23-
* http://jquery.com/
22+
* jQuery Color Animations v2.1.1
23+
* https://github.com/jquery/jquery-color
2424
*
2525
* Copyright 2012 jQuery Foundation and other contributors
2626
* Released under the MIT license.
2727
* http://jquery.org/license
2828
*
29-
* Date: Mon Aug 13 13:41:02 2012 -0500
29+
* Date: Sun Oct 28 15:08:06 2012 -0400
3030
*/
3131
(function( jQuery, undefined ) {
3232

33-
var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor".split(" "),
33+
var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
3434

3535
// plusequals test for += 100 -= 100
3636
rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
3737
// a set of RE's that can match strings and generate color tuples.
3838
stringParsers = [{
39-
re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
39+
re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
4040
parse: function( execResult ) {
4141
return [
4242
execResult[ 1 ],
@@ -46,7 +46,7 @@ $.effects = {
4646
];
4747
}
4848
}, {
49-
re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
49+
re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
5050
parse: function( execResult ) {
5151
return [
5252
execResult[ 1 ] * 2.55,
@@ -76,7 +76,7 @@ $.effects = {
7676
];
7777
}
7878
}, {
79-
re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
79+
re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
8080
space: "hsla",
8181
parse: function( execResult ) {
8282
return [
@@ -293,7 +293,7 @@ color.fn = jQuery.extend( color.prototype, {
293293
});
294294

295295
// everything defined but alpha?
296-
if ( inst[ cache ] && $.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
296+
if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
297297
// use the default of 1
298298
inst[ cache ][ 3 ] = 1;
299299
if ( space.from ) {
@@ -481,8 +481,10 @@ spaces.hsla.to = function ( rgba ) {
481481
h = ( 60 * ( r - g ) / diff ) + 240;
482482
}
483483

484-
if ( l === 0 || l === 1 ) {
485-
s = l;
484+
// chroma (diff) == 0 means greyscale which, by definition, saturation = 0%
485+
// otherwise, saturation is based on the ratio of chroma (diff) to lightness (add)
486+
if ( diff === 0 ) {
487+
s = 0;
486488
} else if ( l <= 0.5 ) {
487489
s = diff / add;
488490
} else {
@@ -586,51 +588,58 @@ each( spaces, function( spaceName, space ) {
586588
});
587589
});
588590

589-
// add .fx.step functions
590-
each( stepHooks, function( i, hook ) {
591-
jQuery.cssHooks[ hook ] = {
592-
set: function( elem, value ) {
593-
var parsed, curElem,
594-
backgroundColor = "";
595-
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;
600-
while (
601-
(backgroundColor === "" || backgroundColor === "transparent") &&
602-
curElem && curElem.style
603-
) {
604-
try {
605-
backgroundColor = jQuery.css( curElem, "backgroundColor" );
606-
curElem = curElem.parentNode;
607-
} catch ( e ) {
591+
// add cssHook and .fx.step function for each named hook.
592+
// accept a space separated string of properties
593+
color.hook = function( hook ) {
594+
var hooks = hook.split( " " );
595+
each( hooks, function( i, hook ) {
596+
jQuery.cssHooks[ hook ] = {
597+
set: function( elem, value ) {
598+
var parsed, curElem,
599+
backgroundColor = "";
600+
601+
if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) {
602+
value = color( parsed || value );
603+
if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
604+
curElem = hook === "backgroundColor" ? elem.parentNode : elem;
605+
while (
606+
(backgroundColor === "" || backgroundColor === "transparent") &&
607+
curElem && curElem.style
608+
) {
609+
try {
610+
backgroundColor = jQuery.css( curElem, "backgroundColor" );
611+
curElem = curElem.parentNode;
612+
} catch ( e ) {
613+
}
608614
}
615+
616+
value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
617+
backgroundColor :
618+
"_default" );
609619
}
610620

611-
value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
612-
backgroundColor :
613-
"_default" );
621+
value = value.toRgbaString();
622+
}
623+
try {
624+
elem.style[ hook ] = value;
625+
} catch( e ) {
626+
// wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
614627
}
615-
616-
value = value.toRgbaString();
617628
}
618-
try {
619-
elem.style[ hook ] = value;
620-
} catch( error ) {
621-
// wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
629+
};
630+
jQuery.fx.step[ hook ] = function( fx ) {
631+
if ( !fx.colorInit ) {
632+
fx.start = color( fx.elem, hook );
633+
fx.end = color( fx.end );
634+
fx.colorInit = true;
622635
}
623-
}
624-
};
625-
jQuery.fx.step[ hook ] = function( fx ) {
626-
if ( !fx.colorInit ) {
627-
fx.start = color( fx.elem, hook );
628-
fx.end = color( fx.end );
629-
fx.colorInit = true;
630-
}
631-
jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
632-
};
633-
});
636+
jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
637+
};
638+
});
639+
640+
};
641+
642+
color.hook( stepHooks );
634643

635644
jQuery.cssHooks.borderColor = {
636645
expand: function( value ) {
@@ -674,7 +683,6 @@ colors = jQuery.Color.names = {
674683
})( jQuery );
675684

676685

677-
678686
/******************************************************************************/
679687
/****************************** CLASS ANIMATIONS ******************************/
680688
/******************************************************************************/

0 commit comments

Comments
 (0)