|
7 | 7 | * Licensed under the MIT license: |
8 | 8 | * http://www.opensource.org/licenses/mit-license.php |
9 | 9 | * |
10 | | - * Version: 1.2.1 (Sat, 19 Aug 2017 07:42:40 GMT) |
| 10 | + * Version: 1.2.2 (Mon, 19 May 2014 20:22:47 GMT) |
11 | 11 | */ |
12 | 12 | (function($) { |
13 | 13 | /** |
|
236 | 236 | displayBox.css('background-color', displayBox.data('color')); |
237 | 237 | if (options.displayColorCode) { |
238 | 238 | displayBox.text(displayBox.data('color')); |
| 239 | + displayBox.css({ |
| 240 | + 'color': getTextColor(displayBox.data('color')), |
| 241 | + }); |
239 | 242 | } |
240 | 243 | } |
241 | 244 | // Execute onClose callback whenever the color chooser is closed. |
|
300 | 303 | // If 'displayColorCode' is turned on, display the currently selected color code as text inside the button. |
301 | 304 | if (options.displayColorCode) { |
302 | 305 | event.data.displayBox.text(color); |
| 306 | + event.data.displayBox.css({ |
| 307 | + 'color': getTextColor(displayBox.data('color')) |
| 308 | + }); |
303 | 309 | } |
304 | 310 |
|
305 | 311 | // If an onSelect callback function is defined then excecute it. |
|
361 | 367 | }; |
362 | 368 |
|
363 | 369 | })(jQuery); |
| 370 | + |
| 371 | +function getTextColor(color){ |
| 372 | + |
| 373 | + rgbColor = hexToRgb(color); |
| 374 | + textColor = |
| 375 | + 0.213 * rgbColor.r/255 + |
| 376 | + 0.715 * rgbColor.g/255 + |
| 377 | + 0.072 * rgbColor.b/255 |
| 378 | + < 0.5 ? '#FFFFFF' : '#000000'; |
| 379 | + |
| 380 | + return textColor; |
| 381 | +} |
| 382 | + |
| 383 | +function hexToRgb(hex) { |
| 384 | + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); |
| 385 | + return result ? { |
| 386 | + r: parseInt(result[1], 16), |
| 387 | + g: parseInt(result[2], 16), |
| 388 | + b: parseInt(result[3], 16) |
| 389 | + } : null; |
| 390 | +} |
0 commit comments