Spectrum

The No Hassle jQuery Colorpicker

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/433654/977772/Spectrum.js

  1. /**
  2. * @version: 2.0.8
  3. * @author: seballot (https://seballot.github.io/spectrum/)
  4. * @date: 2019-03-27
  5. * @copyright: Copyright (c) , seballot (https://seballot.github.io/spectrum/). All rights reserved.
  6. * @license: https://github.com/seballot/spectrum/blob/master/LICENSE
  7. * @website: https://seballot.github.io/spectrum/
  8. */
  9.  
  10. (function (factory) {
  11. "use strict";
  12.  
  13. if (typeof define === 'function' && define.amd) { // AMD
  14. define(['jquery'], factory);
  15. }
  16. else if (typeof exports == "object" && typeof module == "object") { // CommonJS
  17. module.exports = factory(require('jquery'));
  18. }
  19. else { // Browser
  20. factory(jQuery);
  21. }
  22. })(function($, undefined) {
  23. "use strict";
  24.  
  25. var defaultOpts = {
  26.  
  27. // Callbacks
  28. beforeShow: noop,
  29. move: noop,
  30. change: noop,
  31. show: noop,
  32. hide: noop,
  33.  
  34. // Options
  35. color: false,
  36. flat: false, // Deprecated - use type instead
  37. type: '', // text, color, component or flat
  38. showInput: false,
  39. allowEmpty: true,
  40. showButtons: true,
  41. clickoutFiresChange: true,
  42. showInitial: false,
  43. showPalette: true,
  44. showPaletteOnly: false,
  45. hideAfterPaletteSelect: false,
  46. togglePaletteOnly: false,
  47. showSelectionPalette: true,
  48. localStorageKey: false,
  49. appendTo: "body",
  50. maxSelectionSize: 8,
  51. locale: "en",
  52. cancelText: "cancel",
  53. chooseText: "choose",
  54. togglePaletteMoreText: "more",
  55. togglePaletteLessText: "less",
  56. clearText: "Clear Color Selection",
  57. noColorSelectedText: "No Color Selected",
  58. preferredFormat: "name",
  59. className: "", // Deprecated - use containerClassName and replacerClassName instead.
  60. containerClassName: "",
  61. replacerClassName: "",
  62. showAlpha: true,
  63. theme: "sp-light",
  64. palette: [
  65. ["#000000","#444444","#5b5b5b","#999999","#bcbcbc","#eeeeee","#f3f6f4","#ffffff"],
  66. ["#f44336","#744700","#ce7e00","#8fce00","#2986cc","#16537e","#6a329f","#c90076"],
  67. ["#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#cfe2f3","#d9d2e9","#ead1dc"],
  68. ["#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#9fc5e8","#b4a7d6","#d5a6bd"],
  69. ["#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6fa8dc","#8e7cc3","#c27ba0"],
  70. ["#cc0000","#e69138","#f1c232","#6aa84f","#45818e","#3d85c6","#674ea7","#a64d79"],
  71. ["#990000","#b45f06","#bf9000","#38761d","#134f5c","#0b5394","#351c75","#741b47"],
  72. ["#660000","#783f04","#7f6000","#274e13","#0c343d","#073763","#20124d","#4c1130"]
  73. ],
  74. selectionPalette: [],
  75. disabled: false,
  76. offset: null
  77. },
  78. spectrums = [],
  79. IE = !!/msie/i.exec( window.navigator.userAgent ),
  80. rgbaSupport = (function() {
  81. function contains( str, substr ) {
  82. return !!~('' + str).indexOf(substr);
  83. }
  84.  
  85. var elem = document.createElement('div');
  86. var style = elem.style;
  87. style.cssText = 'background-color:rgba(0,0,0,.5)';
  88. return contains(style.backgroundColor, 'rgba') || contains(style.backgroundColor, 'hsla');
  89. })(),
  90. replaceInput = [
  91. "<div class='sp-replacer'>",
  92. "<div class='sp-preview'><div class='sp-preview-inner'></div></div>",
  93. "<div class='sp-dd'>&#9660;</div>",
  94. "</div>"
  95. ].join(''),
  96. markup = (function () {
  97.  
  98. // IE does not support gradients with multiple stops, so we need to simulate
  99. // that for the rainbow slider with 8 divs that each have a single gradient
  100. var gradientFix = "";
  101. if (IE) {
  102. for (var i = 1; i <= 6; i++) {
  103. gradientFix += "<div class='sp-" + i + "'></div>";
  104. }
  105. }
  106.  
  107. return [
  108. "<div class='sp-container sp-hidden'>",
  109. "<div class='sp-palette-container'>",
  110. "<div class='sp-palette sp-thumb sp-cf'></div>",
  111. "<div class='sp-palette-button-container sp-cf'>",
  112. "<button type='button' class='sp-palette-toggle'></button>",
  113. "</div>",
  114. "</div>",
  115. "<div class='sp-picker-container'>",
  116. "<div class='sp-top sp-cf'>",
  117. "<div class='sp-fill'></div>",
  118. "<div class='sp-top-inner'>",
  119. "<div class='sp-color'>",
  120. "<div class='sp-sat'>",
  121. "<div class='sp-val'>",
  122. "<div class='sp-dragger'></div>",
  123. "</div>",
  124. "</div>",
  125. "</div>",
  126. "<div class='sp-clear sp-clear-display'>",
  127. "</div>",
  128. "<div class='sp-hue'>",
  129. "<div class='sp-slider'></div>",
  130. gradientFix,
  131. "</div>",
  132. "</div>",
  133. "<div class='sp-alpha'><div class='sp-alpha-inner'><div class='sp-alpha-handle'></div></div></div>",
  134. "</div>",
  135. "<div class='sp-input-container sp-cf'>",
  136. "<input class='sp-input' type='text' spellcheck='false' />",
  137. "</div>",
  138. "<div class='sp-initial sp-thumb sp-cf'></div>",
  139. "<div class='sp-button-container sp-cf'>",
  140. "<button class='sp-cancel' href='#'></button>",
  141. "<button type='button' class='sp-choose'></button>",
  142. "</div>",
  143. "</div>",
  144. "</div>"
  145. ].join("");
  146. })();
  147.  
  148. function paletteTemplate (p, color, className, opts) {
  149. var html = [];
  150. for (var i = 0; i < p.length; i++) {
  151. var current = p[i];
  152. if(current) {
  153. var tiny = tinycolor(current);
  154. var c = tiny.toHsl().l < 0.5 ? "sp-thumb-el sp-thumb-dark" : "sp-thumb-el sp-thumb-light";
  155. c += (tinycolor.equals(color, current)) ? " sp-thumb-active" : "";
  156. var formattedString = tiny.toString(opts.preferredFormat || "rgb");
  157. var swatchStyle = rgbaSupport ? ("background-color:" + tiny.toRgbString()) : "filter:" + tiny.toFilter();
  158. html.push('<span title="' + formattedString + '" data-color="' + tiny.toRgbString() + '" class="' + c + '"><span class="sp-thumb-inner" style="' + swatchStyle + ';"></span></span>');
  159. } else {
  160. html.push('<span class="sp-thumb-el sp-clear-display" ><span class="sp-clear-palette-only" style="background-color: transparent;"></span></span>');
  161. }
  162. }
  163. return "<div class='sp-cf " + className + "'>" + html.join('') + "</div>";
  164. }
  165.  
  166. function hideAll() {
  167. for (var i = 0; i < spectrums.length; i++) {
  168. if (spectrums[i]) {
  169. spectrums[i].hide();
  170. }
  171. }
  172. }
  173.  
  174. function instanceOptions(o, callbackContext) {
  175. o.locale = o.locale || window.navigator.language;
  176. if (o.locale) o.locale = o.locale.split('-')[0].toLowerCase(); // handle locale like "fr-FR"
  177. if (o.locale != 'en' && $.spectrum.localization[o.locale]) {
  178. o = $.extend({}, $.spectrum.localization[o.locale], o);
  179. }
  180. var opts = $.extend({}, defaultOpts, o);
  181.  
  182. opts.callbacks = {
  183. 'move': bind(opts.move, callbackContext),
  184. 'change': bind(opts.change, callbackContext),
  185. 'show': bind(opts.show, callbackContext),
  186. 'hide': bind(opts.hide, callbackContext),
  187. 'beforeShow': bind(opts.beforeShow, callbackContext)
  188. };
  189.  
  190. return opts;
  191. }
  192.  
  193. function spectrum(element, o) {
  194.  
  195. var opts = instanceOptions(o, element),
  196. type = opts.type,
  197. flat = (type == 'flat'),
  198. showSelectionPalette = opts.showSelectionPalette,
  199. localStorageKey = opts.localStorageKey,
  200. theme = opts.theme,
  201. callbacks = opts.callbacks,
  202. resize = throttle(reflow, 10),
  203. visible = false,
  204. isDragging = false,
  205. dragWidth = 0,
  206. dragHeight = 0,
  207. dragHelperHeight = 0,
  208. slideHeight = 0,
  209. slideWidth = 0,
  210. alphaWidth = 0,
  211. alphaSlideHelperWidth = 0,
  212. slideHelperHeight = 0,
  213. currentHue = 0,
  214. currentSaturation = 0,
  215. currentValue = 0,
  216. currentAlpha = 1,
  217. palette = [],
  218. paletteArray = [],
  219. paletteLookup = {},
  220. selectionPalette = opts.selectionPalette.slice(0),
  221. maxSelectionSize = opts.maxSelectionSize,
  222. draggingClass = "sp-dragging",
  223. abortNextInputChange = false,
  224. shiftMovementDirection = null;
  225.  
  226. var doc = element.ownerDocument,
  227. body = doc.body,
  228. boundElement = $(element),
  229. disabled = false,
  230. container = $(markup, doc).addClass(theme),
  231. pickerContainer = container.find(".sp-picker-container"),
  232. dragger = container.find(".sp-color"),
  233. dragHelper = container.find(".sp-dragger"),
  234. slider = container.find(".sp-hue"),
  235. slideHelper = container.find(".sp-slider"),
  236. alphaSliderInner = container.find(".sp-alpha-inner"),
  237. alphaSlider = container.find(".sp-alpha"),
  238. alphaSlideHelper = container.find(".sp-alpha-handle"),
  239. textInput = container.find(".sp-input"),
  240. paletteContainer = container.find(".sp-palette"),
  241. initialColorContainer = container.find(".sp-initial"),
  242. cancelButton = container.find(".sp-cancel"),
  243. clearButton = container.find(".sp-clear"),
  244. chooseButton = container.find(".sp-choose"),
  245. toggleButton = container.find(".sp-palette-toggle"),
  246. isInput = boundElement.is("input"),
  247. isInputTypeColor = isInput && boundElement.attr("type") === "color" && inputTypeColorSupport(),
  248. shouldReplace = isInput && type == 'color',
  249. replacer = (shouldReplace) ? $(replaceInput).addClass(theme).addClass(opts.className).addClass(opts.replacerClassName) : $([]),
  250. offsetElement = (shouldReplace) ? replacer : boundElement,
  251. previewElement = replacer.find(".sp-preview-inner"),
  252. initialColor = opts.color || (isInput && boundElement.val()),
  253. colorOnShow = false,
  254. currentPreferredFormat = opts.preferredFormat,
  255. clickoutFiresChange = !opts.showButtons || opts.clickoutFiresChange,
  256. isEmpty = !initialColor,
  257. allowEmpty = opts.allowEmpty;
  258.  
  259. // Element to be updated with the input color. Populated in initialize method
  260. var originalInputContainer = null,
  261. colorizeElement = null,
  262. colorizeElementInitialColor = null,
  263. colorizeElementInitialBackground = null;
  264.  
  265. //If there is a label for this element, when clicked on, show the colour picker
  266. var thisId = boundElement.attr('id');
  267. if(thisId !== undefined && thisId.length > 0) {
  268. var label = $('label[for="'+thisId+'"]');
  269. if(label.length) {
  270. label.on('click', function(e){
  271. e.preventDefault();
  272. boundElement.spectrum('show');
  273. return false;
  274. });
  275. }
  276. }
  277. function applyOptions() {
  278.  
  279. if (opts.showPaletteOnly) {
  280. opts.showPalette = true;
  281. }
  282.  
  283. toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
  284.  
  285. if (opts.palette) {
  286. palette = opts.palette.slice(0);
  287. paletteArray = $.isArray(palette[0]) ? palette : [palette];
  288. paletteLookup = {};
  289. for (var i = 0; i < paletteArray.length; i++) {
  290. for (var j = 0; j < paletteArray[i].length; j++) {
  291. var rgb = tinycolor(paletteArray[i][j]).toRgbString();
  292. paletteLookup[rgb] = true;
  293. }
  294. }
  295.  
  296. // if showPaletteOnly and didn't set initialcolor
  297. // set initialcolor to first palette
  298. if (opts.showPaletteOnly && !initialColor) {
  299. initialColor = (palette[0][0] === '') ? palette[0][0] : Object.keys(paletteLookup)[0];
  300. }
  301. }
  302.  
  303. container.toggleClass("sp-flat", flat);
  304. container.toggleClass("sp-input-disabled", !opts.showInput);
  305. container.toggleClass("sp-alpha-enabled", opts.showAlpha);
  306. container.toggleClass("sp-clear-enabled", allowEmpty);
  307. container.toggleClass("sp-buttons-disabled", !opts.showButtons);
  308. container.toggleClass("sp-palette-buttons-disabled", !opts.togglePaletteOnly);
  309. container.toggleClass("sp-palette-disabled", !opts.showPalette);
  310. container.toggleClass("sp-palette-only", opts.showPaletteOnly);
  311. container.toggleClass("sp-initial-disabled", !opts.showInitial);
  312. container.addClass(opts.className).addClass(opts.containerClassName);
  313.  
  314. reflow();
  315. }
  316.  
  317. function initialize() {
  318.  
  319. if (IE) {
  320. container.find("*:not(input)").attr("unselectable", "on");
  321. }
  322.  
  323. applyOptions();
  324.  
  325. originalInputContainer = $('<span class="sp-original-input-container"></span>');
  326. ['margin'].forEach(function(cssProp) {
  327. originalInputContainer.css(cssProp, boundElement.css(cssProp));
  328. });
  329. // inline-flex by default, switching to flex if needed
  330. if (boundElement.css('display') == 'block') originalInputContainer.css('display', 'flex');
  331.  
  332. if (shouldReplace) {
  333. boundElement.after(replacer).hide();
  334. } else if (type == 'text') {
  335. originalInputContainer.addClass('sp-colorize-container');
  336. boundElement.addClass('spectrum sp-colorize').wrap(originalInputContainer);
  337. } else if (type == 'component') {
  338. boundElement.addClass('spectrum').wrap(originalInputContainer);
  339. var addOn = $(["<div class='sp-colorize-container sp-add-on'>",
  340. "<div class='sp-colorize'></div> ",
  341. "</div>"].join(''));
  342. addOn.width(boundElement.outerHeight() + 'px')
  343. .css('border-radius', boundElement.css('border-radius'))
  344. .css('border', boundElement.css('border'));
  345. boundElement.addClass('with-add-on').before(addOn);
  346. }
  347.  
  348. colorizeElement = boundElement.parent().find('.sp-colorize');
  349. colorizeElementInitialColor = colorizeElement.css('color');
  350. colorizeElementInitialBackground = colorizeElement.css('background-color');
  351.  
  352. if (!allowEmpty) {
  353. clearButton.hide();
  354. }
  355.  
  356. if (flat) {
  357. boundElement.after(container).hide();
  358. }
  359. else {
  360.  
  361. var appendTo = opts.appendTo === "parent" ? boundElement.parent() : $(opts.appendTo);
  362. if (appendTo.length !== 1) {
  363. appendTo = $("body");
  364. }
  365.  
  366. appendTo.append(container);
  367. }
  368.  
  369. updateSelectionPaletteFromStorage();
  370.  
  371. offsetElement.on("click.spectrum touchstart.spectrum", function (e) {
  372. if (!disabled) {
  373. show();
  374. }
  375.  
  376. e.stopPropagation();
  377.  
  378. if (!$(e.target).is("input")) {
  379. e.preventDefault();
  380. }
  381. });
  382.  
  383. if(boundElement.is(":disabled") || (opts.disabled === true)) {
  384. disable();
  385. }
  386.  
  387. // Prevent clicks from bubbling up to document. This would cause it to be hidden.
  388. container.click(stopPropagation);
  389.  
  390. // Handle user typed input
  391. [textInput, boundElement].forEach(function(input) {
  392. input.change(function() { setFromTextInput(input.val()); });
  393. input.on("paste", function () {
  394. setTimeout(function() { setFromTextInput(input.val()); }, 1);
  395. });
  396. input.keydown(function (e) { if (e.keyCode == 13) {
  397. setFromTextInput($(input).val());
  398. if (input == boundElement) hide();
  399. } });
  400. });
  401.  
  402. cancelButton.text(opts.cancelText);
  403. cancelButton.on("click.spectrum", function (e) {
  404. e.stopPropagation();
  405. e.preventDefault();
  406. revert();
  407. hide();
  408. });
  409.  
  410. clearButton.attr("title", opts.clearText);
  411. clearButton.on("click.spectrum", function (e) {
  412. e.stopPropagation();
  413. e.preventDefault();
  414. isEmpty = true;
  415. move();
  416.  
  417. if(flat) {
  418. //for the flat style, this is a change event
  419. updateOriginalInput(true);
  420. }
  421. });
  422.  
  423. chooseButton.text(opts.chooseText);
  424. chooseButton.on("click.spectrum", function (e) {
  425. e.stopPropagation();
  426. e.preventDefault();
  427.  
  428. if (IE && textInput.is(":focus")) {
  429. textInput.trigger('change');
  430. }
  431.  
  432. if (isValid()) {
  433. updateOriginalInput(true);
  434. hide();
  435. }
  436. });
  437.  
  438. toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
  439. toggleButton.on("click.spectrum", function (e) {
  440. e.stopPropagation();
  441. e.preventDefault();
  442.  
  443. opts.showPaletteOnly = !opts.showPaletteOnly;
  444.  
  445. // To make sure the Picker area is drawn on the right, next to the
  446. // Palette area (and not below the palette), first move the Palette
  447. // to the left to make space for the picker, plus 5px extra.
  448. // The 'applyOptions' function puts the whole container back into place
  449. // and takes care of the button-text and the sp-palette-only CSS class.
  450. if (!opts.showPaletteOnly && !flat) {
  451. container.css('left', '-=' + (pickerContainer.outerWidth(true) + 5));
  452. }
  453. applyOptions();
  454. });
  455.  
  456. draggable(alphaSlider, function (dragX, dragY, e) {
  457. currentAlpha = (dragX / alphaWidth);
  458. isEmpty = false;
  459. if (e.shiftKey) {
  460. currentAlpha = Math.round(currentAlpha * 10) / 10;
  461. }
  462.  
  463. move();
  464. }, dragStart, dragStop);
  465.  
  466. draggable(slider, function (dragX, dragY) {
  467. currentHue = parseFloat(dragY / slideHeight);
  468. isEmpty = false;
  469. if (!opts.showAlpha) {
  470. currentAlpha = 1;
  471. }
  472. move();
  473. }, dragStart, dragStop);
  474.  
  475. draggable(dragger, function (dragX, dragY, e) {
  476.  
  477. // shift+drag should snap the movement to either the x or y axis.
  478. if (!e.shiftKey) {
  479. shiftMovementDirection = null;
  480. }
  481. else if (!shiftMovementDirection) {
  482. var oldDragX = currentSaturation * dragWidth;
  483. var oldDragY = dragHeight - (currentValue * dragHeight);
  484. var furtherFromX = Math.abs(dragX - oldDragX) > Math.abs(dragY - oldDragY);
  485.  
  486. shiftMovementDirection = furtherFromX ? "x" : "y";
  487. }
  488.  
  489. var setSaturation = !shiftMovementDirection || shiftMovementDirection === "x";
  490. var setValue = !shiftMovementDirection || shiftMovementDirection === "y";
  491.  
  492. if (setSaturation) {
  493. currentSaturation = parseFloat(dragX / dragWidth);
  494. }
  495. if (setValue) {
  496. currentValue = parseFloat((dragHeight - dragY) / dragHeight);
  497. }
  498.  
  499. isEmpty = false;
  500. if (!opts.showAlpha) {
  501. currentAlpha = 1;
  502. }
  503.  
  504. move();
  505.  
  506. }, dragStart, dragStop);
  507.  
  508. if (!!initialColor) {
  509. set(initialColor);
  510.  
  511. // In case color was black - update the preview UI and set the format
  512. // since the set function will not run (default color is black).
  513. updateUI();
  514. currentPreferredFormat = tinycolor(initialColor).format || opts.preferredFormat;
  515. addColorToSelectionPalette(initialColor);
  516. } else if (initialColor === '') {
  517. set(initialColor);
  518. updateUI();
  519. } else {
  520. updateUI();
  521. }
  522.  
  523. if (flat) {
  524. show();
  525. }
  526.  
  527. function paletteElementClick(e) {
  528. if (e.data && e.data.ignore) {
  529. set($(e.target).closest(".sp-thumb-el").data("color"));
  530. move();
  531. }
  532. else {
  533. set($(e.target).closest(".sp-thumb-el").data("color"));
  534. move();
  535.  
  536. // If the picker is going to close immediately, a palette selection
  537. // is a change. Otherwise, it's a move only.
  538. if (opts.hideAfterPaletteSelect) {
  539. updateOriginalInput(true);
  540. hide();
  541. } else {
  542. updateOriginalInput();
  543. }
  544. }
  545.  
  546. return false;
  547. }
  548.  
  549. var paletteEvent = IE ? "mousedown.spectrum" : "click.spectrum touchstart.spectrum";
  550. paletteContainer.on(paletteEvent, ".sp-thumb-el", paletteElementClick);
  551. initialColorContainer.on(paletteEvent, ".sp-thumb-el:nth-child(1)", { ignore: true }, paletteElementClick);
  552. }
  553.  
  554. function updateSelectionPaletteFromStorage() {
  555.  
  556. if (localStorageKey) {
  557. // Migrate old palettes over to new format. May want to remove this eventually.
  558. try {
  559. var localStorage = window.localStorage;
  560. var oldPalette = localStorage[localStorageKey].split(",#");
  561. if (oldPalette.length > 1) {
  562. delete localStorage[localStorageKey];
  563. $.each(oldPalette, function(i, c) {
  564. addColorToSelectionPalette(c);
  565. });
  566. }
  567. }
  568. catch(e) { }
  569.  
  570. try {
  571. selectionPalette = window.localStorage[localStorageKey].split(";");
  572. }
  573. catch (e) { }
  574. }
  575. }
  576.  
  577. function addColorToSelectionPalette(color) {
  578. if (showSelectionPalette) {
  579. var rgb = tinycolor(color).toRgbString();
  580. if (!paletteLookup[rgb] && $.inArray(rgb, selectionPalette) === -1) {
  581. selectionPalette.push(rgb);
  582. while(selectionPalette.length > maxSelectionSize) {
  583. selectionPalette.shift();
  584. }
  585. }
  586.  
  587. if (localStorageKey) {
  588. try {
  589. window.localStorage[localStorageKey] = selectionPalette.join(";");
  590. }
  591. catch(e) { }
  592. }
  593. }
  594. }
  595.  
  596. function getUniqueSelectionPalette() {
  597. var unique = [];
  598. if (opts.showPalette) {
  599. for (var i = 0; i < selectionPalette.length; i++) {
  600. var rgb = tinycolor(selectionPalette[i]).toRgbString();
  601.  
  602. if (!paletteLookup[rgb]) {
  603. unique.push(selectionPalette[i]);
  604. }
  605. }
  606. }
  607.  
  608. return unique.reverse().slice(0, opts.maxSelectionSize);
  609. }
  610.  
  611. function drawPalette() {
  612.  
  613. var currentColor = get();
  614.  
  615. var html = $.map(paletteArray, function (palette, i) {
  616. return paletteTemplate(palette, currentColor, "sp-palette-row sp-palette-row-" + i, opts);
  617. });
  618.  
  619. updateSelectionPaletteFromStorage();
  620.  
  621. if (selectionPalette) {
  622. html.push(paletteTemplate(getUniqueSelectionPalette(), currentColor, "sp-palette-row sp-palette-row-selection", opts));
  623. }
  624.  
  625. paletteContainer.html(html.join(""));
  626. }
  627.  
  628. function drawInitial() {
  629. if (opts.showInitial) {
  630. var initial = colorOnShow;
  631. var current = get();
  632. initialColorContainer.html(paletteTemplate([initial, current], current, "sp-palette-row-initial", opts));
  633. }
  634. }
  635.  
  636. function dragStart() {
  637. if (dragHeight <= 0 || dragWidth <= 0 || slideHeight <= 0) {
  638. reflow();
  639. }
  640. isDragging = true;
  641. container.addClass(draggingClass);
  642. shiftMovementDirection = null;
  643. boundElement.trigger('dragstart.spectrum', [ get() ]);
  644. }
  645.  
  646. function dragStop() {
  647. isDragging = false;
  648. container.removeClass(draggingClass);
  649. boundElement.trigger('dragstop.spectrum', [ get() ]);
  650. }
  651.  
  652. function setFromTextInput(value) {
  653. if (abortNextInputChange) { abortNextInputChange = false; return; }
  654. if ((value === null || value === "") && allowEmpty) {
  655. set(null);
  656. move();
  657. updateOriginalInput();
  658. }
  659. else {
  660. var tiny = tinycolor(value);
  661. if (tiny.isValid()) {
  662. set(tiny);
  663. move();
  664. updateOriginalInput();
  665. }
  666. else {
  667. textInput.addClass("sp-validation-error");
  668. }
  669. }
  670. }
  671.  
  672. function toggle() {
  673. if (visible) {
  674. hide();
  675. }
  676. else {
  677. show();
  678. }
  679. }
  680.  
  681. function show() {
  682. // debugger;
  683. var event = $.Event('beforeShow.spectrum');
  684.  
  685. if (visible) {
  686. reflow();
  687. return;
  688. }
  689.  
  690. boundElement.trigger(event, [ get() ]);
  691.  
  692. if (callbacks.beforeShow(get()) === false || event.isDefaultPrevented()) {
  693. return;
  694. }
  695.  
  696. hideAll();
  697. visible = true;
  698.  
  699. $(doc).on("keydown.spectrum", onkeydown);
  700. $(doc).on("click.spectrum", clickout);
  701. $(window).on("resize.spectrum", resize);
  702. replacer.addClass("sp-active");
  703. container.removeClass("sp-hidden");
  704.  
  705. reflow();
  706. updateUI();
  707.  
  708. colorOnShow = get();
  709.  
  710. drawInitial();
  711. callbacks.show(colorOnShow);
  712. boundElement.trigger('show.spectrum', [ colorOnShow ]);
  713. }
  714.  
  715. function onkeydown(e) {
  716. // Close on ESC
  717. if (e.keyCode === 27) {
  718. hide();
  719. }
  720. }
  721.  
  722. function clickout(e) {
  723. // Return on right click.
  724. if (e.button == 2) { return; }
  725.  
  726. // If a drag event was happening during the mouseup, don't hide
  727. // on click.
  728. if (isDragging) { return; }
  729.  
  730. if (clickoutFiresChange) {
  731. updateOriginalInput(true);
  732. }
  733. else {
  734. revert();
  735. }
  736. hide();
  737. }
  738.  
  739. function hide() {
  740. // Return if hiding is unnecessary
  741. if (!visible || flat) { return; }
  742. visible = false;
  743.  
  744. $(doc).off("keydown.spectrum", onkeydown);
  745. $(doc).off("click.spectrum", clickout);
  746. $(window).off("resize.spectrum", resize);
  747.  
  748. replacer.removeClass("sp-active");
  749. container.addClass("sp-hidden");
  750.  
  751. callbacks.hide(get());
  752. boundElement.trigger('hide.spectrum', [ get() ]);
  753. }
  754.  
  755. function revert() {
  756. set(colorOnShow, true);
  757. updateOriginalInput(true);
  758. }
  759.  
  760. function set(color, ignoreFormatChange) {
  761. if (tinycolor.equals(color, get())) {
  762. // Update UI just in case a validation error needs
  763. // to be cleared.
  764. updateUI();
  765. return;
  766. }
  767.  
  768. var newColor, newHsv;
  769. if ((!color || color === undefined) && allowEmpty) {
  770. isEmpty = true;
  771. } else {
  772. isEmpty = false;
  773. newColor = tinycolor(color);
  774. newHsv = newColor.toHsv();
  775.  
  776. currentHue = (newHsv.h % 360) / 360;
  777. currentSaturation = newHsv.s;
  778. currentValue = newHsv.v;
  779. currentAlpha = newHsv.a;
  780. }
  781. updateUI();
  782.  
  783. if (newColor && newColor.isValid() && !ignoreFormatChange) {
  784. currentPreferredFormat = opts.preferredFormat || newColor.getFormat();
  785. }
  786. }
  787.  
  788. function get(opts) {
  789. opts = opts || { };
  790.  
  791. if (allowEmpty && isEmpty) {
  792. return null;
  793. }
  794.  
  795. return tinycolor.fromRatio({
  796. h: currentHue,
  797. s: currentSaturation,
  798. v: currentValue,
  799. a: Math.round(currentAlpha * 1000) / 1000
  800. }, { format: opts.format || currentPreferredFormat });
  801. }
  802.  
  803. function isValid() {
  804. return !textInput.hasClass("sp-validation-error");
  805. }
  806.  
  807. function move() {
  808. updateUI();
  809.  
  810. callbacks.move(get());
  811. boundElement.trigger('move.spectrum', [ get() ]);
  812. }
  813.  
  814. function updateUI() {
  815.  
  816. textInput.removeClass("sp-validation-error");
  817.  
  818. updateHelperLocations();
  819.  
  820. // Update dragger background color (gradients take care of saturation and value).
  821. var flatColor = tinycolor.fromRatio({ h: currentHue, s: 1, v: 1 });
  822. dragger.css("background-color", flatColor.toHexString());
  823.  
  824. // Get a format that alpha will be included in (hex and names ignore alpha)
  825. var format = currentPreferredFormat;
  826. if (currentAlpha < 1 && !(currentAlpha === 0 && format === "name")) {
  827. if (format === "hex" || format === "hex3" || format === "hex6" || format === "name") {
  828. format = "rgb";
  829. }
  830. }
  831.  
  832. var realColor = get({ format: format }),
  833. displayColor = '';
  834.  
  835. //reset background info for preview element
  836. previewElement.removeClass("sp-clear-display");
  837. previewElement.css('background-color', 'transparent');
  838.  
  839. if (!realColor && allowEmpty) {
  840. // Update the replaced elements background with icon indicating no color selection
  841. previewElement.addClass("sp-clear-display");
  842. }
  843. else {
  844. var realHex = realColor.toHexString(),
  845. realRgb = realColor.toRgbString();
  846.  
  847. // Update the replaced elements background color (with actual selected color)
  848. if (rgbaSupport || realColor.alpha === 1) {
  849. previewElement.css("background-color", realRgb);
  850. }
  851. else {
  852. previewElement.css("background-color", "transparent");
  853. previewElement.css("filter", realColor.toFilter());
  854. }
  855.  
  856. if (opts.showAlpha) {
  857. var rgb = realColor.toRgb();
  858. rgb.a = 0;
  859. var realAlpha = tinycolor(rgb).toRgbString();
  860. var gradient = "linear-gradient(left, " + realAlpha + ", " + realHex + ")";
  861.  
  862. if (IE) {
  863. alphaSliderInner.css("filter", tinycolor(realAlpha).toFilter({ gradientType: 1 }, realHex));
  864. }
  865. else {
  866. alphaSliderInner.css("background", "-webkit-" + gradient);
  867. alphaSliderInner.css("background", "-moz-" + gradient);
  868. alphaSliderInner.css("background", "-ms-" + gradient);
  869. // Use current syntax gradient on unprefixed property.
  870. alphaSliderInner.css("background",
  871. "linear-gradient(to right, " + realAlpha + ", " + realHex + ")");
  872. }
  873. }
  874.  
  875. displayColor = realColor.toString(format);
  876. }
  877.  
  878. // Update the text entry input as it changes happen
  879. if (opts.showInput) {
  880. textInput.val(displayColor);
  881. }
  882. boundElement.val(displayColor);
  883. if (opts.type == "text" || opts.type == "component") {
  884. var color = realColor;
  885. if (color && colorizeElement) {
  886. var textColor = (color.isLight() || color.getAlpha() < 0.4) ? 'black' : 'white';
  887. colorizeElement.css('background-color', color.toRgbString()).css('color', textColor);
  888. } else {
  889. colorizeElement.css('background-color', colorizeElementInitialBackground)
  890. .css('color', colorizeElementInitialColor);
  891. }
  892. }
  893.  
  894. if (opts.showPalette) {
  895. drawPalette();
  896. }
  897.  
  898. drawInitial();
  899. }
  900.  
  901. function updateHelperLocations() {
  902. var s = currentSaturation;
  903. var v = currentValue;
  904.  
  905. if(allowEmpty && isEmpty) {
  906. //if selected color is empty, hide the helpers
  907. alphaSlideHelper.hide();
  908. slideHelper.hide();
  909. dragHelper.hide();
  910. }
  911. else {
  912. //make sure helpers are visible
  913. alphaSlideHelper.show();
  914. slideHelper.show();
  915. dragHelper.show();
  916.  
  917. // Where to show the little circle in that displays your current selected color
  918. var dragX = s * dragWidth;
  919. var dragY = dragHeight - (v * dragHeight);
  920. dragX = Math.max(
  921. -dragHelperHeight,
  922. Math.min(dragWidth - dragHelperHeight, dragX - dragHelperHeight)
  923. );
  924. dragY = Math.max(
  925. -dragHelperHeight,
  926. Math.min(dragHeight - dragHelperHeight, dragY - dragHelperHeight)
  927. );
  928. dragHelper.css({
  929. "top": dragY + "px",
  930. "left": dragX + "px"
  931. });
  932.  
  933. var alphaX = currentAlpha * alphaWidth;
  934. alphaSlideHelper.css({
  935. "left": (alphaX - (alphaSlideHelperWidth / 2)) + "px"
  936. });
  937.  
  938. // Where to show the bar that displays your current selected hue
  939. var slideY = (currentHue) * slideHeight;
  940. slideHelper.css({
  941. "top": (slideY - slideHelperHeight) + "px"
  942. });
  943. }
  944. }
  945.  
  946. function updateOriginalInput(fireCallback) {
  947. var color = get(),
  948. displayColor = '',
  949. hasChanged = !tinycolor.equals(color, colorOnShow);
  950.  
  951. if (color) {
  952. displayColor = color.toString(currentPreferredFormat);
  953. // Update the selection palette with the current color
  954. addColorToSelectionPalette(color);
  955. }
  956.  
  957. if (fireCallback && hasChanged) {
  958. callbacks.change(color);
  959. // we trigger the change event or input, but the input change event is also binded
  960. // to some spectrum processing, that we do no need
  961. abortNextInputChange = true;
  962. boundElement.trigger('change', [ color ]);
  963. }
  964. }
  965.  
  966. function reflow() {
  967. if (!visible) {
  968. return; // Calculations would be useless and wouldn't be reliable anyways
  969. }
  970. dragWidth = dragger.width();
  971. dragHeight = dragger.height();
  972. dragHelperHeight = dragHelper.height();
  973. slideWidth = slider.width();
  974. slideHeight = slider.height();
  975. slideHelperHeight = slideHelper.height();
  976. alphaWidth = alphaSlider.width();
  977. alphaSlideHelperWidth = alphaSlideHelper.width();
  978.  
  979. if (!flat) {
  980. container.css("position", "absolute");
  981. if (opts.offset) {
  982. container.offset(opts.offset);
  983. } else {
  984. container.offset(getOffset(container, offsetElement));
  985. }
  986. }
  987.  
  988. updateHelperLocations();
  989.  
  990. if (opts.showPalette) {
  991. drawPalette();
  992. }
  993.  
  994. boundElement.trigger('reflow.spectrum');
  995. }
  996.  
  997. function destroy() {
  998. boundElement.show().removeClass('spectrum with-add-on sp-colorize');
  999. offsetElement.off("click.spectrum touchstart.spectrum");
  1000. container.remove();
  1001. replacer.remove();
  1002. if (colorizeElement) {
  1003. colorizeElement.css('background-color', colorizeElementInitialBackground)
  1004. .css('color', colorizeElementInitialColor);
  1005. }
  1006. var originalInputContainer = boundElement.closest('.sp-original-input-container');
  1007. if (originalInputContainer.length > 0) {
  1008. originalInputContainer.after(boundElement).remove();
  1009. }
  1010. spectrums[spect.id] = null;
  1011. }
  1012.  
  1013. function option(optionName, optionValue) {
  1014. if (optionName === undefined) {
  1015. return $.extend({}, opts);
  1016. }
  1017. if (optionValue === undefined) {
  1018. return opts[optionName];
  1019. }
  1020.  
  1021. opts[optionName] = optionValue;
  1022.  
  1023. if (optionName === "preferredFormat") {
  1024. currentPreferredFormat = opts.preferredFormat;
  1025. }
  1026. applyOptions();
  1027. }
  1028.  
  1029. function enable() {
  1030. disabled = false;
  1031. boundElement.attr("disabled", false);
  1032. offsetElement.removeClass("sp-disabled");
  1033. }
  1034.  
  1035. function disable() {
  1036. hide();
  1037. disabled = true;
  1038. boundElement.attr("disabled", true);
  1039. offsetElement.addClass("sp-disabled");
  1040. }
  1041.  
  1042. function setOffset(coord) {
  1043. opts.offset = coord;
  1044. reflow();
  1045. }
  1046.  
  1047. initialize();
  1048.  
  1049. var spect = {
  1050. show: show,
  1051. hide: hide,
  1052. toggle: toggle,
  1053. reflow: reflow,
  1054. option: option,
  1055. enable: enable,
  1056. disable: disable,
  1057. offset: setOffset,
  1058. set: function (c) {
  1059. set(c);
  1060. updateOriginalInput();
  1061. },
  1062. get: get,
  1063. destroy: destroy,
  1064. container: container
  1065. };
  1066.  
  1067. spect.id = spectrums.push(spect) - 1;
  1068.  
  1069. return spect;
  1070. }
  1071.  
  1072. /**
  1073. * checkOffset - get the offset below/above and left/right element depending on screen position
  1074. * Thanks https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js
  1075. */
  1076. function getOffset(picker, input) {
  1077. var extraY = 0;
  1078. var dpWidth = picker.outerWidth();
  1079. var dpHeight = picker.outerHeight();
  1080. var inputHeight = input.outerHeight();
  1081. var doc = picker[0].ownerDocument;
  1082. var docElem = doc.documentElement;
  1083. var viewWidth = docElem.clientWidth + $(doc).scrollLeft();
  1084. var viewHeight = docElem.clientHeight + $(doc).scrollTop();
  1085. var offset = input.offset();
  1086. var offsetLeft = offset.left;
  1087. var offsetTop = offset.top;
  1088.  
  1089. offsetTop += inputHeight;
  1090.  
  1091. offsetLeft -=
  1092. Math.min(offsetLeft, (offsetLeft + dpWidth > viewWidth && viewWidth > dpWidth) ?
  1093. Math.abs(offsetLeft + dpWidth - viewWidth) : 0);
  1094.  
  1095. offsetTop -=
  1096. Math.min(offsetTop, ((offsetTop + dpHeight > viewHeight && viewHeight > dpHeight) ?
  1097. Math.abs(dpHeight + inputHeight - extraY) : extraY));
  1098.  
  1099. return {
  1100. top: offsetTop,
  1101. bottom: offset.bottom,
  1102. left: offsetLeft,
  1103. right: offset.right,
  1104. width: offset.width,
  1105. height: offset.height
  1106. };
  1107. }
  1108.  
  1109. /**
  1110. * noop - do nothing
  1111. */
  1112. function noop() {
  1113.  
  1114. }
  1115.  
  1116. /**
  1117. * stopPropagation - makes the code only doing this a little easier to read in line
  1118. */
  1119. function stopPropagation(e) {
  1120. e.stopPropagation();
  1121. }
  1122.  
  1123. /**
  1124. * Create a function bound to a given object
  1125. * Thanks to underscore.js
  1126. */
  1127. function bind(func, obj) {
  1128. var slice = Array.prototype.slice;
  1129. var args = slice.call(arguments, 2);
  1130. return function () {
  1131. return func.apply(obj, args.concat(slice.call(arguments)));
  1132. };
  1133. }
  1134.  
  1135. /**
  1136. * Lightweight drag helper. Handles containment within the element, so that
  1137. * when dragging, the x is within [0,element.width] and y is within [0,element.height]
  1138. */
  1139. function draggable(element, onmove, onstart, onstop) {
  1140. onmove = onmove || function () { };
  1141. onstart = onstart || function () { };
  1142. onstop = onstop || function () { };
  1143. var doc = document;
  1144. var dragging = false;
  1145. var offset = {};
  1146. var maxHeight = 0;
  1147. var maxWidth = 0;
  1148. var hasTouch = ('ontouchstart' in window);
  1149.  
  1150. var duringDragEvents = {};
  1151. duringDragEvents["selectstart"] = prevent;
  1152. duringDragEvents["dragstart"] = prevent;
  1153. duringDragEvents["touchmove mousemove"] = move;
  1154. duringDragEvents["touchend mouseup"] = stop;
  1155.  
  1156. function prevent(e) {
  1157. if (e.stopPropagation) {
  1158. e.stopPropagation();
  1159. }
  1160. if (e.preventDefault) {
  1161. e.preventDefault();
  1162. }
  1163. e.returnValue = false;
  1164. }
  1165.  
  1166. function move(e) {
  1167. if (dragging) {
  1168. // Mouseup happened outside of window
  1169. if (IE && doc.documentMode < 9 && !e.button) {
  1170. return stop();
  1171. }
  1172.  
  1173. var t0 = e.originalEvent && e.originalEvent.touches && e.originalEvent.touches[0];
  1174. var pageX = t0 && t0.pageX || e.pageX;
  1175. var pageY = t0 && t0.pageY || e.pageY;
  1176.  
  1177. var dragX = Math.max(0, Math.min(pageX - offset.left, maxWidth));
  1178. var dragY = Math.max(0, Math.min(pageY - offset.top, maxHeight));
  1179.  
  1180. if (hasTouch) {
  1181. // Stop scrolling in iOS
  1182. prevent(e);
  1183. }
  1184.  
  1185. onmove.apply(element, [dragX, dragY, e]);
  1186. }
  1187. }
  1188.  
  1189. function start(e) {
  1190. var rightclick = (e.which) ? (e.which == 3) : (e.button == 2);
  1191.  
  1192. if (!rightclick && !dragging) {
  1193. if (onstart.apply(element, arguments) !== false) {
  1194. dragging = true;
  1195. maxHeight = $(element).height();
  1196. maxWidth = $(element).width();
  1197. offset = $(element).offset();
  1198.  
  1199. $(doc).on(duringDragEvents);
  1200. $(doc.body).addClass("sp-dragging");
  1201.  
  1202. move(e);
  1203.  
  1204. prevent(e);
  1205. }
  1206. }
  1207. }
  1208.  
  1209. function stop() {
  1210. if (dragging) {
  1211. $(doc).off(duringDragEvents);
  1212. $(doc.body).removeClass("sp-dragging");
  1213.  
  1214. // Wait a tick before notifying observers to allow the click event
  1215. // to fire in Chrome.
  1216. setTimeout(function() {
  1217. onstop.apply(element, arguments);
  1218. }, 0);
  1219. }
  1220. dragging = false;
  1221. }
  1222.  
  1223. $(element).on("touchstart mousedown", start);
  1224. }
  1225.  
  1226. function throttle(func, wait, debounce) {
  1227. var timeout;
  1228. return function () {
  1229. var context = this, args = arguments;
  1230. var throttler = function () {
  1231. timeout = null;
  1232. func.apply(context, args);
  1233. };
  1234. if (debounce) clearTimeout(timeout);
  1235. if (debounce || !timeout) timeout = setTimeout(throttler, wait);
  1236. };
  1237. }
  1238.  
  1239. function inputTypeColorSupport() {
  1240. return $.fn.spectrum.inputTypeColorSupport();
  1241. }
  1242.  
  1243. /**
  1244. * Define a jQuery plugin
  1245. */
  1246. var dataID = "spectrum.id";
  1247. $.fn.spectrum = function (opts, extra) {
  1248.  
  1249. if (typeof opts == "string") {
  1250.  
  1251. var returnValue = this;
  1252. var args = Array.prototype.slice.call( arguments, 1 );
  1253.  
  1254. this.each(function () {
  1255. var spect = spectrums[$(this).data(dataID)];
  1256. if (spect) {
  1257. var method = spect[opts];
  1258. if (!method) {
  1259. throw new Error( "Spectrum: no such method: '" + opts + "'" );
  1260. }
  1261.  
  1262. if (opts == "get") {
  1263. returnValue = spect.get();
  1264. }
  1265. else if (opts == "container") {
  1266. returnValue = spect.container;
  1267. }
  1268. else if (opts == "option") {
  1269. returnValue = spect.option.apply(spect, args);
  1270. }
  1271. else if (opts == "destroy") {
  1272. spect.destroy();
  1273. $(this).removeData(dataID);
  1274. }
  1275. else {
  1276. method.apply(spect, args);
  1277. }
  1278. }
  1279. });
  1280.  
  1281. return returnValue;
  1282. }
  1283.  
  1284. // Initializing a new instance of spectrum
  1285. return this.spectrum("destroy").each(function () {
  1286. var options = $.extend({}, $(this).data(), opts);
  1287. // Infer default type from input params and deprecated options
  1288. if (!$(this).is('input')) options.type = 'noInput';
  1289. else if (options.flat || options.type == "flat") options.type = 'flat';
  1290. else if ($(this).attr('type') == 'color') options.type = 'color';
  1291. else options.type = options.type || 'component';
  1292.  
  1293. var spect = spectrum(this, options);
  1294. $(this).data(dataID, spect.id);
  1295. });
  1296. };
  1297.  
  1298. $.fn.spectrum.load = true;
  1299. $.fn.spectrum.loadOpts = {};
  1300. $.fn.spectrum.draggable = draggable;
  1301. $.fn.spectrum.defaults = defaultOpts;
  1302. $.fn.spectrum.inputTypeColorSupport = function inputTypeColorSupport() {
  1303. if (typeof inputTypeColorSupport._cachedResult === "undefined") {
  1304. var colorInput = $("<input type='color'/>")[0]; // if color element is supported, value will default to not null
  1305. inputTypeColorSupport._cachedResult = colorInput.type === "color" && colorInput.value !== "";
  1306. }
  1307. return inputTypeColorSupport._cachedResult;
  1308. };
  1309.  
  1310. $.spectrum = { };
  1311. $.spectrum.localization = { };
  1312. $.spectrum.palettes = { };
  1313.  
  1314. $.fn.spectrum.processNativeColorInputs = function () {
  1315. var colorInputs = $("input[type=color]");
  1316. if (colorInputs.length && !inputTypeColorSupport()) {
  1317. colorInputs.spectrum({
  1318. preferredFormat: "hex6"
  1319. });
  1320. }
  1321. };
  1322.  
  1323. // TinyColor v1.1.2
  1324. // https://github.com/bgrins/TinyColor
  1325. // Brian Grinstead, MIT License
  1326.  
  1327. (function() {
  1328.  
  1329. var trimLeft = /^[\s,#]+/,
  1330. trimRight = /\s+$/,
  1331. tinyCounter = 0,
  1332. math = Math,
  1333. mathRound = math.round,
  1334. mathMin = math.min,
  1335. mathMax = math.max,
  1336. mathRandom = math.random;
  1337.  
  1338. var tinycolor = function(color, opts) {
  1339.  
  1340. color = (color) ? color : '';
  1341. opts = opts || { };
  1342.  
  1343. // If input is already a tinycolor, return itself
  1344. if (color instanceof tinycolor) {
  1345. return color;
  1346. }
  1347. // If we are called as a function, call using new instead
  1348. if (!(this instanceof tinycolor)) {
  1349. return new tinycolor(color, opts);
  1350. }
  1351.  
  1352. var rgb = inputToRGB(color);
  1353. this._originalInput = color;
  1354. this._r = rgb.r;
  1355. this._g = rgb.g;
  1356. this._b = rgb.b;
  1357. this._a = rgb.a;
  1358. this._roundA = mathRound(1000 * this._a) / 1000;
  1359. this._format = opts.format || rgb.format;
  1360. this._gradientType = opts.gradientType;
  1361.  
  1362. // Don't let the range of [0,255] come back in [0,1].
  1363. // Potentially lose a little bit of precision here, but will fix issues where
  1364. // .5 gets interpreted as half of the total, instead of half of 1
  1365. // If it was supposed to be 128, this was already taken care of by `inputToRgb`
  1366. if (this._r < 1) { this._r = mathRound(this._r); }
  1367. if (this._g < 1) { this._g = mathRound(this._g); }
  1368. if (this._b < 1) { this._b = mathRound(this._b); }
  1369.  
  1370. this._ok = rgb.ok;
  1371. this._tc_id = tinyCounter++;
  1372. };
  1373.  
  1374. tinycolor.prototype = {
  1375. isDark: function() {
  1376. return this.getBrightness() < 128;
  1377. },
  1378. isLight: function() {
  1379. return !this.isDark();
  1380. },
  1381. isValid: function() {
  1382. return this._ok;
  1383. },
  1384. getOriginalInput: function() {
  1385. return this._originalInput;
  1386. },
  1387. getFormat: function() {
  1388. return this._format;
  1389. },
  1390. getAlpha: function() {
  1391. return this._a;
  1392. },
  1393. getBrightness: function() {
  1394. var rgb = this.toRgb();
  1395. return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
  1396. },
  1397. setAlpha: function(value) {
  1398. this._a = boundAlpha(value);
  1399. this._roundA = mathRound(1000 * this._a) / 1000;
  1400. return this;
  1401. },
  1402. toHsv: function() {
  1403. var hsv = rgbToHsv(this._r, this._g, this._b);
  1404. return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
  1405. },
  1406. toHsvString: function() {
  1407. var hsv = rgbToHsv(this._r, this._g, this._b);
  1408. var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
  1409. return (this._a == 1) ?
  1410. "hsv(" + h + ", " + s + "%, " + v + "%)" :
  1411. "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
  1412. },
  1413. toHsl: function() {
  1414. var hsl = rgbToHsl(this._r, this._g, this._b);
  1415. return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
  1416. },
  1417. toHslString: function() {
  1418. var hsl = rgbToHsl(this._r, this._g, this._b);
  1419. var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
  1420. return (this._a == 1) ?
  1421. "hsl(" + h + ", " + s + "%, " + l + "%)" :
  1422. "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
  1423. },
  1424. toHex: function(allow3Char) {
  1425. return rgbToHex(this._r, this._g, this._b, allow3Char);
  1426. },
  1427. toHexString: function(allow3Char) {
  1428. return '#' + this.toHex(allow3Char);
  1429. },
  1430. toHex8: function() {
  1431. return rgbaToHex(this._r, this._g, this._b, this._a);
  1432. },
  1433. toHex8String: function() {
  1434. return '#' + this.toHex8();
  1435. },
  1436. toRgb: function() {
  1437. return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
  1438. },
  1439. toRgbString: function() {
  1440. return (this._a == 1) ?
  1441. "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
  1442. "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
  1443. },
  1444. toPercentageRgb: function() {
  1445. return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
  1446. },
  1447. toPercentageRgbString: function() {
  1448. return (this._a == 1) ?
  1449. "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
  1450. "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
  1451. },
  1452. toName: function() {
  1453. if (this._a === 0) {
  1454. return "transparent";
  1455. }
  1456.  
  1457. if (this._a < 1) {
  1458. return false;
  1459. }
  1460.  
  1461. return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
  1462. },
  1463. toFilter: function(secondColor) {
  1464. var hex8String = '#' + rgbaToHex(this._r, this._g, this._b, this._a);
  1465. var secondHex8String = hex8String;
  1466. var gradientType = this._gradientType ? "GradientType = 1, " : "";
  1467.  
  1468. if (secondColor) {
  1469. var s = tinycolor(secondColor);
  1470. secondHex8String = s.toHex8String();
  1471. }
  1472.  
  1473. return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
  1474. },
  1475. toString: function(format) {
  1476. var formatSet = !!format;
  1477. format = format || this._format;
  1478.  
  1479. var formattedString = false;
  1480. var hasAlpha = this._a < 1 && this._a >= 0;
  1481. var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "name");
  1482.  
  1483. if (needsAlphaFormat) {
  1484. // Special case for "transparent", all other non-alpha formats
  1485. // will return rgba when there is transparency.
  1486. if (format === "name" && this._a === 0) {
  1487. return this.toName();
  1488. }
  1489. return this.toRgbString();
  1490. }
  1491. if (format === "rgb") {
  1492. formattedString = this.toRgbString();
  1493. }
  1494. if (format === "prgb") {
  1495. formattedString = this.toPercentageRgbString();
  1496. }
  1497. if (format === "hex" || format === "hex6") {
  1498. formattedString = this.toHexString();
  1499. }
  1500. if (format === "hex3") {
  1501. formattedString = this.toHexString(true);
  1502. }
  1503. if (format === "hex8") {
  1504. formattedString = this.toHex8String();
  1505. }
  1506. if (format === "name") {
  1507. formattedString = this.toName();
  1508. }
  1509. if (format === "hsl") {
  1510. formattedString = this.toHslString();
  1511. }
  1512. if (format === "hsv") {
  1513. formattedString = this.toHsvString();
  1514. }
  1515.  
  1516. return formattedString || this.toHexString();
  1517. },
  1518.  
  1519. _applyModification: function(fn, args) {
  1520. var color = fn.apply(null, [this].concat([].slice.call(args)));
  1521. this._r = color._r;
  1522. this._g = color._g;
  1523. this._b = color._b;
  1524. this.setAlpha(color._a);
  1525. return this;
  1526. },
  1527. lighten: function() {
  1528. return this._applyModification(lighten, arguments);
  1529. },
  1530. brighten: function() {
  1531. return this._applyModification(brighten, arguments);
  1532. },
  1533. darken: function() {
  1534. return this._applyModification(darken, arguments);
  1535. },
  1536. desaturate: function() {
  1537. return this._applyModification(desaturate, arguments);
  1538. },
  1539. saturate: function() {
  1540. return this._applyModification(saturate, arguments);
  1541. },
  1542. greyscale: function() {
  1543. return this._applyModification(greyscale, arguments);
  1544. },
  1545. spin: function() {
  1546. return this._applyModification(spin, arguments);
  1547. },
  1548.  
  1549. _applyCombination: function(fn, args) {
  1550. return fn.apply(null, [this].concat([].slice.call(args)));
  1551. },
  1552. analogous: function() {
  1553. return this._applyCombination(analogous, arguments);
  1554. },
  1555. complement: function() {
  1556. return this._applyCombination(complement, arguments);
  1557. },
  1558. monochromatic: function() {
  1559. return this._applyCombination(monochromatic, arguments);
  1560. },
  1561. splitcomplement: function() {
  1562. return this._applyCombination(splitcomplement, arguments);
  1563. },
  1564. triad: function() {
  1565. return this._applyCombination(triad, arguments);
  1566. },
  1567. tetrad: function() {
  1568. return this._applyCombination(tetrad, arguments);
  1569. }
  1570. };
  1571.  
  1572. // If input is an object, force 1 into "1.0" to handle ratios properly
  1573. // String input requires "1.0" as input, so 1 will be treated as 1
  1574. tinycolor.fromRatio = function(color, opts) {
  1575. if (typeof color == "object") {
  1576. var newColor = {};
  1577. for (var i in color) {
  1578. if (color.hasOwnProperty(i)) {
  1579. if (i === "a") {
  1580. newColor[i] = color[i];
  1581. }
  1582. else {
  1583. newColor[i] = convertToPercentage(color[i]);
  1584. }
  1585. }
  1586. }
  1587. color = newColor;
  1588. }
  1589.  
  1590. return tinycolor(color, opts);
  1591. };
  1592.  
  1593. // Given a string or object, convert that input to RGB
  1594. // Possible string inputs:
  1595. //
  1596. // "red"
  1597. // "#f00" or "f00"
  1598. // "#ff0000" or "ff0000"
  1599. // "#ff000000" or "ff000000"
  1600. // "rgb 255 0 0" or "rgb (255, 0, 0)"
  1601. // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
  1602. // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
  1603. // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
  1604. // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
  1605. // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
  1606. // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
  1607. //
  1608. function inputToRGB(color) {
  1609.  
  1610. var rgb = { r: 0, g: 0, b: 0 };
  1611. var a = 1;
  1612. var ok = false;
  1613. var format = false;
  1614.  
  1615. if (typeof color == "string") {
  1616. color = stringInputToObject(color);
  1617. }
  1618.  
  1619. if (typeof color == "object") {
  1620. if (color.hasOwnProperty("r") && color.hasOwnProperty("g") && color.hasOwnProperty("b")) {
  1621. rgb = rgbToRgb(color.r, color.g, color.b);
  1622. ok = true;
  1623. format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
  1624. }
  1625. else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("v")) {
  1626. color.s = convertToPercentage(color.s);
  1627. color.v = convertToPercentage(color.v);
  1628. rgb = hsvToRgb(color.h, color.s, color.v);
  1629. ok = true;
  1630. format = "hsv";
  1631. }
  1632. else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("l")) {
  1633. color.s = convertToPercentage(color.s);
  1634. color.l = convertToPercentage(color.l);
  1635. rgb = hslToRgb(color.h, color.s, color.l);
  1636. ok = true;
  1637. format = "hsl";
  1638. }
  1639.  
  1640. if (color.hasOwnProperty("a")) {
  1641. a = color.a;
  1642. }
  1643. }
  1644.  
  1645. a = boundAlpha(a);
  1646.  
  1647. return {
  1648. ok: ok,
  1649. format: color.format || format,
  1650. r: mathMin(255, mathMax(rgb.r, 0)),
  1651. g: mathMin(255, mathMax(rgb.g, 0)),
  1652. b: mathMin(255, mathMax(rgb.b, 0)),
  1653. a: a
  1654. };
  1655. }
  1656.  
  1657.  
  1658. // Conversion Functions
  1659. // --------------------
  1660.  
  1661. // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
  1662. // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
  1663.  
  1664. // `rgbToRgb`
  1665. // Handle bounds / percentage checking to conform to CSS color spec
  1666. // <http://www.w3.org/TR/css3-color/>
  1667. // *Assumes:* r, g, b in [0, 255] or [0, 1]
  1668. // *Returns:* { r, g, b } in [0, 255]
  1669. function rgbToRgb(r, g, b){
  1670. return {
  1671. r: bound01(r, 255) * 255,
  1672. g: bound01(g, 255) * 255,
  1673. b: bound01(b, 255) * 255
  1674. };
  1675. }
  1676.  
  1677. // `rgbToHsl`
  1678. // Converts an RGB color value to HSL.
  1679. // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
  1680. // *Returns:* { h, s, l } in [0,1]
  1681. function rgbToHsl(r, g, b) {
  1682.  
  1683. r = bound01(r, 255);
  1684. g = bound01(g, 255);
  1685. b = bound01(b, 255);
  1686.  
  1687. var max = mathMax(r, g, b), min = mathMin(r, g, b);
  1688. var h, s, l = (max + min) / 2;
  1689.  
  1690. if(max == min) {
  1691. h = s = 0; // achromatic
  1692. }
  1693. else {
  1694. var d = max - min;
  1695. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  1696. switch(max) {
  1697. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  1698. case g: h = (b - r) / d + 2; break;
  1699. case b: h = (r - g) / d + 4; break;
  1700. }
  1701.  
  1702. h /= 6;
  1703. }
  1704.  
  1705. return { h: h, s: s, l: l };
  1706. }
  1707.  
  1708. // `hslToRgb`
  1709. // Converts an HSL color value to RGB.
  1710. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
  1711. // *Returns:* { r, g, b } in the set [0, 255]
  1712. function hslToRgb(h, s, l) {
  1713. var r, g, b;
  1714.  
  1715. h = bound01(h, 360);
  1716. s = bound01(s, 100);
  1717. l = bound01(l, 100);
  1718.  
  1719. function hue2rgb(p, q, t) {
  1720. if(t < 0) t += 1;
  1721. if(t > 1) t -= 1;
  1722. if(t < 1/6) return p + (q - p) * 6 * t;
  1723. if(t < 1/2) return q;
  1724. if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
  1725. return p;
  1726. }
  1727.  
  1728. if(s === 0) {
  1729. r = g = b = l; // achromatic
  1730. }
  1731. else {
  1732. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  1733. var p = 2 * l - q;
  1734. r = hue2rgb(p, q, h + 1/3);
  1735. g = hue2rgb(p, q, h);
  1736. b = hue2rgb(p, q, h - 1/3);
  1737. }
  1738.  
  1739. return { r: r * 255, g: g * 255, b: b * 255 };
  1740. }
  1741.  
  1742. // `rgbToHsv`
  1743. // Converts an RGB color value to HSV
  1744. // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
  1745. // *Returns:* { h, s, v } in [0,1]
  1746. function rgbToHsv(r, g, b) {
  1747.  
  1748. r = bound01(r, 255);
  1749. g = bound01(g, 255);
  1750. b = bound01(b, 255);
  1751.  
  1752. var max = mathMax(r, g, b), min = mathMin(r, g, b);
  1753. var h, s, v = max;
  1754.  
  1755. var d = max - min;
  1756. s = max === 0 ? 0 : d / max;
  1757.  
  1758. if(max == min) {
  1759. h = 0; // achromatic
  1760. }
  1761. else {
  1762. switch(max) {
  1763. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  1764. case g: h = (b - r) / d + 2; break;
  1765. case b: h = (r - g) / d + 4; break;
  1766. }
  1767. h /= 6;
  1768. }
  1769. return { h: h, s: s, v: v };
  1770. }
  1771.  
  1772. // `hsvToRgb`
  1773. // Converts an HSV color value to RGB.
  1774. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
  1775. // *Returns:* { r, g, b } in the set [0, 255]
  1776. function hsvToRgb(h, s, v) {
  1777.  
  1778. h = bound01(h, 360) * 6;
  1779. s = bound01(s, 100);
  1780. v = bound01(v, 100);
  1781.  
  1782. var i = math.floor(h),
  1783. f = h - i,
  1784. p = v * (1 - s),
  1785. q = v * (1 - f * s),
  1786. t = v * (1 - (1 - f) * s),
  1787. mod = i % 6,
  1788. r = [v, q, p, p, t, v][mod],
  1789. g = [t, v, v, q, p, p][mod],
  1790. b = [p, p, t, v, v, q][mod];
  1791.  
  1792. return { r: r * 255, g: g * 255, b: b * 255 };
  1793. }
  1794.  
  1795. // `rgbToHex`
  1796. // Converts an RGB color to hex
  1797. // Assumes r, g, and b are contained in the set [0, 255]
  1798. // Returns a 3 or 6 character hex
  1799. function rgbToHex(r, g, b, allow3Char) {
  1800.  
  1801. var hex = [
  1802. pad2(mathRound(r).toString(16)),
  1803. pad2(mathRound(g).toString(16)),
  1804. pad2(mathRound(b).toString(16))
  1805. ];
  1806.  
  1807. // Return a 3 character hex if possible
  1808. if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
  1809. return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
  1810. }
  1811.  
  1812. return hex.join("");
  1813. }
  1814. // `rgbaToHex`
  1815. // Converts an RGBA color plus alpha transparency to hex
  1816. // Assumes r, g, b and a are contained in the set [0, 255]
  1817. // Returns an 8 character hex
  1818. function rgbaToHex(r, g, b, a) {
  1819.  
  1820. var hex = [
  1821. pad2(convertDecimalToHex(a)),
  1822. pad2(mathRound(r).toString(16)),
  1823. pad2(mathRound(g).toString(16)),
  1824. pad2(mathRound(b).toString(16))
  1825. ];
  1826.  
  1827. return hex.join("");
  1828. }
  1829.  
  1830. // `equals`
  1831. // Can be called with any tinycolor input
  1832. tinycolor.equals = function (color1, color2) {
  1833. if (!color1 || !color2) { return false; }
  1834. return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
  1835. };
  1836. tinycolor.random = function() {
  1837. return tinycolor.fromRatio({
  1838. r: mathRandom(),
  1839. g: mathRandom(),
  1840. b: mathRandom()
  1841. });
  1842. };
  1843.  
  1844.  
  1845. // Modification Functions
  1846. // ----------------------
  1847. // Thanks to less.js for some of the basics here
  1848. // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
  1849.  
  1850. function desaturate(color, amount) {
  1851. amount = (amount === 0) ? 0 : (amount || 10);
  1852. var hsl = tinycolor(color).toHsl();
  1853. hsl.s -= amount / 100;
  1854. hsl.s = clamp01(hsl.s);
  1855. return tinycolor(hsl);
  1856. }
  1857.  
  1858. function saturate(color, amount) {
  1859. amount = (amount === 0) ? 0 : (amount || 10);
  1860. var hsl = tinycolor(color).toHsl();
  1861. hsl.s += amount / 100;
  1862. hsl.s = clamp01(hsl.s);
  1863. return tinycolor(hsl);
  1864. }
  1865.  
  1866. function greyscale(color) {
  1867. return tinycolor(color).desaturate(100);
  1868. }
  1869.  
  1870. function lighten (color, amount) {
  1871. amount = (amount === 0) ? 0 : (amount || 10);
  1872. var hsl = tinycolor(color).toHsl();
  1873. hsl.l += amount / 100;
  1874. hsl.l = clamp01(hsl.l);
  1875. return tinycolor(hsl);
  1876. }
  1877.  
  1878. function brighten(color, amount) {
  1879. amount = (amount === 0) ? 0 : (amount || 10);
  1880. var rgb = tinycolor(color).toRgb();
  1881. rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
  1882. rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
  1883. rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
  1884. return tinycolor(rgb);
  1885. }
  1886.  
  1887. function darken (color, amount) {
  1888. amount = (amount === 0) ? 0 : (amount || 10);
  1889. var hsl = tinycolor(color).toHsl();
  1890. hsl.l -= amount / 100;
  1891. hsl.l = clamp01(hsl.l);
  1892. return tinycolor(hsl);
  1893. }
  1894.  
  1895. // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
  1896. // Values outside of this range will be wrapped into this range.
  1897. function spin(color, amount) {
  1898. var hsl = tinycolor(color).toHsl();
  1899. var hue = (mathRound(hsl.h) + amount) % 360;
  1900. hsl.h = hue < 0 ? 360 + hue : hue;
  1901. return tinycolor(hsl);
  1902. }
  1903.  
  1904. // Combination Functions
  1905. // ---------------------
  1906. // Thanks to jQuery xColor for some of the ideas behind these
  1907. // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
  1908.  
  1909. function complement(color) {
  1910. var hsl = tinycolor(color).toHsl();
  1911. hsl.h = (hsl.h + 180) % 360;
  1912. return tinycolor(hsl);
  1913. }
  1914.  
  1915. function triad(color) {
  1916. var hsl = tinycolor(color).toHsl();
  1917. var h = hsl.h;
  1918. return [
  1919. tinycolor(color),
  1920. tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
  1921. tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
  1922. ];
  1923. }
  1924.  
  1925. function tetrad(color) {
  1926. var hsl = tinycolor(color).toHsl();
  1927. var h = hsl.h;
  1928. return [
  1929. tinycolor(color),
  1930. tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
  1931. tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
  1932. tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
  1933. ];
  1934. }
  1935.  
  1936. function splitcomplement(color) {
  1937. var hsl = tinycolor(color).toHsl();
  1938. var h = hsl.h;
  1939. return [
  1940. tinycolor(color),
  1941. tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
  1942. tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
  1943. ];
  1944. }
  1945.  
  1946. function analogous(color, results, slices) {
  1947. results = results || 6;
  1948. slices = slices || 30;
  1949.  
  1950. var hsl = tinycolor(color).toHsl();
  1951. var part = 360 / slices;
  1952. var ret = [tinycolor(color)];
  1953.  
  1954. for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
  1955. hsl.h = (hsl.h + part) % 360;
  1956. ret.push(tinycolor(hsl));
  1957. }
  1958. return ret;
  1959. }
  1960.  
  1961. function monochromatic(color, results) {
  1962. results = results || 6;
  1963. var hsv = tinycolor(color).toHsv();
  1964. var h = hsv.h, s = hsv.s, v = hsv.v;
  1965. var ret = [];
  1966. var modification = 1 / results;
  1967.  
  1968. while (results--) {
  1969. ret.push(tinycolor({ h: h, s: s, v: v}));
  1970. v = (v + modification) % 1;
  1971. }
  1972.  
  1973. return ret;
  1974. }
  1975.  
  1976. // Utility Functions
  1977. // ---------------------
  1978.  
  1979. tinycolor.mix = function(color1, color2, amount) {
  1980. amount = (amount === 0) ? 0 : (amount || 50);
  1981.  
  1982. var rgb1 = tinycolor(color1).toRgb();
  1983. var rgb2 = tinycolor(color2).toRgb();
  1984.  
  1985. var p = amount / 100;
  1986. var w = p * 2 - 1;
  1987. var a = rgb2.a - rgb1.a;
  1988.  
  1989. var w1;
  1990.  
  1991. if (w * a == -1) {
  1992. w1 = w;
  1993. } else {
  1994. w1 = (w + a) / (1 + w * a);
  1995. }
  1996.  
  1997. w1 = (w1 + 1) / 2;
  1998.  
  1999. var w2 = 1 - w1;
  2000.  
  2001. var rgba = {
  2002. r: rgb2.r * w1 + rgb1.r * w2,
  2003. g: rgb2.g * w1 + rgb1.g * w2,
  2004. b: rgb2.b * w1 + rgb1.b * w2,
  2005. a: rgb2.a * p + rgb1.a * (1 - p)
  2006. };
  2007.  
  2008. return tinycolor(rgba);
  2009. };
  2010.  
  2011.  
  2012. // Readability Functions
  2013. // ---------------------
  2014. // <http://www.w3.org/TR/AERT#color-contrast>
  2015.  
  2016. // `readability`
  2017. // Analyze the 2 colors and returns an object with the following properties:
  2018. // `brightness`: difference in brightness between the two colors
  2019. // `color`: difference in color/hue between the two colors
  2020. tinycolor.readability = function(color1, color2) {
  2021. var c1 = tinycolor(color1);
  2022. var c2 = tinycolor(color2);
  2023. var rgb1 = c1.toRgb();
  2024. var rgb2 = c2.toRgb();
  2025. var brightnessA = c1.getBrightness();
  2026. var brightnessB = c2.getBrightness();
  2027. var colorDiff = (
  2028. Math.max(rgb1.r, rgb2.r) - Math.min(rgb1.r, rgb2.r) +
  2029. Math.max(rgb1.g, rgb2.g) - Math.min(rgb1.g, rgb2.g) +
  2030. Math.max(rgb1.b, rgb2.b) - Math.min(rgb1.b, rgb2.b)
  2031. );
  2032.  
  2033. return {
  2034. brightness: Math.abs(brightnessA - brightnessB),
  2035. color: colorDiff
  2036. };
  2037. };
  2038.  
  2039. // `readable`
  2040. // http://www.w3.org/TR/AERT#color-contrast
  2041. // Ensure that foreground and background color combinations provide sufficient contrast.
  2042. // *Example*
  2043. // tinycolor.isReadable("#000", "#111") => false
  2044. tinycolor.isReadable = function(color1, color2) {
  2045. var readability = tinycolor.readability(color1, color2);
  2046. return readability.brightness > 125 && readability.color > 500;
  2047. };
  2048.  
  2049. // `mostReadable`
  2050. // Given a base color and a list of possible foreground or background
  2051. // colors for that base, returns the most readable color.
  2052. // *Example*
  2053. // tinycolor.mostReadable("#123", ["#fff", "#000"]) => "#000"
  2054. tinycolor.mostReadable = function(baseColor, colorList) {
  2055. var bestColor = null;
  2056. var bestScore = 0;
  2057. var bestIsReadable = false;
  2058. for (var i=0; i < colorList.length; i++) {
  2059.  
  2060. // We normalize both around the "acceptable" breaking point,
  2061. // but rank brightness constrast higher than hue.
  2062.  
  2063. var readability = tinycolor.readability(baseColor, colorList[i]);
  2064. var readable = readability.brightness > 125 && readability.color > 500;
  2065. var score = 3 * (readability.brightness / 125) + (readability.color / 500);
  2066.  
  2067. if ((readable && ! bestIsReadable) ||
  2068. (readable && bestIsReadable && score > bestScore) ||
  2069. ((! readable) && (! bestIsReadable) && score > bestScore)) {
  2070. bestIsReadable = readable;
  2071. bestScore = score;
  2072. bestColor = tinycolor(colorList[i]);
  2073. }
  2074. }
  2075. return bestColor;
  2076. };
  2077.  
  2078.  
  2079. // Big List of Colors
  2080. // ------------------
  2081. // <http://www.w3.org/TR/css3-color/#svg-color>
  2082. var names = tinycolor.names = {
  2083. aliceblue: "f0f8ff",
  2084. antiquewhite: "faebd7",
  2085. aqua: "0ff",
  2086. aquamarine: "7fffd4",
  2087. azure: "f0ffff",
  2088. beige: "f5f5dc",
  2089. bisque: "ffe4c4",
  2090. black: "000",
  2091. blanchedalmond: "ffebcd",
  2092. blue: "00f",
  2093. blueviolet: "8a2be2",
  2094. brown: "a52a2a",
  2095. burlywood: "deb887",
  2096. burntsienna: "ea7e5d",
  2097. cadetblue: "5f9ea0",
  2098. chartreuse: "7fff00",
  2099. chocolate: "d2691e",
  2100. coral: "ff7f50",
  2101. cornflowerblue: "6495ed",
  2102. cornsilk: "fff8dc",
  2103. crimson: "dc143c",
  2104. cyan: "0ff",
  2105. darkblue: "00008b",
  2106. darkcyan: "008b8b",
  2107. darkgoldenrod: "b8860b",
  2108. darkgray: "a9a9a9",
  2109. darkgreen: "006400",
  2110. darkgrey: "a9a9a9",
  2111. darkkhaki: "bdb76b",
  2112. darkmagenta: "8b008b",
  2113. darkolivegreen: "556b2f",
  2114. darkorange: "ff8c00",
  2115. darkorchid: "9932cc",
  2116. darkred: "8b0000",
  2117. darksalmon: "e9967a",
  2118. darkseagreen: "8fbc8f",
  2119. darkslateblue: "483d8b",
  2120. darkslategray: "2f4f4f",
  2121. darkslategrey: "2f4f4f",
  2122. darkturquoise: "00ced1",
  2123. darkviolet: "9400d3",
  2124. deeppink: "ff1493",
  2125. deepskyblue: "00bfff",
  2126. dimgray: "696969",
  2127. dimgrey: "696969",
  2128. dodgerblue: "1e90ff",
  2129. firebrick: "b22222",
  2130. floralwhite: "fffaf0",
  2131. forestgreen: "228b22",
  2132. fuchsia: "f0f",
  2133. gainsboro: "dcdcdc",
  2134. ghostwhite: "f8f8ff",
  2135. gold: "ffd700",
  2136. goldenrod: "daa520",
  2137. gray: "808080",
  2138. green: "008000",
  2139. greenyellow: "adff2f",
  2140. grey: "808080",
  2141. honeydew: "f0fff0",
  2142. hotpink: "ff69b4",
  2143. indianred: "cd5c5c",
  2144. indigo: "4b0082",
  2145. ivory: "fffff0",
  2146. khaki: "f0e68c",
  2147. lavender: "e6e6fa",
  2148. lavenderblush: "fff0f5",
  2149. lawngreen: "7cfc00",
  2150. lemonchiffon: "fffacd",
  2151. lightblue: "add8e6",
  2152. lightcoral: "f08080",
  2153. lightcyan: "e0ffff",
  2154. lightgoldenrodyellow: "fafad2",
  2155. lightgray: "d3d3d3",
  2156. lightgreen: "90ee90",
  2157. lightgrey: "d3d3d3",
  2158. lightpink: "ffb6c1",
  2159. lightsalmon: "ffa07a",
  2160. lightseagreen: "20b2aa",
  2161. lightskyblue: "87cefa",
  2162. lightslategray: "789",
  2163. lightslategrey: "789",
  2164. lightsteelblue: "b0c4de",
  2165. lightyellow: "ffffe0",
  2166. lime: "0f0",
  2167. limegreen: "32cd32",
  2168. linen: "faf0e6",
  2169. magenta: "f0f",
  2170. maroon: "800000",
  2171. mediumaquamarine: "66cdaa",
  2172. mediumblue: "0000cd",
  2173. mediumorchid: "ba55d3",
  2174. mediumpurple: "9370db",
  2175. mediumseagreen: "3cb371",
  2176. mediumslateblue: "7b68ee",
  2177. mediumspringgreen: "00fa9a",
  2178. mediumturquoise: "48d1cc",
  2179. mediumvioletred: "c71585",
  2180. midnightblue: "191970",
  2181. mintcream: "f5fffa",
  2182. mistyrose: "ffe4e1",
  2183. moccasin: "ffe4b5",
  2184. navajowhite: "ffdead",
  2185. navy: "000080",
  2186. oldlace: "fdf5e6",
  2187. olive: "808000",
  2188. olivedrab: "6b8e23",
  2189. orange: "ffa500",
  2190. orangered: "ff4500",
  2191. orchid: "da70d6",
  2192. palegoldenrod: "eee8aa",
  2193. palegreen: "98fb98",
  2194. paleturquoise: "afeeee",
  2195. palevioletred: "db7093",
  2196. papayawhip: "ffefd5",
  2197. peachpuff: "ffdab9",
  2198. peru: "cd853f",
  2199. pink: "ffc0cb",
  2200. plum: "dda0dd",
  2201. powderblue: "b0e0e6",
  2202. purple: "800080",
  2203. rebeccapurple: "663399",
  2204. red: "f00",
  2205. rosybrown: "bc8f8f",
  2206. royalblue: "4169e1",
  2207. saddlebrown: "8b4513",
  2208. salmon: "fa8072",
  2209. sandybrown: "f4a460",
  2210. seagreen: "2e8b57",
  2211. seashell: "fff5ee",
  2212. sienna: "a0522d",
  2213. silver: "c0c0c0",
  2214. skyblue: "87ceeb",
  2215. slateblue: "6a5acd",
  2216. slategray: "708090",
  2217. slategrey: "708090",
  2218. snow: "fffafa",
  2219. springgreen: "00ff7f",
  2220. steelblue: "4682b4",
  2221. tan: "d2b48c",
  2222. teal: "008080",
  2223. thistle: "d8bfd8",
  2224. tomato: "ff6347",
  2225. turquoise: "40e0d0",
  2226. violet: "ee82ee",
  2227. wheat: "f5deb3",
  2228. white: "fff",
  2229. whitesmoke: "f5f5f5",
  2230. yellow: "ff0",
  2231. yellowgreen: "9acd32"
  2232. };
  2233.  
  2234. // Make it easy to access colors via `hexNames[hex]`
  2235. var hexNames = tinycolor.hexNames = flip(names);
  2236.  
  2237.  
  2238. // Utilities
  2239. // ---------
  2240.  
  2241. // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
  2242. function flip(o) {
  2243. var flipped = { };
  2244. for (var i in o) {
  2245. if (o.hasOwnProperty(i)) {
  2246. flipped[o[i]] = i;
  2247. }
  2248. }
  2249. return flipped;
  2250. }
  2251.  
  2252. // Return a valid alpha value [0,1] with all invalid values being set to 1
  2253. function boundAlpha(a) {
  2254. a = parseFloat(a);
  2255.  
  2256. if (isNaN(a) || a < 0 || a > 1) {
  2257. a = 1;
  2258. }
  2259.  
  2260. return a;
  2261. }
  2262.  
  2263. // Take input from [0, n] and return it as [0, 1]
  2264. function bound01(n, max) {
  2265. if (isOnePointZero(n)) { n = "100%"; }
  2266.  
  2267. var processPercent = isPercentage(n);
  2268. n = mathMin(max, mathMax(0, parseFloat(n)));
  2269.  
  2270. // Automatically convert percentage into number
  2271. if (processPercent) {
  2272. n = parseInt(n * max, 10) / 100;
  2273. }
  2274.  
  2275. // Handle floating point rounding errors
  2276. if ((math.abs(n - max) < 0.000001)) {
  2277. return 1;
  2278. }
  2279.  
  2280. // Convert into [0, 1] range if it isn't already
  2281. return (n % max) / parseFloat(max);
  2282. }
  2283.  
  2284. // Force a number between 0 and 1
  2285. function clamp01(val) {
  2286. return mathMin(1, mathMax(0, val));
  2287. }
  2288.  
  2289. // Parse a base-16 hex value into a base-10 integer
  2290. function parseIntFromHex(val) {
  2291. return parseInt(val, 16);
  2292. }
  2293.  
  2294. // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
  2295. // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
  2296. function isOnePointZero(n) {
  2297. return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
  2298. }
  2299.  
  2300. // Check to see if string passed in is a percentage
  2301. function isPercentage(n) {
  2302. return typeof n === "string" && n.indexOf('%') != -1;
  2303. }
  2304.  
  2305. // Force a hex value to have 2 characters
  2306. function pad2(c) {
  2307. return c.length == 1 ? '0' + c : '' + c;
  2308. }
  2309.  
  2310. // Replace a decimal with it's percentage value
  2311. function convertToPercentage(n) {
  2312. if (n <= 1) {
  2313. n = (n * 100) + "%";
  2314. }
  2315.  
  2316. return n;
  2317. }
  2318.  
  2319. // Converts a decimal to a hex value
  2320. function convertDecimalToHex(d) {
  2321. return Math.round(parseFloat(d) * 255).toString(16);
  2322. }
  2323. // Converts a hex value to a decimal
  2324. function convertHexToDecimal(h) {
  2325. return (parseIntFromHex(h) / 255);
  2326. }
  2327.  
  2328. var matchers = (function() {
  2329.  
  2330. // <http://www.w3.org/TR/css3-values/#integers>
  2331. var CSS_INTEGER = "[-\\+]?\\d+%?";
  2332.  
  2333. // <http://www.w3.org/TR/css3-values/#number-value>
  2334. var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
  2335.  
  2336. // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
  2337. var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
  2338.  
  2339. // Actual matching.
  2340. // Parentheses and commas are optional, but not required.
  2341. // Whitespace can take the place of commas or opening paren
  2342. var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
  2343. var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
  2344.  
  2345. return {
  2346. rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
  2347. rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
  2348. hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
  2349. hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
  2350. hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
  2351. hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
  2352. hex3: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
  2353. hex6: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
  2354. hex8: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
  2355. };
  2356. })();
  2357.  
  2358. // `stringInputToObject`
  2359. // Permissive string parsing. Take in a number of formats, and output an object
  2360. // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
  2361. function stringInputToObject(color) {
  2362.  
  2363. color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
  2364. var named = false;
  2365. if (names[color]) {
  2366. color = names[color];
  2367. named = true;
  2368. }
  2369. else if (color == 'transparent') {
  2370. return { r: 0, g: 0, b: 0, a: 0, format: "name" };
  2371. }
  2372.  
  2373. // Try to match string input using regular expressions.
  2374. // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
  2375. // Just return an object and let the conversion functions handle that.
  2376. // This way the result will be the same whether the tinycolor is initialized with string or object.
  2377. var match;
  2378. if ((match = matchers.rgb.exec(color))) {
  2379. return { r: match[1], g: match[2], b: match[3] };
  2380. }
  2381. if ((match = matchers.rgba.exec(color))) {
  2382. return { r: match[1], g: match[2], b: match[3], a: match[4] };
  2383. }
  2384. if ((match = matchers.hsl.exec(color))) {
  2385. return { h: match[1], s: match[2], l: match[3] };
  2386. }
  2387. if ((match = matchers.hsla.exec(color))) {
  2388. return { h: match[1], s: match[2], l: match[3], a: match[4] };
  2389. }
  2390. if ((match = matchers.hsv.exec(color))) {
  2391. return { h: match[1], s: match[2], v: match[3] };
  2392. }
  2393. if ((match = matchers.hsva.exec(color))) {
  2394. return { h: match[1], s: match[2], v: match[3], a: match[4] };
  2395. }
  2396. if ((match = matchers.hex8.exec(color))) {
  2397. return {
  2398. a: convertHexToDecimal(match[1]),
  2399. r: parseIntFromHex(match[2]),
  2400. g: parseIntFromHex(match[3]),
  2401. b: parseIntFromHex(match[4]),
  2402. format: named ? "name" : "hex8"
  2403. };
  2404. }
  2405. if ((match = matchers.hex6.exec(color))) {
  2406. return {
  2407. r: parseIntFromHex(match[1]),
  2408. g: parseIntFromHex(match[2]),
  2409. b: parseIntFromHex(match[3]),
  2410. format: named ? "name" : "hex"
  2411. };
  2412. }
  2413. if ((match = matchers.hex3.exec(color))) {
  2414. return {
  2415. r: parseIntFromHex(match[1] + '' + match[1]),
  2416. g: parseIntFromHex(match[2] + '' + match[2]),
  2417. b: parseIntFromHex(match[3] + '' + match[3]),
  2418. format: named ? "name" : "hex"
  2419. };
  2420. }
  2421.  
  2422. return false;
  2423. }
  2424.  
  2425. window.tinycolor = tinycolor;
  2426. })();
  2427.  
  2428. $(function () {
  2429. if ($.fn.spectrum.load) {
  2430. $.fn.spectrum.processNativeColorInputs();
  2431. }
  2432. });
  2433.  
  2434. });
  2435.  
  2436. // Spectrum Colorpicker
  2437. // Arabic (ar) localization
  2438. // https://github.com/seballot/spectrum
  2439. (function ( $ ) {
  2440.  
  2441. var localization = $.spectrum.localization["ar"] = {
  2442. cancelText: "إلغاء",
  2443. chooseText: "إختار",
  2444. clearText: "إرجاع الألوان على ما كانت",
  2445. noColorSelectedText: "لم تختار أي لون",
  2446. togglePaletteMoreText: "أكثر",
  2447. togglePaletteLessText: "أقل"
  2448. };
  2449.  
  2450. })( jQuery );
  2451.  
  2452. // Spectrum Colorpicker
  2453. // Catalan (ca) localization
  2454. // https://github.com/seballot/spectrum
  2455.  
  2456. (function ( $ ) {
  2457.  
  2458. var localization = $.spectrum.localization["ca"] = {
  2459. cancelText: "Cancel·lar",
  2460. chooseText: "Escollir",
  2461. clearText: "Esborrar color seleccionat",
  2462. noColorSelectedText: "Cap color seleccionat",
  2463. togglePaletteMoreText: "Més",
  2464. togglePaletteLessText: "Menys"
  2465. };
  2466.  
  2467. })( jQuery );
  2468.  
  2469. // Spectrum Colorpicker
  2470. // Czech (cs) localization
  2471. // https://github.com/seballot/spectrum
  2472. // author localization cs Pavel Laupe Dvorak pavel@pavel-dvorak.cz
  2473.  
  2474. (function ( $ ) {
  2475.  
  2476. var localization = $.spectrum.localization["cs"] = {
  2477. cancelText: "zrušit",
  2478. chooseText: "vybrat",
  2479. clearText: "Resetovat výběr barev",
  2480. noColorSelectedText: "Žádná barva nebyla vybrána",
  2481. togglePaletteMoreText: "více",
  2482. togglePaletteLessText: "méně"
  2483. };
  2484.  
  2485. })( jQuery );
  2486.  
  2487. // Spectrum Colorpicker
  2488. // German (de) localization
  2489. // https://github.com/seballot/spectrum
  2490.  
  2491. (function ( $ ) {
  2492.  
  2493. var localization = $.spectrum.localization["de"] = {
  2494. cancelText: "Abbrechen",
  2495. chooseText: "Wählen",
  2496. clearText: "Farbauswahl zurücksetzen",
  2497. noColorSelectedText: "Keine Farbe ausgewählt",
  2498. togglePaletteMoreText: "Mehr",
  2499. togglePaletteLessText: "Weniger"
  2500. };
  2501.  
  2502. })( jQuery );
  2503.  
  2504. // Spectrum Colorpicker
  2505. // Danish (dk) localization
  2506. // https://github.com/seballot/spectrum
  2507.  
  2508. (function ( $ ) {
  2509.  
  2510. var localization = $.spectrum.localization["dk"] = {
  2511. cancelText: "annuller",
  2512. chooseText: "Vælg"
  2513. };
  2514.  
  2515. })( jQuery );
  2516.  
  2517. // Spectrum Colorpicker
  2518. // Spanish (es) localization
  2519. // https://github.com/seballot/spectrum
  2520.  
  2521. (function ( $ ) {
  2522.  
  2523. var localization = $.spectrum.localization["es"] = {
  2524. cancelText: "Cancelar",
  2525. chooseText: "Elegir",
  2526. clearText: "Borrar color seleccionado",
  2527. noColorSelectedText: "Ningún color seleccionado",
  2528. togglePaletteMoreText: "Más",
  2529. togglePaletteLessText: "Menos"
  2530. };
  2531.  
  2532. })( jQuery );
  2533.  
  2534. // Spectrum Colorpicker
  2535. // Estonian (et) localization
  2536. // https://github.com/bgrins/spectrum
  2537.  
  2538. (function ( $ ) {
  2539.  
  2540. var localization = $.spectrum.localization["et"] = {
  2541. cancelText: "Katkesta",
  2542. chooseText: "Vali",
  2543. clearText: "Tühista värvivalik",
  2544. noColorSelectedText: "Ühtki värvi pole valitud",
  2545. togglePaletteMoreText: "Rohkem",
  2546. togglePaletteLessText: "Vähem"
  2547. };
  2548.  
  2549. })( jQuery );
  2550.  
  2551. // Spectrum Colorpicker
  2552. // Persian (fa) localization
  2553. // https://github.com/seballot/spectrum
  2554.  
  2555. (function ( $ ) {
  2556.  
  2557. var localization = $.spectrum.localization["fa"] = {
  2558. cancelText: "لغو",
  2559. chooseText: "انتخاب",
  2560. clearText: "تنظیم مجدد رنگ",
  2561. noColorSelectedText: "هیچ رنگی انتخاب نشده است!",
  2562. togglePaletteMoreText: "بیشتر",
  2563. togglePaletteLessText: "کمتر"
  2564. };
  2565.  
  2566. })( jQuery );
  2567.  
  2568. // Spectrum Colorpicker
  2569. // Finnish (fi) localization
  2570. // https://github.com/seballot/spectrum
  2571.  
  2572. (function ( $ ) {
  2573.  
  2574. var localization = $.spectrum.localization["fi"] = {
  2575. cancelText: "Kumoa",
  2576. chooseText: "Valitse"
  2577. };
  2578.  
  2579. })( jQuery );
  2580.  
  2581. // Spectrum Colorpicker
  2582. // French (fr) localization
  2583. // https://github.com/seballot/spectrum
  2584.  
  2585. (function ( $ ) {
  2586.  
  2587. var localization = $.spectrum.localization["fr"] = {
  2588. cancelText: "Annuler",
  2589. chooseText: "Valider",
  2590. clearText: "Effacer couleur sélectionnée",
  2591. noColorSelectedText: "Aucune couleur sélectionnée",
  2592. togglePaletteMoreText: "Plus",
  2593. togglePaletteLessText: "Moins"
  2594. };
  2595.  
  2596. })( jQuery );
  2597.  
  2598. // Spectrum Colorpicker
  2599. // Greek (gr) localization
  2600. // https://github.com/seballot/spectrum
  2601.  
  2602. (function ( $ ) {
  2603.  
  2604. var localization = $.spectrum.localization["gr"] = {
  2605. cancelText: "Ακύρωση",
  2606. chooseText: "Επιλογή",
  2607. clearText: "Καθαρισμός επιλεγμένου χρώματος",
  2608. noColorSelectedText: "Δεν έχει επιλεχθεί κάποιο χρώμα",
  2609. togglePaletteMoreText: "Περισσότερα",
  2610. togglePaletteLessText: "Λιγότερα"
  2611. };
  2612.  
  2613. })( jQuery );
  2614.  
  2615. // Spectrum Colorpicker
  2616. // Hebrew (he) localization
  2617. // https://github.com/seballot/spectrum
  2618.  
  2619. (function ( $ ) {
  2620.  
  2621. var localization = $.spectrum.localization["he"] = {
  2622. cancelText: "בטל בחירה",
  2623. chooseText: "בחר צבע",
  2624. clearText: "אפס בחירה",
  2625. noColorSelectedText: "לא נבחר צבע",
  2626. togglePaletteMoreText: "עוד צבעים",
  2627. togglePaletteLessText: "פחות צבעים"
  2628. };
  2629.  
  2630. })( jQuery );
  2631.  
  2632. // Spectrum Colorpicker
  2633. // Croatian (hr) localization
  2634. // https://github.com/seballot/spectrum
  2635.  
  2636. (function ( $ ) {
  2637.  
  2638. var localization = $.spectrum.localization["hr"] = {
  2639. cancelText: "Odustani",
  2640. chooseText: "Odaberi",
  2641. clearText: "Poništi odabir",
  2642. noColorSelectedText: "Niti jedna boja nije odabrana",
  2643. togglePaletteMoreText: "Više",
  2644. togglePaletteLessText: "Manje"
  2645. };
  2646.  
  2647. })( jQuery );
  2648.  
  2649. // Spectrum Colorpicker
  2650. // Hungarian (hu) localization
  2651. // https://github.com/seballot/spectrum
  2652.  
  2653. (function ( $ ) {
  2654.  
  2655. var localization = $.spectrum.localization["hu"] = {
  2656. cancelText: "Mégsem",
  2657. chooseText: "Mentés",
  2658. clearText: "A színválasztás visszaállítása",
  2659. noColorSelectedText: "Nincs szín kijelölve",
  2660. togglePaletteMoreText: "Több",
  2661. togglePaletteLessText: "Kevesebb"
  2662. };
  2663.  
  2664. })( jQuery );
  2665.  
  2666. // Spectrum Colorpicker
  2667. // Indonesia/Bahasa Indonesia (id) localization
  2668. // https://github.com/seballot/spectrum
  2669.  
  2670. (function ( $ ) {
  2671.  
  2672. var localization = $.spectrum.localization["id"] = {
  2673. cancelText: "Batal",
  2674. chooseText: "Pilih",
  2675. clearText: "Hapus Pilihan Warna",
  2676. noColorSelectedText: "Warna Tidak Dipilih",
  2677. togglePaletteMoreText: "tambah",
  2678. togglePaletteLessText: "kurangi"
  2679. };
  2680.  
  2681. })( jQuery );
  2682.  
  2683. // Spectrum Colorpicker
  2684. // Italian (it) localization
  2685. // https://github.com/seballot/spectrum
  2686.  
  2687. (function ( $ ) {
  2688.  
  2689. var localization = $.spectrum.localization["it"] = {
  2690. cancelText: "annulla",
  2691. chooseText: "scegli",
  2692. clearText: "Annulla selezione colore",
  2693. noColorSelectedText: "Nessun colore selezionato"
  2694. };
  2695.  
  2696. })( jQuery );
  2697.  
  2698. // Spectrum Colorpicker
  2699. // Japanese (ja) localization
  2700. // https://github.com/seballot/spectrum
  2701.  
  2702. (function ( $ ) {
  2703.  
  2704. var localization = $.spectrum.localization["ja"] = {
  2705. cancelText: "中止",
  2706. chooseText: "選択"
  2707. };
  2708.  
  2709. })( jQuery );
  2710.  
  2711. // Spectrum Colorpicker
  2712. // Korean (ko) localization
  2713. // https://github.com/seballot/spectrum
  2714.  
  2715. (function ( $ ) {
  2716.  
  2717. var localization = $.spectrum.localization["ko"] = {
  2718. cancelText: "취소",
  2719. chooseText: "선택",
  2720. clearText: "선택 초기화",
  2721. noColorSelectedText: "선택된 색상 없음",
  2722. togglePaletteMoreText: "더보기",
  2723. togglePaletteLessText: "줄이기"
  2724. };
  2725.  
  2726. })( jQuery );
  2727.  
  2728. // Spectrum Colorpicker
  2729. // Lithuanian (lt) localization
  2730. // https://github.com/liesislukas
  2731.  
  2732. (function ( $ ) {
  2733.  
  2734. var localization = $.spectrum.localization["lt"] = {
  2735. cancelText: "Atšaukti",
  2736. chooseText: "Pasirinkti",
  2737. clearText: "Išvalyti pasirinkimą",
  2738. noColorSelectedText: "Spalva nepasirinkta",
  2739. togglePaletteMoreText: "Daugiau",
  2740. togglePaletteLessText: "Mažiau"
  2741. };
  2742.  
  2743. })( jQuery );
  2744.  
  2745. // Spectrum Colorpicker
  2746. // Norwegian, Bokmål (nb-no) localization
  2747. // https://github.com/greendimka
  2748.  
  2749. (function ( $ ) {
  2750.  
  2751. var localization = $.spectrum.localization["nb-no"] = {
  2752. cancelText: "Avbryte",
  2753. chooseText: "Velg",
  2754. clearText: "Tilbakestill",
  2755. noColorSelectedText: "Farge er ikke valgt",
  2756. togglePaletteMoreText: "Mer",
  2757. togglePaletteLessText: "Mindre"
  2758. };
  2759.  
  2760. })( jQuery );
  2761.  
  2762. // Spectrum Colorpicker
  2763. // Dutch (nl-nl) localization
  2764. // https://github.com/seballot/spectrum
  2765.  
  2766. (function ( $ ) {
  2767.  
  2768. var localization = $.spectrum.localization["nl-nl"] = {
  2769. cancelText: "Annuleer",
  2770. chooseText: "Kies",
  2771. clearText: "Wis kleur selectie",
  2772. togglePaletteMoreText: 'Meer',
  2773. togglePaletteLessText: 'Minder'
  2774. };
  2775.  
  2776. })( jQuery );
  2777.  
  2778. // Spectrum Colorpicker
  2779. // Polish (pl) localization
  2780. // https://github.com/seballot/spectrum
  2781.  
  2782. (function ( $ ) {
  2783.  
  2784. var localization = $.spectrum.localization["pl"] = {
  2785. cancelText: "Anuluj",
  2786. chooseText: "Wybierz",
  2787. clearText: "Usuń wybór koloru",
  2788. noColorSelectedText: "Nie wybrano koloru",
  2789. togglePaletteMoreText: "Więcej",
  2790. togglePaletteLessText: "Mniej"
  2791. };
  2792.  
  2793. })( jQuery );
  2794.  
  2795. // Spectrum Colorpicker
  2796. // Brazilian (pt-br) localization
  2797. // https://github.com/seballot/spectrum
  2798.  
  2799. (function ( $ ) {
  2800.  
  2801. var localization = $.spectrum.localization["pt-br"] = {
  2802. cancelText: "Cancelar",
  2803. chooseText: "Escolher",
  2804. clearText: "Limpar cor selecionada",
  2805. noColorSelectedText: "Nenhuma cor selecionada",
  2806. togglePaletteMoreText: "Mais",
  2807. togglePaletteLessText: "Menos"
  2808. };
  2809.  
  2810. })( jQuery );
  2811.  
  2812. // Spectrum Colorpicker
  2813. // Portuguese (pt-pt) localization
  2814. // https://github.com/bgrins/spectrum
  2815.  
  2816. (function ( $ ) {
  2817.  
  2818. var localization = $.spectrum.localization["pt-pt"] = {
  2819. cancelText: "Cancelar",
  2820. chooseText: "Escolher",
  2821. clearText: "Limpar cor seleccionada",
  2822. noColorSelectedText: "Nenhuma cor seleccionada",
  2823. togglePaletteMoreText: "Mais",
  2824. togglePaletteLessText: "Menos"
  2825. };
  2826.  
  2827. })( jQuery );
  2828.  
  2829. // Spectrum Colorpicker
  2830. // Russian (ru) localization
  2831. // https://github.com/seballot/spectrum
  2832.  
  2833. (function ( $ ) {
  2834.  
  2835. var localization = $.spectrum.localization["ru"] = {
  2836. cancelText: "Отмена",
  2837. chooseText: "Выбрать",
  2838. clearText: "Сбросить",
  2839. noColorSelectedText: "Цвет не выбран",
  2840. togglePaletteMoreText: "Ещё",
  2841. togglePaletteLessText: "Скрыть"
  2842. };
  2843.  
  2844. })( jQuery );
  2845.  
  2846. // Spectrum Colorpicker
  2847. // Swedish (sv) localization
  2848. // https://github.com/seballot/spectrum
  2849.  
  2850. (function ( $ ) {
  2851.  
  2852. var localization = $.spectrum.localization["sv"] = {
  2853. cancelText: "Avbryt",
  2854. chooseText: "Välj"
  2855. };
  2856.  
  2857. })( jQuery );
  2858.  
  2859. // Spectrum Colorpicker
  2860. // Turkish (tr) localization
  2861. // https://github.com/seballot/spectrum
  2862.  
  2863. (function ( $ ) {
  2864.  
  2865. var localization = $.spectrum.localization["tr"] = {
  2866. cancelText: "iptal",
  2867. chooseText: "tamam"
  2868. };
  2869.  
  2870. })( jQuery );
  2871.  
  2872. // Spectrum Colorpicker
  2873. // Simplified Chinese (zh-cn) localization
  2874. // https://github.com/seballot/spectrum
  2875.  
  2876. (function ( $ ) {
  2877.  
  2878. var localization = $.spectrum.localization["zh-cn"] = {
  2879. cancelText: "取消",
  2880. chooseText: "选择",
  2881. clearText: "清除",
  2882. togglePaletteMoreText: "更多选项",
  2883. togglePaletteLessText: "隐藏",
  2884. noColorSelectedText: "尚未选择任何颜色"
  2885. };
  2886.  
  2887. })( jQuery );
  2888.  
  2889. // Spectrum Colorpicker
  2890. // Traditional Chinese (zh-tw) localization
  2891. // https://github.com/seballot/spectrum
  2892.  
  2893. (function ( $ ) {
  2894.  
  2895. var localization = $.spectrum.localization["zh-tw"] = {
  2896. cancelText: "取消",
  2897. chooseText: "選擇",
  2898. clearText: "清除",
  2899. togglePaletteMoreText: "更多選項",
  2900. togglePaletteLessText: "隱藏",
  2901. noColorSelectedText: "尚未選擇任何顏色"
  2902. };
  2903.  
  2904. })( jQuery );

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址