colorPicker

Advanced javaScript color picker and color conversion / calculation (rgb, hsv, hsl, hex, cmyk, cmy, XYZ, Lab, alpha, WCAG 2.0, ...)

目前為 2016-09-13 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/23181/147216/colorPicker.js

  1. /** jsColor Picker (https://github.com/PitPik/colorPicker)
  2. * MIT license
  3. * This library contains the following files from that same repository:
  4. * - colors.js
  5. * - colorPicker.data.js
  6. * - colorPicker.js
  7. * - javascript_implementation/jsColor.js
  8. */
  9. /*! color.js */
  10. ;(function(window, undefined){
  11. "use strict"
  12.  
  13. var _valueRanges = {
  14. rgb: {r: [0, 255], g: [0, 255], b: [0, 255]},
  15. hsv: {h: [0, 360], s: [0, 100], v: [0, 100]},
  16. hsl: {h: [0, 360], s: [0, 100], l: [0, 100]},
  17. cmy: {c: [0, 100], m: [0, 100], y: [0, 100]},
  18. cmyk: {c: [0, 100], m: [0, 100], y: [0, 100], k: [0, 100]},
  19. Lab: {L: [0, 100], a: [-128, 127], b: [-128, 127]},
  20. XYZ: {X: [0, 100], Y: [0, 100], Z: [0, 100]},
  21. alpha: {alpha: [0, 1]},
  22. HEX: {HEX: [0, 16777215]} // maybe we don't need this
  23. },
  24.  
  25. _instance = {},
  26. _colors = {},
  27.  
  28. // http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html for more
  29. XYZMatrix = { // Observer = 2° (CIE 1931), Illuminant = D65
  30. X: [ 0.4124564, 0.3575761, 0.1804375],
  31. Y: [ 0.2126729, 0.7151522, 0.0721750],
  32. Z: [ 0.0193339, 0.1191920, 0.9503041],
  33. R: [ 3.2404542, -1.5371385, -0.4985314],
  34. G: [-0.9692660, 1.8760108, 0.0415560],
  35. B: [ 0.0556434, -0.2040259, 1.0572252]
  36. },
  37. grey = {r: 0.298954, g: 0.586434, b: 0.114612}, // CIE-XYZ 1931
  38. luminance = {r: 0.2126, g: 0.7152, b: 0.0722}, // W3C 2.0
  39.  
  40. _math = window.Math,
  41. _parseint = window.parseInt,
  42.  
  43. Colors = window.Colors = function(options) {
  44. this.colors = {RND: {}};
  45. this.options = {
  46. color: 'rgba(204, 82, 37, 0.8)', // init value(s)...
  47. XYZMatrix: XYZMatrix,
  48. // XYZReference: {},
  49. grey: grey,
  50. luminance: luminance,
  51. valueRanges: _valueRanges
  52. // customBG: '#808080'
  53. // convertCallback: undefined,
  54. // allMixDetails: false
  55. };
  56. initInstance(this, options || {});
  57. },
  58. initInstance = function(THIS, options) {
  59. var matrix,
  60. importColor,
  61. _options = THIS.options,
  62. customBG;
  63.  
  64. focusInstance(THIS);
  65. for (var option in options) {
  66. if (options[option] !== undefined) _options[option] = options[option];
  67. }
  68. matrix = _options.XYZMatrix;
  69. if (!options.XYZReference) _options.XYZReference = {
  70. X: matrix.X[0] + matrix.X[1] + matrix.X[2],
  71. Y: matrix.Y[0] + matrix.Y[1] + matrix.Y[2],
  72. Z: matrix.Z[0] + matrix.Z[1] + matrix.Z[2]
  73. };
  74. customBG = _options.customBG;
  75. _options.customBG = (typeof customBG === 'string') ? ColorConverter.txt2color(customBG).rgb : customBG;
  76. _colors = setColor(THIS.colors, _options.color, undefined, true); // THIS.colors = _colors =
  77. },
  78. focusInstance = function(THIS) {
  79. if (_instance !== THIS) {
  80. _instance = THIS;
  81. _colors = THIS.colors;
  82. }
  83. };
  84.  
  85. Colors.prototype.setColor = function(newCol, type, alpha) {
  86. focusInstance(this);
  87. if (newCol) {
  88. return setColor(this.colors, newCol, type, undefined, alpha);
  89. } else {
  90. if (alpha !== undefined) {
  91. this.colors.alpha = limitValue(alpha, 0, 1);
  92. }
  93. return convertColors(type);
  94. }
  95. };
  96.  
  97. Colors.prototype.getColor = function(type) {
  98. var result = this.colors, n = 0;
  99.  
  100. if (type) {
  101. type = type.split('.');
  102. while (result[type[n]]) {
  103. result = result[type[n++]];
  104. }
  105. if (type.length !== n) {
  106. result = undefined;
  107. }
  108. }
  109. return result;
  110. };
  111.  
  112. Colors.prototype.setCustomBackground = function(col) { // wild gues,... check again...
  113. focusInstance(this); // needed???
  114. this.options.customBG = (typeof col === 'string') ? ColorConverter.txt2color(col).rgb : col;
  115. // return setColor(this.colors, this.options.customBG, 'rgb', true); // !!!!RGB
  116. return setColor(this.colors, undefined, 'rgb'); // just recalculate existing
  117. };
  118.  
  119. Colors.prototype.saveAsBackground = function() { // alpha
  120. focusInstance(this); // needed???
  121. // return setColor(this.colors, this.colors.RND.rgb, 'rgb', true);
  122. return setColor(this.colors, undefined, 'rgb', true);
  123. };
  124.  
  125. Colors.prototype.convertColor = function(color, type) {
  126. var convert = ColorConverter,
  127. ranges = _valueRanges,
  128. types = type.split('2'),
  129. fromType = types[0],
  130. toType = types[1],
  131. test = /(?:RG|HS|CM|LA)/,
  132. normalizeFrom = test.test(fromType),
  133. normalizeTo = test.test(toType),
  134. exceptions = {LAB: 'Lab'},
  135. normalize = function(color, type, reverse) {
  136. var result = {},
  137. Lab = type === 'Lab' ? 1 : 0;
  138.  
  139. for (var n in color) { // faster (but bigger) way: if/else outside 2 for loops
  140. result[n] = reverse ?
  141. _math.round(color[n] * (Lab || ranges[type][n][1])) :
  142. color[n] / (Lab || ranges[type][n][1]);
  143. }
  144.  
  145. return result;
  146. };
  147.  
  148. fromType = ranges[fromType] ? fromType : exceptions[fromType] || fromType.toLowerCase();
  149. toType = ranges[toType] ? toType : exceptions[toType] || toType.toLowerCase();
  150.  
  151. if (normalizeFrom && type !== 'RGB2HEX') { // from ABC to abc
  152. color = normalize(color, fromType);
  153. }
  154. color = fromType === toType ? color : ( // same type; returns same/normalized version
  155. convert[fromType + '2' + toType] ? convert[fromType + '2' + toType](color, true) : // existing converter
  156. toType === 'HEX' ? convert.RGB2HEX(type === 'RGB2HEX' ? color : normalize(fromType === 'rgb' ? color :
  157. convert[fromType + '2rgb'](color, true), 'rgb', true)) :
  158. convert['rgb2' + toType](convert[fromType + '2rgb'](color, true), true) // not in ColorConverter
  159. );
  160. if (normalizeTo) { // from abc to ABC
  161. color = normalize(color, toType, true);
  162. }
  163.  
  164. return color;
  165. };
  166.  
  167. Colors.prototype.toString = function(colorMode, forceAlpha) {
  168. return ColorConverter.color2text((colorMode || 'rgb').toLowerCase(), this.colors, forceAlpha);
  169. };
  170.  
  171.  
  172. // ------------------------------------------------------ //
  173. // ---------- Color calculation related stuff ---------- //
  174. // -------------------------------------------------------//
  175.  
  176. function setColor(colors, color, type, save, alpha) { // color only full range
  177. if (typeof color === 'string') {
  178. var color = ColorConverter.txt2color(color); // new object
  179. type = color.type;
  180. _colors[type] = color[type];
  181. alpha = alpha !== undefined ? alpha : color.alpha;
  182. } else if (color) {
  183. for (var n in color) {
  184. colors[type][n] = type === 'Lab' ?
  185. limitValue(color[n], _valueRanges[type][n][0], _valueRanges[type][n][1]) :
  186. limitValue(color[n] / _valueRanges[type][n][1], 0 , 1);
  187. }
  188. }
  189. if (alpha !== undefined) {
  190. colors.alpha = limitValue(+alpha, 0, 1);
  191. }
  192. return convertColors(type, save ? colors : undefined);
  193. }
  194.  
  195. function saveAsBackground(RGB, rgb, alpha) {
  196. var grey = _instance.options.grey,
  197. color = {};
  198.  
  199. color.RGB = {r: RGB.r, g: RGB.g, b: RGB.b};
  200. color.rgb = {r: rgb.r, g: rgb.g, b: rgb.b};
  201. color.alpha = alpha;
  202. // color.RGBLuminance = getLuminance(RGB);
  203. color.equivalentGrey = _math.round(grey.r * RGB.r + grey.g * RGB.g + grey.b * RGB.b);
  204.  
  205. color.rgbaMixBlack = mixColors(rgb, {r: 0, g: 0, b: 0}, alpha, 1);
  206. color.rgbaMixWhite = mixColors(rgb, {r: 1, g: 1, b: 1}, alpha, 1);
  207. color.rgbaMixBlack.luminance = getLuminance(color.rgbaMixBlack, true);
  208. color.rgbaMixWhite.luminance = getLuminance(color.rgbaMixWhite, true);
  209.  
  210. if (_instance.options.customBG) {
  211. color.rgbaMixCustom = mixColors(rgb, _instance.options.customBG, alpha, 1);
  212. color.rgbaMixCustom.luminance = getLuminance(color.rgbaMixCustom, true);
  213. _instance.options.customBG.luminance = getLuminance(_instance.options.customBG, true);
  214. }
  215.  
  216. return color;
  217. }
  218.  
  219. function convertColors(type, colorObj) {
  220. // console.time('convertColors');
  221. var _Math = _math,
  222. colors = colorObj || _colors,
  223. convert = ColorConverter,
  224. options = _instance.options,
  225. ranges = _valueRanges,
  226. RND = colors.RND,
  227. // type = colorType, // || _mode.type,
  228. modes, mode = '', from = '', // value = '',
  229. exceptions = {hsl: 'hsv', cmyk: 'cmy', rgb: type},
  230. RGB = RND.rgb, SAVE, SMART;
  231.  
  232. if (type !== 'alpha') {
  233. for (var typ in ranges) {
  234. if (!ranges[typ][typ]) { // no alpha|HEX
  235. if (type !== typ && typ !== 'XYZ') {
  236. from = exceptions[typ] || 'rgb';
  237. colors[typ] = convert[from + '2' + typ](colors[from]);
  238. }
  239.  
  240. if (!RND[typ]) RND[typ] = {};
  241. modes = colors[typ];
  242. for(mode in modes) {
  243. RND[typ][mode] = _Math.round(modes[mode] * (typ === 'Lab' ? 1 : ranges[typ][mode][1]));
  244. }
  245. }
  246. }
  247. if (type !== 'Lab') {
  248. delete colors._rgb;
  249. }
  250.  
  251. RGB = RND.rgb;
  252. colors.HEX = convert.RGB2HEX(RGB);
  253. colors.equivalentGrey =
  254. options.grey.r * colors.rgb.r +
  255. options.grey.g * colors.rgb.g +
  256. options.grey.b * colors.rgb.b;
  257. colors.webSave = SAVE = getClosestWebColor(RGB, 51);
  258. // colors.webSave.HEX = convert.RGB2HEX(colors.webSave);
  259. colors.webSmart = SMART = getClosestWebColor(RGB, 17);
  260. // colors.webSmart.HEX = convert.RGB2HEX(colors.webSmart);
  261. colors.saveColor =
  262. RGB.r === SAVE.r && RGB.g === SAVE.g && RGB.b === SAVE.b ? 'web save' :
  263. RGB.r === SMART.r && RGB.g === SMART.g && RGB.b === SMART.b ? 'web smart' : '';
  264. colors.hueRGB = convert.hue2RGB(colors.hsv.h);
  265.  
  266. if (colorObj) {
  267. colors.background = saveAsBackground(RGB, colors.rgb, colors.alpha);
  268. }
  269. } // else RGB = RND.rgb;
  270.  
  271. var rgb = colors.rgb, // for better minification...
  272. alpha = colors.alpha,
  273. luminance = 'luminance',
  274. background = colors.background,
  275. rgbaMixBlack, rgbaMixWhite, rgbaMixCustom,
  276. rgbaMixBG, rgbaMixBGMixBlack, rgbaMixBGMixWhite, rgbaMixBGMixCustom,
  277. _mixColors = mixColors,
  278. _getLuminance = getLuminance,
  279. _getWCAG2Ratio = getWCAG2Ratio,
  280. _getHueDelta = getHueDelta;
  281.  
  282. rgbaMixBlack = _mixColors(rgb, {r: 0, g: 0, b: 0}, alpha, 1);
  283. rgbaMixBlack[luminance] = _getLuminance(rgbaMixBlack, true);
  284. colors.rgbaMixBlack = rgbaMixBlack;
  285.  
  286. rgbaMixWhite = _mixColors(rgb, {r: 1, g: 1, b: 1}, alpha, 1);
  287. rgbaMixWhite[luminance] = _getLuminance(rgbaMixWhite, true);
  288. colors.rgbaMixWhite = rgbaMixWhite;
  289.  
  290. if (options.allMixDetails) {
  291. rgbaMixBlack.WCAG2Ratio = _getWCAG2Ratio(rgbaMixBlack[luminance], 0);
  292. rgbaMixWhite.WCAG2Ratio = _getWCAG2Ratio(rgbaMixWhite[luminance], 1);
  293.  
  294. if (options.customBG) {
  295. rgbaMixCustom = _mixColors(rgb, options.customBG, alpha, 1);
  296. rgbaMixCustom[luminance] = _getLuminance(rgbaMixCustom, true);
  297. rgbaMixCustom.WCAG2Ratio = _getWCAG2Ratio(rgbaMixCustom[luminance], options.customBG[luminance]);
  298. colors.rgbaMixCustom = rgbaMixCustom;
  299. }
  300.  
  301. rgbaMixBG = _mixColors(rgb, background.rgb, alpha, background.alpha);
  302. rgbaMixBG[luminance] = _getLuminance(rgbaMixBG, true); // ?? do we need this?
  303. colors.rgbaMixBG = rgbaMixBG;
  304.  
  305. rgbaMixBGMixBlack = _mixColors(rgb, background.rgbaMixBlack, alpha, 1);
  306. rgbaMixBGMixBlack[luminance] = _getLuminance(rgbaMixBGMixBlack, true);
  307. rgbaMixBGMixBlack.WCAG2Ratio = _getWCAG2Ratio(rgbaMixBGMixBlack[luminance],
  308. background.rgbaMixBlack[luminance]);
  309. /* ------ */
  310. rgbaMixBGMixBlack.luminanceDelta = _Math.abs(
  311. rgbaMixBGMixBlack[luminance] - background.rgbaMixBlack[luminance]);
  312. rgbaMixBGMixBlack.hueDelta = _getHueDelta(background.rgbaMixBlack, rgbaMixBGMixBlack, true);
  313. /* ------ */
  314. colors.rgbaMixBGMixBlack = rgbaMixBGMixBlack;
  315.  
  316. rgbaMixBGMixWhite = _mixColors(rgb, background.rgbaMixWhite, alpha, 1);
  317. rgbaMixBGMixWhite[luminance] = _getLuminance(rgbaMixBGMixWhite, true);
  318. rgbaMixBGMixWhite.WCAG2Ratio = _getWCAG2Ratio(rgbaMixBGMixWhite[luminance],
  319. background.rgbaMixWhite[luminance]);
  320. /* ------ */
  321. rgbaMixBGMixWhite.luminanceDelta = _Math.abs(
  322. rgbaMixBGMixWhite[luminance] - background.rgbaMixWhite[luminance]);
  323. rgbaMixBGMixWhite.hueDelta = _getHueDelta(background.rgbaMixWhite, rgbaMixBGMixWhite, true);
  324. /* ------ */
  325. colors.rgbaMixBGMixWhite = rgbaMixBGMixWhite;
  326. }
  327.  
  328. if (options.customBG) {
  329. rgbaMixBGMixCustom = _mixColors(rgb, background.rgbaMixCustom, alpha, 1);
  330. rgbaMixBGMixCustom[luminance] = _getLuminance(rgbaMixBGMixCustom, true);
  331. rgbaMixBGMixCustom.WCAG2Ratio = _getWCAG2Ratio(rgbaMixBGMixCustom[luminance],
  332. background.rgbaMixCustom[luminance]);
  333. colors.rgbaMixBGMixCustom = rgbaMixBGMixCustom;
  334. /* ------ */
  335. rgbaMixBGMixCustom.luminanceDelta = _Math.abs(
  336. rgbaMixBGMixCustom[luminance] - background.rgbaMixCustom[luminance]);
  337. rgbaMixBGMixCustom.hueDelta = _getHueDelta(background.rgbaMixCustom, rgbaMixBGMixCustom, true);
  338. /* ------ */
  339. }
  340.  
  341. colors.RGBLuminance = _getLuminance(RGB);
  342. colors.HUELuminance = _getLuminance(colors.hueRGB);
  343.  
  344. // renderVars.readyToRender = true;
  345. if (options.convertCallback) {
  346. options.convertCallback(colors, type); //, convert); //, _mode);
  347. }
  348.  
  349. // console.timeEnd('convertColors')
  350. // if (colorObj)
  351. return colors;
  352. }
  353.  
  354.  
  355. // ------------------------------------------------------ //
  356. // ------------------ color conversion ------------------ //
  357. // -------------------------------------------------------//
  358.  
  359. var ColorConverter = {
  360. txt2color: function(txt) {
  361. var color = {},
  362. parts = txt.replace(/(?:#|\)|%)/g, '').split('('),
  363. values = (parts[1] || '').split(/,\s*/),
  364. type = parts[1] ? parts[0].substr(0, 3) : 'rgb',
  365. m = '';
  366.  
  367. color.type = type;
  368. color[type] = {};
  369. if (parts[1]) {
  370. for (var n = 3; n--; ) {
  371. m = type[n] || type.charAt(n); // IE7
  372. color[type][m] = +values[n] / _valueRanges[type][m][1];
  373. }
  374. } else {
  375. color.rgb = ColorConverter.HEX2rgb(parts[0]);
  376. }
  377. // color.color = color[type];
  378. color.alpha = values[3] ? +values[3] : 1;
  379.  
  380. return color;
  381. },
  382.  
  383. color2text: function(colorMode, colors, forceAlpha) {
  384. var alpha = forceAlpha !== false && _math.round(colors.alpha * 100) / 100,
  385. hasAlpha = typeof alpha === 'number' &&
  386. forceAlpha !== false && (forceAlpha || alpha !== 1),
  387. RGB = colors.RND.rgb,
  388. HSL = colors.RND.hsl,
  389. shouldBeHex = colorMode === 'hex' && hasAlpha,
  390. isHex = colorMode === 'hex' && !shouldBeHex,
  391. isRgb = colorMode === 'rgb' || shouldBeHex,
  392. innerText = isRgb ? RGB.r + ', ' + RGB.g + ', ' + RGB.b :
  393. !isHex ? HSL.h + ', ' + HSL.s + '%, ' + HSL.l + '%' :
  394. '#' + colors.HEX;
  395.  
  396. return isHex ? innerText : (shouldBeHex ? 'rgb' : colorMode) +
  397. (hasAlpha ? 'a' : '') + '(' + innerText + (hasAlpha ? ', ' + alpha : '') + ')';
  398. },
  399.  
  400. RGB2HEX: function(RGB) {
  401. return (
  402. (RGB.r < 16 ? '0' : '') + RGB.r.toString(16) +
  403. (RGB.g < 16 ? '0' : '') + RGB.g.toString(16) +
  404. (RGB.b < 16 ? '0' : '') + RGB.b.toString(16)
  405. ).toUpperCase();
  406. },
  407.  
  408. HEX2rgb: function(HEX) {
  409. HEX = HEX.split(''); // IE7
  410. return {
  411. r: +('0x' + HEX[0] + HEX[HEX[3] ? 1 : 0]) / 255,
  412. g: +('0x' + HEX[HEX[3] ? 2 : 1] + (HEX[3] || HEX[1])) / 255,
  413. b: +('0x' + (HEX[4] || HEX[2]) + (HEX[5] || HEX[2])) / 255
  414. };
  415. },
  416.  
  417. hue2RGB: function(hue) {
  418. var _Math = _math,
  419. h = hue * 6,
  420. mod = ~~h % 6, // Math.floor(h) -> faster in most browsers
  421. i = h === 6 ? 0 : (h - mod);
  422.  
  423. return {
  424. r: _Math.round([1, 1 - i, 0, 0, i, 1][mod] * 255),
  425. g: _Math.round([i, 1, 1, 1 - i, 0, 0][mod] * 255),
  426. b: _Math.round([0, 0, i, 1, 1, 1 - i][mod] * 255)
  427. };
  428. },
  429.  
  430. // ------------------------ HSV ------------------------ //
  431.  
  432. rgb2hsv: function(rgb) { // faster
  433. var _Math = _math,
  434. r = rgb.r,
  435. g = rgb.g,
  436. b = rgb.b,
  437. k = 0, chroma, min, s;
  438.  
  439. if (g < b) {
  440. g = b + (b = g, 0);
  441. k = -1;
  442. }
  443. min = b;
  444. if (r < g) {
  445. r = g + (g = r, 0);
  446. k = -2 / 6 - k;
  447. min = _Math.min(g, b); // g < b ? g : b; ???
  448. }
  449. chroma = r - min;
  450. s = r ? (chroma / r) : 0;
  451. return {
  452. h: s < 1e-15 ? ((_colors && _colors.hsl && _colors.hsl.h) || 0) :
  453. chroma ? _Math.abs(k + (g - b) / (6 * chroma)) : 0,
  454. s: r ? (chroma / r) : ((_colors && _colors.hsv && _colors.hsv.s) || 0), // ??_colors.hsv.s || 0
  455. v: r
  456. };
  457. },
  458.  
  459. hsv2rgb: function(hsv) {
  460. var h = hsv.h * 6,
  461. s = hsv.s,
  462. v = hsv.v,
  463. i = ~~h, // Math.floor(h) -> faster in most browsers
  464. f = h - i,
  465. p = v * (1 - s),
  466. q = v * (1 - f * s),
  467. t = v * (1 - (1 - f) * s),
  468. mod = i % 6;
  469.  
  470. return {
  471. r: [v, q, p, p, t, v][mod],
  472. g: [t, v, v, q, p, p][mod],
  473. b: [p, p, t, v, v, q][mod]
  474. };
  475. },
  476.  
  477. // ------------------------ HSL ------------------------ //
  478.  
  479. hsv2hsl: function(hsv) {
  480. var l = (2 - hsv.s) * hsv.v,
  481. s = hsv.s * hsv.v;
  482.  
  483. s = !hsv.s ? 0 : l < 1 ? (l ? s / l : 0) : s / (2 - l);
  484.  
  485. return {
  486. h: hsv.h,
  487. s: !hsv.v && !s ? ((_colors && _colors.hsl && _colors.hsl.s) || 0) : s, // ???
  488. l: l / 2
  489. };
  490. },
  491.  
  492. rgb2hsl: function(rgb, dependent) { // not used in Color
  493. var hsv = ColorConverter.rgb2hsv(rgb);
  494.  
  495. return ColorConverter.hsv2hsl(dependent ? hsv : (_colors.hsv = hsv));
  496. },
  497.  
  498. hsl2rgb: function(hsl) {
  499. var h = hsl.h * 6,
  500. s = hsl.s,
  501. l = hsl.l,
  502. v = l < 0.5 ? l * (1 + s) : (l + s) - (s * l),
  503. m = l + l - v,
  504. sv = v ? ((v - m) / v) : 0,
  505. sextant = ~~h, // Math.floor(h) -> faster in most browsers
  506. fract = h - sextant,
  507. vsf = v * sv * fract,
  508. t = m + vsf,
  509. q = v - vsf,
  510. mod = sextant % 6;
  511.  
  512. return {
  513. r: [v, q, m, m, t, v][mod],
  514. g: [t, v, v, q, m, m][mod],
  515. b: [m, m, t, v, v, q][mod]
  516. };
  517. },
  518.  
  519. // ------------------------ CMYK ------------------------ //
  520. // Quote from Wikipedia:
  521. // "Since RGB and CMYK spaces are both device-dependent spaces, there is no
  522. // simple or general conversion formula that converts between them.
  523. // Conversions are generally done through color management systems, using
  524. // color profiles that describe the spaces being converted. Nevertheless, the
  525. // conversions cannot be exact, since these spaces have very different gamuts."
  526. // Translation: the following are just simple RGB to CMY(K) and visa versa conversion functions.
  527.  
  528. rgb2cmy: function(rgb) {
  529. return {
  530. c: 1 - rgb.r,
  531. m: 1 - rgb.g,
  532. y: 1 - rgb.b
  533. };
  534. },
  535.  
  536. cmy2cmyk: function(cmy) {
  537. var _Math = _math,
  538. k = _Math.min(_Math.min(cmy.c, cmy.m), cmy.y),
  539. t = 1 - k || 1e-20;
  540.  
  541. return { // regular
  542. c: (cmy.c - k) / t,
  543. m: (cmy.m - k) / t,
  544. y: (cmy.y - k) / t,
  545. k: k
  546. };
  547. },
  548.  
  549. cmyk2cmy: function(cmyk) {
  550. var k = cmyk.k;
  551.  
  552. return { // regular
  553. c: cmyk.c * (1 - k) + k,
  554. m: cmyk.m * (1 - k) + k,
  555. y: cmyk.y * (1 - k) + k
  556. };
  557. },
  558.  
  559. cmy2rgb: function(cmy) {
  560. return {
  561. r: 1 - cmy.c,
  562. g: 1 - cmy.m,
  563. b: 1 - cmy.y
  564. };
  565. },
  566.  
  567. rgb2cmyk: function(rgb, dependent) {
  568. var cmy = ColorConverter.rgb2cmy(rgb); // doppelt??
  569.  
  570. return ColorConverter.cmy2cmyk(dependent ? cmy : (_colors.cmy = cmy));
  571. },
  572.  
  573. cmyk2rgb: function(cmyk, dependent) {
  574. var cmy = ColorConverter.cmyk2cmy(cmyk); // doppelt??
  575.  
  576. return ColorConverter.cmy2rgb(dependent ? cmy : (_colors.cmy = cmy));
  577. },
  578.  
  579. // ------------------------ LAB ------------------------ //
  580.  
  581. XYZ2rgb: function(XYZ, skip) {
  582. var _Math = _math,
  583. M = _instance.options.XYZMatrix,
  584. X = XYZ.X,
  585. Y = XYZ.Y,
  586. Z = XYZ.Z,
  587. r = X * M.R[0] + Y * M.R[1] + Z * M.R[2],
  588. g = X * M.G[0] + Y * M.G[1] + Z * M.G[2],
  589. b = X * M.B[0] + Y * M.B[1] + Z * M.B[2],
  590. N = 1 / 2.4;
  591.  
  592. M = 0.0031308;
  593.  
  594. r = (r > M ? 1.055 * _Math.pow(r, N) - 0.055 : 12.92 * r);
  595. g = (g > M ? 1.055 * _Math.pow(g, N) - 0.055 : 12.92 * g);
  596. b = (b > M ? 1.055 * _Math.pow(b, N) - 0.055 : 12.92 * b);
  597.  
  598. if (!skip) { // out of gammut
  599. _colors._rgb = {r: r, g: g, b: b};
  600. }
  601.  
  602. return {
  603. r: limitValue(r, 0, 1),
  604. g: limitValue(g, 0, 1),
  605. b: limitValue(b, 0, 1)
  606. };
  607. },
  608.  
  609. rgb2XYZ: function(rgb) {
  610. var _Math = _math,
  611. M = _instance.options.XYZMatrix,
  612. r = rgb.r,
  613. g = rgb.g,
  614. b = rgb.b,
  615. N = 0.04045;
  616.  
  617. r = (r > N ? _Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92);
  618. g = (g > N ? _Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92);
  619. b = (b > N ? _Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92);
  620.  
  621. return {
  622. X: r * M.X[0] + g * M.X[1] + b * M.X[2],
  623. Y: r * M.Y[0] + g * M.Y[1] + b * M.Y[2],
  624. Z: r * M.Z[0] + g * M.Z[1] + b * M.Z[2]
  625. };
  626. },
  627.  
  628. XYZ2Lab: function(XYZ) {
  629. var _Math = _math,
  630. R = _instance.options.XYZReference,
  631. X = XYZ.X / R.X,
  632. Y = XYZ.Y / R.Y,
  633. Z = XYZ.Z / R.Z,
  634. N = 16 / 116, M = 1 / 3, K = 0.008856, L = 7.787037;
  635.  
  636. X = X > K ? _Math.pow(X, M) : (L * X) + N;
  637. Y = Y > K ? _Math.pow(Y, M) : (L * Y) + N;
  638. Z = Z > K ? _Math.pow(Z, M) : (L * Z) + N;
  639.  
  640. return {
  641. L: (116 * Y) - 16,
  642. a: 500 * (X - Y),
  643. b: 200 * (Y - Z)
  644. };
  645. },
  646.  
  647. Lab2XYZ: function(Lab) {
  648. var _Math = _math,
  649. R = _instance.options.XYZReference,
  650. Y = (Lab.L + 16) / 116,
  651. X = Lab.a / 500 + Y,
  652. Z = Y - Lab.b / 200,
  653. X3 = _Math.pow(X, 3),
  654. Y3 = _Math.pow(Y, 3),
  655. Z3 = _Math.pow(Z, 3),
  656. N = 16 / 116, K = 0.008856, L = 7.787037;
  657.  
  658. return {
  659. X: (X3 > K ? X3 : (X - N) / L) * R.X,
  660. Y: (Y3 > K ? Y3 : (Y - N) / L) * R.Y,
  661. Z: (Z3 > K ? Z3 : (Z - N) / L) * R.Z
  662. };
  663. },
  664.  
  665. rgb2Lab: function(rgb, dependent) {
  666. var XYZ = ColorConverter.rgb2XYZ(rgb);
  667.  
  668. return ColorConverter.XYZ2Lab(dependent ? XYZ : (_colors.XYZ = XYZ));
  669. },
  670.  
  671. Lab2rgb: function(Lab, dependent) {
  672. var XYZ = ColorConverter.Lab2XYZ(Lab);
  673.  
  674. return ColorConverter.XYZ2rgb(dependent ? XYZ : (_colors.XYZ = XYZ), dependent);
  675. }
  676. };
  677.  
  678. // ------------------------------------------------------ //
  679. // ------------------ helper functions ------------------ //
  680. // -------------------------------------------------------//
  681.  
  682. function getClosestWebColor(RGB, val) {
  683. var out = {},
  684. tmp = 0,
  685. half = val / 2;
  686.  
  687. for (var n in RGB) {
  688. tmp = RGB[n] % val; // 51 = 'web save', 17 = 'web smart'
  689. out[n] = RGB[n] + (tmp > half ? val - tmp : -tmp);
  690. }
  691. return out;
  692. }
  693.  
  694. function getHueDelta(rgb1, rgb2, nominal) {
  695. var _Math = _math;
  696.  
  697. return (_Math.max(rgb1.r - rgb2.r, rgb2.r - rgb1.r) +
  698. _Math.max(rgb1.g - rgb2.g, rgb2.g - rgb1.g) +
  699. _Math.max(rgb1.b - rgb2.b, rgb2.b - rgb1.b)) * (nominal ? 255 : 1) / 765;
  700. }
  701.  
  702. function getLuminance(rgb, normalized) {
  703. var div = normalized ? 1 : 255,
  704. RGB = [rgb.r / div, rgb.g / div, rgb.b / div],
  705. luminance = _instance.options.luminance;
  706.  
  707. for (var i = RGB.length; i--; ) {
  708. RGB[i] = RGB[i] <= 0.03928 ? RGB[i] / 12.92 : _math.pow(((RGB[i] + 0.055) / 1.055), 2.4);
  709. }
  710. return ((luminance.r * RGB[0]) + (luminance.g * RGB[1]) + (luminance.b * RGB[2]));
  711. }
  712.  
  713. function mixColors(topColor, bottomColor, topAlpha, bottomAlpha) {
  714. var newColor = {},
  715. alphaTop = (topAlpha !== undefined ? topAlpha : 1),
  716. alphaBottom = (bottomAlpha !== undefined ? bottomAlpha : 1),
  717. alpha = alphaTop + alphaBottom * (1 - alphaTop); // 1 - (1 - alphaTop) * (1 - alphaBottom);
  718.  
  719. for(var n in topColor) {
  720. newColor[n] = (topColor[n] * alphaTop + bottomColor[n] * alphaBottom * (1 - alphaTop)) / alpha;
  721. }
  722. newColor.a = alpha;
  723. return newColor;
  724. }
  725.  
  726. function getWCAG2Ratio(lum1, lum2) {
  727. var ratio = 1;
  728.  
  729. if (lum1 >= lum2) {
  730. ratio = (lum1 + 0.05) / (lum2 + 0.05);
  731. } else {
  732. ratio = (lum2 + 0.05) / (lum1 + 0.05);
  733. }
  734. return _math.round(ratio * 100) / 100;
  735. }
  736.  
  737. function limitValue(value, min, max) {
  738. // return Math.max(min, Math.min(max, value)); // faster??
  739. return (value > max ? max : value < min ? min : value);
  740. }
  741. })(window);
  742.  
  743. /*! colorPicker.data.js */
  744. ;(function(window, undefined){
  745. "use strict"
  746.  
  747. // see colorPicker.html for the following encrypted variables... will only be used in buildView()
  748. var _html = ('^§app alpha-bg-w">^§slds">^§sldl-1">$^§sldl-2">$^§sldl-3">$^§curm">$^§sldr-1">$^§sldr-2">$^§sldr-4">$^§curl">$^§curr">$$^§opacity">|^§opacity-slider">$$$^§memo">^§raster">$^§raster-bg">$|$|$|$|$|$|$|$|$^§memo-store">$^§memo-cursor">$$^§panel">^§hsv">^hsl-mode §ß">$^hsv-h-ß §ß">H$^hsv-h-~ §~">-^§nsarrow">$$^hsl-h-@ §@">H$^hsv-s-ß §ß">S$^hsv-s-~ §~">-$^hsl-s-@ §@">S$^hsv-v-ß §ß">B$^hsv-v-~ §~">-$^hsl-l-@ §@">L$$^§hsl §hide">^hsv-mode §ß">$^hsl-h-ß §ß">H$^hsl-h-~ §~">-$^hsv-h-@ §@">H$^hsl-s-ß §ß">S$^hsl-s-~ §~">-$^hsv-s-@ §@">S$^hsl-l-ß §ß">L$^hsl-l-~ §~">-$^hsv-v-@ §@">B$$^§rgb">^rgb-r-ß §ß">R$^rgb-r-~ §~">-$^rgb-r-@ §ß">&nbsp;$^rgb-g-ß §ß">G$^rgb-g-~ §~">-$^rgb-g-@ §ß">&nbsp;$^rgb-b-ß §ß">B$^rgb-b-~ §~">-$^rgb-b-@ §ß">&nbsp;$$^§cmyk">^Lab-mode §ß">$^cmyk-c-ß §@">C$^cmyk-c-~ §~">-$^Lab-L-@ §@">L$^cmyk-m-ß §@">M$^cmyk-m-~ §~">-$^Lab-a-@ §@">a$^cmyk-y-ß §@">Y$^cmyk-y-~ §~">-$^Lab-b-@ §@">b$^cmyk-k-ß §@">K$^cmyk-k-~ §~">-$^Lab-x-@ §ß">&nbsp;$$^§Lab §hide">^cmyk-mode §ß">$^Lab-L-ß §@">L$^Lab-L-~ §~">-$^cmyk-c-@ §@">C$^Lab-a-ß §@">a$^Lab-a-~ §~">-$^cmyk-m-@ §@">M$^Lab-b-ß §@">b$^Lab-b-~ §~">-$^cmyk-y-@ §@">Y$^Lab-x-ß §@">&nbsp;$^Lab-x-~ §~">-$^cmyk-k-@ §@">K$$^§alpha">^alpha-ß §ß">A$^alpha-~ §~">-$^alpha-@ §ß">W$$^§HEX">^HEX-ß §ß">#$^HEX-~ §~">-$^HEX-@ §ß">M$$^§ctrl">^§raster">$^§cont">$^§cold">$^§col1">|&nbsp;$$^§col2">|&nbsp;$$^§bres">RESET$^§bsav">SAVE$$$^§exit">$^§resize">$^§resizer">|$$$').
  749. replace(/\^/g, '<div class="').replace(/\$/g, '</div>').replace(/~/g, 'disp').replace(/ß/g, 'butt').replace(/@/g, 'labl').replace(/\|/g, '<div>'),
  750. _cssFunc = ('är^1,äg^1,äb^1,öh^1,öh?1,öh?2,ös?1,öv?1,üh^1,üh?1,üh?2,üs?1,ül?1,.no-rgb-r är?2,.no-rgb-r är?3,.no-rgb-r är?4,.no-rgb-g äg?2,.no-rgb-g äg?3,.no-rgb-g äg?4,.no-rgb-b äb?2,.no-rgb-b äb?3,.no-rgb-b äb?4{visibility:hidden}är^2,är^3,äg^2,äg^3,äb^2,äb^3{@-image:url(_patches.png)}.§slds div{@-image:url(_vertical.png)}öh^2,ös^1,öv^1,üh^2,üs^1,ül^1{@-image:url(_horizontal.png)}ös?4,öv^3,üs?4,ül^3{@:#000}üs?3,ül^4{@:#fff}är?1{@-color:#f00}äg?1{@-color:#0f0}äb?1{@-color:#00f}är^2{@|-1664px 0}är^3{@|-896px 0}är?1,äg?1,äb?1,öh^3,ös^2,öv?2Ü-2432Öär?2Ü-2944Öär?3Ü-4480Öär?4Ü-3202Öäg^2Äöh^2{@|-640px 0}äg^3{@|-384px 0}äg?2Ü-4736Öäg?3Ü-3968Öäg?4Ü-3712Öäb^2{@|-1152px 0}äb^3{@|-1408px 0}äb?2Ü-3456Öäb?3Ü-4224Öäb?4Ü-2688Ööh^2Äär^3Ääb?4Ü0}öh?4,üh?4Ü-1664Öös^1,öv^1,üs^1,ül^1Ääg^3{@|-256px 0}ös^3,öv?4,üs^3,ül?4Ü-2176Öös?2,öv^2Ü-1920Öüh^2{@|-768px 0}üh^3,üs^2,ül?2Ü-5184Öüs?2,ül^2Ü-5824Ö.S är^2{@|-128px -128Ö.S är?1Ääg?1Ääb?1Äöh^3Äös^2Äöv?2Ü-1408Ö.S är?2Ääb^3Ü-128Ö.S är?3Ü-896Ö.S är?4Ü-256Ö.S äg^2{@|-256px -128Ö.S äg?2Ü-1024Ö.S äg?3Ü-640Ö.S äg?4Ü-512Ö.S äb^2{@|-128px 0}.S äb?2Ü-384Ö.S äb?3Ü-768Ö.S öh?4Äüh?4Ü-1536Ö.S ös^1Äöv^1Äüs^1Äül^1{@|-512px 0}.S ös^3Äöv?4Äüs^3Äül?4Ü-1280Ö.S ös?2Äöv^2Ü-1152Ö.S üh^2{@|-1024px 0}.S üh^3Äüs^2Äül?2Ü-5440Ö.S üs?2Äül^2Ü-5696Ö.XXS ös^2,.XXS öv?2Ü-5120Ö.XXS ös^3,.XXS öv?4,.XXS üs^3,.XXS ül^3,.XXS ül?4Ü-5056Ö.XXS ös?2,.XXS öv^2Ü-4992Ö.XXS üs^2,.XXS ül?2Ü-5568Ö.XXS üs?2,.XXS ül^2Ü-5632Ö').
  751. replace(/Ü/g, '{@|0 ').replace(/Ö/g, 'px}').replace(/Ä/g, ',.S ').replace(/\|/g, '-position:').replace(/@/g, 'background').replace(/ü/g, '.hsl-').replace(/ö/g, '.hsv-').replace(/ä/g, '.rgb-').replace(/~/g, ' .no-rgb-}').replace(/\?/g, ' .§sldr-').replace(/\^/g, ' .§sldl-'),
  752. _cssMain = ('∑{@#bbb;font-family:monospace, "Courier New", Courier, mono;font-size:12¥line-ä15¥font-weight:bold;cursor:default;~412¥ä323¥?top-left-radius:7¥?top-Ü-radius:7¥?bottom-Ü-radius:7¥?bottom-left-radius:7¥ö@#444}.S{~266¥ä177px}.XS{~158¥ä173px}.XXS{ä105¥~154px}.no-alpha{ä308px}.no-alpha .§opacity,.no-alpha .§alpha{display:none}.S.no-alpha{ä162px}.XS.no-alpha{ä158px}.XXS.no-alpha{ä90px}∑,∑ div{border:none;padding:0¥float:none;margin:0¥outline:none;box-sizing:content-box}∑ div{|absolute}^s .§curm,«§disp,«§nsarrow,∑ .§exit,∑ ø-cursor,∑ .§resize{öimage:url(_icons.png)}∑ .do-drag div{cursor:none}∑ .§opacity,ø .§raster-bg,∑ .§raster{öimage:url(_bgs.png)}∑ ^s{~287¥ä256¥top:10¥left:10¥overflow:hidden;cursor:crosshair}.S ^s{~143¥ä128¥left:9¥top:9px}.XS ^s{left:7¥top:7px}.XXS ^s{left:5¥top:5px}^s div{~256¥ä256¥left:0px}.S ^l-1,.S ^l-2,.S ^l-3,.S ^l-4{~128¥ä128px}.XXS ^s,.XXS ^s ^l-1,.XXS ^s ^l-2,.XXS ^s ^l-3,.XXS ^s ^l-4{ä64px}^s ^r-1,^s ^r-2,^s ^r-3,^s ^r-4{~31¥left:256¥cursor:default}.S ^r-1,.S ^r-2,.S ^r-3,.S ^r-4{~15¥ä128¥left:128px}^s .§curm{margin:-5¥~11¥ä11¥ö|-36px -30px}.light .§curm{ö|-7px -30px}^s .§curl,^s .§curr{~0¥ä0¥margin:-3px -4¥border:4px solid;cursor:default;left:auto;öimage:none}^s .§curl,∑ ^s .§curl-dark,.hue-dark div.§curl{Ü:27¥?@† † † #fff}.light .§curl,∑ ^s .§curl-light,.hue-light .§curl{?@† † † #000}.S ^s .§curl,.S ^s .§curr{?~3px}.S ^s .§curl-light,.S ^s .§curl{Ü:13px}^s .§curr,∑ ^s .§curr-dark{Ü:4¥?@† #fff † †}.light .§curr,∑ ^s .§curr-light{?@† #000 † †}∑ .§opacity{bottom:44¥left:10¥ä10¥~287¥ö|0 -87px}.S .§opacity{bottom:27¥left:9¥~143¥ö|0 -100px}.XS .§opacity{left:7¥bottom:25px}.XXS .§opacity{left:5¥bottom:23px}.§opacity div{~100%;ä16¥margin-top:-3¥overflow:hidden}.§opacity .§opacity-slider{margin:0 -4¥~0¥ä8¥?~4¥?style:solid;?@#eee †}∑ ø{bottom:10¥left:10¥~288¥ä31¥ö@#fff}.S ø{ä15¥~144¥left:9¥bottom:9px}.XS ø{left:7¥bottom:7px}.XXS ø{left:5¥bottom:5px}ø div{|relative;float:left;~31¥ä31¥margin-Ü:1px}.S ø div{~15¥ä15px}∑ .§raster,ø .§raster-bg,.S ø .§raster,.S ø .§raster-bg{|absolute;top:0¥Ü:0¥bottom:0¥left:0¥~100%}.S ø .§raster-bg{ö|0 -31px}∑ .§raster{opacity:0.2;ö|0 -49px}.alpha-bg-b ø{ö@#333}.alpha-bg-b .§raster{opacity:1}ø ø-cursor{|absolute;Ü:0¥ö|-26px -87px}∑ .light ø-cursor{ö|3px -87px}.S ø-cursor{ö|-34px -95px}.S .light ø-cursor{ö|-5px -95px}∑ .§panel{|absolute;top:10¥Ü:10¥bottom:10¥~94¥?~1¥?style:solid;?@#222 #555 #555 #222;overflow:hidden;ö@#333}.S .§panel{top:9¥Ü:9¥bottom:9px}.XS .§panel{display:none}.§panel div{|relative}«§hsv,«§hsl,«§rgb,«§cmyk,«§Lab,«§alpha,.no-alpha «§HEX,«§HEX{~86¥margin:-1px 0px 1px 4¥padding:1px 0px 3¥?top-~1¥?top-style:solid;?top-@#444;?bottom-~1¥?bottom-style:solid;?bottom-@#222;float:Ö«§hsv,«§hsl{padding-top:2px}.S .§hsv,.S .§hsl{padding-top:1px}«§HEX{?bottom-style:none;?top-~0¥margin-top:-4¥padding-top:0px}.no-alpha «§HEX{?bottom-style:none}«§alpha{?bottom-style:none}.S .rgb-r .§hsv,.S .rgb-g .§hsv,.S .rgb-b .§hsv,.S .rgb-r .§hsl,.S .rgb-g .§hsl,.S .rgb-b .§hsl,.S .hsv-h .§rgb,.S .hsv-s .§rgb,.S .hsv-v .§rgb,.S .hsl-h .§rgb,.S .hsl-s .§rgb,.S .hsl-l .§rgb,.S .§cmyk,.S .§Lab{display:none}«§butt,«§labl{float:left;~14¥ä14¥margin-top:2¥text-align:center;border:1px solid}«§butt{?@#555 #222 #222 #555}«§butt:active{ö@#444}«§labl{?@†}«Lab-mode,«cmyk-mode,«hsv-mode,«hsl-mode{|absolute;Ü:0¥top:1¥ä50px}«hsv-mode,«hsl-mode{top:2px}«cmyk-mode{ä68px}.hsl-h .hsl-h-labl,.hsl-s .hsl-s-labl,.hsl-l .hsl-l-labl,.hsv-h .hsv-h-labl,.hsv-s .hsv-s-labl,.hsv-v .hsv-v-labl{@#f90}«cmyk-mode,«hsv-mode,.rgb-r .rgb-r-butt,.rgb-g .rgb-g-butt,.rgb-b .rgb-b-butt,.hsv-h .hsv-h-butt,.hsv-s .hsv-s-butt,.hsv-v .hsv-v-butt,.hsl-h .hsl-h-butt,.hsl-s .hsl-s-butt,.hsl-l .hsl-l-butt,«rgb-r-labl,«rgb-g-labl,«rgb-b-labl,«alpha-butt,«HEX-butt,«Lab-x-labl{?@#222 #555 #555 #222;ö@#444}.no-rgb-r .rgb-r-labl,.no-rgb-g .rgb-g-labl,.no-rgb-b .rgb-b-labl,.mute-alpha .alpha-butt,.no-HEX .HEX-butt,.cmy-only .Lab-x-labl{?@#555 #222 #222 #555;ö@#333}.Lab-x-disp,.cmy-only .cmyk-k-disp,.cmy-only .cmyk-k-butt{visibility:hidden}«HEX-disp{öimage:none}«§disp{float:left;~48¥ä14¥margin:2px 2px 0¥cursor:text;text-align:left;text-indent:3¥?~1¥?style:solid;?@#222 #555 #555 #222}∑ .§nsarrow{|absolute;top:0¥left:-13¥~8¥ä16¥display:none;ö|-87px -23px}∑ .start-change .§nsarrow{display:block}∑ .do-change .§nsarrow{display:block;ö|-87px -36px}.do-change .§disp{cursor:default}«§hide{display:none}«§cont,«§cold{|absolute;top:-5¥left:0¥ä3¥border:1px solid #333}«§cold{z-index:1;ö@#c00}«§cont{margin-Ü:-1¥z-index:2}«contrast .§cont{z-index:1;ö@#ccc}«orange .§cold{ö@#f90}«green .§cold{ö@#4d0}«§ctrl{|absolute;bottom:0¥left:0¥~100%;ö@#fff}.alpha-bg-b .§ctrl,«§bres,«§bsav{ö@#333}«§col1,«§col2,«§bres,«§bsav{?~1¥?style:solid;?@#555 #222 #222 #555;float:left;~45¥line-ä28¥text-align:center;top:0px}.§panel div div{ä100%}.S .§ctrl div{line-ä25px}.S «§bres,.S «§bsav{line-ä26px}∑ .§exit,∑ .§resize{Ü:3¥top:3¥~15¥ä15¥ö|0 -52px}∑ .§resize{top:auto;bottom:3¥cursor:nwse-resize;ö|-15px -52px}.S .§exit{ö|1px -52px}.XS .§resize,.XS .§exit{~10¥ä10¥Ü:0¥öimage:none}.XS .§exit{top:0px}.XS .§resize{bottom:0px}∑ .§resizer,∑ .§resizer div{|absolute;border:1px solid #888;top:-1¥Ü:-1¥bottom:-1¥left:-1¥z-index:2;display:none;cursor:nwse-resize}∑ .§resizer div{border:1px dashed #333;opacity:0.3;display:block;ö@#bbb}').
  753. replace(/Ü/g, 'right').replace(/Ö/g, 'left}').replace(/∑/g, '.§app').replace(/«/g, '.§panel .').replace(/¥/g, 'px;').replace(/\|/g, 'position:').replace(/@/g, 'color:').replace(/ö/g, 'background-').replace(/ä/g, 'height:').replace(/ø/g, '.§memo').replace(/†/g, 'transparent').replace(/\~/g, 'width:').replace(/\?/g, 'border-').replace(/\^/g, '.§sld'),
  754. _horizontalPng = 'iVBORw0KGgoAAAANSUhEUgAABIAAAAABCAYAAACmC9U0AAABT0lEQVR4Xu2S3Y6CMBCFhyqIsjGBO1/B9/F5DC/pK3DHhVkUgc7Zqus2DVlGU/cnQZKTjznttNPJBABA149HyRf1iN//4mIBCg0jV4In+j9xJiuihly1V/Z9X88v//kNeDXVvyO/lK+IPR76B019+1Riab3H1zkmeqerKnL+Bzwxx6PAgZxaSQU8vB62T28pxcQeRQ2sHw6GxCOWHvP78zwHAARBABOfdYtd30rwxXOEPDF+dj2+91r6vV/id3k+/brrXmaGUkqKhX3i+ffSt16HQ/dorTGZTHrs7ev7Tl7XdZhOpzc651nfsm1bRFF0YRiGaJoGs9nsQuN/xafTCXEco65rzOdzHI9HJEmCqqqwXC6x3++RZRnKssRqtUJRFFiv19jtdthutyAi5Hl+Jo9VZg7+7f3yXuvZf5c3KaXYzByb+WIzO5ymKW82G/0BNcFhO/tOuuMAAAAASUVORK5CYII=',
  755. _verticalPng = 'iVBORw0KGgoAAAANSUhEUgAAAAEAABfACAYAAABn2KvYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABHtJREFUeNrtnN9SqzAQxpOF1to6zuiVvoI+j6/gva/lA/kKeqUzjtX+QTi7SzSYBg49xdIzfL34+e1usoQQklCnmLwoCjImNwDQA2xRGMqNAYB+gPEH9IdCgIUA6Aem0P1fLoMQAPYNHYDoCKAv8OMHFgKgX2AjDPQDXn4t1l+gt/1fId//yWgE/hUJ+mAn8EyY5wCwXxhrbaHzn8E9iPlv79DdHxXTqciZ4KROnXRVZMF/6U2OPhcEavtAbZH1SM7wRDD7VoHZItCiyEQf4t6+MW9UOxaZybmdCGKqNrB9Eb5SfMg3wTyiagMtigTmWofiSDCOYNTSNz6sLDIoaCU9GWDd0tdhoMMsRm+r8U/EfB0GfjmLXiqzimDd0tdhoLMsI7la45+I+ToM/HIW0kfGVQTrlr7tA91kaUr//fxrKo8jUFB7VAn6AKpHJf+EKwAAAIYD/f7F7/8MVgMo7P+gBqDKr57Lf72V8x8AAMDgYIuvH4EAAAAMDQX6AACAQcI9GGMjDADA4MA/P2KlP8IEAAAYFCz6AACAgaLA8y8AAIN+CMYXoQAADA7u/UPYCAMAMDjI7z9S+SdwDFQX2C9Gh9GMEOWriz8/Pw1lWQZsi/L3R4czzP678Ve+P8f9nCv/C7hwLq99ah8NfKrU15zPB5pVcwtiJt9qGy0IfEE+jQa+Fn0VtI/fkxUPqBlEfRENeF+tqUpbGpi1iu8epwJzvV5XA4GpWC6XGz7F+/u766EgwJ+ckiTJKU3TnI6OjnI6OzvLZf6zMggt3dzckPhIoiTlSGpQ+eEsVegdz0fbCCi4fRs+Po+4yWdeDXiT+6pBSTeHple1pkz3FZ+avpyavoiPxgLN0B7yprY08PlyQTTm0+PWmkH7ynedNKraar4F/lRj1WpTtYh+ozL/cY2sAvZl0gcbZm0gSLBLvkxGoaogiy/HDXemQk2t5pUm8OAhH8/HH6e0mkJ9q9XKKQXfb07xfZnJbZrRxcVFVt6/t7e3Kc1ms5RGo1Eq5VIZuyl9fHw4k/M5xYeoKj64A7eqCt1ZeqWFVSl8NV9OTV3fmvP5qE9VmzSoEcsXpArK1UHen/hZbgL53BZSdyEXalGau/hU8TEW0u3VcoFPy3EDFrTgT+njydeZ0+l0UV7fu7u7iVzziQQmUm4iqRw4n/NxMxw4s/Mp1NSALxf4NEtQ10cjMDwSl+b+/j6hp6enVGb+jUvrn05iKobm6PboOt8vPISY5Pr6OqGXlxe3fOokoGtAbMUJZmqvYmaLQDP+sdrecOjtO/SXeH69P8Imutm5urqy9PDwYOny8tLS4+OjpfPzc0vPz8+WTk9PLb2+vlpZbCzN53NLx8fHVtYZS5PJxMoEZWWqsjKULY3HYytTi1Pex5OMldXKRVXxuLcy/20onmms3BBOxcr5qCrZtsrd45SPel8sGlOxGoGy0neynQ6VL9fsa1YtWlCrtj9G83G7PjdVush5n5q1iJWLZW6u21a1bUvbVnVzlru0pe3RdmlV1/23fZtbZv4Dx+7FBypx77kAAAAASUVORK5CYII=',
  756. _patchesPng = ('iVBORw0KGgo^NSUhEUgAAB4^EACAI#DdoPxz#L0UlEQVR4Xu3cQWrDQBREwR7FF8/BPR3wXktnQL+KvxfypuEhvLJXcp06d/bXd71OPt+trIw95zr33Z1bk1/fudEv79wa++7OfayZ59wrO2PBzklcGQmAZggAAOBYgAYBmpWRAGg^BGgRofAENgAAN#I0CBA6w8AG^ECABgEa/QH§AI0CNDoDwAY^QIAGAVp/AM§AjQI0OgPAAY^QoEGARn8Aw§CNAjQ+gMABg#BCgQYCmGQmABgAAEKBBgEZ/AM§AjQI0PoDAAY^QoEGARn8AM^IAADQI0+gMABg#BCgQYDWHwAw^gAANAjT6A4AB^BGgQoNEfAD^C#0CtP4AgAE^EaBCgaUYCoAE#RoEKDRHwAw^gAANArT+AIAB^BGgQoNEfAAw^gQIMAjf4AgAE^EaBCg9QcAD^CBAgwCN/gBg§EaBGj0BwAM^IECDAK0/AG§ARoEaJqRAGg^BGgRo9AcAD^CBAgwCtPwBg§EaBGj0BwAD^CNAgQKM/AG§ARoEaP0BAAM^I0CBAoz8AG^ECABgEa/QEAAw^jQIEDrDwAY^QIAGAZpmJACaBw^RoEKD1BwAM^IECDAK0/AG§ARoEaPQHAAw^gQIMArT8AY§BGgRo/QEAAw^jQIECjPwBg§EaBGj9AQAD^CNAgQOsPABg#BAgAYBGv0BAANwCwAAGB6gYeckmpEAa^AEaBGj0BwAM^IECDAK0/AG§ARoEaPQHAAM^I0CBAoz8AY§BGgRo/QEAAw^jQIECjPwAY^QIAGARr9AQAD^CNAgQOsPABg#BAgAYBmmYkABoAAECABgEa/QEAAw^jQIEDrDwAY^QIAGARr9Ac§AjQI0OgPABg#BAgAYBWn8Aw§CNAjQ6A8ABg#BCgQYBGfwD§AI0CND6AwAG^EKBBgKYZCYAG#QoEGARn8Aw§CNAjQ+gMABg#BCgQYBGfwAw^gAANAjT6AwAG^EKBBgNYfAD^C#0CNPoDgAE^EaBCg0R8AM^IAADQK0/gCAAQ^RoEKBpRgKgAQAABGgQoNEfAD^C#0CtP4AgAE^EaBCg0R8AD^CBAgwCN/gCAAQ^RoEKD1BwAM^IECDAI3+AG§ARoEaPQHAAw^gQIMArT8AY§BGgRomsMAM^IAADQK0/gCAAQ^RoEKDRHwAw^gAANO7fQHwAw^gAANArT+AIAB^BGgQoNEfAGg^BGgRo9AcAD^CBAgwCtPwBg§EaBGj0BwAD^RIB+Ntg5iea5AD^DAIwI0CND6AwAG^EKBBgEZ/AKAB#EaBCg0R8AM^IAADQK0/gCAAQ^RoEKDRHwAM^IECDAI3+AIAB^BGgQoPUHAAw^gQIMAjf4AY§BGgRo9AcAD^CBAgwCtPwBg§EaBGiakQBo^ARoEaPQHAAw^gQIMArT8AY§BGgRo9AcAAw^jQIECjPwBg§EaBGj9AQAD^CNAgQKM/ABg#BAgAYBGv0BAAM^I0CBA6w8AG^ECABgGaZiQAGgAAQIAGARr9AQAD^CNAgQOsPABg#BAgAYBGv0Bw§CNAjQ6A8AG^ECABgFafwD§AI0CNDoDwAG^EKBBgEZ/AM§AjQI0PoDAAY^QoEGApjkMAAM^I0CBA6w8AG^ECABgEa/QEAAw^jQsIP+AIAB^BGgQoPUHAAw^gQIMAjf4AgAE#Bea/fK+3P5/3PJOvh8t1cO4nflmQAQoAEAAF9Aw/7JHfQHAAw^gQIMArT8AY§BGvwHNPoDAA0AACBAgwCN/gCAAQ^RoEKD1BwAM^IECDAI3+AG§ARoEaPQHAAw^gQIMArT8AY§BGgRo9AcAAw^jQIECjPwBg§EaBGj9AQAD^CNAgQNOMBEAD#I0CBAoz8AY§BGgRo/QEAAw^jQIECjPwAY^QIAGARr9AQAD^CNAgQOsPABg#BAgAYBGv0Bw§CNAjQ6A8AG^ECABgFafwD§AI0CNA0IwHQ^AjQI0OgPABg#BAgAYBWn8Aw§CNAjQ6A8ABg#BCgQYBGfwD§AI0CND6AwAG^EKBBgEZ/AD^C#0CNPoDAAY^QoEGA1h8AM^IAADQI0DQAG^EKBBgEZ/AM§AjQI0PoDAAY^QoEGA1h8AM^IAADQI0+gMABg#BCgQYDWHwAw^gAANArT+AIAB^BGgQoNEfAD^C#0CtP4AgAE^EaBCg9QcAD^CBAgwCN/gCAAQ^RoEKD1BwAM^IECDAK0/AG§ARoEaPQHAAw^gQIMArT8AY§BGgRo/QEAAw^jQIECjPwBgACDhFgC#07t9AfAD^C#0CtP4AgAE^EaBCg0R8Aa^AEaBGj0BwAM^IECDAK0/AG§ARoEaPQHAAM^I0CBAoz8AY§BGgRo/QEAAw^jQIECjPwAY^QIAGARr9AQAD^CNAgQOsPABg#BAgAYBmmYkABoAAECABgEa/QEAAw^jQIEDrDwAY^QIAGARr9Ac§AjQI0OgPABg#BAgAYBWn8Aw§CNAjQ6A8ABg#BCgQYBGfwD§AI0CND6AwAG^EKBBgKYZCYAG#QoEGARn8Aw§CNAjQ+gMABg#BCgQYBGfwAw^gAANAjT6AwAG^EKBBgNYfAD^C#0CNPoDgAE^EaBCg0R8AM^IAADQK0/gCAAQ^RoEKBpRgKgAQAABGgQoNEfAD^C#0CtP4AgAE^EaBCg0R8AD^CBAgwCN/gCAAQ^RoEKD1BwAM^IECDAI3+AG§ARoEaPQHAAw^gQIMArT8AY§BGgRommEAM^CBAgwCN/gCAAQ^RoEKD1BwAM^IECDAI3+AIAB^ARoEaPQHAAw^gQIMArT8AY§BGgRo9AcAGgAAQICGCNBfRfNcABg#BgeICGnVvoDwAY^QIAGAVp/AM§AjQI0OgPADQAAIAADQI0+gMABg#BCgQYDWHwAw^gAANAjT6A4AB^BGgQoNEfAD^C#0CtP4AgAE^EaBCg0R8AD^CBAgwCN/gCAAQ^RoEKD1BwAM^IECDAE0zEgAN#gQIMAjf4AgAE^EaBCg9QcAD^CBAgwCN/gBg§EaBGj0BwAM^IECDAK0/AG§ARoEaPQHAAM^I0CBAoz8AY§BGgRo/QEAAw^jQIEDTjARAAwAACNAgQKM/AG§ARoEaP0BAAM^I0CBAoz8AG^ECABgEa/QEAAw^jQIEDrDwAY^QIAGARr9Ac§AjQI0OgPABg#BAgAYBWn8Aw§CNAjQNIcBY§BGgRo/QEAAw^jQIECjPwBg§EadtAfAD^C#0CtP4AgAE^EaBCgAQABGgAA+AO2TAbHupOgH^ABJRU5ErkJggg==').
  757. replace(/§/g, 'AAAAAA').replace(/\^/g, 'AAAA').replace(/#/g, 'AAA'),
  758. _iconsPng = 'iVBORw0KGgoAAAANSUhEUgAAAGEAAABDCAMAAAC7vJusAAAAkFBMVEUAAAAvLy9ERERubm7///8AAAD///9EREREREREREREREQAAAD///8AAAD///8AAAD///8AAAD///8AAAD///8AAAD///8AAAD///8AAAD///8AAAD///8cHBwkJCQnJycoKCgpKSkqKiouLi4vLy8/Pz9AQEBCQkJDQ0NdXV1ubm58fHykpKRERERVVVUzMzPx7Ab+AAAAHXRSTlMAAAAAAAQEBQ4QGR4eIyMtLUVFVVVqapKSnJy7u9JKTggAAAFUSURBVHja7dXbUoMwEAbgSICqLYeW88F6KIogqe//dpoYZ0W4AXbv8g9TwkxmvtndZMrEwlw/F8YIRjCCEYxgBCOsFmzqGMEI28J5zzmt0Pc9rdDL0NYgMxIYC5KiKpKAzZphWtZlGm4SjlnkOV6UHeeEUx77rh/npw1dCrI9k9lnwUwF+UG9D3m4ftJJxH4SJdPtaawXcbr+tBaeFrxiur309cIv19+4ytGCU0031a5euPVigLYGqjlAqM4ShOQ+QAYQUO80AMMAAkUGGfMfR9Ul+kmvPq2QGxXKOQBAKdjUgk0t2NiCGEVP+rHT3/iCUMBT90YrPMsKsIWP3x/VolaonJEETchHCS8AYAmaUICQQwaAQnjoXgHAES7jLkEFaHO4bdq/k25HAIpgWY34FwAE5xjCffM+D2DV8B0gRsAZT7hr5gE8wdrJcU+CJqhcqQD7Cx5L7Ph4WnrKAAAAAElFTkSuQmCC',
  759. _bgsPng = 'iVBORw0KGgoAAAANSUhEUgAAASAAAABvCAYAAABM+h2NAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABORJREFUeNrs3VtTW1UYBuCEcxAI4YydWqTWdqr1V7T/2QsvvPDCCy9qjxZbamsrhZIQUHsCEtfafpmJe8qFjpUxfZ4Zuvt2feydJvAOARZUut1u5bRerl692nV913f99/f6QxWAU6KAAAUEKCAABQQoIAAFBCggAAUEKCAABQQoIAAFBCggAAUEKCAABQQoIEABASggQAEBKCBAAQEoIEABASggQAEBKCBAAQEoIGBQC+jatWvd07zxrv9+Xx8fAQEoIEABASggQAEBKCBAAQEoIEABAQoIQAEBCghAAQEKCEABAQOk2u36kS6AAgLetwJKL29toFRM1be+QrVq3rx58//KvM8BAadGAQEKCFBAAAoIGHwnfhneZ+/Nmzf/LufzrI+AAE/BAAUEoIAABQTwztgLZt68eXvBAE/BABQQoIAAFBAweOwFM2/evL1ggKdgAAoIUEAACggYPPaCmTdv3l4wwFMwAAUEKCAABQQMHnvBzJs3by8Y4CkYgAICFBCAAgIGz4lfBQNQQMDgFlCtVisaaHV1tThubW1VInciD0U+ysdnz54N5+PKysphOnRTHsvHlN9EHo/1l5FrkV9Enoz8W87b29tTOS8vLx9EnoncjlyPvBe5EbkZeT4fU96NvBDr2znv7Ows57y0tLQVeSXy08gf5mNfPhPrjyOfrVarlcXFxZ9yfv78+bl8TPlh5LU8n/KDyOuxfj/y+VjfyHl3d/dCKv28fi/yp/m4sLDwQ+SLke9GvhT5Tinfjnw5f4/F/Pz8rZybzeZn+ZjyzVK+EfnzUr4S+Xopf9/L+fxzc3M5d1qt1hf531Mu5k/IxzGf85VYL+fefHH+RqNRrO/t7RW3L+UbkS9Hvhk5/386Kd/qW8/5duRLMV/OdyJfzNebnZ0t7t92u53v/07K9yJfiLwROT9+ef7HyOux/iDyWuSHkT+K+eLtZX9//2xer9frjyOfyY9/Wn8S86v59qT1p7Ge315zLt4RU16K19+O9YXIu5HnYn435hux3opcj9yOPB3z+5E/iPXf43y1yMX778HBQS3f3pTz+28l5bHIr2N+LN3+zszMzGHkoh/S+mHMF98XlNaP8zHd/0W/pMe943NAwKlSQIACAhQQgAICFBCAAgIUEIACAhQQgAIC/n9GqtXqYbfbHa38+RtSu32llPdqdNL6aOSj+LfxyMVekLTem39Ryr/mPDQ0NBznzXtROikPRW6W8k7k3m9rzXthOsPDw73bUuylGRkZ6cR63nvTSfko8oPIr+Pnz96P/DLW816ezujoaN6DdtyX9+P8eS9QZ2xs7Hxf7qa8Xlr/JO6Ljcjrcf6cj1P+OO+N6V1/fHz8XLz+/Tjfubh+sZcorZ+N9Ycxfybyo8ircf6fc56YmFiJ1/8l8mLk7cjzkfP92U15Ns63G+u9nPcKdWq12lQ8Xu3Ixd6f9Pd8P3UmJycnUszzL2N9LM7/anNzs9V7Q2q32395w/q7ubdH6L/KrVbrpPxlKX9Vyl+X8jel/G0pf5f/aDabvXy9tH6ztH63lDdKebOUH5Xyk1LeKuWd/ry2tlap9P125Onp6Zf9eWpq6lW3b8f6zMzM6/71er3+ppSP+u/XNN/pz41Go+sjIMBTMEABASggQAEBKCBAAQEoIEABASggQAEB/CN/CDAAw78uW9AVDw4AAAAASUVORK5CYII=';
  760.  
  761. window.ColorPicker = {
  762. _html: _html,
  763. _cssFunc: _cssFunc,
  764. _cssMain: _cssMain,
  765. _horizontalPng: _horizontalPng,
  766. _verticalPng: _verticalPng,
  767. _patchesPng: _patchesPng,
  768. _iconsPng: _iconsPng,
  769. _bgsPng: _bgsPng
  770. }
  771. })(window);
  772.  
  773. /*! colorPicker.js */
  774. ;(function(window, undefined){
  775. "use strict"
  776.  
  777. var _data = window.ColorPicker, // will be deleted in buildView() and holds:
  778. // window.ColorPicker = { // comes from colorPicker.data.js and will be overwritten.
  779. // _html: ..., // holds the HTML markup of colorPicker
  780. // _cssFunc: ..., // CSS for all the sliders
  781. // _cssMain: ..., // CSS of the GUI
  782. // _horizontalPng: ..., // horizontal background images for sliders
  783. // _verticalPng: ..., // vertical background images for sliders
  784. // _patchesPng: ..., // background images for square sliders in RGB mode
  785. // _iconsPng: ..., // some icon sprite images
  786. // _bgsPng: ..., // some more icon sprite images
  787. // }
  788. _devMode = !_data, // if no _data we assume that colorPicker.data.js is missing (for development)
  789. _isIE = false,
  790. _doesOpacity = false,
  791. // _isIE8 = _isIE && document.querySelectorAll,
  792.  
  793. _valueRanges = {}, // will be assigned in initInstance() by Colors instance
  794. // _valueRanges = {
  795. // rgb: {r: [0, 255], g: [0, 255], b: [0, 255]},
  796. // hsv: {h: [0, 360], s: [0, 100], v: [0, 100]},
  797. // hsl: {h: [0, 360], s: [0, 100], l: [0, 100]},
  798. // cmyk: {c: [0, 100], m: [0, 100], y: [0, 100], k: [0, 100]},
  799. // cmy: {c: [0, 100], m: [0, 100], y: [0, 100]},
  800. // XYZ: {X: [0, 100], Y: [0, 100], Z: [0, 100]},
  801. // Lab: {L: [0, 100], a: [-128, 127], b: [-128, 127]},
  802. // alpha: {alpha: [0, 1]},
  803. // HEX: {HEX: [0, 16777215]}
  804. // },
  805. _bgTypes = {w: 'White', b: 'Black', c: 'Custom'},
  806.  
  807. _mouseMoveAction, // current mouseMove handler assigned on mouseDown
  808. _action = '', // needed for action callback; needed due to minification of javaScript
  809. _mainTarget, // target on mouseDown, might be parent element though...
  810. _valueType, // check this variable; gets missused/polutet over time
  811. _delayState = 1, // mouseMove offset (y-axis) in display elements // same here...
  812. _startCoords = {},
  813. _targetOrigin = {},
  814. _renderTimer, // animationFrame/interval variable
  815. _newData = true,
  816. // _txt = {
  817. // selection: document.selection || window.getSelection(),
  818. // range: (document.createRange ? document.createRange() : document.body.createTextRange())
  819. // },
  820.  
  821. _renderVars = {}, // used only in renderAll and convertColors
  822. _cashedVars = {}, // reset in initSliders
  823.  
  824. _colorPicker,
  825. _previousInstance, // only used for recycling purposes in buildView()
  826. _colorInstance = {},
  827. _colors = {},
  828. _options = {},
  829. _nodes = {},
  830.  
  831. _math = Math,
  832.  
  833. animationFrame = 'AnimationFrame', // we also need this later
  834. requestAnimationFrame = 'request' + animationFrame,
  835. cancelAnimationFrame = 'cancel' + animationFrame,
  836. vendors = ['ms', 'moz', 'webkit', 'o'],
  837. ColorPicker = function(options) { // as tiny as possible...
  838. this.options = {
  839. color: 'rgba(204, 82, 37, 0.8)',
  840. mode: 'rgb-b',
  841. fps: 60, // 1000 / 60 = ~16.7ms
  842. delayOffset: 8,
  843. CSSPrefix: 'cp-',
  844. allMixDetails: true,
  845. alphaBG: 'w',
  846. imagePath: ''
  847. // devPicker: false // uses existing HTML for development...
  848. // noAlpha: true,
  849. // customBG: '#808080'
  850. // size: 0,
  851. // cmyOnly: false,
  852. // initStyle: 'display: none',
  853.  
  854. // memoryColors: "'rgba(82,80,151,1)','rgba(100,200,10,0.5)','rgba(100,0,0,1)','rgba(0,0,0,1)'"
  855. // memoryColors: [{r: 100, g: 200, b: 10, a: 0.5}] //
  856.  
  857. // opacityPositionRelative: undefined,
  858. // customCSS: undefined,
  859. // appendTo: document.body,
  860. // noRangeBackground: false,
  861. // textRight: false, ?????
  862. // noHexButton: false,
  863. // noResize: false,
  864.  
  865. // noRGBr: false,
  866. // noRGBg: false,
  867. // noRGBb: false,
  868.  
  869. // ------ CSSStrength: 'div.',
  870. // XYZMatrix: XYZMatrix,
  871. // XYZReference: {},
  872. // grey: grey,
  873. // luminance: luminance,
  874.  
  875. // renderCallback: undefined,
  876. // actionCallback: undefined,
  877. // convertCallback: undefined,
  878. };
  879. initInstance(this, options || {});
  880. };
  881.  
  882. window.ColorPicker = ColorPicker; // export differently
  883. ColorPicker.addEvent = addEvent;
  884. ColorPicker.removeEvent = removeEvent;
  885. ColorPicker.getOrigin = getOrigin;
  886. ColorPicker.limitValue = limitValue;
  887. ColorPicker.changeClass = changeClass;
  888.  
  889. // ------------------------------------------------------ //
  890.  
  891. ColorPicker.prototype.setColor = function(newCol, type, alpha, forceRender) {
  892. focusInstance(this);
  893. _valueType = true; // right cursor...
  894. // https://github.com/petkaantonov/bluebird/wiki/Optimization-killers
  895. preRenderAll(_colorInstance.setColor.apply(_colorInstance, arguments));
  896. if (forceRender) {
  897. this.startRender(true);
  898. }
  899. };
  900.  
  901. ColorPicker.prototype.saveAsBackground = function() {
  902. focusInstance(this);
  903. return saveAsBackground(true);
  904. };
  905.  
  906. ColorPicker.prototype.setCustomBackground = function(col) {
  907. focusInstance(this); // needed???
  908. return _colorInstance.setCustomBackground(col);
  909. };
  910.  
  911. ColorPicker.prototype.startRender = function(oneTime) {
  912. focusInstance(this);
  913. if (oneTime) {
  914. _mouseMoveAction = false; // prevents window[requestAnimationFrame] in renderAll()
  915. renderAll();
  916. this.stopRender();
  917. } else {
  918. _mouseMoveAction = 1;
  919. _renderTimer = window[requestAnimationFrame](renderAll);
  920. }
  921. };
  922.  
  923. ColorPicker.prototype.stopRender = function() {
  924. focusInstance(this); // check again
  925. window[cancelAnimationFrame](_renderTimer);
  926. if (_valueType) {
  927. // renderAll();
  928. _mouseMoveAction = 1;
  929. stopChange(undefined, 'external');
  930. // _valueType = undefined;
  931. }
  932. };
  933.  
  934. ColorPicker.prototype.setMode = function(mode) { // check again ... right cursor
  935. focusInstance(this);
  936. setMode(mode);
  937. initSliders();
  938. renderAll();
  939. };
  940.  
  941. ColorPicker.prototype.destroyAll = function() { // check this again...
  942. var html = this.nodes.colorPicker,
  943. destroyReferences = function(nodes) {
  944. for (var n in nodes) {
  945. if (nodes[n] && nodes[n].toString() === '[object Object]' || nodes[n] instanceof Array) {
  946. destroyReferences(nodes[n]);
  947. }
  948. nodes[n] = null;
  949. delete nodes[n];
  950. }
  951. };
  952.  
  953. this.stopRender();
  954. installEventListeners(this, true);
  955. destroyReferences(this);
  956. html.parentNode.removeChild(html);
  957. html = null;
  958. };
  959.  
  960. ColorPicker.prototype.renderMemory = function(memory) {
  961. var memos = this.nodes.memos,
  962. tmp = [];
  963.  
  964. if (typeof memory === 'string') { // revisit!!!
  965. memory = memory.replace(/^'|'$/g, '').replace(/\s*/, '').split('\',\'');
  966. }
  967. for (var n = memos.length; n--; ) { // check again how to handle alpha...
  968. if (memory && typeof memory[n] === 'string') {
  969. tmp = memory[n].replace('rgba(', '').replace(')', '').split(',');
  970. memory[n] = {r: tmp[0], g: tmp[1], b: tmp[2], a: tmp[3]}
  971. }
  972. memos[n].style.cssText = 'background-color: ' + (memory && memory[n] !== undefined ?
  973. color2string(memory[n]) + ';' + getOpacityCSS(memory[n]['a'] || 1) : 'rgb(0,0,0);');
  974. }
  975. };
  976.  
  977. // ------------------------------------------------------ //
  978.  
  979. function initInstance(THIS, options) {
  980. var exporter, // do something here..
  981. mode = '',
  982. CSSPrefix = '',
  983. optionButtons;
  984.  
  985. for (var option in options) { // deep copy ??
  986. THIS.options[option] = options[option];
  987. }
  988. _isIE = document.createStyleSheet !== undefined && document.getElementById || !!window.MSInputMethodContext;
  989. _doesOpacity = typeof document.body.style.opacity !== 'undefined';
  990. _colorInstance = new Colors(THIS.options);
  991. // We transfer the responsibility to the instance of Color (to save space and memory)
  992. delete THIS.options;
  993. _options = _colorInstance.options;
  994. _options.scale = 1;
  995. CSSPrefix = _options.CSSPrefix;
  996.  
  997. THIS.color = _colorInstance; // check this again...
  998. _valueRanges = _options.valueRanges;
  999. THIS.nodes = _nodes = getInstanceNodes(buildView(THIS), THIS); // ha, ha,... make this different
  1000. setMode(_options.mode);
  1001. focusInstance(THIS);
  1002. saveAsBackground();
  1003.  
  1004. mode = ' ' + _options.mode.type + '-' + _options.mode.z;
  1005. _nodes.slds.className += mode;
  1006. _nodes.panel.className += mode;
  1007. //_nodes.colorPicker.className += ' cmy-' + _options.cmyOnly;
  1008.  
  1009. if (_options.noHexButton) {
  1010. changeClass(_nodes.HEX_butt, CSSPrefix + 'butt', CSSPrefix + 'labl');
  1011. }
  1012.  
  1013. if (_options.size !== undefined) {
  1014. resizeApp(undefined, _options.size);
  1015. }
  1016.  
  1017. optionButtons = {
  1018. alphaBG: _nodes.alpha_labl,
  1019. cmyOnly: _nodes.HEX_labl // test... take out
  1020. };
  1021. for (var n in optionButtons) {
  1022. if (_options[n] !== undefined) {
  1023. buttonActions({target: optionButtons[n], data: _options[n]});
  1024. }
  1025. }
  1026. if (_options.noAlpha) {
  1027. _nodes.colorPicker.className += ' no-alpha'; // IE6 ??? maybe for IE6 on document.body
  1028. }
  1029.  
  1030. THIS.renderMemory(_options.memoryColors);
  1031.  
  1032. installEventListeners(THIS);
  1033. _mouseMoveAction = true;
  1034. stopChange(undefined, 'init');
  1035.  
  1036. if (_previousInstance) {
  1037. focusInstance(_previousInstance);
  1038. renderAll();
  1039. }
  1040. }
  1041.  
  1042. function focusInstance(THIS) {
  1043. _newData = true;
  1044. if (_colorPicker !== THIS) {
  1045. _colorPicker = THIS;
  1046. _colors = THIS.color.colors;
  1047. _options = THIS.color.options;
  1048. _nodes = THIS.nodes;
  1049. _colorInstance = THIS.color;
  1050.  
  1051. _cashedVars = {};
  1052. preRenderAll(_colors);
  1053. }
  1054. }
  1055.  
  1056. function getUISizes() {
  1057. var sizes = ['L', 'S', 'XS', 'XXS'];
  1058. _options.sizes = {};
  1059. _nodes.testNode.style.cssText = 'position:absolute;left:-1000px;top:-1000px;';
  1060. document.body.appendChild(_nodes.testNode);
  1061. for (var n = sizes.length; n--; ) {
  1062. _nodes.testNode.className = _options.CSSPrefix + 'app ' + sizes[n];
  1063. _options.sizes[sizes[n]] = [_nodes.testNode.offsetWidth, _nodes.testNode.offsetHeight];
  1064. }
  1065. if (_nodes.testNode.removeNode) { // old IEs
  1066. _nodes.testNode.removeNode(true);
  1067. } else {
  1068. document.body.removeChild(_nodes.testNode);
  1069. }
  1070. }
  1071.  
  1072. function buildView(THIS) {
  1073. var app = document.createElement('div'),
  1074. prefix = _options.CSSPrefix,
  1075. urlData = 'data:image/png;base64,',
  1076. addStyleSheet = function(cssText, id) {
  1077. var style = document.createElement('style');
  1078.  
  1079. style.setAttribute('type', 'text/css');
  1080. if (id) {
  1081. style.setAttribute('id', id);
  1082. }
  1083. if (!style.styleSheet) {
  1084. style.appendChild(document.createTextNode(cssText));
  1085. }
  1086. document.getElementsByTagName('head')[0].appendChild(style);
  1087. if (style.styleSheet) { // IE compatible
  1088. document.styleSheets[document.styleSheets.length-1].cssText = cssText;
  1089. }
  1090. },
  1091. processCSS = function(doesBAS64){
  1092. // CSS - system
  1093. _data._cssFunc = _data._cssFunc.
  1094. replace(/§/g, prefix).
  1095. replace('_patches.png', doesBAS64 ? urlData + _data._patchesPng : _options.imagePath + '_patches.png').
  1096. replace('_vertical.png', doesBAS64 ? urlData + _data._verticalPng : _options.imagePath + '_vertical.png').
  1097. replace('_horizontal.png', doesBAS64 ? urlData + _data._horizontalPng :
  1098. _options.imagePath + '_horizontal.png');
  1099. addStyleSheet(_data._cssFunc, 'colorPickerCSS');
  1100. // CSS - main
  1101. if (!_options.customCSS) {
  1102. _data._cssMain = _data._cssMain.
  1103. replace(/§/g, prefix).
  1104. replace('_bgs.png', doesBAS64 ? urlData + _data._bgsPng : _options.imagePath + '_bgs.png').
  1105. replace('_icons.png', doesBAS64 ? urlData + _data._iconsPng : _options.imagePath + '_icons.png').
  1106. // replace('"Courier New",', !_isIE ? '' : '"Courier New",').
  1107. replace(/opacity:(\d*\.*(\d+))/g, function($1, $2){
  1108. return !_doesOpacity ? '-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=' +
  1109. _math.round(+$2 * 100) + ')";filter: alpha(opacity=' + _math.round(+$2 * 100) + ')' :
  1110. '-moz-opacity: ' + $2 + '; -khtml-opacity: ' + $2 + '; opacity: ' + $2;
  1111. });
  1112. // style.appendChild(document.createTextNode(_data._cssFunc));
  1113. addStyleSheet(_data._cssMain);
  1114. }
  1115. // for (var n in _data) { // almost 25k of memory ;o)
  1116. // _data[n] = null;
  1117. // }
  1118. },
  1119. test = document.createElement('img');
  1120.  
  1121. // development mode
  1122. if (_devMode) {
  1123. return THIS.color.options.devPicker;
  1124. }
  1125.  
  1126. // CSS
  1127. if (!document.getElementById('colorPickerCSS')) { // only once needed
  1128. test.onload = test.onerror = function(){
  1129. if (_data._cssFunc) {
  1130. processCSS(this.width === 1 && this.height === 1);
  1131. }
  1132. THIS.cssIsReady = true;
  1133. };
  1134. test.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
  1135. } else {
  1136. THIS.cssIsReady = true;
  1137. }
  1138.  
  1139. // HTML
  1140. if (_previousInstance = _colorPicker) {
  1141. // we need to be careful with recycling HTML as slider calssNames might have been changed...
  1142. initSliders();
  1143. }
  1144. // app.innerHTML = _colorPicker ? _colorPicker.nodes.colorPicker.outerHTML : _data._html.replace(/§/g, prefix);
  1145. // faster ... FF8.0 (2011) though (but IE4)
  1146. // outerHTML ... FF11 (2013)
  1147. app.insertAdjacentHTML('afterbegin',
  1148. _colorPicker ? _colorPicker.nodes.colorPicker.outerHTML ||
  1149. new XMLSerializer().serializeToString(_colorPicker.nodes.colorPicker) : // FF before F11
  1150. _data._html.replace(/§/g, prefix));
  1151. // _colorPicker ? _colorPicker.nodes.colorPicker.parentNode.innerHTML : _data._html.replace(/§/g, prefix));
  1152. // _data._html = null;
  1153.  
  1154. app = app.children[0];
  1155. app.style.cssText = _options.initStyle || ''; // for initial hiding...
  1156. // get a better addClass for this....
  1157. // app.className = app.className.split(' ')[0]; // cleanup for multy instances
  1158.  
  1159. return (_options.appendTo || document.body).appendChild(app);
  1160. }
  1161.  
  1162. function getInstanceNodes(colorPicker, THIS) { // check nodes again... are they all needed?
  1163. var all = colorPicker.getElementsByTagName('*'),
  1164. nodes = {colorPicker: colorPicker}, // length ?? // rename nodes.colorPicker
  1165. node,
  1166. className,
  1167. memoCounter = 0,
  1168. regexp = new RegExp(_options.CSSPrefix);
  1169.  
  1170. // nodes.displayStyles = {}; // not needed ... or change to CSS
  1171. nodes.styles = {};
  1172. // nodes.styles.displays = {};
  1173.  
  1174. nodes.textNodes = {};
  1175. nodes.memos = [];
  1176. nodes.testNode = document.createElement('div');
  1177.  
  1178. for (var n = 0, m = all.length; n < m; n++) {
  1179. node = all[n];
  1180. if ((className = node.className) && regexp.test(className)) {
  1181. className = className.split(' ')[0].replace(_options.CSSPrefix, '').replace(/-/g, '_');
  1182. if (/_disp/.test(className)) {
  1183. className = className.replace('_disp', '');
  1184. // nodes.styles.displays[className] = node.style;
  1185. nodes.styles[className] = node.style;
  1186. nodes.textNodes[className] = node.firstChild;
  1187. node.contentEditable = true; // does this slow down rendering??
  1188. } else {
  1189. if (!(/(?:hs|cmyk|Lab).*?(?:butt|labl)/.test(className))) {
  1190. nodes[className] = node;
  1191. }
  1192. if (/(?:cur|sld[^s]|opacity|cont|col)/.test(className)) {
  1193. nodes.styles[className] = /(?:col\d)/.test(className) ? node.children[0].style : node.style;
  1194. }
  1195. }
  1196. } else if (/memo/.test(node.parentNode.className)) {
  1197. nodes.memos.push(node);
  1198. }
  1199. }
  1200.  
  1201. // Chrome bug: focuses contenteditable on mouse over while dragging
  1202. nodes.panelCover = nodes.panel.appendChild(document.createElement('div'));
  1203.  
  1204. return nodes;
  1205. }
  1206.  
  1207. // ------------------------------------------------------ //
  1208. // ---- Add event listners to colorPicker and window ---- //
  1209. // -------------------------------------------------------//
  1210.  
  1211. function installEventListeners(THIS, off) {
  1212. var onOffEvent = off ? removeEvent : addEvent;
  1213.  
  1214. onOffEvent(_nodes.colorPicker, 'mousedown', function(e) {
  1215. var event = e || window.event,
  1216. page = getPageXY(event),
  1217. target = (event.button || event.which) < 2 ?
  1218. (event.target || event.srcElement) : {},
  1219. className = target.className;
  1220.  
  1221. focusInstance(THIS);
  1222. _mainTarget = target;
  1223. stopChange(undefined, 'resetEventListener');
  1224. _action = ''; // needed due to minification of javaScript
  1225.  
  1226. if (target === _nodes.sldl_3 || target === _nodes.curm) {
  1227. _mainTarget = _nodes.sldl_3;
  1228. _mouseMoveAction = changeXYValue;
  1229. _action = 'changeXYValue';
  1230. changeClass(_nodes.slds, 'do-drag');
  1231. } else if (/sldr/.test(className) || target === _nodes.curl || target === _nodes.curr) {
  1232. _mainTarget = _nodes.sldr_4;
  1233. _mouseMoveAction = changeZValue;
  1234. _action = 'changeZValue';
  1235. } else if (target === _nodes.opacity.children[0] || target === _nodes.opacity_slider) {
  1236. _mainTarget = _nodes.opacity;
  1237. _mouseMoveAction = changeOpacityValue;
  1238. _action = 'changeOpacityValue';
  1239. } else if (/-disp/.test(className) && !/HEX-/.test(className)) {
  1240. _mouseMoveAction = changeInputValue;
  1241. _action = 'changeInputValue';
  1242. (target.nextSibling.nodeType === 3 ? target.nextSibling.nextSibling : target.nextSibling).
  1243. appendChild(_nodes.nsarrow); // nextSibling for better text selection
  1244. _valueType = className.split('-disp')[0].split('-');
  1245. _valueType = {type: _valueType[0], z: _valueType[1] || ''};
  1246. changeClass(_nodes.panel, 'start-change');
  1247. _delayState = 0;
  1248. } else if (target === _nodes.resize && !_options.noResize) {
  1249. if (!_options.sizes) {
  1250. getUISizes();
  1251. }
  1252. _mainTarget = _nodes.resizer;
  1253. _mouseMoveAction = resizeApp;
  1254. _action = 'resizeApp';
  1255. } else {
  1256. _mouseMoveAction = undefined;
  1257. }
  1258.  
  1259. if (_mouseMoveAction) {
  1260. _startCoords = {pageX: page.X, pageY: page.Y};
  1261. _mainTarget.style.display = 'block'; // for resizer...
  1262. _targetOrigin = getOrigin(_mainTarget);
  1263. _targetOrigin.width = _nodes.opacity.offsetWidth; // ???????
  1264. _targetOrigin.childWidth = _nodes.opacity_slider.offsetWidth; // ???????
  1265. _mainTarget.style.display = ''; // ??? for resizer...
  1266. _mouseMoveAction(event);
  1267. addEvent(_isIE ? document.body : window, 'mousemove', _mouseMoveAction);
  1268. _renderTimer = window[requestAnimationFrame](renderAll);
  1269. } else {
  1270. // console.log(className)
  1271. // console.log(THIS.nodes[className.split(' ')[0].replace('cp-', '').replace('-', '_')])
  1272. // resize, button states, etc...
  1273. }
  1274.  
  1275. // if (_mouseMoveAction !== changeInputValue) preventDefault(event);
  1276. if (!/-disp/.test(className)) {
  1277. return preventDefault(event);
  1278. // document.activeElement.blur();
  1279. }
  1280. });
  1281.  
  1282. onOffEvent(_nodes.colorPicker, 'click', function(e) {
  1283. focusInstance(THIS);
  1284. buttonActions(e);
  1285. });
  1286.  
  1287. onOffEvent(_nodes.colorPicker, 'dblclick', buttonActions);
  1288.  
  1289. onOffEvent(_nodes.colorPicker, 'keydown', function(e) {
  1290. focusInstance(THIS);
  1291. keyControl(e);
  1292. });
  1293.  
  1294. // keydown is before keypress and focuses already
  1295. onOffEvent(_nodes.colorPicker, 'keypress', keyControl);
  1296. // onOffEvent(_nodes.colorPicker, 'keyup', keyControl);
  1297.  
  1298. onOffEvent(_nodes.colorPicker, 'paste', function(e) {
  1299. e.target.firstChild.data = e.clipboardData.getData('Text');
  1300. return preventDefault(e);
  1301. });
  1302. }
  1303.  
  1304. addEvent(_isIE ? document.body : window, 'mouseup', stopChange);
  1305.  
  1306. // ------------------------------------------------------ //
  1307. // --------- Event listner's callback functions -------- //
  1308. // -------------------------------------------------------//
  1309.  
  1310. function stopChange(e, action) {
  1311. var mouseMoveAction = _mouseMoveAction;
  1312.  
  1313. if (_mouseMoveAction) { // why??? please test again...
  1314. // if (document.selection && _mouseMoveAction !== changeInputValue) {
  1315. // //ie -> prevent showing the accelerator menu
  1316. // document.selection.empty();
  1317. // }
  1318. window[cancelAnimationFrame](_renderTimer);
  1319. removeEvent(_isIE ? document.body : window, 'mousemove', _mouseMoveAction);
  1320. if (_delayState) { // hapens on inputs
  1321. _valueType = {type: 'alpha'};
  1322. renderAll();
  1323. }
  1324. // this is dirty... has to do with M|W|! button
  1325. if (typeof _mouseMoveAction === 'function' || typeof _mouseMoveAction === 'number') {
  1326. delete _options.webUnsave;
  1327. }
  1328.  
  1329. _delayState = 1;
  1330. _mouseMoveAction = undefined;
  1331.  
  1332. changeClass(_nodes.slds, 'do-drag', '');
  1333. changeClass(_nodes.panel, '(?:start-change|do-change)', '');
  1334.  
  1335. _nodes.resizer.style.cssText = '';
  1336. _nodes.panelCover.style.cssText = '';
  1337.  
  1338. _nodes.memo_store.style.cssText = 'background-color: ' +
  1339. color2string(_colors.RND.rgb) + '; ' + getOpacityCSS(_colors.alpha);
  1340. _nodes.memo.className = _nodes.memo.className.replace(/\s+(?:dark|light)/, '') +
  1341. // (/dark/.test(_nodes.colorPicker.className) ? ' dark' : ' light');
  1342. (_colors['rgbaMix' + _bgTypes[_options.alphaBG]].luminance < 0.22 ? ' dark' : ' light');
  1343. // (_colors.rgbaMixCustom.luminance < 0.22 ? ' dark' : ' light')
  1344.  
  1345. _valueType = undefined;
  1346.  
  1347. resetCursors();
  1348.  
  1349. if (_options.actionCallback) {
  1350. _options.actionCallback(e, _action || mouseMoveAction.name || action || 'external');
  1351. }
  1352. }
  1353. }
  1354.  
  1355. function changeXYValue(e) {
  1356. var event = e || window.event,
  1357. scale = _options.scale,
  1358. page = getPageXY(event),
  1359. x = (page.X - _targetOrigin.left) * (scale === 4 ? 2 : scale),
  1360. y = (page.Y - _targetOrigin.top) * scale,
  1361. mode = _options.mode;
  1362.  
  1363. _colors[mode.type][mode.x] = limitValue(x / 255, 0, 1);
  1364. _colors[mode.type][mode.y] = 1 - limitValue(y / 255, 0, 1);
  1365. convertColors();
  1366. return preventDefault(event);
  1367. }
  1368.  
  1369. function changeZValue(e) { // make this part of changeXYValue
  1370. var event = e || window.event,
  1371. page = getPageXY(event),
  1372. z = (page.Y - _targetOrigin.top) * _options.scale,
  1373. mode = _options.mode;
  1374.  
  1375. _colors[mode.type][mode.z] = 1 - limitValue(z / 255, 0, 1);
  1376. convertColors();
  1377. return preventDefault(event);
  1378. }
  1379.  
  1380. function changeOpacityValue(e) {
  1381. var event = e || window.event,
  1382. page = getPageXY(event);
  1383.  
  1384. _newData = true;
  1385. _colors.alpha = limitValue(_math.round(
  1386. (page.X - _targetOrigin.left) / _targetOrigin.width * 100), 0, 100
  1387. ) / 100;
  1388. convertColors('alpha');
  1389. return preventDefault(event);
  1390. }
  1391.  
  1392. function changeInputValue(e) {
  1393. var event = e || window.event,
  1394. page = getPageXY(event),
  1395. delta = _startCoords.pageY - page.Y,
  1396. delayOffset = _options.delayOffset,
  1397. type = _valueType.type,
  1398. isAlpha = type === 'alpha',
  1399. ranges;
  1400.  
  1401. if (_delayState || _math.abs(delta) >= delayOffset) {
  1402. if (!_delayState) {
  1403. _delayState = (delta > 0 ? -delayOffset : delayOffset) +
  1404. (+_mainTarget.firstChild.data) * (isAlpha ? 100 : 1);
  1405. _startCoords.pageY += _delayState;
  1406. delta += _delayState;
  1407. _delayState = 1;
  1408. changeClass(_nodes.panel, 'start-change', 'do-change');
  1409. _nodes.panelCover.style.cssText = 'position:absolute;left:0;top:0;right:0;bottom:0';
  1410. // window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1411. document.activeElement.blur();
  1412. _renderTimer = window[requestAnimationFrame](renderAll);
  1413. }
  1414.  
  1415. if (type === 'cmyk' && _options.cmyOnly) {
  1416. type = 'cmy';
  1417. }
  1418.  
  1419. if (isAlpha) {
  1420. _newData = true;
  1421. _colors.alpha = limitValue(delta / 100, 0, 1);
  1422. } else {
  1423. ranges = _valueRanges[type][_valueType.z];
  1424. _colors[type][_valueType.z] = type === 'Lab' ? limitValue(delta, ranges[0], ranges[1]) :
  1425. limitValue(delta / ranges[1], 0, 1);
  1426. }
  1427. convertColors(isAlpha ? 'alpha' : type);
  1428. // event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
  1429. // event.returnValue = false; // see: pauseEvent(event);
  1430. return preventDefault(event);
  1431. }
  1432. }
  1433.  
  1434. function keyControl(e) { // this is quite big for what it does...
  1435. var event = e || window.event,
  1436. keyCode = event.which || event.keyCode,
  1437. key = String.fromCharCode(keyCode),
  1438. elm = document.activeElement,
  1439.  
  1440. cln = elm.className.replace(_options.CSSPrefix, '').split('-'),
  1441. type = cln[0],
  1442. mode = cln[1],
  1443.  
  1444. isAlpha = type === 'alpha',
  1445. isHex = type === 'HEX',
  1446. arrowKey = {k40: -1, k38: 1, k34: -10, k33: 10}['k' + keyCode] / (isAlpha ? 100 : 1),
  1447. validKeys = {'HEX': /[0-9a-fA-F]/, 'Lab': /[\-0-9]/, 'alpha': /[\.0-9]/}[type] || /[0-9]/,
  1448. valueRange = _valueRanges[type][type] || _valueRanges[type][mode], // let op!
  1449.  
  1450. textNode = elm.firstChild, // chnge on TAB key
  1451. rangeData = caret(elm),
  1452. origValue = textNode.data, // do not change
  1453. value,
  1454. val = origValue === '0' && !isHex ? [] : origValue.split(''); // gefixt
  1455.  
  1456. if (/^(?:27|13)$/.test(keyCode)) { // ENTER || ESC
  1457. preventDefault(event);
  1458. elm.blur();
  1459. } else if (event.type === 'keydown') { // functional keys
  1460. if (arrowKey) { // arrow/page keys
  1461. value = limitValue(_math.round((+origValue + arrowKey) * 1e+6) / 1e+6, valueRange[0], valueRange[1]);
  1462. } else if (/^(?:8|46)$/.test(keyCode)) { // DELETE / BACKSPACE
  1463. if (!rangeData.range) {
  1464. rangeData.range++;
  1465. rangeData.start -= keyCode === 8 ? 1 : 0;
  1466. }
  1467. val.splice(rangeData.start, rangeData.range);
  1468. value = val.join('') || '0'; // never loose elm.firstChild
  1469. }
  1470.  
  1471. if (value !== undefined) { // prevent keypress
  1472. preventDefault(event, true);
  1473. }
  1474. } else if (event.type === 'keypress') {
  1475. if (!/^(?:37|39|8|46|9)$/.test(keyCode)) { // left, right,DEL, BACK, TAB for FF
  1476. preventDefault(event, true);
  1477. }
  1478. if (validKeys.test(key)) { // regular input
  1479. val.splice(rangeData.start, rangeData.range, key);
  1480. value = val.join('');
  1481. }
  1482. rangeData.start++;
  1483. }
  1484.  
  1485. if (keyCode === 13 && isHex) {
  1486. if (textNode.data.length % 3 === 0 || textNode.data === '0') { // textNode.data.length &&
  1487. return _colorPicker.setColor(textNode.data === '0' ? '000' : textNode.data, 'rgb', _colors.alpha, true);
  1488. } else {
  1489. preventDefault(event, true);
  1490. return elm.focus();
  1491. }
  1492. }
  1493.  
  1494. if (isHex && value !== undefined) {
  1495. value = /^0+/.test(value) ? value : parseInt(''+value, 16) || 0;
  1496. }
  1497.  
  1498. if (value !== undefined && value !== '' && +value >= valueRange[0] && +value <= valueRange[1]) {
  1499. if (isHex) {
  1500. value = value.toString(16).toUpperCase() || '0';
  1501. }
  1502. if (isAlpha) {
  1503. _colors[type] = +value;
  1504. } else if (!isHex) {
  1505. _colors[type][mode] = +value / (type === 'Lab' ? 1 : valueRange[1]);
  1506. }
  1507. convertColors(isAlpha ? 'alpha' : type);
  1508.  
  1509. preRenderAll(_colors);
  1510. _mouseMoveAction = true;
  1511. stopChange(e, event.type);
  1512.  
  1513. textNode.data = value; // if
  1514. caret(elm, _math.min(elm.firstChild.data.length, rangeData.start < 0 ? 0 : rangeData.start));
  1515. }
  1516. }
  1517.  
  1518. function buttonActions(e) {
  1519. var event = e || window.event,
  1520. target = event.target || event.srcElement,
  1521. targetClass = target.className,
  1522. parent = target.parentNode,
  1523. options = _options,
  1524. RGB = _colors.RND.rgb,
  1525. customBG, alphaBG,
  1526. mode = _options.mode,
  1527. newMode = '',
  1528. prefix = options.CSSPrefix,
  1529. isModeButton = /(?:hs|rgb)/.test(parent.className) && /^[HSBLRG]$/.test(
  1530. target.firstChild ? target.firstChild.data : ''
  1531. ),
  1532. isDblClick = /dblc/.test(event.type),
  1533. buttonAction = ''; // think this over again....
  1534.  
  1535. if (isDblClick && !isModeButton) {
  1536. return;
  1537. } else if (targetClass.indexOf('-labl ' + prefix + 'labl') !== -1) { // HSB -> HSL; CMYK -> Lab buttons
  1538. changeClass(_nodes[targetClass.split('-')[0]], prefix + 'hide', '');
  1539. changeClass(_nodes[parent.className.split('-')[1]], prefix + 'hide');
  1540. } else if (targetClass.indexOf(prefix + 'butt') !== -1) { // BUTTONS
  1541. if (isModeButton) { // set render modes
  1542. if (isDblClick && _options.scale === 2) {
  1543. newMode = /hs/.test(mode.type) ? 'rgb' : /hide/.test(_nodes.hsl.className) ? 'hsv' : 'hsl';
  1544. newMode = newMode + '-' + newMode[mode.type.indexOf(mode.z)];
  1545. }
  1546. _colorPicker.setMode(newMode ? newMode : targetClass.replace('-butt', '').split(' ')[0]);
  1547. buttonAction = 'modeChange';
  1548. } else if (/^[rgb]/.test(targetClass)) { // no vertical slider rendering in RGB mode
  1549. newMode = targetClass.split('-')[1];
  1550. changeClass(_nodes.colorPicker, 'no-rgb-' + newMode,
  1551. (options['noRGB' + newMode] = !options['noRGB' + newMode]) ? undefined : '');
  1552. buttonAction = 'noRGB' + newMode;
  1553. // preRenderAll();
  1554. } else if (target === _nodes.alpha_labl) { // alpha button right (background of raster)
  1555. customBG = options.customBG;
  1556. alphaBG = options.alphaBG;
  1557. changeClass(_nodes.colorPicker, 'alpha-bg-' + alphaBG, 'alpha-bg-' +
  1558. (alphaBG = options.alphaBG = e.data || (alphaBG === 'w' ? (customBG ? 'c' : 'b') :
  1559. alphaBG === 'c' ? 'b' : 'w')));
  1560. target.firstChild.data = alphaBG.toUpperCase();
  1561. _nodes.ctrl.style.backgroundColor = _nodes.memo.style.backgroundColor =
  1562. alphaBG !== 'c' ? '' : 'rgb(' + _math.round(customBG.r * 255) + ', ' +
  1563. _math.round(customBG.g * 255) + ', ' +
  1564. _math.round(customBG.b * 255) + ')';
  1565. _nodes.raster.style.cssText = _nodes.raster_bg.previousSibling.style.cssText =
  1566. alphaBG !== 'c' ? '' : getOpacityCSS(customBG.luminance < 0.22 ? 0.5 : 0.4);
  1567. buttonAction = 'alphaBackground';
  1568. } else if (target === _nodes.alpha_butt) { // alpha button left (disable alpha rendering)
  1569. changeClass(_nodes.colorPicker, 'mute-alpha', (options.muteAlpha = !options.muteAlpha) ? undefined : '');
  1570. buttonAction = 'alphaState';
  1571. } else if (target === _nodes.HEX_butt) { // make it on/off
  1572. changeClass(_nodes.colorPicker, 'no-HEX', (options.HEXState = !options.HEXState) ? undefined : '');
  1573. buttonAction = 'HEXState';
  1574. } else if (target === _nodes.HEX_labl) { // web save state change
  1575. var isWebSave = _colors.saveColor === 'web save';
  1576.  
  1577. if (_colors.saveColor !== 'web smart' && !isWebSave) {
  1578. options.webUnsave = copyColor(RGB);
  1579. _colorPicker.setColor(_colors.webSmart, 'rgb');
  1580. } else if (!isWebSave) {
  1581. if (!options.webUnsave) {
  1582. options.webUnsave = copyColor(RGB);
  1583. }
  1584. _colorPicker.setColor(_colors.webSave, 'rgb');
  1585. } else {
  1586. _colorPicker.setColor(options.webUnsave, 'rgb');
  1587. }
  1588. buttonAction = 'webColorState';
  1589. } else if (/Lab-x-labl/.test(targetClass)) { //target === _nodes.cmyk_type) {
  1590. // switch between CMYK and CMY
  1591. changeClass(_nodes.colorPicker, 'cmy-only', (options.cmyOnly = !options.cmyOnly) ? undefined : '');
  1592. buttonAction = 'cmykState';
  1593. }
  1594. } else if (target === _nodes.bsav) { // SAVE
  1595. saveAsBackground();
  1596. buttonAction = 'saveAsBackground';
  1597. } else if (target === _nodes.bres) { // RESET
  1598. var tmpColor = copyColor(RGB),
  1599. tmpAlpha = _colors.alpha;
  1600.  
  1601. // a bit heavy but... doesn't matter here
  1602. // newCol, type, alpha, forceRender
  1603. _colorPicker.setColor(options.color);
  1604. saveAsBackground();
  1605. _colorPicker.setColor(tmpColor, 'rgb', tmpAlpha);
  1606. buttonAction = 'resetColor';
  1607. } else if (parent === _nodes.col1) { // COLOR left
  1608. // _colors.hsv.h = (_colors.hsv.h + 0.5) % 1; // not acurate
  1609. _colors.hsv.h -= (_colors.hsv.h > 0.5 ? 0.5 : -0.5);
  1610. convertColors('hsv');
  1611. buttonAction = 'shiftColor';
  1612.  
  1613. } else if (parent === _nodes.col2) { // COLOR right
  1614. _colorPicker.setColor(target.style.backgroundColor, 'rgb', _colors.background.alpha);
  1615. buttonAction = 'setSavedColor';
  1616. } else if (parent === _nodes.memo) { // MEMORIES // revisit...
  1617. var resetBlink = function() {
  1618. if (_nodes.memos.blinker) _nodes.memos.blinker.style.cssText = _nodes.memos.cssText;
  1619. },
  1620. doBlink = function(elm) {
  1621. _nodes.memos.blinker = elm;
  1622. elm.style.cssText = 'background-color:' + (_colors.RGBLuminance > 0.22 ? '#333' : '#DDD');
  1623. window.setTimeout(resetBlink, 200);
  1624. };
  1625.  
  1626. if (target === _nodes.memo_cursor) { // save color in memo
  1627. resetBlink();
  1628. _nodes.memos.blinker = undefined;
  1629. _nodes.testNode.style.cssText = _nodes.memo_store.style.cssText;
  1630. _nodes.memos.cssText = _nodes.testNode.style.cssText; // ...how browser sees css
  1631. for (var n = _nodes.memos.length - 1; n--; ) { // check if color already exists
  1632. if (_nodes.memos.cssText === _nodes.memos[n].style.cssText) {
  1633. doBlink(_nodes.memos[n]); // sets _nodes.memos.blinker
  1634. break;
  1635. }
  1636. }
  1637. if (!_nodes.memos.blinker) { // right shift colors
  1638. for (var n = _nodes.memos.length - 1; n--; ) {
  1639. _nodes.memos[n + 1].style.cssText = _nodes.memos[n].style.cssText;
  1640. }
  1641. _nodes.memos[0].style.cssText = _nodes.memo_store.style.cssText;
  1642. }
  1643. buttonAction = 'toMemory';
  1644. } else { // reset color from memo
  1645. resetBlink();
  1646. _colorPicker.setColor(target.style.backgroundColor, 'rgb', target.style.opacity || 1);
  1647. _nodes.memos.cssText = target.style.cssText;
  1648. doBlink(target);
  1649. // this is dirty... has to do with M|W|! button
  1650. _mouseMoveAction = 1;
  1651. buttonAction = 'fromMemory';
  1652. }
  1653.  
  1654. }
  1655. // think this over again, does this need to be like this??
  1656. if (buttonAction) {
  1657. preRenderAll(_colors);
  1658. _mouseMoveAction = _mouseMoveAction || true; // !!!! search for: // this is dirty...
  1659. stopChange(e, buttonAction);
  1660. }
  1661. }
  1662.  
  1663. function resizeApp(e, size) {
  1664. var event = e || window.event,
  1665. page = event ? getPageXY(event) : {},
  1666. isSize = size !== undefined,
  1667. x = isSize ? size : page.X - _targetOrigin.left + 8,
  1668. y = isSize ? size : page.Y - _targetOrigin.top + 8,
  1669. values = [' S XS XXS', ' S XS', ' S', ''],
  1670. sizes = _options.sizes, // from getUISizes();
  1671. currentSize = isSize ? size :
  1672. y < sizes.XXS[1] + 25 ? 0 :
  1673. x < sizes.XS[0] + 25 ? 1 :
  1674. x < sizes.S[0] + 25 || y < sizes.S[1] + 25 ? 2 : 3,
  1675. value = values[currentSize],
  1676. isXXS = false,
  1677. mode,
  1678. tmp = '';
  1679.  
  1680. if (_cashedVars.resizer !== value) {
  1681. isXXS = /XX/.test(value);
  1682. mode = _options.mode;
  1683.  
  1684. if (isXXS && (!/hs/.test(mode.type) || mode.z === 'h')) {
  1685. tmp = mode.type + '-' + mode.z;
  1686. _colorPicker.setMode(/hs/.test(mode.type) ? mode.type + '-s': 'hsv-s');
  1687. _options.mode.original = tmp;
  1688. } else if (mode.original) {
  1689. // setMode(mode) creates a new object so mode.original gets deleted automatically
  1690. _colorPicker.setMode(mode.original);
  1691. }
  1692.  
  1693. _nodes.colorPicker.className = _nodes.colorPicker.className.replace(/\s+(?:S|XS|XXS)/g, '') + value;
  1694. _options.scale = isXXS ? 4 : /S/.test(value) ? 2 : 1;
  1695. _options.currentSize = currentSize;
  1696.  
  1697. _cashedVars.resizer = value;
  1698.  
  1699. // fix this... from this point on inside if() ... convertColors();
  1700. _newData = true;
  1701. renderAll();
  1702. resetCursors();
  1703. }
  1704.  
  1705. _nodes.resizer.style.cssText = 'display: block;' +
  1706. 'width: ' + (x > 10 ? x : 10) + 'px;' +
  1707. 'height: ' + (y > 10 ? y : 10) + 'px;';
  1708. }
  1709.  
  1710. // ------------------------------------------------------ //
  1711. // --- Colors calculation and rendering related stuff --- //
  1712. // -------------------------------------------------------//
  1713.  
  1714. function setMode(mode) {
  1715. var ModeMatrix = {
  1716. rgb_r : {x: 'b', y: 'g'},
  1717. rgb_g : {x: 'b', y: 'r'},
  1718. rgb_b : {x: 'r', y: 'g'},
  1719.  
  1720. hsv_h : {x: 's', y: 'v'},
  1721. hsv_s : {x: 'h', y: 'v'},
  1722. hsv_v : {x: 'h', y: 's'},
  1723.  
  1724. hsl_h : {x: 's', y: 'l'},
  1725. hsl_s : {x: 'h', y: 'l'},
  1726. hsl_l : {x: 'h', y: 's'}
  1727. },
  1728. key = mode.replace('-', '_'),
  1729. regex = '\\b(?:rg|hs)\\w\\-\\w\\b'; // \\b\\w{3}\\-\\w\\b';
  1730.  
  1731. // changeClass(_nodes.colorPicker, '(?:.*?)$', mode);
  1732. // changeClass(_nodes.colorPicker, '\\b\\w{3}\\-\\w\\b', mode);
  1733. // changeClass(_nodes.slds, '\\b\\w{3}\\-\\w\\b', mode);
  1734. changeClass(_nodes.panel, regex, mode);
  1735. changeClass(_nodes.slds, regex, mode);
  1736.  
  1737. mode = mode.split('-');
  1738. return _options.mode = {
  1739. type: mode[0],
  1740. x: ModeMatrix[key].x,
  1741. y: ModeMatrix[key].y,
  1742. z: mode[1]
  1743. };
  1744. }
  1745.  
  1746. function initSliders() { // function name...
  1747. var regex = /\s+(?:hue-)*(?:dark|light)/g,
  1748. className = 'className'; // minification
  1749.  
  1750. _nodes.curl[className] = _nodes.curl[className].replace(regex, ''); // .....
  1751. _nodes.curr[className] = _nodes.curr[className].replace(regex, ''); // .....
  1752. _nodes.slds[className] = _nodes.slds[className].replace(regex, '');
  1753. // var sldrs = ['sldr_2', 'sldr_4', 'sldl_3'];
  1754. // for (var n = sldrs.length; n--; ) {
  1755. // _nodes[sldrs[n]][className] = _options.CSSPrefix + sldrs[n].replace('_', '-');
  1756. // }
  1757. _nodes.sldr_2[className] = _options.CSSPrefix + 'sldr-2';
  1758. _nodes.sldr_4[className] = _options.CSSPrefix + 'sldr-4';
  1759. _nodes.sldl_3[className] = _options.CSSPrefix + 'sldl-3';
  1760.  
  1761. for (var style in _nodes.styles) {
  1762. if (!style.indexOf('sld')) _nodes.styles[style].cssText = '';
  1763. }
  1764. _cashedVars = {};
  1765. }
  1766.  
  1767. function resetCursors() {
  1768. // _renderVars.isNoRGB = undefined;
  1769. _nodes.styles.curr.cssText = _nodes.styles.curl.cssText; // only coordinates
  1770. _nodes.curl.className = _options.CSSPrefix + 'curl' + (
  1771. _renderVars.noRGBZ ? ' ' + _options.CSSPrefix + 'curl-' +_renderVars.noRGBZ: '');
  1772. _nodes.curr.className = _options.CSSPrefix + 'curr ' + _options.CSSPrefix + 'curr-' +
  1773. (_options.mode.z === 'h' ? _renderVars.HUEContrast : _renderVars.noRGBZ ?
  1774. _renderVars.noRGBZ : _renderVars.RGBLuminance);
  1775. }
  1776.  
  1777. function convertColors(type) {
  1778. preRenderAll(_colorInstance.setColor(undefined, type || _options.mode.type));
  1779. _newData = true;
  1780. }
  1781.  
  1782. function saveAsBackground(refresh) {
  1783. _colorInstance.saveAsBackground();
  1784. _nodes.styles.col2.cssText = 'background-color: ' + color2string(_colors.background.RGB) + ';' +
  1785. getOpacityCSS(_colors.background.alpha);
  1786. if (refresh) {
  1787. preRenderAll(_colors);
  1788. // renderAll();
  1789. }
  1790. return (_colors);
  1791. }
  1792.  
  1793. function preRenderAll(colors) {
  1794. var _Math = _math,
  1795. renderVars = _renderVars,
  1796. bgType = _bgTypes[_options.alphaBG];
  1797.  
  1798. renderVars.hueDelta = _Math.round(colors['rgbaMixBGMix' + bgType].hueDelta * 100);
  1799. // renderVars.RGBLuminanceDelta = _Math.round(colors.RGBLuminanceDelta * 100);
  1800. renderVars.luminanceDelta = _Math.round(colors['rgbaMixBGMix' + bgType].luminanceDelta * 100);
  1801. renderVars.RGBLuminance = colors.RGBLuminance > 0.22 ? 'light' : 'dark';
  1802. renderVars.HUEContrast = colors.HUELuminance > 0.22 ? 'light' : 'dark';
  1803. // renderVars.contrast = renderVars.RGBLuminanceDelta > renderVars.hueDelta ? 'contrast' : '';
  1804. renderVars.contrast = renderVars.luminanceDelta > renderVars.hueDelta ? 'contrast' : '';
  1805. renderVars.readabiltiy =
  1806. colors['rgbaMixBGMix' + bgType].WCAG2Ratio >= 7 ? 'green' :
  1807. colors['rgbaMixBGMix' + bgType].WCAG2Ratio >= 4.5 ? 'orange': '';
  1808. renderVars.noRGBZ = _options['no' + _options.mode.type.toUpperCase() + _options.mode.z] ?
  1809. (_options.mode.z === 'g' && colors.rgb.g < 0.59 || _options.mode.z === 'b' || _options.mode.z === 'r' ?
  1810. 'dark' : 'light') : undefined;
  1811. }
  1812.  
  1813. function renderAll() { // maybe render alpha seperately...
  1814. if (_mouseMoveAction) {
  1815. // _renderTimer = window[requestAnimationFrame](renderAll);
  1816. if (!_newData) return (_renderTimer = window[requestAnimationFrame](renderAll));
  1817. _newData = false;
  1818. }
  1819. // console.time('renderAll');
  1820. var options = _options,
  1821. mode = options.mode,
  1822. scale = options.scale,
  1823. prefix = options.CSSPrefix,
  1824. colors = _colors,
  1825. nodes = _nodes,
  1826. CSS = nodes.styles,
  1827. textNodes = nodes.textNodes,
  1828. valueRanges = _valueRanges,
  1829. valueType = _valueType,
  1830. renderVars = _renderVars,
  1831. cashedVars = _cashedVars,
  1832.  
  1833. _Math = _math,
  1834. _getOpacityCSS = getOpacityCSS,
  1835. _color2string = color2string,
  1836.  
  1837. a = 0,
  1838. b = 0,
  1839. x = colors[mode.type][mode.x],
  1840. X = _Math.round(x * 255 / (scale === 4 ? 2 : scale)),
  1841. y_ = colors[mode.type][mode.y],
  1842. y = 1 - y_,
  1843. Y = _Math.round(y * 255 / scale),
  1844. z = 1 - colors[mode.type][mode.z],
  1845. Z = _Math.round(z * 255 / scale),
  1846. coords = (1 === 1) ? [x, y_] : [0, 0], // (1 === 2) button label up
  1847.  
  1848. isRGB = mode.type === 'rgb',
  1849. isHue = mode.z === 'h',
  1850. isHSL = mode.type === 'hsl',
  1851. isHSL_S = isHSL && mode.z === 's',
  1852. moveXY = _mouseMoveAction === changeXYValue,
  1853. moveZ = _mouseMoveAction === changeZValue,
  1854. display, tmp, value, slider;
  1855.  
  1856. if (isRGB) {
  1857. if (coords[0] >= coords[1]) b = 1; else a = 1;
  1858. if (cashedVars.sliderSwap !== a) {
  1859. nodes.sldr_2.className = options.CSSPrefix + 'sldr-' + (3 - a);
  1860. cashedVars.sliderSwap = a;
  1861. }
  1862. }
  1863. if ((isRGB && !moveZ) || (isHue && !moveXY) || (!isHue && !moveZ)) {
  1864. CSS[isHue ? 'sldl_2' : 'sldr_2'][isRGB ? 'cssText' : 'backgroundColor'] =
  1865. isRGB ? _getOpacityCSS((coords[a] - coords[b]) / (1 - (coords[b]) || 0)) : _color2string(colors.hueRGB);
  1866. }
  1867. if (!isHue) {
  1868. if (!moveZ) CSS.sldr_4.cssText = _getOpacityCSS(isRGB ? coords[b] : isHSL_S ? _Math.abs(1 - y * 2) : y);
  1869. if (!moveXY) CSS.sldl_3.cssText = _getOpacityCSS(isHSL && mode.z === 'l' ? _Math.abs(1 - z * 2) : z);
  1870. if (isHSL) { // switch slider class name for black/white color half way through in HSL(S|L) mode(s)
  1871. slider = isHSL_S ? 'sldr_4' : 'sldl_3';
  1872. tmp = isHSL_S ? 'r-' : 'l-';
  1873. value = isHSL_S ? (y > 0.5 ? 4 : 3) : (z > 0.5 ? 3 : 4);
  1874.  
  1875. if (cashedVars[slider] !== value) {
  1876. nodes[slider].className = options.CSSPrefix + 'sld' + tmp + value;
  1877. cashedVars[slider] = value;
  1878. }
  1879. }
  1880. }
  1881.  
  1882. if (!moveZ) CSS.curm.cssText = 'left: ' + X + 'px; top: ' + Y + 'px;';
  1883. if (!moveXY) CSS.curl.top = Z + 'px';
  1884. if (valueType) CSS.curr.top = Z + 'px'; // && valueType.type !== mode.type
  1885. if ((valueType && valueType.type === 'alpha') || _mainTarget === nodes.opacity) {
  1886. CSS.opacity_slider.left = options.opacityPositionRelative ? (colors.alpha * (
  1887. (_targetOrigin.width || nodes.opacity.offsetWidth) -
  1888. (_targetOrigin.childWidth || nodes.opacity_slider.offsetWidth))) + 'px' :
  1889. (colors.alpha * 100) + '%';
  1890. }
  1891.  
  1892. CSS.col1.cssText = 'background-color: ' + _color2string(colors.RND.rgb) + '; ' +
  1893. (options.muteAlpha ? '' : _getOpacityCSS(colors.alpha));
  1894. CSS.opacity.backgroundColor = _color2string(colors.RND.rgb);
  1895. CSS.cold.width = renderVars.hueDelta + '%';
  1896. CSS.cont.width = renderVars.luminanceDelta + '%';
  1897.  
  1898. for (display in textNodes) {
  1899. tmp = display.split('_');
  1900. if (options.cmyOnly) {
  1901. tmp[0] = tmp[0].replace('k', '');
  1902. }
  1903. value = tmp[1] ? colors.RND[tmp[0]][tmp[1]] : colors.RND[tmp[0]] || colors[tmp[0]];
  1904. if (cashedVars[display] !== value) {
  1905. cashedVars[display] = value;
  1906. textNodes[display].data = value > 359.5 && display !== 'HEX' ? 0 : value;
  1907.  
  1908. if (display !== 'HEX' && !options.noRangeBackground) {
  1909. value = colors[tmp[0]][tmp[1]] !== undefined ? colors[tmp[0]][tmp[1]] : colors[tmp[0]];
  1910. if (tmp[0] === 'Lab') {
  1911. value = (value - valueRanges[tmp[0]][tmp[1]][0]) /
  1912. (valueRanges[tmp[0]][tmp[1]][1] - valueRanges[tmp[0]][tmp[1]][0]);
  1913. }
  1914. CSS[display].backgroundPosition = _Math.round((1 - value) * 100) + '% 0%';
  1915. }
  1916. }
  1917. }
  1918. // Lab out of gammut
  1919. tmp = colors._rgb ? [
  1920. colors._rgb.r !== colors.rgb.r,
  1921. colors._rgb.g !== colors.rgb.g,
  1922. colors._rgb.b !== colors.rgb.b
  1923. ] : [];
  1924. if (tmp.join('') !== cashedVars.outOfGammut) {
  1925. nodes.rgb_r_labl.firstChild.data = tmp[0] ? '!' : ' ';
  1926. nodes.rgb_g_labl.firstChild.data = tmp[1] ? '!' : ' ';
  1927. nodes.rgb_b_labl.firstChild.data = tmp[2] ? '!' : ' ';
  1928. cashedVars.outOfGammut = tmp.join('');
  1929. }
  1930. if (renderVars.noRGBZ) {
  1931. if (cashedVars.noRGBZ !== renderVars.noRGBZ) {
  1932. nodes.curl.className = prefix + 'curl ' + prefix + 'curl-' + renderVars.noRGBZ;
  1933. if (!moveZ) {
  1934. nodes.curr.className = prefix + 'curr ' + prefix + 'curr-' + renderVars.noRGBZ;
  1935. }
  1936. cashedVars.noRGBZ = renderVars.noRGBZ;
  1937. }
  1938. }
  1939. if (cashedVars.HUEContrast !== renderVars.HUEContrast && mode.z === 'h') {
  1940. nodes.slds.className = nodes.slds.className.replace(/\s+hue-(?:dark|light)/, '') +
  1941. ' hue-' + renderVars.HUEContrast;
  1942. if (!moveZ) {
  1943. nodes.curr.className = prefix + 'curr ' + prefix + 'curr-' + renderVars.HUEContrast;
  1944. }
  1945. cashedVars.HUEContrast = renderVars.HUEContrast;
  1946. } else if (cashedVars.RGBLuminance !== renderVars.RGBLuminance) { // test for no else
  1947. nodes.colorPicker.className = nodes.colorPicker.className.replace(/\s+(?:dark|light)/, '') +
  1948. ' ' + renderVars.RGBLuminance;
  1949. if (!moveZ && mode.z !== 'h' && !renderVars.noRGBZ) {
  1950. nodes.curr.className = prefix + 'curr ' + prefix + 'curr-' + renderVars.RGBLuminance;
  1951. }
  1952. cashedVars.RGBLuminance = renderVars.RGBLuminance;
  1953. }
  1954.  
  1955. if (cashedVars.contrast !== renderVars.contrast || cashedVars.readabiltiy !== renderVars.readabiltiy) {
  1956. nodes.ctrl.className = nodes.ctrl.className.replace(' contrast', '').replace(/\s*(?:orange|green)/, '') +
  1957. (renderVars.contrast ? ' ' + renderVars.contrast : '') +
  1958. (renderVars.readabiltiy ? ' ' + renderVars.readabiltiy : '');
  1959. cashedVars.contrast = renderVars.contrast;
  1960. cashedVars.readabiltiy = renderVars.readabiltiy;
  1961. }
  1962.  
  1963. if (cashedVars.saveColor !== colors.saveColor) {
  1964. nodes.HEX_labl.firstChild.data = !colors.saveColor ? '!' : colors.saveColor === 'web save' ? 'W' : 'M';
  1965. cashedVars.saveColor = colors.saveColor;
  1966. }
  1967.  
  1968. if (options.renderCallback) {
  1969. options.renderCallback(colors, mode); // maybe more parameters
  1970. }
  1971.  
  1972. if (_mouseMoveAction) {
  1973. _renderTimer = window[requestAnimationFrame](renderAll);
  1974. }
  1975.  
  1976. // console.timeEnd('renderAll')
  1977. }
  1978.  
  1979.  
  1980. // ------------------------------------------------------ //
  1981. // ------------------ helper functions ------------------ //
  1982. // -------------------------------------------------------//
  1983.  
  1984. function copyColor(color) {
  1985. var newColor = {};
  1986.  
  1987. for (var n in color) {
  1988. newColor[n] = color[n];
  1989. }
  1990. return newColor;
  1991. }
  1992.  
  1993. // function color2string(color, type) {
  1994. // var out = [],
  1995. // n = 0;
  1996.  
  1997. // type = type || 'rgb';
  1998. // while (type.charAt(n)) { // IE7 // V8 type[n] ||
  1999. // out.push(color[type.charAt(n)]);
  2000. // n++;
  2001. // }
  2002. // return type + '(' + out.join(', ') + ')';
  2003. // }
  2004.  
  2005. function color2string(color, type) { // ~2 x faster on V8
  2006. var out = '',
  2007. t = (type || 'rgb').split(''),
  2008. n = t.length;
  2009.  
  2010. for ( ; n--; ) {
  2011. out = ', ' + color[t[n]] + out;
  2012. }
  2013. return (type || 'rgb') + '(' + out.substr(2) + ')';
  2014. }
  2015.  
  2016.  
  2017. function limitValue(value, min, max) {
  2018. // return Math.max(min, Math.min(max, value)); // faster??
  2019. return (value > max ? max : value < min ? min : value);
  2020. }
  2021.  
  2022. function getOpacityCSS(value) {
  2023. if (value === undefined) value = 1;
  2024.  
  2025. if (_doesOpacity) {
  2026. return 'opacity: ' + (_math.round(value * 10000000000) / 10000000000) + ';'; // value.toFixed(16) = 99% slower
  2027. // some speed test:
  2028. // return ['opacity: ', (Math.round(value * 1e+10) / 1e+10), ';'].join('');
  2029. } else {
  2030. return 'filter: alpha(opacity=' + _math.round(value * 100) + ');';
  2031. }
  2032. }
  2033.  
  2034. function preventDefault(e, skip) {
  2035. e.preventDefault ? e.preventDefault() : e.returnValue = false;
  2036. if (!skip) window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2037. return false;
  2038. }
  2039.  
  2040. function changeClass(elm, cln, newCln) {
  2041. return !elm ? false : elm.className = (newCln !== undefined ?
  2042. elm.className.replace(new RegExp('\\s+?' + cln, 'g'), newCln ? ' ' + newCln : '') :
  2043. elm.className + ' ' + cln);
  2044. }
  2045.  
  2046. function getOrigin(elm) {
  2047. var box = (elm.getBoundingClientRect) ? elm.getBoundingClientRect() : {top: 0, left: 0},
  2048. doc = elm && elm.ownerDocument,
  2049. body = doc.body,
  2050. win = doc.defaultView || doc.parentWindow || window,
  2051. docElem = doc.documentElement || body.parentNode,
  2052. clientTop = docElem.clientTop || body.clientTop || 0, // border on html or body or both
  2053. clientLeft = docElem.clientLeft || body.clientLeft || 0;
  2054.  
  2055. return {
  2056. left: box.left + (win.pageXOffset || docElem.scrollLeft) - clientLeft,
  2057. top: box.top + (win.pageYOffset || docElem.scrollTop) - clientTop
  2058. };
  2059. }
  2060.  
  2061. function getPageXY(e) {
  2062. var doc = window.document;
  2063.  
  2064. return {
  2065. X: e.pageX || e.clientX + doc.body.scrollLeft + doc.documentElement.scrollLeft,
  2066. Y: e.pageY || e.clientY + doc.body.scrollTop + doc.documentElement.scrollTop
  2067. };
  2068. }
  2069.  
  2070. function addEvent(obj, type, func) {
  2071. addEvent.cache = addEvent.cache || {
  2072. _get: function(obj, type, func, checkOnly) {
  2073. var cache = addEvent.cache[type] || [];
  2074.  
  2075. for (var n = cache.length; n--; ) {
  2076. if (obj === cache[n].obj && '' + func === '' + cache[n].func) {
  2077. func = cache[n].func;
  2078. if (!checkOnly) {
  2079. cache[n] = cache[n].obj = cache[n].func = null;
  2080. cache.splice(n, 1);
  2081. }
  2082. return func;
  2083. }
  2084. }
  2085. },
  2086. _set: function(obj, type, func) {
  2087. var cache = addEvent.cache[type] = addEvent.cache[type] || [];
  2088. if (addEvent.cache._get(obj, type, func, true)) {
  2089. return true;
  2090. } else {
  2091. cache.push({
  2092. func: func,
  2093. obj: obj
  2094. });
  2095. }
  2096. }
  2097. };
  2098.  
  2099. if (!func.name && addEvent.cache._set(obj, type, func) || typeof func !== 'function') {
  2100. return;
  2101. }
  2102.  
  2103. if (obj.addEventListener) obj.addEventListener(type, func, false);
  2104. else obj.attachEvent('on' + type, func);
  2105. }
  2106.  
  2107. function removeEvent(obj, type, func) {
  2108. if (typeof func !== 'function') return;
  2109. if (!func.name) {
  2110. func = addEvent.cache._get(obj, type, func) || func;
  2111. }
  2112.  
  2113. if (obj.removeEventListener) obj.removeEventListener(type, func, false);
  2114. else obj.detachEvent('on' + type, func);
  2115. }
  2116.  
  2117. function caret(target, pos) { // only for contenteditable
  2118. var out = {};
  2119.  
  2120. if (pos === undefined) { // get
  2121. if (window.getSelection) { // HTML5
  2122. target.focus();
  2123. var range1 = window.getSelection().getRangeAt(0),
  2124. range2 = range1.cloneRange();
  2125. range2.selectNodeContents(target);
  2126. range2.setEnd(range1.endContainer, range1.endOffset);
  2127. out = {
  2128. end: range2.toString().length,
  2129. range: range1.toString().length
  2130. };
  2131. } else { // IE < 9
  2132. target.focus();
  2133. var range1 = document.selection.createRange(),
  2134. range2 = document.body.createTextRange();
  2135. range2.moveToElementText(target);
  2136. range2.setEndPoint('EndToEnd', range1);
  2137. out = {
  2138. end: range2.text.length,
  2139. range: range1.text.length
  2140. };
  2141. }
  2142. out.start = out.end - out.range;
  2143. return out;
  2144. }
  2145. // set
  2146. if (pos == -1) pos = target['text']().length;
  2147. if (window.getSelection) { // HTML5
  2148. target.focus();
  2149. window.getSelection().collapse(target.firstChild, pos);
  2150. } else { // IE < 9
  2151. var range = document.body.createTextRange();
  2152. range.moveToElementText(target);
  2153. range.moveStart('character', pos);
  2154. range.collapse(true);
  2155. range.select();
  2156. }
  2157. return pos;
  2158. }
  2159.  
  2160. // ------------- requestAnimationFrame shim ------------- //
  2161. // ---------- quite optimized for minification ---------- //
  2162.  
  2163. for(var n = vendors.length; n-- && !window[requestAnimationFrame]; ) {
  2164. window[requestAnimationFrame] = window[vendors[n] + 'Request' + animationFrame];
  2165. window[cancelAnimationFrame] = window[vendors[n] + 'Cancel' + animationFrame] ||
  2166. window[vendors[n] + 'CancelRequest' + animationFrame];
  2167. }
  2168.  
  2169. window[requestAnimationFrame] = window[requestAnimationFrame] || function(callback) {
  2170. // this is good enough... and better than setTimeout
  2171. return window.setTimeout(callback, 1000 / _options.fps);
  2172. // return _renderTimer ? _renderTimer : window.setInterval(callback, 1000 / _options.fps);
  2173. };
  2174.  
  2175. window[cancelAnimationFrame] = window[cancelAnimationFrame] || function(id) {
  2176. // console.log('OFF-', id + '-' + _renderTimer)
  2177. window.clearTimeout(id);
  2178. return _renderTimer = null;
  2179. };
  2180.  
  2181. })(window);
  2182.  
  2183. /*! javascript_implementation/jsColor.js */
  2184. (function (window) {
  2185. window.jsColorPicker = function(selectors, config) {
  2186. var renderCallback = function(colors, mode) {
  2187. var options = this,
  2188. input = options.input,
  2189. patch = options.patch,
  2190. RGB = colors.RND.rgb,
  2191. HSL = colors.RND.hsl,
  2192. AHEX = options.isIE8 ? (colors.alpha < 0.16 ? '0' : '') +
  2193. (Math.round(colors.alpha * 100)).toString(16).toUpperCase() + colors.HEX : '',
  2194. RGBInnerText = RGB.r + ', ' + RGB.g + ', ' + RGB.b,
  2195. RGBAText = 'rgba(' + RGBInnerText + ', ' + colors.alpha + ')',
  2196. isAlpha = colors.alpha !== 1 && !options.isIE8,
  2197. colorMode = input.getAttribute('data-colorMode');
  2198.  
  2199. patch.style.cssText =
  2200. 'color:' + (colors.rgbaMixCustom.luminance > 0.22 ? '#222' : '#ddd') + ';' + // Black...???
  2201. 'background-color:' + RGBAText + ';' +
  2202. 'filter:' + (options.isIE8 ? 'progid:DXImageTransform.Microsoft.gradient(' + // IE<9
  2203. 'startColorstr=#' + AHEX + ',' + 'endColorstr=#' + AHEX + ')' : '');
  2204.  
  2205. input.value = (colorMode === 'HEX' && !isAlpha ? '#' + (options.isIE8 ? AHEX : colors.HEX) :
  2206. colorMode === 'rgb' || (colorMode === 'HEX' && isAlpha) ?
  2207. (!isAlpha ? 'rgb(' + RGBInnerText + ')' : RGBAText) :
  2208. ('hsl' + (isAlpha ? 'a(' : '(') + HSL.h + ', ' + HSL.s + '%, ' + HSL.l + '%' +
  2209. (isAlpha ? ', ' + colors.alpha : '') + ')')
  2210. );
  2211.  
  2212. if (options.displayCallback) {
  2213. options.displayCallback(colors, mode, options);
  2214. }
  2215. },
  2216. extractValue = function(elm) {
  2217. return elm.value || elm.getAttribute('value') || elm.style.backgroundColor || '#FFFFFF';
  2218. },
  2219. actionCallback = function(event, action) {
  2220. var options = this,
  2221. colorPicker = colorPickers.current;
  2222.  
  2223. if (action === 'toMemory') {
  2224. var memos = colorPicker.nodes.memos,
  2225. backgroundColor = '',
  2226. opacity = 0,
  2227. cookieTXT = [];
  2228.  
  2229. for (var n = 0, m = memos.length; n < m; n++) {
  2230. backgroundColor = memos[n].style.backgroundColor;
  2231. opacity = memos[n].style.opacity;
  2232. opacity = Math.round((opacity === '' ? 1 : opacity) * 100) / 100;
  2233. cookieTXT.push(backgroundColor.
  2234. replace(/, /g, ',').
  2235. replace('rgb(', 'rgba(').
  2236. replace(')', ',' + opacity + ')')
  2237. );
  2238. }
  2239. cookieTXT = '\'' + cookieTXT.join('\',\'') + '\'';
  2240. ColorPicker.docCookies('colorPickerMemos' + (options.noAlpha ? 'NoAlpha' : ''), cookieTXT);
  2241. } else if (action === 'resizeApp') {
  2242. ColorPicker.docCookies('colorPickerSize', colorPicker.color.options.currentSize);
  2243. } else if (action === 'modeChange') {
  2244. var mode = colorPicker.color.options.mode;
  2245.  
  2246. ColorPicker.docCookies('colorPickerMode', mode.type + '-' + mode.z);
  2247. }
  2248. },
  2249. createInstance = function(elm, config) {
  2250. var initConfig = {
  2251. klass: window.ColorPicker,
  2252. input: elm,
  2253. patch: elm,
  2254. isIE8: !!document.all && !document.addEventListener, // Opera???
  2255. // *** animationSpeed: 200,
  2256. // *** draggable: true,
  2257. margin: {left: -1, top: 2},
  2258. customBG: '#FFFFFF',
  2259. // displayCallback: displayCallback,
  2260. /* --- regular colorPicker options from this point --- */
  2261. color: extractValue(elm),
  2262. initStyle: 'display: none',
  2263. mode: ColorPicker.docCookies('colorPickerMode') || 'hsv-h',
  2264. // memoryColors: (function(colors, config) {
  2265. // return config.noAlpha ?
  2266. // colors.replace(/\,\d*\.*\d*\)/g, ',1)') : colors;
  2267. // })($.docCookies('colorPickerMemos'), config || {}),
  2268. memoryColors: ColorPicker.docCookies('colorPickerMemos' +
  2269. ((config || {}).noAlpha ? 'NoAlpha' : '')),
  2270. size: ColorPicker.docCookies('colorPickerSize') || 1,
  2271. renderCallback: renderCallback,
  2272. actionCallback: actionCallback
  2273. };
  2274.  
  2275. for (var n in config) {
  2276. initConfig[n] = config[n];
  2277. }
  2278. return new initConfig.klass(initConfig);
  2279. },
  2280. doEventListeners = function(elm, multiple, off) {
  2281. var onOff = off ? 'removeEventListener' : 'addEventListener',
  2282. focusListener = function(e) {
  2283. var input = this,
  2284. position = window.ColorPicker.getOrigin(input),
  2285. index = multiple ? Array.prototype.indexOf.call(elms, this) : 0,
  2286. colorPicker = colorPickers[index] ||
  2287. (colorPickers[index] = createInstance(this, config)),
  2288. options = colorPicker.color.options,
  2289. colorPickerUI = colorPicker.nodes.colorPicker,
  2290. appendTo = (options.appendTo || document.body),
  2291. isStatic = /static/.test(window.getComputedStyle(appendTo).position),
  2292. atrect = isStatic ? {left: 0, top: 0} : appendTo.getBoundingClientRect(),
  2293. waitTimer = 0;
  2294.  
  2295. options.color = extractValue(elm); // brings color to default on reset
  2296. colorPickerUI.style.cssText =
  2297. 'position: absolute;' + (!colorPickers[index].cssIsReady ? 'display: none;' : '') +
  2298. 'left:' + (position.left + options.margin.left - atrect.left) + 'px;' +
  2299. 'top:' + (position.top + +input.offsetHeight + options.margin.top - atrect.top) + 'px;';
  2300.  
  2301. if (!multiple) {
  2302. options.input = elm;
  2303. options.patch = elm; // check again???
  2304. colorPicker.setColor(extractValue(elm), undefined, undefined, true);
  2305. colorPicker.saveAsBackground();
  2306. }
  2307. colorPickers.current = colorPickers[index];
  2308. appendTo.appendChild(colorPickerUI);
  2309. waitTimer = setInterval(function() { // compensating late style on onload in colorPicker
  2310. if (colorPickers.current.cssIsReady) {
  2311. waitTimer = clearInterval(waitTimer);
  2312. colorPickerUI.style.display = 'block';
  2313. }
  2314. }, 10);
  2315. },
  2316. mousDownListener = function(e) {
  2317. var colorPicker = colorPickers.current,
  2318. colorPickerUI = (colorPicker ? colorPicker.nodes.colorPicker : undefined),
  2319. animationSpeed = colorPicker ? colorPicker.color.options.animationSpeed : 0,
  2320. isColorPicker = colorPicker && (function(elm) {
  2321. while (elm) {
  2322. if ((elm.className || '').indexOf('cp-app') !== -1) return elm;
  2323. elm = elm.parentNode;
  2324. }
  2325. return false;
  2326. })(e.target),
  2327. inputIndex = Array.prototype.indexOf.call(elms, e.target);
  2328.  
  2329. if (isColorPicker && Array.prototype.indexOf.call(colorPickers, isColorPicker)) {
  2330. if (e.target === colorPicker.nodes.exit) {
  2331. colorPickerUI.style.display = 'none';
  2332. document.activeElement.blur();
  2333. } else {
  2334. // ...
  2335. }
  2336. } else if (inputIndex !== -1) {
  2337. // ...
  2338. } else if (colorPickerUI) {
  2339. colorPickerUI.style.display = 'none';
  2340. }
  2341. };
  2342.  
  2343. elm[onOff]('focus', focusListener);
  2344.  
  2345. if (!colorPickers.evt || off) {
  2346. colorPickers.evt = true; // prevent new eventListener for window
  2347.  
  2348. window[onOff]('mousedown', mousDownListener);
  2349. }
  2350. },
  2351. // this is a way to prevent data binding on HTMLElements
  2352. colorPickers = window.jsColorPicker.colorPickers || [],
  2353. elms = document.querySelectorAll(selectors),
  2354. testColors = new window.Colors({customBG: config.customBG, allMixDetails: true});
  2355.  
  2356. window.jsColorPicker.colorPickers = colorPickers;
  2357.  
  2358. for (var n = 0, m = elms.length; n < m; n++) {
  2359. var elm = elms[n];
  2360.  
  2361. if (config === 'destroy') {
  2362. doEventListeners(elm, (config && config.multipleInstances), true);
  2363. if (colorPickers[n]) {
  2364. colorPickers[n].destroyAll();
  2365. }
  2366. } else {
  2367. var color = extractValue(elm);
  2368. var value = color.split('(');
  2369.  
  2370. testColors.setColor(color);
  2371. if (config && config.init) {
  2372. config.init(elm, testColors.colors);
  2373. }
  2374. elm.setAttribute('data-colorMode', value[1] ? value[0].substr(0, 3) : 'HEX');
  2375. doEventListeners(elm, (config && config.multipleInstances), false);
  2376. if (config && config.readOnly) {
  2377. elm.readOnly = true;
  2378. }
  2379. }
  2380. };
  2381.  
  2382. return window.jsColorPicker.colorPickers;
  2383. };
  2384.  
  2385. window.ColorPicker.docCookies = function(key, val, options) {
  2386. var encode = encodeURIComponent, decode = decodeURIComponent,
  2387. cookies, n, tmp, cache = {},
  2388. days;
  2389.  
  2390. if (val === undefined) { // all about reading cookies
  2391. cookies = document.cookie.split(/;\s*/) || [];
  2392. for (n = cookies.length; n--; ) {
  2393. tmp = cookies[n].split('=');
  2394. if (tmp[0]) cache[decode(tmp.shift())] = decode(tmp.join('=')); // there might be '='s in the value...
  2395. }
  2396.  
  2397. if (!key) return cache; // return Json for easy access to all cookies
  2398. else return cache[key]; // easy access to cookies from here
  2399. } else { // write/delete cookie
  2400. options = options || {};
  2401.  
  2402. if (val === '' || options.expires < 0) { // prepare deleteing the cookie
  2403. options.expires = -1;
  2404. // options.path = options.domain = options.secure = undefined; // to make shure the cookie gets deleted...
  2405. }
  2406.  
  2407. if (options.expires !== undefined) { // prepare date if any
  2408. days = new Date();
  2409. days.setDate(days.getDate() + options.expires);
  2410. }
  2411.  
  2412. document.cookie = encode(key) + '=' + encode(val) +
  2413. (days ? '; expires=' + days.toUTCString() : '') +
  2414. (options.path ? '; path=' + options.path : '') +
  2415. (options.domain ? '; domain=' + options.domain : '') +
  2416. (options.secure ? '; secure' : '');
  2417. }
  2418. };
  2419. })(this);