|
145 | 145 | floor: true |
146 | 146 | } |
147 | 147 | }, |
| 148 | + support = color.support = {}, |
| 149 | + |
| 150 | + // element for support tests |
| 151 | + supportElem = jQuery( "<p>" )[ 0 ], |
148 | 152 |
|
149 | 153 | // colors = jQuery.Color.names |
150 | 154 | colors, |
151 | 155 |
|
152 | 156 | // local aliases of functions called often |
153 | 157 | each = jQuery.each; |
154 | 158 |
|
| 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 | + |
155 | 163 | // define cache name and alpha properties |
156 | 164 | // for rgba and hsla spaces |
157 | 165 | each( spaces, function( spaceName, space ) { |
@@ -189,6 +197,12 @@ function clamp( value, prop, allowEmpty ) { |
189 | 197 | // ~~ is an short way of doing floor for positive numbers |
190 | 198 | value = type.floor ? ~~value : parseFloat( value ); |
191 | 199 |
|
| 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 | + |
192 | 206 | if ( type.mod ) { |
193 | 207 |
|
194 | 208 | // we add mod before modding to make sure that negatives values |
@@ -446,7 +460,8 @@ color.fn = jQuery.extend( color.prototype, { |
446 | 460 | return "#" + jQuery.map( rgba, function( v ) { |
447 | 461 |
|
448 | 462 | // 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; |
450 | 465 | } ).join( "" ); |
451 | 466 | }, |
452 | 467 | toString: function() { |
@@ -617,13 +632,36 @@ color.hook = function( hook ) { |
617 | 632 | each( hooks, function( _i, hook ) { |
618 | 633 | jQuery.cssHooks[ hook ] = { |
619 | 634 | set: function( elem, value ) { |
620 | | - var parsed; |
| 635 | + var parsed, curElem, |
| 636 | + backgroundColor = ""; |
621 | 637 |
|
622 | 638 | if ( value !== "transparent" && ( getType( value ) !== "string" || ( parsed = stringParse( value ) ) ) ) { |
623 | 639 | 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 | + |
624 | 658 | value = value.toRgbaString(); |
625 | 659 | } |
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 | + } |
627 | 665 | } |
628 | 666 | }; |
629 | 667 | jQuery.fx.step[ hook ] = function( fx ) { |
|
0 commit comments