Skip to content

Commit ac020a1

Browse files
committed
Revert "Core: Drop workarounds for IE <9"
This reverts commit fff7a1b. It also updates README to mention details relevant for jQuery Color 2.x.
1 parent f4d0fd8 commit ac020a1

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ Supported jQuery versions: 1.5+
66

77
## Browser Support
88

9-
jQuery Color 3.x supports the following browsers:
9+
jQuery Color 2.x supports the following browsers:
1010

1111
Desktop:
1212
* Chrome: (Current - 1) and Current
1313
* Edge: (Current - 1) and Current, 18
1414
* Firefox: (Current - 1) and Current, ESR
15-
* Internet Explorer: 9+
16-
* Safari: (Current - 1) and Current
15+
* Internet Explorer: 6+
16+
* Safari: 5.1+
1717
* Opera: Current
1818

1919
Mobile:
20-
* Chrome on Android: (Current - 1) and Current
21-
* Safari on iOS: (Current - 2), (Current - 1) and Current
22-
23-
Information on browser support of jQuery Color 2.x can be found in the [Browser Support section](https://github.com/jquery/jquery-color/blob/2.x-stable/README.md#browser-support) in its README.
20+
* Stock browser on Android 4.0+
21+
* Safari on iOS 7+
2422

2523
## Using jQuery Color in Production
2624
We release jQuery Color by itself, or in a bundle. The extended names can be included as a jQuery Color plugin, or you can download the version of jQuery Color that includes the names. Choose your build from the following list:

jquery.color.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,21 @@
145145
floor: true
146146
}
147147
},
148+
support = color.support = {},
149+
150+
// element for support tests
151+
supportElem = jQuery( "<p>" )[ 0 ],
148152

149153
// colors = jQuery.Color.names
150154
colors,
151155

152156
// local aliases of functions called often
153157
each = jQuery.each;
154158

159+
// determine rgba support immediately
160+
supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
161+
support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
162+
155163
// define cache name and alpha properties
156164
// for rgba and hsla spaces
157165
each( spaces, function( spaceName, space ) {
@@ -189,6 +197,12 @@ function clamp( value, prop, allowEmpty ) {
189197
// ~~ is an short way of doing floor for positive numbers
190198
value = type.floor ? ~~value : parseFloat( value );
191199

200+
// IE will pass in empty strings as value for alpha,
201+
// which will hit this case
202+
if ( isNaN( value ) ) {
203+
return prop.def;
204+
}
205+
192206
if ( type.mod ) {
193207

194208
// we add mod before modding to make sure that negatives values
@@ -446,7 +460,8 @@ color.fn = jQuery.extend( color.prototype, {
446460
return "#" + jQuery.map( rgba, function( v ) {
447461

448462
// default to 0 when nulls exist
449-
return ( "0" + ( v || 0 ).toString( 16 ) ).substr( -2 );
463+
v = ( v || 0 ).toString( 16 );
464+
return v.length === 1 ? "0" + v : v;
450465
} ).join( "" );
451466
},
452467
toString: function() {
@@ -617,13 +632,36 @@ color.hook = function( hook ) {
617632
each( hooks, function( _i, hook ) {
618633
jQuery.cssHooks[ hook ] = {
619634
set: function( elem, value ) {
620-
var parsed;
635+
var parsed, curElem,
636+
backgroundColor = "";
621637

622638
if ( value !== "transparent" && ( getType( value ) !== "string" || ( parsed = stringParse( value ) ) ) ) {
623639
value = color( parsed || value );
640+
if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
641+
curElem = hook === "backgroundColor" ? elem.parentNode : elem;
642+
while (
643+
(backgroundColor === "" || backgroundColor === "transparent") &&
644+
curElem && curElem.style
645+
) {
646+
try {
647+
backgroundColor = jQuery.css( curElem, "backgroundColor" );
648+
curElem = curElem.parentNode;
649+
} catch ( e ) {
650+
}
651+
}
652+
653+
value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
654+
backgroundColor :
655+
"_default" );
656+
}
657+
624658
value = value.toRgbaString();
625659
}
626-
elem.style[ hook ] = value;
660+
try {
661+
elem.style[ hook ] = value;
662+
} catch( e ) {
663+
// wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
664+
}
627665
}
628666
};
629667
jQuery.fx.step[ hook ] = function( fx ) {

0 commit comments

Comments
 (0)