toHex / toHexString fails in IE7 or quirks mode #11

Closed
Pyro979 opened this Issue Jan 11, 2013 · 3 comments

Comments

Projects
None yet
2 participants

Pyro979 commented Jan 11, 2013

I figured out why. You're using a non-standard way to get a character from a string.

Array-like character access (the second way above) is not part of ECMAScript 3. It is a JavaScript and ECMAScript 5 feature.

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String#Character_access

// Return a 3 character hex if possible
    if (hex[0][0] == hex[0][1] && hex[1][0] == hex[1][1] && hex[2][0] == hex[2][1]) {
        return hex[0][0] + hex[1][0] + hex[2][0];
    }

should be

// Return a 3 character hex if possible
    if (hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
        return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
    }

Thanks for the plugin, it's pretty awesome.

Owner

bgrins commented Jan 11, 2013

Thanks! Good catch, I've ran into this problem before.

Owner

bgrins commented Jan 11, 2013

Can you confirm the fix on: http://bgrins.github.com/TinyColor/. Fixed by a968c2c

@bgrins bgrins closed this Jan 11, 2013

Pyro979 commented Jan 11, 2013

looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment