Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

spectrum.js 95KB

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