| 4926 | } |
| 4927 | |
| 4928 | function stringParse( string ) { |
| 4929 | var inst = color(), |
| 4930 | rgba = inst._rgba = []; |
| 4931 | |
| 4932 | string = string.toLowerCase(); |
| 4933 | |
| 4934 | each( stringParsers, function( i, parser ) { |
| 4935 | var parsed, |
| 4936 | match = parser.re.exec( string ), |
| 4937 | values = match && parser.parse( match ), |
| 4938 | spaceName = parser.space || "rgba"; |
| 4939 | |
| 4940 | if ( values ) { |
| 4941 | parsed = inst[ spaceName ]( values ); |
| 4942 | |
| 4943 | // if this was an rgba parse the assignment might happen twice |
| 4944 | // oh well.... |
| 4945 | inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ]; |
| 4946 | rgba = inst._rgba = parsed._rgba; |
| 4947 | |
| 4948 | // exit each( stringParsers ) here because we matched |
| 4949 | return false; |
| 4950 | } |
| 4951 | }); |
| 4952 | |
| 4953 | // Found a stringParser that handled it |
| 4954 | if ( rgba.length ) { |
| 4955 | |
| 4956 | // if this came from a parsed string, force "transparent" when alpha is 0 |
| 4957 | // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0) |
| 4958 | if ( rgba.join() === "0,0,0,0" ) { |
| 4959 | jQuery.extend( rgba, colors.transparent ); |
| 4960 | } |
| 4961 | return inst; |
| 4962 | } |
| 4963 | |
| 4964 | // named colors |
| 4965 | return colors[ string ]; |
| 4966 | } |
| 4967 | |
| 4968 | color.fn = jQuery.extend( color.prototype, { |
| 4969 | parse: function( red, green, blue, alpha ) { |