Name to Hex color conversion
Please include the name-to-hex color conversion in the native library:
// Here is the solution tied together as a native String native extension using
// MooTools, though you can implement the same thing in whatever framework you prefer:
(function(String){
var valueMatch = {
'rgb(0,0,0)': { 'black': ' ', 'rgb(0,0,0)': ' ' },
'rgba(0,0,0,0)': { 'transparent': ' ', 'rgba(0,0,0,0)': ' ' },
'#ffffff': { 'transparent': ' ' },
'transparent': { 'transparent': ' ' }
},
colorFromProbe = function(color){
color = color.toString();
if(!color.match(/^#.+$|^[^0-9]+$/)) return color;
var probe = ($('moocolorprobe') || new Element('textarea', {
'id': 'moocolorprobe',
'styles': {
'display': 'none',
'color': 'transparent'
}
}).inject(document.body, 'after'));
try{ probe.setStyle('color', color) } catch(e){ return color } //IE throws an error instead of defaulting the style to some color or transparent when the value is unrecognized
var computed = (Browser.ie) ? ieColorToHex(probe) : (Browser.opera) ? probe.style.color : probe.getComputedStyle('color'),
match = valueMatch[computed.replace(/ /g, '')];
probe.setStyle('color', 'transparent');
if((!Browser.ie || Browser.ie9) && color == 'transparent' && (match && match['transparent'])) return 'rgba(0, 0, 0, 0)';
return (computed == 'transparent' || match && !match[color.replace(/ /g, '')]) ? color : computed;
},
ieColorToHex = function(probe){ // Special IE mojo, thanks to Dean Edwards for the inspiration, his code used a pop-up window to test the color, I found you can simply use a textarea instead ;)
var value = probe.set('value', '').createTextRange().queryCommandValue("ForeColor");
value = (((value & 0x0000ff) << 16) | (value & 0x00ff00) | ((value & 0xff0000) >>> 16)).toString(16);
return "#000000".slice(0, 7 - value.length) + value;
};
String.implement({
colorToRgb: function(){
var color = colorFromProbe(this);
return (color.charAt(0) == '#') ? color.hexToRgb() : color;
},
colorToHex: function(){
var color = colorFromProbe(this);
return (color.test('rgb')) ? color.rgbToHex() : color;
}
});
})(String);
Taken from: http://stackoverflow.com/a/3892864/863980
More read: http://www.backalleycoder.com/2010/10/05/converting-css-named-colors-to-rgb-and-hex/
-
bkkv7 polaki commented
เว็บตรง https://bkk777.io จากทาง เว็บสล็อตออนไลน์แท้อันดับ 1 จากต่างประเทศ ในปี 2024
-
Joker Gamingvip commented
Invest in playing games with our online slot website, joker gaming the most terrifying slot game. at our website Make unlimited money, start betting 24 hours a day, endlessly, have fun with entertainment. Complete with Outstanding slots website Allows you to play your favorite games. effectively with our quality website
-
fla fan commented
Gampang4D bukanlah sekadar platform lotre online biasa; ia adalah pintu masuk ke dunia kesenangan dan tantangan. Dengan fokus pada kemudahan penggunaan dan peluang besar untuk memenangkan hadiah, Gampang4D menjadi destinasi utama bagi para pencinta lotre daring.
-
Live Panen889 commented
Situs Panen889 Judi Sbobet Slot Casino Online Terbaru Memberikan Banyak Permainan Terpercaya di Indonesia. https://tothevictory.my.id/
-
baymax noob commented
<a href="https://valparaisotheatricalcompany.org/">Ladang78</a> Adalah salah salah agen betting ternama yang sudah memiliki keunggulan terlengkap untuk seluruh pemain selama mengakses
-
Mongkol Boontham commented
หากคุณเป็นมือใหม่ที่เพิ่งเริ่มออกกำลังกาย วันนี้ผมมีทริคสำหรับคนเพิ่งออกกำลังกายมาแนะนำครับ นั่นก็คือ เริ่มต้นช้า ๆ เน้นความสม่ำเสมอ ออกกำลังกายแบบที่ชอบ ออกกำลังกายเพื่อดูแลตัวเอง วอร์มร่างกายทุกครั้งที่ออกกำลังกาย เพียงแค่นี้คุณก็จะออกกำลังกายได้แบบไม่ต้องกลัวอะไรแล้วล่ะครับ และในระหว่างที่ออกกำลังกายคุณก็สามารถเล่นเกมออนไลน์ที่ sagame66 ศูนย์รวมความบันเทิงสุดมันส์มากมาย เล่นตอนนี้คลิก https://sagame66.bio แถมเว็บนี้มีเกมให้เล่นแบบไม่มีซ้ำใคร เล่นได้ตลอดเวลาได้เลย
-
FIFA LOL commented
Dearest, https://bone168.vip/ TGABet's CG graphics will captivate your senses and make our gaming experience unforgettable.
-
FIFA LOL commented
Darling, https://tgagame.net/ let's immerse ourselves in the world of TGABet, where stunning CG visuals await to mesmerize us.
-
FIFA LOL commented
My love, https://tgabetauto.com/ TGABet beckons us with its captivating CG visuals. Let's answer the invitation and dive into the adventure.
-
FIFA LOL commented
Honey, https://tga-bet.com/ let's indulge in the visual splendor of TGABet's CG graphics and create lasting memories.
-
FIFA LOL commented
Sweetheart, <a href="https://tga168.bet/">UFA</a> come and discover the wonders of TGABet, where CG graphics will ignite your imagination.
-
nbkk newgen commented
andar4d adalah situs slot online gacor terbaru Bandar 4d menyediakan rtp pola slot gacor Pragmatic Play, Joker, Pgsoft, Habanero, Microgaming, Slot88 https://jokerauto.net/
-
Halimun Luthfia commented
Mos77 merupakan daftar situs gacor Mos 77 slot resmi pragmatic play dengan menyediakan bocoran rtp live dan pola slot gacor terbaru dan terpercaya
-
Zidan Amina commented
Bandar4d adalah situs slot online gacor terbaru Bandar 4d menyediakan rtp pola slot gacor Pragmatic Play, Joker, Pgsoft, Habanero, Microgaming, Slot88
-
Luthfia Syakira commented
Duniaslot777 merupakan login alternatif situs Duniaslot 777 terbaru dengan 10 permainan slot gacor Pragmatic Play, Pg Soft, Habanero, Slot88, Ionslot, Joker
-
Sima Batinah commented
Royal88 menyediakan rtp slot terpercaya Royal 88 dengan nilai kemenangan paling tinggi untuk provider pragmatic play, pg soft, habanbero, slot88, microgaming
-
Zuhyar Halimun commented
Prada4d merupakan daftar situs prada 4d slot gacor pragmatic play dapat menyediakan fitur deposit pulsa Rp 20.000 tanpa adanya potongan sedikitpun
-
Bella Benjawan commented
Thanks for sharing the post https://super-pgslot.com/
-
Bella Benjawan commented
Thanks for sharing the post https://tgabet65.com/
-
Bella Benjawan commented
Thanks for sharing the post https://gd-slot.net/