├── README.md ├── bower.json ├── jquery.xcolor.js ├── jquery.xcolor.min.js └── xcolor.jquery.json /README.md: -------------------------------------------------------------------------------- 1 | jQuery xcolor Plugin 2 | ==================== 3 | 4 | Description 5 | ----------- 6 | The jQuery xcolor plugin is an extensive library for color manipulation. 7 | 8 | 9 | 10 | Calculating Colors 11 | --- 12 | ```javascript 13 | // Calculate a grey level color value 14 | $.xcolor.greyfilter('#c00'); 15 | 16 | // Calculate a gradient color between #fc0 and #f00 at position 23/100 17 | $.xcolor.gradientlevel('#fc0', '#f00', 23, 100); 18 | 19 | // Calculate the opacity as if lightgrey would overlay #f00 with an opacity of 69%. 20 | $.xcolor.opacity('#f00', 'lightgrey', 0.69); 21 | ``` 22 | 23 | and many more! [Check out the full documentation!](http://www.xarg.org/project/jquery-color-plugin-xcolor/) 24 | 25 | Colorizing Text 26 | ---- 27 | ```javascript 28 | $(".foo").colorize("burntsienna", "blue", function() { 29 | // Return a value between 0 and 1, indicating a gradient level between "burntsienna" and "blue" 30 | return Math.random(); 31 | }); 32 | ``` 33 | 34 | 35 | CSS Hook 36 | ----- 37 | 38 | The color parser implements a CSS hook. Using a random color is now as easy as 39 | 40 | ```javascript 41 | $('h1').css('background', 'rand'); 42 | 43 | ``` 44 | 45 | 46 | Further examples and documentation 47 | ========================== 48 | For further details and code examples take a look at the demonstration and documentation page on: 49 | 50 | http://www.xarg.org/project/jquery-color-plugin-xcolor/ 51 | 52 | License 53 | ====== 54 | Copyright (c) 2014, [Robert Eisele](http://www.xarg.org/) 55 | Dual licensed under the MIT or GPL Version 2 licenses. 56 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "xcolor", 3 | "main": "jquery.xcolor.js", 4 | "version": "1.8.0", 5 | "homepage": "http://www.xarg.org/project/jquery-color-plugin-xcolor/", 6 | "description": "An easy to use color manipulation plugin for jQuery.", 7 | "keywords": [ 8 | "color", 9 | "colors", 10 | "text", 11 | "ui" 12 | ], 13 | "authors": [ 14 | "Robert Eisele " 15 | ], 16 | "dependencies": { 17 | "jquery": ">=1.5" 18 | }, 19 | "license": [ 20 | "MIT", 21 | "GPL" 22 | ], 23 | "repository": { 24 | "type": "git", 25 | "url": "git://github.com/infusion/jQuery-xcolor.git" 26 | } 27 | } -------------------------------------------------------------------------------- /jquery.xcolor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license jQuery paging plugin v1.8.0 06/21/2010 3 | * http://www.xarg.org/project/jquery-color-plugin-xcolor/ 4 | * 5 | * Copyright (c) 2010, Robert Eisele (robert@xarg.org) 6 | * Dual licensed under the MIT or GPL Version 2 licenses. 7 | **/ 8 | // ([^a-z."/])m([^a-z:"]) 9 | (function ($, undefined) { 10 | 11 | // http://www.w3.org/TR/css3-color/#svg-color 12 | var color_names = { 13 | "aliceblue": "f0f8ff", 14 | "antiquewhite": "faebd7", 15 | "aqua": "0ff", 16 | "aquamarine": "7fffd4", 17 | "azure": "f0ffff", 18 | "beige": "f5f5dc", 19 | "bisque": "ffe4c4", 20 | "black": "000", 21 | "blanchedalmond": "ffebcd", 22 | "blue": "00f", 23 | "blueviolet": "8a2be2", 24 | "brown": "a52a2a", 25 | "burlywood": "deb887", 26 | "burntsienna": "ea7e5d", 27 | "cadetblue": "5f9ea0", 28 | "chartreuse": "7fff00", 29 | "chocolate": "d2691e", 30 | "coral": "ff7f50", 31 | "cornflowerblue": "6495ed", 32 | "cornsilk": "fff8dc", 33 | "crimson": "dc143c", 34 | "cyan": "0ff", 35 | "darkblue": "00008b", 36 | "darkcyan": "008b8b", 37 | "darkgoldenrod": "b8860b", 38 | "darkgray": "a9a9a9", 39 | "darkgreen": "006400", 40 | "darkgrey": "a9a9a9", 41 | "darkkhaki": "bdb76b", 42 | "darkmagenta": "8b008b", 43 | "darkolivegreen": "556b2f", 44 | "darkorange": "ff8c00", 45 | "darkorchid": "9932cc", 46 | "darkred": "8b0000", 47 | "darksalmon": "e9967a", 48 | "darkseagreen": "8fbc8f", 49 | "darkslateblue": "483d8b", 50 | "darkslategray": "2f4f4f", 51 | "darkslategrey": "2f4f4f", 52 | "darkturquoise": "00ced1", 53 | "darkviolet": "9400d3", 54 | "deeppink": "ff1493", 55 | "deepskyblue": "00bfff", 56 | "dimgray": "696969", 57 | "dimgrey": "696969", 58 | "dodgerblue": "1e90ff", 59 | "firebrick": "b22222", 60 | "floralwhite": "fffaf0", 61 | "forestgreen": "228b22", 62 | "fuchsia": "f0f", 63 | "gainsboro": "dcdcdc", 64 | "ghostwhite": "f8f8ff", 65 | "gold": "ffd700", 66 | "goldenrod": "daa520", 67 | "gray": "808080", 68 | "green": "008000", 69 | "greenyellow": "adff2f", 70 | "grey": "808080", 71 | "honeydew": "f0fff0", 72 | "hotpink": "ff69b4", 73 | "indianred": "cd5c5c", 74 | "indigo": "4b0082", 75 | "ivory": "fffff0", 76 | "khaki": "f0e68c", 77 | "lavender": "e6e6fa", 78 | "lavenderblush": "fff0f5", 79 | "lawngreen": "7cfc00", 80 | "lemonchiffon": "fffacd", 81 | "lightblue": "add8e6", 82 | "lightcoral": "f08080", 83 | "lightcyan": "e0ffff", 84 | "lightgoldenrodyellow": "fafad2", 85 | "lightgray": "d3d3d3", 86 | "lightgreen": "90ee90", 87 | "lightgrey": "d3d3d3", 88 | "lightpink": "ffb6c1", 89 | "lightsalmon": "ffa07a", 90 | "lightseagreen": "20b2aa", 91 | "lightskyblue": "87cefa", 92 | "lightslategray": "789", 93 | "lightslategrey": "789", 94 | "lightsteelblue": "b0c4de", 95 | "lightyellow": "ffffe0", 96 | "lime": "0f0", 97 | "limegreen": "32cd32", 98 | "linen": "faf0e6", 99 | "magenta": "f0f", 100 | "maroon": "800000", 101 | "mediumaquamarine": "66cdaa", 102 | "mediumblue": "0000cd", 103 | "mediumorchid": "ba55d3", 104 | "mediumpurple": "9370db", 105 | "mediumseagreen": "3cb371", 106 | "mediumslateblue": "7b68ee", 107 | "mediumspringgreen": "00fa9a", 108 | "mediumturquoise": "48d1cc", 109 | "mediumvioletred": "c71585", 110 | "midnightblue": "191970", 111 | "mintcream": "f5fffa", 112 | "mistyrose": "ffe4e1", 113 | "moccasin": "ffe4b5", 114 | "navajowhite": "ffdead", 115 | "navy": "000080", 116 | "oldlace": "fdf5e6", 117 | "olive": "808000", 118 | "olivedrab": "6b8e23", 119 | "orange": "ffa500", 120 | "orangered": "ff4500", 121 | "orchid": "da70d6", 122 | "palegoldenrod": "eee8aa", 123 | "palegreen": "98fb98", 124 | "paleturquoise": "afeeee", 125 | "palevioletred": "db7093", 126 | "papayawhip": "ffefd5", 127 | "peachpuff": "ffdab9", 128 | "peru": "cd853f", 129 | "pink": "ffc0cb", 130 | "plum": "dda0dd", 131 | "powderblue": "b0e0e6", 132 | "purple": "800080", 133 | "red": "f00", 134 | "rosybrown": "bc8f8f", 135 | "royalblue": "4169e1", 136 | "saddlebrown": "8b4513", 137 | "salmon": "fa8072", 138 | "sandybrown": "f4a460", 139 | "seagreen": "2e8b57", 140 | "seashell": "fff5ee", 141 | "sienna": "a0522d", 142 | "silver": "c0c0c0", 143 | "skyblue": "87ceeb", 144 | "slateblue": "6a5acd", 145 | "slategray": "708090", 146 | "slategrey": "708090", 147 | "snow": "fffafa", 148 | "springgreen": "00ff7f", 149 | "steelblue": "4682b4", 150 | "tan": "d2b48c", 151 | "teal": "008080", 152 | "thistle": "d8bfd8", 153 | "tomato": "ff6347", 154 | "turquoise": "40e0d0", 155 | "violet": "ee82ee", 156 | "wheat": "f5deb3", 157 | "white": "fff", 158 | "whitesmoke": "f5f5f5", 159 | "yellow": "ff0", 160 | "yellowgreen": "9acd32" 161 | }, _RGBAtoCSS; 162 | 163 | /** 164 | * @constructor 165 | */ 166 | function xColor(color) { 167 | 168 | /** 169 | * normalize function 170 | * @param {(number|string)=} n (optional) 171 | * @param {(number|string)=} s (optional) 172 | */ 173 | function _normalize(n, s) { 174 | 175 | var m; 176 | 177 | if (undefined !== n) { 178 | n = parseFloat(n); 179 | } 180 | 181 | if (undefined === s) { 182 | s = 255; 183 | m = 255; 184 | } else if (1 === s) { 185 | 186 | if (undefined === n || 1 === n) { 187 | return 1; 188 | } 189 | s = 100; 190 | m = 1; 191 | } else { 192 | m = s; 193 | } 194 | 195 | if (isNaN(n) || n <= 0) { 196 | return 0; 197 | } 198 | 199 | if (s < n) { 200 | return m; 201 | } 202 | 203 | if (n < 1 || 1 === s) { 204 | if (1 === m) { 205 | return n; 206 | } else { 207 | return (n * m) | 0; 208 | } 209 | } 210 | return n * m / s; 211 | } 212 | 213 | function _hsl(h,s,l) { 214 | 215 | h = _normalize(h, 360) / 360; 216 | s = _normalize(s, 1); 217 | l = _normalize(l, 1); 218 | 219 | if (0 === s) { 220 | l = Math.round(255 * l); 221 | return [l, l, l]; 222 | } 223 | 224 | function _hue(v1, v2, h) { 225 | h = ++h % 1; 226 | 227 | if (6 * h < 1) return v1 + (v2 - v1) * 6 * h; 228 | if (2 * h < 1) return v2; 229 | if (3 * h < 2) return v1 + (v2 - v1) * (4 - 6 * h); 230 | return v1; 231 | } 232 | 233 | var v = l < .5 ? (l + l * s) : (l + s - l * s); 234 | var m = l + l - v; 235 | 236 | return [ 237 | Math.round(255 *_hue(m, v, h + 1 / 3)), 238 | Math.round(255 *_hue(m, v, h)), 239 | Math.round(255 *_hue(m, v, h - 1 / 3)) ]; 240 | } 241 | 242 | function _hsv(h,s,v) { 243 | 244 | h = _normalize(h, 360) / 60; 245 | s = _normalize(s, 1); 246 | v = _normalize(v, 1); 247 | 248 | var hi = h|0; 249 | var f = h - hi; 250 | 251 | var p = Math.round(255 * v * (1 - s)); 252 | var q = Math.round(255 * v * (1 - s * f)); 253 | var t = Math.round(255 * v * (1 - s * (1 - f))); 254 | v = Math.round(255 * v); 255 | 256 | switch(hi) { 257 | case 1: 258 | return [q, v, p]; 259 | case 2: 260 | return [p, v, t]; 261 | case 3: 262 | return [p, q, v]; 263 | case 4: 264 | return [t, p, v]; 265 | case 5: 266 | return [v, p, q]; 267 | } 268 | return [v, t, p]; 269 | } 270 | 271 | this["setColor"] = function (color) { 272 | 273 | this.success = true; 274 | 275 | if ("number" === typeof color) { 276 | 277 | this["a"] =((color >> 24) & 0xff) / 255; 278 | this["r"] = (color >> 16) & 0xff; 279 | this["g"] = (color >> 8) & 0xff; 280 | this["b"] = (color ) & 0xff; 281 | return; 282 | } 283 | 284 | while ("object" === typeof color) { 285 | 286 | if (0 in color && 1 in color && 2 in color) { 287 | this["a"] = _normalize(color[3], 1); 288 | this["r"] = _normalize(color[0]); 289 | this["g"] = _normalize(color[1]); 290 | this["b"] = _normalize(color[2]); 291 | return; 292 | } else if ('r' in color && 'g' in color && 'b' in color) { 293 | this["a"] = _normalize(color["a"], 1); 294 | this["r"] = _normalize(color["r"]); 295 | this["g"] = _normalize(color["g"]); 296 | this["b"] = _normalize(color["b"]); 297 | return; 298 | } else if ('h' in color && 's' in color) { 299 | 300 | var rgb; 301 | 302 | if ('l' in color) { 303 | rgb = _hsl(color["h"], color["s"], color["l"]); 304 | } else if ('v' in color) { 305 | rgb = _hsv(color["h"], color["s"], color["v"]); 306 | } else if ('b' in color) { 307 | rgb = _hsv(color["h"], color["s"], color["b"]); 308 | } else { 309 | break; 310 | } 311 | 312 | this["a"] = _normalize(color["a"], 1); 313 | this["r"] = rgb[0]; 314 | this["g"] = rgb[1]; 315 | this["b"] = rgb[2]; 316 | return; 317 | } 318 | break; 319 | } 320 | 321 | if ("string" === typeof color) { 322 | 323 | color = color.toLowerCase().replace(/[^a-z0-9,.()#%]/g, ''); 324 | 325 | var part, c; 326 | 327 | if ('transparent' === color) { 328 | this["a"] = /* void */ 329 | this["r"] = /* void */ 330 | this["g"] = /* void */ 331 | this["b"] = 0; 332 | return; 333 | } 334 | 335 | if ('rand' === color) { 336 | 337 | c = Math.random() * 0xffffff|0; 338 | 339 | this["a"] = 1; 340 | this["r"] = ((c >> 16) & 0xff); 341 | this["g"] = ((c >> 8) & 0xff); 342 | this["b"] = ((c ) & 0xff); 343 | return; 344 | } 345 | 346 | if (undefined !== color_names[color]) { 347 | color = '#' + color_names[color]; 348 | } 349 | 350 | // #ff9000, #ff0000 351 | if ((part = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/.exec(color))) { 352 | this["a"] = 1; 353 | this["r"] = parseInt(part[1], 16); 354 | this["g"] = parseInt(part[2], 16); 355 | this["b"] = parseInt(part[3], 16); 356 | return; 357 | } 358 | 359 | // #f00, fff 360 | if ((part = /^#?([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(color))) { 361 | this["a"] = 1; 362 | this["r"] = parseInt(part[1] + part[1], 16); 363 | this["g"] = parseInt(part[2] + part[2], 16); 364 | this["b"] = parseInt(part[3] + part[3], 16); 365 | return; 366 | } 367 | 368 | // rgb(1, 234, 56) 369 | if ((part = /^rgba?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?\)$/.exec(color))) { 370 | this["a"] = _normalize(part[5], 1); 371 | this["r"] = _normalize(part[1]); 372 | this["g"] = _normalize(part[2]); 373 | this["b"] = _normalize(part[3]); 374 | return; 375 | } 376 | 377 | // rgb(66%, 55%, 44%) in [0,100]%, [0,100]%, [0,100]% 378 | if ((part = /^rgba?\(([0-9.]+\%),([0-9.]+\%),([0-9.]+\%)(,([0-9.]+)\%?)?\)$/.exec(color))) { 379 | this["a"] = _normalize(part[5], 1); 380 | this["r"] = Math.round(2.55 * _normalize(part[1], 100)); 381 | this["g"] = Math.round(2.55 * _normalize(part[2], 100)); 382 | this["b"] = Math.round(2.55 * _normalize(part[3], 100)); 383 | return; 384 | } 385 | 386 | // hsv(64, 40, 16) in [0, 360], [0,100], [0,100] 387 | if ((part = /^hs([bvl])a?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?\)$/.exec(color))) { 388 | var func; 389 | if ("l" === part[1]) { 390 | func = _hsl; 391 | } else { 392 | func = _hsv; 393 | } 394 | 395 | c = func(parseInt(part[2], 10), parseInt(part[3], 10), parseInt(part[4], 10)); 396 | 397 | this["a"] = _normalize(part[6], 1); 398 | this["r"] = c[0]; 399 | this["g"] = c[1]; 400 | this["b"] = c[2]; 401 | return; 402 | } 403 | 404 | // 1, 234, 56 405 | if ((part = /^(\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?$/.exec(color))) { 406 | this["a"] = _normalize(part[5], 1); 407 | this["r"] = _normalize(part[1]); 408 | this["g"] = _normalize(part[2]); 409 | this["b"] = _normalize(part[3]); 410 | return; 411 | } 412 | } 413 | this.success = false; 414 | }; 415 | 416 | this["getColor"] = function (type) { 417 | 418 | if (undefined !== type) switch (type.toLowerCase()) { 419 | case "rgb": 420 | return this["getRGB"](); 421 | case "hsv": 422 | case "hsb": 423 | return this["getHSV"](); 424 | case "hsl": 425 | return this["getHSL"](); 426 | case "int": 427 | return this["getInt"](); 428 | case "array": 429 | return this["getArray"](); 430 | case "fraction": 431 | return this["getFraction"](); 432 | case "css": 433 | case "style": 434 | return this["getCSS"](); 435 | case "name": 436 | return this["getName"](); 437 | } 438 | return this["getHex"](); 439 | }; 440 | 441 | this["getRGB"] = function () { 442 | 443 | if (this.success) { 444 | 445 | return { 446 | "r": this["r"], 447 | "g": this["g"], 448 | "b": this["b"], 449 | "a": this["a"] 450 | }; 451 | } 452 | return null; 453 | }; 454 | 455 | this["getCSS"] = function () { 456 | 457 | if (this.success) { 458 | 459 | if (0 === this["a"]) { 460 | return "transparent"; 461 | } 462 | 463 | if (1 === this["a"]) { 464 | return 'rgb(' + this["r"] + ',' + this["g"] + ',' + this["b"] + ')'; 465 | } 466 | return _RGBAtoCSS(this["r"], this["g"], this["b"], this["a"]); 467 | } 468 | return null; 469 | }; 470 | 471 | this["getArray"] = function () { 472 | 473 | if (this.success) { 474 | return [this["r"], this["g"], this["b"], 100 * this["a"]|0]; 475 | } 476 | return null; 477 | }; 478 | 479 | this["getName"] = function () { 480 | 481 | if (this.success) { 482 | 483 | var lowest = null; 484 | var lowest_ndx; 485 | 486 | var table = color_names; 487 | 488 | var a = this["getHSL"](); 489 | 490 | for (var i in table) { 491 | 492 | /* We do not handle transparency */ 493 | var b = new xColor(table[i])["getHSL"](); 494 | 495 | var tmp = Math.sqrt(.5 * (a["h"] - b["h"]) * (a["h"] - b["h"]) + .5 * (a["s"] - b["s"]) * (a["s"] - b["s"]) + (a["l"] - b["l"]) * (a["l"] - b["l"])); 496 | 497 | if (null === lowest || tmp < lowest) { 498 | lowest = tmp; 499 | lowest_ndx = i; 500 | } 501 | } 502 | return lowest_ndx; 503 | } 504 | return null; 505 | }; 506 | 507 | this["getFraction"] = function () { 508 | 509 | if (this.success) { 510 | 511 | return { 512 | "r": this["r"] / 255, 513 | "g": this["g"] / 255, 514 | "b": this["b"] / 255, 515 | "a": this["a"] 516 | }; 517 | } 518 | return null; 519 | }; 520 | 521 | this["getHSL"] = function () { 522 | 523 | // inspiration: http://130.113.54.154/~monger/hsl-rgb.html 524 | if (this.success) { 525 | 526 | var r = this["r"] / 255; 527 | var g = this["g"] / 255; 528 | var b = this["b"] / 255; 529 | 530 | var min = Math.min(r, g, b); 531 | var max = Math.max(r, g, b); 532 | var delta = max - min; 533 | 534 | var h, s, l = (max + min) / 2; 535 | 536 | if (0 === delta) { 537 | h = 0; 538 | s = 0; 539 | } else { 540 | 541 | if (r === max) { 542 | h = (g - b) / delta; 543 | } else if (g === max) { 544 | h = 2 + (b - r) / delta; 545 | } else { 546 | h = 4 + (r - g) / delta; 547 | } 548 | 549 | s = delta / (l < .5 ? max + min : 2 - max - min); 550 | } 551 | return { 552 | "h": Math.round( 60 * ((6 + h) % 6)), 553 | "s": Math.round(100 * s), 554 | "l": Math.round(100 * l), 555 | "a": this["a"] 556 | }; 557 | } 558 | return null; 559 | }; 560 | 561 | this["getHSV"] = function () { 562 | 563 | if (this.success) { 564 | 565 | var r = this["r"] / 255; 566 | var g = this["g"] / 255; 567 | var b = this["b"] / 255; 568 | 569 | /* 570 | if (r > g) { 571 | max = r; 572 | min = g; 573 | } else { 574 | min = r; 575 | max = g; 576 | } 577 | 578 | if (b > max) 579 | max = b; 580 | 581 | if (b < min) 582 | min = b; 583 | */ 584 | 585 | var min = Math.min(r, g, b); 586 | var max = Math.max(r, g, b); 587 | var delta = max - min; 588 | 589 | var h, s, v = max; 590 | 591 | if (0 === max) { 592 | s = 0; 593 | } else { 594 | s = delta / max; 595 | } 596 | 597 | if (0 === delta) { 598 | h = 0; 599 | } else if (r === max) { 600 | h = (g - b) / delta; 601 | } else if (g === max) { 602 | h = 2 + (b - r) / delta; 603 | } else { 604 | h = 4 + (r - g) / delta; 605 | } 606 | 607 | return { 608 | "h": Math.round( 60 * ((6 + h) % 6)), 609 | "s": Math.round(100 * s), 610 | "v": Math.round(100 * v), 611 | "a": this["a"] 612 | }; 613 | } 614 | return null; 615 | }; 616 | 617 | this["getHex"] = function () { 618 | 619 | if (this.success) { 620 | 621 | var chars = "0123456789abcdef"; 622 | 623 | var r1 = this["r"] >> 4; 624 | var g1 = this["g"] >> 4; 625 | var b1 = this["b"] >> 4; 626 | 627 | var r2 = this["r"] & 0xf; 628 | var g2 = this["g"] & 0xf; 629 | var b2 = this["b"] & 0xf; 630 | 631 | return '#' 632 | + chars.charAt(r1) + chars.charAt(r2) 633 | + chars.charAt(g1) + chars.charAt(g2) 634 | + chars.charAt(b1) + chars.charAt(b2); 635 | } 636 | return null; 637 | }; 638 | 639 | this["getInt"] = function (alpha) { 640 | 641 | if (this.success) { 642 | if (undefined !== alpha) { 643 | return ((100 * this["a"]|0) << 24 ^ this["r"] << 16 ^ this["g"] << 8 ^ this["b"]); 644 | } 645 | return (this["r"] << 16 ^ this["g"] << 8 ^ this["b"]) & 0xffffff; 646 | } 647 | return null; 648 | }; 649 | 650 | this["toString"] = function () { 651 | return this["getHex"](); 652 | }; 653 | 654 | this["setColor"](color); 655 | } 656 | 657 | $["each"](['color', 'backgroundColor', 'borderColor', 'borderTopColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'outlineColor'], function(i, attr) { 658 | 659 | $["cssHooks"][attr] = { 660 | 661 | "set": function(elem, value) { 662 | elem["style"][attr] = (new xColor(value))["getCSS"](); 663 | } 664 | }; 665 | 666 | $["fx"]["step"][attr] = function(fx) { 667 | 668 | if (undefined === fx["xinit"]) { 669 | 670 | if ("string" === typeof fx["end"] && -1 !== fx["end"].indexOf(";")) { 671 | 672 | var x, arr = fx["end"].split(";"); 673 | 674 | if (arr.length > 2) { 675 | 676 | for (x in arr) { 677 | if (-1 === arr[x].indexOf('native')) { 678 | arr[x] = new xColor(arr[x]); 679 | } else { 680 | arr[x] = findColor(fx["elem"], attr); 681 | } 682 | } 683 | fx["start"] = null; 684 | fx["end"] = arr; 685 | } else { 686 | fx["start"] = new xColor(arr[0]); 687 | fx["end"] = new xColor(arr[1]); 688 | } 689 | } else { 690 | fx["start"] = findColor(fx["elem"], attr); 691 | fx["end"] = new xColor(fx["end"]); 692 | } 693 | 694 | fx["xinit"] = 1; 695 | } 696 | 697 | var S = fx["start"]; 698 | var E = fx["end"]; 699 | var P = fx["pos"]; 700 | 701 | if (null === S) { 702 | var m = P * (E.length - 1), 703 | n = P < 1 ? m | 0 : E.length - 2; 704 | S = E[n]; 705 | E = E[n + 1]; 706 | P = m - n; 707 | } 708 | 709 | fx["elem"]["style"][attr] =_RGBAtoCSS( 710 | S["r"] + P * (E["r"] - S["r"])|0, 711 | S["g"] + P * (E["g"] - S["g"])|0, 712 | S["b"] + P * (E["b"] - S["b"])|0, 713 | S["a"] + P * (E["a"] - S["a"]) 714 | ); 715 | } 716 | }); 717 | 718 | $(function() { 719 | var div = document.createElement("div"), 720 | div_style = div["style"]; 721 | 722 | _RGBAtoCSS = function(r, g, b, a) { 723 | return "rgba(" + r + "," + g + "," + b + "," + a + ")"; 724 | }; 725 | 726 | div_style["cssText"] = "background-color:rgba(1,1,1,.5)"; 727 | 728 | if (!($["support"]["rgba"] = div_style["backgroundColor"].indexOf("rgba") > -1)) { 729 | _RGBAtoCSS = function(r, g, b) { 730 | return "rgb(" + r + "," + g + "," + b + ")"; 731 | }; 732 | } 733 | }); 734 | 735 | function findColor(elem, attr) { 736 | 737 | var color = ""; 738 | 739 | do { 740 | color = $["css"](elem, attr); 741 | 742 | if ("" !== color && "transparent" !== color && "rgba(0, 0, 0, 0)" !== color || $["nodeName"](elem, "body")) break; 743 | 744 | } while ((elem = elem["parentNode"])); 745 | 746 | if ("" === color) { 747 | 748 | if ($["support"]["rgba"]) { 749 | color = "transparent"; 750 | } else if ("backgroundColor" === attr) { 751 | color = "white"; 752 | } else { 753 | color = "black"; 754 | } 755 | } 756 | return new xColor(color); 757 | } 758 | 759 | /** 760 | * @constructor 761 | */ 762 | function xColorMix() { 763 | 764 | this["test"] = function (col) { 765 | 766 | var c = new xColor(col); 767 | 768 | if (c.success) { 769 | return c; 770 | } 771 | return null; 772 | }; 773 | 774 | this["red"] = function (col) { 775 | 776 | var c = new xColor(col); 777 | 778 | if (c.success) { 779 | c["g"] = 0xff; 780 | c["b"] = 0xff; 781 | return c; 782 | } 783 | return null; 784 | }; 785 | 786 | this["blue"] = function (col) { 787 | 788 | var c = new xColor(col); 789 | 790 | if (c.success) { 791 | c["r"] = 0xff; 792 | c["g"] = 0xff; 793 | return c; 794 | } 795 | return null; 796 | }; 797 | 798 | this["green"] = function (col) { 799 | 800 | var c = new xColor(col); 801 | 802 | if (c.success) { 803 | c["r"] = 0xff; 804 | c["b"] = 0xff; 805 | return c; 806 | } 807 | return null; 808 | }; 809 | 810 | this["sepia"] = function(col) { 811 | 812 | var c = new xColor(col); 813 | 814 | // Microsoft's sepia function http://msdn.microsoft.com/en-us/magazine/cc163866.aspx 815 | if (c.success) { 816 | 817 | var r = c["r"], g = c["g"], b = c["b"]; 818 | 819 | c["r"] = Math.round(r * .393 + g * .769 + b * .189); 820 | c["g"] = Math.round(r * .349 + g * .686 + b * .168); 821 | c["b"] = Math.round(r * .272 + g * .534 + b * .131); 822 | 823 | return c; 824 | } 825 | return null; 826 | }; 827 | 828 | this["random"] = function () { 829 | 830 | return new xColor([ 831 | (255 * Math.random())|0, 832 | (255 * Math.random())|0, 833 | (255 * Math.random())|0 834 | ]); 835 | }; 836 | 837 | this["inverse"] = function (col) { 838 | 839 | var c = new xColor(col); 840 | 841 | if (c.success) { 842 | c["r"]^= 0xff; 843 | c["g"]^= 0xff; 844 | c["b"]^= 0xff; 845 | return c; 846 | } 847 | return null; 848 | }; 849 | 850 | this["opacity"] = function (x, y, o) { 851 | 852 | var a = new xColor(x); 853 | var b = new xColor(y); 854 | 855 | if (a.success & b.success) { 856 | 857 | if (o > 1) { 858 | o/= 100; 859 | } 860 | 861 | o = Math.max(o - 1 + b["a"], 0); 862 | 863 | a["r"] = Math.round((b["r"] - a["r"]) * o + a["r"]); 864 | a["g"] = Math.round((b["g"] - a["g"]) * o + a["g"]); 865 | a["b"] = Math.round((b["b"] - a["b"]) * o + a["b"]); 866 | 867 | return a; 868 | } 869 | return null; 870 | }; 871 | 872 | this["greyfilter"] = function (col, formula) { 873 | 874 | var v, c = new xColor(col); 875 | 876 | if (c.success) { 877 | switch (formula) { 878 | case 1: 879 | // My own formula 880 | v = .35 + 13 * (c["r"] + c["g"] + c["b"]) / 60; 881 | break; 882 | case 2: 883 | // Sun's formula: (1 - avg) / (100 / 35) + avg) 884 | v = (13 * (c["r"] + c["g"] + c["b"]) + 5355) / 60; 885 | break; 886 | default: 887 | v = c["r"] * .3 + c["g"] * .59 + c["b"] * .11; 888 | } 889 | c["r"] = c["g"] = c["b"] = Math.min(v|0, 255); 890 | 891 | return c; 892 | } 893 | return null; 894 | }; 895 | 896 | this["webround"] = function (col) { 897 | 898 | var c = new xColor(col); 899 | 900 | if (c.success) { 901 | if ((c["r"]+= 0x33 - c["r"] % 0x33) > 0xff) c["r"] = 0xff; 902 | if ((c["g"]+= 0x33 - c["g"] % 0x33) > 0xff) c["g"] = 0xff; 903 | if ((c["b"]+= 0x33 - c["b"] % 0x33) > 0xff) c["b"] = 0xff; 904 | return c; 905 | } 906 | return null; 907 | }; 908 | 909 | this["distance"] = function (x, y) { 910 | 911 | var a = new xColor(x); 912 | var b = new xColor(y); 913 | 914 | if (a.success & b.success) { 915 | // Approximation attempt of http://www.compuphase.com/cmetric.htm 916 | return Math.sqrt(3 * (b["r"] - a["r"]) * (b["r"] - a["r"]) + 4 * (b["g"] - a["g"]) * (b["g"] - a["g"]) + 2 * (b["b"] - a["b"]) * (b["b"] - a["b"])); 917 | } 918 | return null; 919 | }; 920 | 921 | this["readable"] = function (bg, col, size) { 922 | 923 | // good ressource: http://www.hgrebdes.com/colour/spectrum/colourvisibility.html 924 | 925 | var a = new xColor(col); 926 | var b = new xColor(bg); 927 | 928 | size = size || 10; 929 | 930 | if (a.success & b.success) { 931 | 932 | // but here's my version based on the idea: 933 | 934 | var diff = b["r"] * 0.299 + b["g"] * 0.587 + b["b"] * 0.114 - 935 | a["r"] * 0.299 - a["g"] * 0.587 - a["b"] * 0.114; 936 | 937 | return !((diff < (1.5 + 141.162 * Math.pow(0.975, size))) 938 | && (diff > (-.5 - 154.709 * Math.pow(0.990, size)))); 939 | } 940 | return null; 941 | }; 942 | 943 | this["combine"] = function (x, y) { 944 | 945 | var a = new xColor(x); 946 | var b = new xColor(y); 947 | 948 | if (a.success & b.success) { 949 | a["r"]^= b["r"]; 950 | a["g"]^= b["g"]; 951 | a["b"]^= b["b"]; 952 | return a; 953 | } 954 | return null; 955 | }; 956 | 957 | this["breed"] = function (x, y) { 958 | 959 | var a = new xColor(x); 960 | var b = new xColor(y); 961 | 962 | var mask = 0, i = 6; 963 | 964 | if (a.success & b.success) { 965 | 966 | while (i--) { 967 | if (Math.random() < .5) { 968 | mask|= 0x0f << (i << 2); 969 | } 970 | } 971 | 972 | a["r"] = (a["r"] & ((mask >> 0x10) & 0xff)) | (b["r"] & (((mask >> 0x10) & 0xff) ^ 0xff)); 973 | a["g"] = (a["g"] & ((mask >> 0x08) & 0xff)) | (b["g"] & (((mask >> 0x08) & 0xff) ^ 0xff)); 974 | a["b"] = (a["b"] & ((mask >> 0x00) & 0xff)) | (b["b"] & (((mask >> 0x00) & 0xff) ^ 0xff)); 975 | return a; 976 | } 977 | return null; 978 | }; 979 | 980 | this["additive"] = function (x, y) { 981 | 982 | var a = new xColor(x); 983 | var b = new xColor(y); 984 | 985 | if (a.success & b.success) { 986 | 987 | if ((a["r"]+= b["r"]) > 0xff) a["r"] = 0xff; 988 | if ((a["g"]+= b["g"]) > 0xff) a["g"] = 0xff; 989 | if ((a["b"]+= b["b"]) > 0xff) a["b"] = 0xff; 990 | 991 | return a; 992 | } 993 | return null; 994 | }; 995 | 996 | this["subtractive"] = function (x, y) { 997 | 998 | var a = new xColor(x); 999 | var b = new xColor(y); 1000 | 1001 | if (a.success & b.success) { 1002 | 1003 | if ((a["r"]+= b["r"] - 0xff) < 0) a["r"] = 0; 1004 | if ((a["g"]+= b["g"] - 0xff) < 0) a["g"] = 0; 1005 | if ((a["b"]+= b["b"] - 0xff) < 0) a["b"] = 0; 1006 | 1007 | return a; 1008 | } 1009 | return null; 1010 | }; 1011 | 1012 | this["subtract"] = function (x, y) { 1013 | 1014 | var a = new xColor(x); 1015 | var b = new xColor(y); 1016 | 1017 | if (a.success & b.success) { 1018 | 1019 | if ((a["r"]-= b["r"]) < 0) a["r"] = 0; 1020 | if ((a["g"]-= b["g"]) < 0) a["g"] = 0; 1021 | if ((a["b"]-= b["b"]) < 0) a["b"] = 0; 1022 | 1023 | return a; 1024 | } 1025 | return null; 1026 | }; 1027 | 1028 | this["multiply"] = function (x, y) { 1029 | 1030 | var a = new xColor(x); 1031 | var b = new xColor(y); 1032 | 1033 | if (a.success & b.success) { 1034 | a["r"] = (a["r"] / 255 * b["r"])|0; 1035 | a["g"] = (a["g"] / 255 * b["g"])|0; 1036 | a["b"] = (a["b"] / 255 * b["b"])|0; 1037 | return a; 1038 | } 1039 | return null; 1040 | }; 1041 | 1042 | this["average"] = function (x, y) { 1043 | 1044 | var a = new xColor(x); 1045 | var b = new xColor(y); 1046 | 1047 | if (a.success & b.success) { 1048 | a["r"] = (a["r"] + b["r"]) >> 1; 1049 | a["g"] = (a["g"] + b["g"]) >> 1; 1050 | a["b"] = (a["b"] + b["b"]) >> 1; 1051 | return a; 1052 | } 1053 | return null; 1054 | }; 1055 | 1056 | this["triad"] = function (col) { 1057 | 1058 | var c = new xColor(col); 1059 | 1060 | if (c.success) { 1061 | 1062 | return [c, 1063 | new xColor([c["b"], c["r"], c["g"]]), 1064 | new xColor([c["g"], c["b"], c["r"]])]; 1065 | } 1066 | return null; 1067 | }; 1068 | 1069 | this["tetrad"] = function (col) { 1070 | 1071 | var c = new xColor(col); 1072 | 1073 | if (c.success) { 1074 | 1075 | return [c, 1076 | new xColor([c["b"], c["r"], c["b"]]), 1077 | new xColor([c["b"], c["g"], c["r"]]), 1078 | new xColor([c["r"], c["b"], c["r"]])]; 1079 | } 1080 | return null; 1081 | }; 1082 | 1083 | this["gradientlevel"] = function (x, y, level, deg) { 1084 | 1085 | if (undefined === deg) deg = 1; 1086 | 1087 | if (level > deg) return null; 1088 | 1089 | var a = new xColor(x); 1090 | var b = new xColor(y); 1091 | 1092 | if (a.success & b.success) { 1093 | 1094 | a["r"] = (a["r"] + ((b["r"] - a["r"]) / deg) * level)|0; 1095 | a["g"] = (a["g"] + ((b["g"] - a["g"]) / deg) * level)|0; 1096 | a["b"] = (a["b"] + ((b["b"] - a["b"]) / deg) * level)|0; 1097 | 1098 | return a; 1099 | } 1100 | return null; 1101 | }; 1102 | 1103 | this["gradientarray"] = function(arr, level, deg) { 1104 | 1105 | if (level > deg || !arr.length) return null; 1106 | 1107 | if (arr.length == 1) { 1108 | return new xColor(arr[0]); 1109 | } 1110 | 1111 | var e = level * (arr.length - 1) / (deg + 1) | 0; 1112 | var step = deg / (arr.length - 1); 1113 | 1114 | return $["xcolor"]["gradientlevel"](arr[e], arr[e + 1], level - e * step, step); 1115 | }; 1116 | 1117 | this["nearestname"] = function (a) { 1118 | 1119 | a = new xColor(a); 1120 | 1121 | if (a.success) { 1122 | return a["getName"](); 1123 | } 1124 | return null; 1125 | }; 1126 | 1127 | this["darken"] = function (col, by, shade) { 1128 | 1129 | if (undefined === by) { 1130 | by = 1; 1131 | } else if (by < 0) return this["lighten"](col, -by, shade); 1132 | 1133 | if (undefined === shade) { 1134 | shade = 32; 1135 | } 1136 | 1137 | var c = new xColor(col); 1138 | 1139 | if (c.success) { 1140 | if ((c["r"]-= shade * by) < 0) c["r"] = 0; 1141 | if ((c["g"]-= shade * by) < 0) c["g"] = 0; 1142 | if ((c["b"]-= shade * by) < 0) c["b"] = 0; 1143 | return c; 1144 | } 1145 | return null; 1146 | }; 1147 | 1148 | this["lighten"] = function (col, by, shade) { 1149 | 1150 | if (undefined === by) { 1151 | by = 1; 1152 | } else if (by < 0) return this["darken"](col, -by, shade); 1153 | 1154 | if (undefined === shade) { 1155 | shade = 32; 1156 | } 1157 | 1158 | var c = new xColor(col); 1159 | 1160 | if (c.success) { 1161 | if ((c["r"]+= shade * by) > 0xff) c["r"] = 0xff; 1162 | if ((c["g"]+= shade * by) > 0xff) c["g"] = 0xff; 1163 | if ((c["b"]+= shade * by) > 0xff) c["b"] = 0xff; 1164 | return c; 1165 | } 1166 | return null; 1167 | }; 1168 | 1169 | this["analogous"] = function (col, results, slices) { 1170 | 1171 | if (undefined === results) { 1172 | results = 8; 1173 | } 1174 | 1175 | if (undefined === slices) { 1176 | slices = 30; 1177 | } 1178 | 1179 | var c = new xColor(col); 1180 | 1181 | if (c.success) { 1182 | 1183 | var hsv = c["getHSV"](); 1184 | var part = 360 / slices, ret = [ c ]; 1185 | 1186 | for (hsv["h"] = ((hsv["h"] - (part * results >> 1)) + 720) % 360; --results; ) { 1187 | hsv["h"]+= part; 1188 | hsv["h"]%= 360; 1189 | ret.push(new xColor(hsv)); 1190 | } 1191 | return ret; 1192 | } 1193 | return null; 1194 | }; 1195 | 1196 | this["complementary"] = function(col) { 1197 | 1198 | var c = new xColor(col); 1199 | 1200 | if(c.success) { 1201 | 1202 | var hsl = c["getHSL"](); 1203 | 1204 | hsl["h"] = (hsl["h"] + 180) % 360; 1205 | 1206 | return new xColor(hsl); 1207 | } 1208 | return null; 1209 | }; 1210 | 1211 | this["splitcomplement"] = function (col) { 1212 | 1213 | var c = new xColor(col); 1214 | 1215 | if (c.success) { 1216 | 1217 | var hsv = c["getHSV"](); 1218 | var ret = [ c ]; 1219 | 1220 | hsv["h"]+= 72; 1221 | hsv["h"]%= 360; 1222 | ret.push(new xColor(hsv)); 1223 | 1224 | hsv["h"]+= 144; 1225 | hsv["h"]%= 360; 1226 | ret.push(new xColor(hsv)); 1227 | 1228 | return ret; 1229 | } 1230 | return null; 1231 | }; 1232 | 1233 | this["monochromatic"] = function (col, results) { 1234 | 1235 | if (undefined === results) { 1236 | results = 6; 1237 | } 1238 | 1239 | var c = new xColor(col); 1240 | 1241 | if (c.success) { 1242 | 1243 | var hsv = c["getHSV"](); 1244 | var ret = [ c ]; 1245 | 1246 | while (--results) { 1247 | hsv["v"]+= 20; 1248 | hsv["v"]%= 100; 1249 | ret.push(new xColor(hsv)); 1250 | } 1251 | return ret; 1252 | } 1253 | return null; 1254 | }; 1255 | } 1256 | 1257 | $["xcolor"] = new xColorMix(); 1258 | 1259 | $["fn"]["readable"] = function () { 1260 | 1261 | var elem = this[0]; 1262 | var f = ""; 1263 | var b = ""; 1264 | 1265 | do { 1266 | 1267 | if ("" === f && ("transparent" === (f = $["css"](elem, "color")) || "rgba(0, 0, 0, 0)" === f)) { 1268 | f = ""; 1269 | } 1270 | 1271 | if ("" === b && ("transparent" === (b = $["css"](elem, "backgroundColor")) || "rgba(0, 0, 0, 0)" === b)) { 1272 | b = ""; 1273 | } 1274 | 1275 | if ("" !== f && "" !== b || $["nodeName"](elem, "body")) { 1276 | break; 1277 | } 1278 | 1279 | } while ((elem = elem["parentNode"])); 1280 | 1281 | if ("" === f) { 1282 | f = "black"; 1283 | } 1284 | 1285 | if ("" === b) { 1286 | b = "white"; 1287 | } 1288 | 1289 | // todo: if alpha != 1, use opacity() to calculate correct color on certain element and it's parent 1290 | return $["xcolor"]["readable"](b, f); 1291 | }; 1292 | 1293 | $["fn"]["colorize"] = function (FROM, TO, TYPE) { 1294 | 1295 | var modifiers = { 1296 | 1297 | // Returns number in [0, 1] (0 = FROM, 1 = TO) 1298 | 1299 | "gradient": function (k, l, diff, c) { 1300 | return k / l; 1301 | }, 1302 | "flip": function (k, l, diff, c) { 1303 | return (" " === c) ? diff : !diff; 1304 | }, 1305 | "pillow": function (k, l, diff, c) { 1306 | k*= 2; 1307 | return (k <= l) 1308 | ? (k / l) 1309 | : (2 - k / l); 1310 | } 1311 | }; 1312 | 1313 | if ("function" === typeof TYPE) { 1314 | /* void */ 1315 | } else if (void 0 === modifiers[TYPE]) { 1316 | return; 1317 | } else { 1318 | TYPE = modifiers[TYPE]; 1319 | } 1320 | 1321 | FROM = new xColor(FROM); 1322 | TO = new xColor(TO); 1323 | 1324 | this["each"](function() { 1325 | 1326 | var tmp = this.childNodes, 1327 | LEN = 0, 1328 | K = 0; 1329 | 1330 | if (FROM.success & TO.success) { 1331 | 1332 | for (var i = tmp.length; i--; LEN+= tmp[i]["textContent"].length){} 1333 | 1334 | (function replace(node) { 1335 | 1336 | var i = 0, 1337 | len; 1338 | 1339 | if (3 === node.nodeType) { 1340 | 1341 | var x = FROM; 1342 | var y = TO; 1343 | var l = LEN; 1344 | var elem, ctx, diff = 0, c, calc = TYPE; 1345 | 1346 | len = node.nodeValue.length; 1347 | ctx = document.createElement('span'); 1348 | 1349 | for (i = 0; i < len; ++i) { 1350 | 1351 | elem = document.createElement('span'); 1352 | c = node.nodeValue.charAt(i); 1353 | 1354 | diff = calc(K, l, diff, c); 1355 | 1356 | elem["style"]["color"] =_RGBAtoCSS( 1357 | x["r"] + diff * (y["r"] - x["r"])|0, 1358 | x["g"] + diff * (y["g"] - x["g"])|0, 1359 | x["b"] + diff * (y["b"] - x["b"])|0, 1360 | x["a"] + diff * (y["a"] - x["a"]) 1361 | ); 1362 | 1363 | elem.appendChild(document.createTextNode( 1364 | c 1365 | ) 1366 | ); 1367 | ctx.appendChild(elem); 1368 | ++K; 1369 | } 1370 | node.parentNode.replaceChild(ctx, node); 1371 | 1372 | } else { 1373 | for (len = node.childNodes.length; i < len; ++i) { 1374 | replace(node.childNodes[i]); 1375 | } 1376 | } 1377 | })(this); 1378 | 1379 | } 1380 | }); 1381 | }; 1382 | 1383 | }(jQuery)); 1384 | -------------------------------------------------------------------------------- /jquery.xcolor.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | jQuery paging plugin v1.8.0 06/21/2010 3 | http://www.xarg.org/project/jquery-color-plugin-xcolor/ 4 | 5 | Copyright (c) 2010, Robert Eisele (robert@xarg.org) 6 | Dual licensed under the MIT or GPL Version 2 licenses. 7 | */ 8 | (function(h,k){function e(a){function d(a,b){var d;k!==a&&(a=parseFloat(a));if(k===b)d=b=255;else if(1===b){if(k===a||1===a)return 1;b=100;d=1}else d=b;return isNaN(a)||0>=a?0:ba||1===b?1===d?a:a*d|0:a*d/b}function b(a,b,c){function e(a,b,d){d=++d%1;return 1>6*d?a+6*(b-a)*d:1>2*d?b:2>3*d?a+(b-a)*(4-6*d):a}a=d(a,360)/360;b=d(b,1);c=d(c,1);if(0===b)return c=Math.round(255*c),[c,c,c];b=0.5>c?c+c*b:c+b-c*b;c=c+c-b;return[Math.round(255*e(c,b,a+1/3)),Math.round(255*e(c,b,a)),Math.round(255*e(c, 9 | b,a-1/3))]}function c(a,b,c){a=d(a,360)/60;b=d(b,1);c=d(c,1);var e=a|0,n=a-e;a=Math.round(255*c*(1-b));var l=Math.round(255*c*(1-b*n));b=Math.round(255*c*(1-b*(1-n)));c=Math.round(255*c);switch(e){case 1:return[l,c,a];case 2:return[a,c,b];case 3:return[a,l,c];case 4:return[b,a,c];case 5:return[c,a,l]}return[c,b,a]}this.setColor=function(a){this.c=!0;if("number"===typeof a)this.a=(a>>24&255)/255,this.r=a>>16&255,this.g=a>>8&255,this.b=a&255;else{for(;"object"===typeof a;){if(0 in a&&1 in a&&2 in a){this.a= 10 | d(a[3],1);this.r=d(a[0]);this.g=d(a[1]);this.b=d(a[2]);return}if("r"in a&&"g"in a&&"b"in a){this.a=d(a.a,1);this.r=d(a.r);this.g=d(a.g);this.b=d(a.b);return}if("h"in a&&"s"in a){var f;if("l"in a)f=b(a.h,a.s,a.l);else if("v"in a)f=c(a.h,a.s,a.v);else if("b"in a)f=c(a.h,a.s,a.b);else break;this.a=d(a.a,1);this.r=f[0];this.g=f[1];this.b=f[2];return}break}if("string"===typeof a){a=a.toLowerCase().replace(/[^a-z0-9,.()#%]/g,"");if("transparent"===a){this.a=this.r=this.g=this.b=0;return}if("rand"===a){a= 11 | 16777215*Math.random()|0;this.a=1;this.r=a>>16&255;this.g=a>>8&255;this.b=a&255;return}k!==q[a]&&(a="#"+q[a]);if(f=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/.exec(a)){this.a=1;this.r=parseInt(f[1],16);this.g=parseInt(f[2],16);this.b=parseInt(f[3],16);return}if(f=/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(a)){this.a=1;this.r=parseInt(f[1]+f[1],16);this.g=parseInt(f[2]+f[2],16);this.b=parseInt(f[3]+f[3],16);return}if(f=/^rgba?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?\)$/.exec(a)){this.a=d(f[5], 12 | 1);this.r=d(f[1]);this.g=d(f[2]);this.b=d(f[3]);return}if(f=/^rgba?\(([0-9.]+\%),([0-9.]+\%),([0-9.]+\%)(,([0-9.]+)\%?)?\)$/.exec(a)){this.a=d(f[5],1);this.r=Math.round(2.55*d(f[1],100));this.g=Math.round(2.55*d(f[2],100));this.b=Math.round(2.55*d(f[3],100));return}if(f=/^hs([bvl])a?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?\)$/.exec(a)){a=("l"===f[1]?b:c)(parseInt(f[2],10),parseInt(f[3],10),parseInt(f[4],10));this.a=d(f[6],1);this.r=a[0];this.g=a[1];this.b=a[2];return}if(f=/^(\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?$/.exec(a)){this.a= 13 | d(f[5],1);this.r=d(f[1]);this.g=d(f[2]);this.b=d(f[3]);return}}this.c=!1}};this.getColor=function(a){if(k!==a)switch(a.toLowerCase()){case "rgb":return this.getRGB();case "hsv":case "hsb":return this.getHSV();case "hsl":return this.getHSL();case "int":return this.getInt();case "array":return this.getArray();case "fraction":return this.getFraction();case "css":case "style":return this.getCSS();case "name":return this.getName()}return this.getHex()};this.getRGB=function(){return this.c?{r:this.r,g:this.g, 14 | b:this.b,a:this.a}:null};this.getCSS=function(){return this.c?0===this.a?"transparent":1===this.a?"rgb("+this.r+","+this.g+","+this.b+")":r(this.r,this.g,this.b,this.a):null};this.getArray=function(){return this.c?[this.r,this.g,this.b,100*this.a|0]:null};this.getName=function(){if(this.c){var a=null,b,d=q,c=this.getHSL(),n;for(n in d){var l=(new e(d[n])).getHSL(),l=Math.sqrt(0.5*(c.h-l.h)*(c.h-l.h)+0.5*(c.s-l.s)*(c.s-l.s)+(c.l-l.l)*(c.l-l.l));if(null===a||lh?e+c:2-e-c));return{h:Math.round((6+a)%6*60),s:Math.round(100*c),l:Math.round(100*h),a:this.a}}return null};this.getHSV=function(){if(this.c){var a=this.r/255,b=this.g/255,c=this.b/255,d=Math.min(a,b,c),e=Math.max(a,b,c),d=e-d; 16 | return{h:Math.round((6+(0===d?0:a===e?(b-c)/d:b===e?2+(c-a)/d:4+(a-b)/d))%6*60),s:Math.round(100*(0===e?0:d/e)),v:Math.round(100*e),a:this.a}}return null};this.getHex=function(){return this.c?"#"+"0123456789abcdef".charAt(this.r>>4)+"0123456789abcdef".charAt(this.r&15)+"0123456789abcdef".charAt(this.g>>4)+"0123456789abcdef".charAt(this.g&15)+"0123456789abcdef".charAt(this.b>>4)+"0123456789abcdef".charAt(this.b&15):null};this.getInt=function(a){return this.c?k!==a?(100*this.a|0)<<24^this.r<<16^this.g<< 17 | 8^this.b:(this.r<<16^this.g<<8^this.b)&16777215:null};this.toString=function(){return this.getHex()};this.setColor(a)}function s(a,d){var b="";do if(b=h.css(a,d),""!==b&&"transparent"!==b&&"rgba(0, 0, 0, 0)"!==b||h.nodeName(a,"body"))break;while(a=a.parentNode);""===b&&(b=h.support.rgba?"transparent":"backgroundColor"===d?"white":"black");return new e(b)}var q={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd", 18 | blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f", 19 | darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0", 20 | khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa", 21 | mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5", 22 | peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3", 23 | white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},r;h.each("color backgroundColor borderColor borderTopColor borderBottomColor borderLeftColor borderRightColor outlineColor".split(" "),function(a,d){h.cssHooks[d]={set:function(a,c){a.style[d]=(new e(c)).getCSS()}};h.fx.step[d]=function(a){if(k===a.xinit){if("string"===typeof a.end&&-1!==a.end.indexOf(";")){var c,g=a.end.split(";");if(2f?h|0:g.length-2;c=g[f];g=g[f+1];f=h-f}a.elem.style[d]=r(c.r+f*(g.r-c.r)|0,c.g+f*(g.g-c.g)|0,c.b+f*(g.b-c.b)|0,c.a+f*(g.a-c.a))}});h(function(){var a=document.createElement("div").style;r=function(a,b,c,e){return"rgba("+a+","+b+","+c+","+e+")"};a.cssText="background-color:rgba(1,1,1,.5)";(h.support.rgba=-1-0.5-154.709*Math.pow(0.99,b))):null};this.combine=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(b.r^=c.r,b.g^=c.g,b.b^=c.b,b):null};this.breed=function(a,d){var b=new e(a),c=new e(d),g=0,f=6;if(b.c&c.c){for(;f--;)0.5>Math.random()&&(g|=15<<(f<<2));b.r=b.r&g>>16&255|c.r&(g>>16&255^255);b.g=b.g&g>>8&255|c.g&(g>>8&255^255);b.b=b.b&g>>0&255|c.b&(g>>0&255^255); 29 | return b}return null};this.additive=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(255<(b.r+=c.r)&&(b.r=255),255<(b.g+=c.g)&&(b.g=255),255<(b.b+=c.b)&&(b.b=255),b):null};this.subtractive=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(0>(b.r+=c.r-255)&&(b.r=0),0>(b.g+=c.g-255)&&(b.g=0),0>(b.b+=c.b-255)&&(b.b=0),b):null};this.subtract=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(0>(b.r-=c.r)&&(b.r=0),0>(b.g-=c.g)&&(b.g=0),0>(b.b-=c.b)&&(b.b=0),b):null};this.multiply=function(a, 30 | d){var b=new e(a),c=new e(d);return b.c&c.c?(b.r=b.r/255*c.r|0,b.g=b.g/255*c.g|0,b.b=b.b/255*c.b|0,b):null};this.average=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(b.r=b.r+c.r>>1,b.g=b.g+c.g>>1,b.b=b.b+c.b>>1,b):null};this.triad=function(a){a=new e(a);return a.c?[a,new e([a.b,a.r,a.g]),new e([a.g,a.b,a.r])]:null};this.tetrad=function(a){a=new e(a);return a.c?[a,new e([a.b,a.r,a.b]),new e([a.b,a.g,a.r]),new e([a.r,a.b,a.r])]:null};this.gradientlevel=function(a,d,b,c){k===c&&(c=1);if(b> 31 | c)return null;a=new e(a);d=new e(d);return a.c&d.c?(a.r=a.r+(d.r-a.r)/c*b|0,a.g=a.g+(d.g-a.g)/c*b|0,a.b=a.b+(d.b-a.b)/c*b|0,a):null};this.gradientarray=function(a,d,b){if(d>b||!a.length)return null;if(1==a.length)return new e(a[0]);var c=d*(a.length-1)/(b+1)|0;b=b/(a.length-1);return h.xcolor.gradientlevel(a[c],a[c+1],d-c*b,b)};this.nearestname=function(a){a=new e(a);return a.c?a.getName():null};this.darken=function(a,d,b){if(k===d)d=1;else if(0>d)return this.lighten(a,-d,b);k===b&&(b=32);a=new e(a); 32 | return a.c?(0>(a.r-=b*d)&&(a.r=0),0>(a.g-=b*d)&&(a.g=0),0>(a.b-=b*d)&&(a.b=0),a):null};this.lighten=function(a,d,b){if(k===d)d=1;else if(0>d)return this.darken(a,-d,b);k===b&&(b=32);a=new e(a);return a.c?(255<(a.r+=b*d)&&(a.r=255),255<(a.g+=b*d)&&(a.g=255),255<(a.b+=b*d)&&(a.b=255),a):null};this.analogous=function(a,d,b){k===d&&(d=8);k===b&&(b=30);var c=new e(a);if(c.c){a=c.getHSV();b=360/b;c=[c];for(a.h=(a.h-(b*d>>1)+720)%360;--d;)a.h+=b,a.h%=360,c.push(new e(a));return c}return null};this.complementary= 33 | function(a){a=new e(a);return a.c?(a=a.getHSL(),a.h=(a.h+180)%360,new e(a)):null};this.splitcomplement=function(a){var d=new e(a);return d.c?(a=d.getHSV(),d=[d],a.h+=72,a.h%=360,d.push(new e(a)),a.h+=144,a.h%=360,d.push(new e(a)),d):null};this.monochromatic=function(a,d){k===d&&(d=6);var b=new e(a);if(b.c){for(var c=b.getHSV(),b=[b];--d;)c.v+=20,c.v%=100,b.push(new e(c));return b}return null}};h.fn.readable=function(){var a=this[0],d="",b="";do if(""!==d||"transparent"!==(d=h.css(a,"color"))&&"rgba(0, 0, 0, 0)"!== 34 | d||(d=""),""!==b||"transparent"!==(b=h.css(a,"backgroundColor"))&&"rgba(0, 0, 0, 0)"!==b||(b=""),""!==d&&""!==b||h.nodeName(a,"body"))break;while(a=a.parentNode);""===d&&(d="black");""===b&&(b="white");return h.xcolor.readable(b,d)};h.fn.colorize=function(a,d,b){var c={gradient:function(a,b){return a/b},flip:function(a,b,c,d){return" "===d?c:!c},pillow:function(a,b){a*=2;return a<=b?a/b:2-a/b}};if("function"!==typeof b){if(void 0===c[b])return;b=c[b]}a=new e(a);d=new e(d);this.each(function(){var c= 35 | this.childNodes,e=0,h=0;if(a.c&d.c){for(var k=c.length;k--;e+=c[k].textContent.length);(function l(c){var g=0,k;if(3===c.nodeType){var m=a,t=d,q=e,u,v,p=0,w,s=b;k=c.nodeValue.length;v=document.createElement("span");for(g=0;g=1.5" 25 | }, 26 | "homepage": "https://github.com/infusion/jQuery-xcolor", 27 | "demo": "http://www.xarg.org/project/jquery-color-plugin-xcolor/" 28 | } --------------------------------------------------------------------------------