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.

index.html 46KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. <title>Spectrum - The No Hassle jQuery Colorpicker</title>
  6. <meta name="description" content="Spectrum is a JavaScript colorpicker plugin using the jQuery framework. It is highly customizable, but can also be used as a simple input type=color polyfill">
  7. <meta name="author" content="Brian Grinstead and Spectrum contributors">
  8. <link rel="stylesheet" type="text/css" href="dist/spectrum.css">
  9. <link rel="stylesheet" type="text/css" href="docs/docs.css">
  10. <link rel="stylesheet" type="text/css" href="docs/highlight/styles/default.css">
  11. <link rel="stylesheet" type="text/css" href="docs/highlight/styles/monokai-sublime.css">
  12. <script type="text/javascript" src="docs/jquery-1.9.1.js"></script>
  13. <script type="text/javascript" src="dist/spectrum.js"></script>
  14. <script type='text/javascript' src='docs/toc.js'></script>
  15. <script type='text/javascript' src='docs/docs.js'></script>
  16. <script type='text/javascript' src='docs/highlight/highlight.pack.js'></script>
  17. </head>
  18. <body>
  19. <div id='toc'></div>
  20. <div class="main-container">
  21. <div id='header'>
  22. <h1><a href='http://seballot.github.com/spectrum'>Spectrum</a></h1>
  23. <h2 class="subtitle"><em>The No Hassle jQuery Colorpicker</em></h2>
  24. <div id='links'>
  25. View the <a href='http://github.com/seballot/spectrum'>Source code</a>.
  26. </div>
  27. </div>
  28. <div id='docs'>
  29. <div id='docs-content'>
  30. <h2>Configurator</h2>
  31. <div class="configurator-container">
  32. <div class="config-section type-selector">
  33. <h5>Type</h5>
  34. <label><input type="radio" name="type" data-rule="type" value="color"><span>Color</span></label>
  35. <label><input type="radio" name="type" data-rule="type" value="text"><span>Text</span></label>
  36. <label><input type="radio" name="type" data-rule="type" value="component"><span>Text + Color</span></label>
  37. <label><input type="radio" name="type" data-rule="type" value="flat"><span>Flat</span></label>
  38. </div>
  39. <div class="config-section palette-options">
  40. <h5>Palette</h5>
  41. <label><input type="checkbox" data-rule='showPalette'><span>Show Palette</span></label>
  42. <label><input type="checkbox" data-rule='showPaletteOnly'><span>Show Palette Only</span></label>
  43. <label><input type="checkbox" data-rule='togglePaletteOnly'><span>Toggle Picker Button</span></label>
  44. <label><input type="checkbox" data-rule='hideAfterPaletteSelect'><span>Hide After Palette Select</span></label>
  45. </div>
  46. <div class="config-section picker-options">
  47. <h5>Picker</h5>
  48. <label><input type="checkbox" data-rule='showInput'><span>Show Input</span></label>
  49. <label><input type="checkbox" data-rule='showInitial'><span>Show Initial Color</span></label>
  50. <label><input type="checkbox" data-rule='showAlpha'><span>Transparency</span></label>
  51. <label><input type="checkbox" data-rule='showButtons'><span>Show Cancel/Submit Buttons</span></label>
  52. <label><input type="checkbox" data-rule='allowEmpty'><span>Clear Button</span></label>
  53. </div>
  54. </div>
  55. <div class="configurator-renderer">
  56. <input id="color-picker" value='#276cb8' />
  57. <pre>&lt;input id="color-picker" value='#276cb8' /&gt;</pre>
  58. <pre id="sp-options">$('#color-picker').spectrum();</pre>
  59. </div>
  60. <h2>Usage</h2>
  61. <h3>CDN</h3>
  62. <pre>
  63. &lt;script src="https://cdn.jsdelivr.net/npm/spectrum-colorpicker2/dist/spectrum.min.js"></script>
  64. &lt;link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/spectrum-colorpicker2/dist/spectrum.min.css">
  65. </pre>
  66. <h3>npm</h3>
  67. <pre>npm install spectrum-colorpicker2</pre>
  68. <h3>Download files</h3>
  69. <a href='https://github.com/seballot/spectrum/releases/latest' class="btn btn-primary">Download Zip</a>
  70. <pre>
  71. &lt;script src="spectrum.min.js"></script>
  72. &lt;link rel="stylesheet" type="text/css" href="spectrum.min.css">
  73. </pre>
  74. <h2 id="options">All Options</h2>
  75. <pre>
  76. $("#picker").spectrum({
  77. color: <strong>tinycolor</strong>,
  78. type: sting, // text, component, color, flat
  79. showInput: bool,
  80. showInitial: bool,
  81. allowEmpty: bool,
  82. showAlpha: bool,
  83. disabled: bool,
  84. localStorageKey: string,
  85. showPalette: bool,
  86. showPaletteOnly: bool,
  87. togglePaletteOnly: bool,
  88. showSelectionPalette: bool,
  89. clickoutFiresChange: bool,
  90. containerClassName: string,
  91. replacerClassName: string,
  92. preferredFormat: string,
  93. maxSelectionSize: int,
  94. palette: [[string]],
  95. selectionPalette: [string],
  96. // specify locale
  97. locale: string,
  98. // or directly change the translations
  99. cancelText: string,
  100. chooseText: string,
  101. togglePaletteMoreText: string,
  102. togglePaletteLessText: string,
  103. clearText: string,
  104. noColorSelectedText: string,
  105. });
  106. </pre>
  107. <div class="alert alert-info">
  108. Tip: options can be specified in an options object in the <code>spectrum</code> initializer, like <code>$(element).spectrum({showAlpha: true })</code> or on the element's markup, like <code>&lt;input data-show-alpha="true" /&gt;</code>.
  109. </div>
  110. <h3 id="options-color">Color</h3>
  111. <div class='option-content'>
  112. <div class='description'>
  113. <p>
  114. The initial color will be set with the <code>color</code> option.
  115. If you don't pass in a color, Spectrum will use the <code>value</code> attribute on the input.
  116. </p>
  117. <p>
  118. The color parsing is based on the <a href='https://github.com/bgrins/TinyColor'>TinyColor</a> plugin.
  119. This should parse any color string you throw at it.
  120. </p>
  121. </p>
  122. </div>
  123. <pre>
  124. &lt;input type='text' class='basic' value='red' /&gt;
  125. &lt;input type='text' class='basic' value='#0f0' /&gt;
  126. &lt;input type='text' class='basic' value='blue' /&gt;
  127. &lt;br /&gt;
  128. &lt;input type='text' class='override' /&gt;
  129. &lt;br /&gt;
  130. &lt;input type='text' class='startEmpty' value='' /&gt;
  131. </pre>
  132. <pre>
  133. &lt;script&gt;
  134. $(".basic").spectrum();
  135. $(".override").spectrum({
  136. color: "yellow"
  137. });
  138. (".startEmpty").spectrum({
  139. allowEmpty: true
  140. });
  141. &lt;/script&gt;
  142. </pre>
  143. <div class='example'>
  144. <input type='text' class='basic' value='red' />
  145. <input type='text' class='basic' value='green' />
  146. <input type='text' class='basic' value='blue' />
  147. <br />
  148. <input type='text' class='override' />
  149. <br />
  150. <input type='text' class='startEmpty' value='' />
  151. </div>
  152. </div>
  153. <h3 id="options-showInput">Show Input</h3>
  154. <div class='option-content'>
  155. <div class='description'>
  156. <p>You can add an input to allow free form typing. The color parsing is very permissive in the allowed strings. See <a href='https://github.com/bgrins/TinyColor'>TinyColor</a> for more details.
  157. </div>
  158. <pre>
  159. $("#showInput").spectrum({
  160. showInput: true
  161. });
  162. $("#showInputWithClear").spectrum({
  163. showInput: true,
  164. allowEmpty:true
  165. });
  166. </pre>
  167. <div class='example'>
  168. <input type='text' name='showInput' id='showInput' />
  169. <br />
  170. <input type='text' name='showInputWithClear' id='showInputWithClear' value='' />
  171. </div>
  172. </div>
  173. <h3 id="options-showAlpha">Show Alpha</h3>
  174. <div class='option-content'>
  175. <div class='description'>
  176. <p>You can allow alpha transparency selection. Check out these examples: </p>
  177. </div>
  178. <pre>
  179. $("#showAlpha").spectrum({
  180. showAlpha: true
  181. });
  182. </pre>
  183. <div class='example'>
  184. <input type='text' name='showAlpha' id='showAlpha' />
  185. </div>
  186. <div class='example'>
  187. <input type='text' name='showAlphaWithInput' id='showAlphaWithInput' />
  188. </div>
  189. </div>
  190. <h3 id="options-disabled">Disabled</h3>
  191. <div class='option-content'>
  192. <div class='description'>
  193. <p>Spectrum can be automatically disabled if you pass in the <code>disabled</code> flag. Additionally, if the input that you initialize spectrum on is disabled, this will be the default value. Note: you <strong>cannot</strong> enable spectrum if the input is disabled (see below).</p>
  194. </div>
  195. <pre>
  196. $("#disabled").spectrum({
  197. disabled: true
  198. });
  199. $("input:disabled").spectrum({
  200. });
  201. </pre>
  202. <div class='example'>
  203. <input type='text' name='disabled' id='disabled' value='lightblue' />
  204. <input type='text' disabled value='lightblue' />
  205. <button id='toggle-disabled' class='btn'>Toggle Disabled</button>
  206. </div>
  207. </div>
  208. <h3 id="options-showPalette">Show Palette</h3>
  209. <div class='option-content'>
  210. <div class='description'>
  211. <p>Spectrum can show a palette below the colorpicker to make it convenient for users to choose from frequently or recently used colors. When the colorpicker is closed, the current color will be added to the palette if it isn't there already. Check it out here: </p>
  212. </div>
  213. <pre>
  214. $("#showPalette").spectrum({
  215. showPalette: true,
  216. palette: [
  217. ['black', 'white', 'blanchedalmond'],
  218. ['rgb(255, 128, 0);', 'hsv 100 70 50', 'lightyellow']
  219. ]
  220. });
  221. </pre>
  222. <div class='example'>
  223. <input type='text' name='showPalette' id='showPalette' value='lightblue' />
  224. <em data-label-for="showPalette" class='em-label'></em>
  225. </div>
  226. </div>
  227. <h3 id="options-showPaletteOnly">Show Palette Only</h3>
  228. <div class='option-content'>
  229. <div class='description'>
  230. <p>If you'd like, spectrum can show the palettes you specify, and nothing else.</p>
  231. </div>
  232. <pre>
  233. $("#showPaletteOnly").spectrum({
  234. showPaletteOnly: true,
  235. showPalette:true,
  236. color: 'blanchedalmond',
  237. palette: [
  238. ['black', 'white', 'blanchedalmond',
  239. 'rgb(255, 128, 0);', 'hsv 100 70 50'],
  240. ['red', 'yellow', 'green', 'blue', 'violet']
  241. ]
  242. });
  243. </pre>
  244. <div class='example'>
  245. <input type='text' name='showPaletteOnly' id='showPaletteOnly' />
  246. <em data-label-for="showPaletteOnly" class='em-label'></em>
  247. </div>
  248. </div>
  249. <h3 id="options-togglePaletteOnly">Toggle Palette Only</h3>
  250. <div class='option-content'>
  251. <div class='description'>
  252. <p>
  253. Spectrum can show a button to toggle the colorpicker next to the palette. This way, the user can choose from a limited number of colors in the palette, but still be able to pick a color that's not in the palette.<br />
  254. The default value for <code>togglePaletteOnly</code> is FALSE. Set it to TRUE to enable the Toggle button.<br /><br />
  255. You can also change the text on the Toggle Button with the options <code>togglePaletteMoreText</code> (default is "more") and <code>togglePaletteLessText</code> (default is "less").
  256. </p>
  257. </div>
  258. <pre>
  259. $("#togglePaletteOnly").spectrum({
  260. showPaletteOnly: true,
  261. togglePaletteOnly: true,
  262. togglePaletteMoreText: 'more',
  263. togglePaletteLessText: 'less',
  264. color: 'blanchedalmond',
  265. palette: [
  266. ["#000","#444","#666","#999","#ccc","#eee","#f3f3f3","#fff"],
  267. ["#f00","#f90","#ff0","#0f0","#0ff","#00f","#90f","#f0f"],
  268. ["#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#cfe2f3","#d9d2e9","#ead1dc"],
  269. ["#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#9fc5e8","#b4a7d6","#d5a6bd"],
  270. ["#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6fa8dc","#8e7cc3","#c27ba0"],
  271. ["#c00","#e69138","#f1c232","#6aa84f","#45818e","#3d85c6","#674ea7","#a64d79"],
  272. ["#900","#b45f06","#bf9000","#38761d","#134f5c","#0b5394","#351c75","#741b47"],
  273. ["#600","#783f04","#7f6000","#274e13","#0c343d","#073763","#20124d","#4c1130"]
  274. ]
  275. });
  276. </pre>
  277. <div class='example'>
  278. <input type='text' name='togglePaletteOnly' id='togglePaletteOnly' />
  279. </div>
  280. </div>
  281. <h3 id="options-showSelectionPalette">Show Selection Palette</h3>
  282. <div class='option-content'>
  283. <div class='description'>
  284. <p>Spectrum can keep track of what has been selected by the user with the <code>showSelectionPalette</code> option.</p>
  285. <p>If the <code>localStorageKey</code> option is defined, the selection will be saved in the browser's localStorage object</p>
  286. </div>
  287. <pre>
  288. $("#showSelectionPalette").spectrum({
  289. showPalette: true,
  290. showSelectionPalette: true, // true by default
  291. palette: [ ]
  292. });
  293. $("#showSelectionPaletteStorage").spectrum({
  294. showPalette: true,
  295. showSelectionPalette: true,
  296. palette: [ ],
  297. localStorageKey: "spectrum.homepage", // Any Spectrum with the same string will share selection
  298. });
  299. </pre>
  300. <div class='example'>
  301. <span class='label label-info'>This colorpicker will store what you pick:</span><br /><br />
  302. <input type='text' name='showSelectionPalette' id='showSelectionPalette' value='lightblue' /><br /><br />
  303. <span class='label label-info'>Try switching between the two colorpickers or reloading your page, the chosen colors are always available:</span><br /><br />
  304. <input type='text' name='showSelectionPaletteStorage' id='showSelectionPaletteStorage' value='lightblue' />
  305. <input type='text' name='showSelectionPaletteStorage2' id='showSelectionPaletteStorage2' value='pink' />
  306. </div>
  307. </div>
  308. <h3 id="options-selectionPalette">Selection Palette</h3>
  309. <div class='option-content'>
  310. <div class='description'>
  311. <p>The default values inside of the selection palette. Make sure that <a href="#options-showSelectionPalette">showSelectionPalette</a> and <a href="#options-showPalette">showPalette</a> are both enabled.</p>
  312. <p>If a <code>localStorageKey</code> is defined, then this value will be overwritten by it.</p>
  313. </div>
  314. <pre>
  315. $("#selectionPalette").spectrum({
  316. showPalette: true,
  317. palette: [ ],
  318. showSelectionPalette: true, // true by default
  319. selectionPalette: ["red", "green", "blue"]
  320. });
  321. </pre>
  322. <div class='example'>
  323. <span class='label label-info'>This colorpicker has default values in the selection palette:</span><br /><br />
  324. <input type='text' name='selectionPalette' id='selectionPalette' value='orange' />
  325. </div>
  326. </div>
  327. <h3 id="options-maxSelectionSize">Max Selection Size</h3>
  328. <div class='option-content'>
  329. <div class='description'>
  330. <p>This is how many elements are allowed in the <a href="#options-selectionPalette">selectionPallete</a> at once.</p>
  331. <p>Elements will be removed from the palette in first in - first out order if this limit is reached.</p>
  332. </div>
  333. <pre>
  334. $("#maxSelectionSize").spectrum({
  335. showPalette: true,
  336. palette: [ ],
  337. showSelectionPalette: true, // true by default
  338. selectionPalette: ["red", "green", "blue"],
  339. maxSelectionSize: 2
  340. });
  341. </pre>
  342. <div class='example'>
  343. <span class='label label-info'>This colorpicker starts removing selection palette colors older than 2:</span><br /><br />
  344. <input type='text' name='maxSelectionSize' id='maxSelectionSize' value='red' />
  345. </div>
  346. </div>
  347. <h3 id="options-hideAfterPaletteSelect">Hide After Palette Select</h3>
  348. <div class='option-content'>
  349. <div class='description'>
  350. <p>You can have the colorpicker automatically hide after a palette color is selected.</p>
  351. </div>
  352. <pre>
  353. $("#hideAfterPaletteSelect").spectrum({
  354. showPaletteOnly: true,
  355. showPalette:true,
  356. hideAfterPaletteSelect:true,
  357. color: 'blanchedalmond',
  358. palette: [
  359. ['black', 'white', 'blanchedalmond',
  360. 'rgb(255, 128, 0);', 'hsv 100 70 50'],
  361. ['red', 'yellow', 'green', 'blue', 'violet']
  362. ]
  363. });
  364. </pre>
  365. <div class='example'>
  366. <input type='text' name='hideAfterPaletteSelect' id='hideAfterPaletteSelect' />
  367. <em data-label-for="hideAfterPaletteSelect" class='em-label'></em>
  368. </div>
  369. </div>
  370. <h3 id="options-clickoutFiresChange">Clickout Fires Change</h3>
  371. <div class='option-content'>
  372. <div class='description'>
  373. <p>
  374. When clicking outside of the colorpicker, you can force it to fire a <code>change</code> event rather than having it revert the change. This is <code>true</code> by default.
  375. </p>
  376. </div>
  377. <pre>
  378. $("#clickoutFiresChange").spectrum({
  379. clickoutFiresChange: true
  380. });
  381. $("#clickoutDoesntChange").spectrum({
  382. clickoutFiresChange: false
  383. });
  384. </pre>
  385. <div class='example'>
  386. <input type='text' name='clickoutFiresChange' id='clickoutFiresChange' value='goldenrod' />
  387. <input type='text' name='clickoutDoesntFireChange' id='clickoutDoesntFireChange' value='goldenrod' />
  388. </div>
  389. </div>
  390. <h3 id="options-showInitial">Show Initial</h3>
  391. <div class='option-content'>
  392. <div class='description'>
  393. <p>
  394. Spectrum can show the color that was initially set when opening.
  395. This provides an easy way to click back to what was set when opened.
  396. </p>
  397. </div>
  398. <pre>
  399. $("#showInitial").spectrum({
  400. showInitial: true
  401. });
  402. </pre>
  403. <div class='example'>
  404. <input type='text' name='showInitial' id='showInitial' value='goldenrod' />
  405. </div>
  406. </div>
  407. <h3 id="options-showInputAndInitial">Show Input and Initial</h3>
  408. <div class='option-content'>
  409. <div class='description'>
  410. <p>If you specify both the <code>showInput</code> and <code>showInitial</code> options, the CSS keeps things in order by wrapping the buttons to the bottom row, and shrinking the input. <em>Note: this is all customizable via CSS.</em></p>
  411. </div>
  412. <pre>
  413. $("#showInputAndInitial").spectrum({
  414. showInitial: true,
  415. showInput: true
  416. });
  417. </pre>
  418. <div class='example'>
  419. <input type='text' name='showInputAndInitial' id='showInputAndInitial' value='goldenrod' />
  420. </div>
  421. </div>
  422. <h3>Show Input, Initial, and Clear</h3>
  423. <div class='option-content'>
  424. <div class='description'>
  425. <p>If you specify both the <code>showInput</code>, <code>showInitial</code>, and <code>allowEmpty</code> options, the CSS keeps things in order by wrapping the buttons to the bottom row, and shrinking the input. <em>Note: this is all customizable via CSS.</em></p>
  426. </div>
  427. <pre>
  428. $("#showInputInitialClear").spectrum({
  429. allowEmpty:true,
  430. showInitial: true,
  431. showInput: true
  432. });
  433. </pre>
  434. <div class='example'>
  435. <input type='text' name='showInputInitialClear' id='showInputInitialClear' value='' />
  436. </div>
  437. </div>
  438. <h3 id="options-buttonText">Internationalisation</h3>
  439. <div class='option-content'>
  440. <div class='description'>
  441. <p>Specify `locale` so choose a language. If not specified, spectrum will try to use the navigator language. Alternatly, you can directly specify translated text with <code>cancelText</code>, <code>chooseText</code>, <code>togglePaletteMoreText</code>, <code>togglePaletteLessText</code>, <code>clearText</code> and <code>noColorSelectedText</code> properties.</p>
  442. </div>
  443. <pre>
  444. $("#buttonText").spectrum({
  445. locale: "fr"
  446. chooseText: "OK!" // use 'OK' instead of 'Valider'
  447. });
  448. </pre>
  449. <div class='example'>
  450. <input type='text' name='buttonText' id='buttonText' value='orangered' />
  451. </div>
  452. </div>
  453. <h3 id="options-showButtons">Show Buttons</h3>
  454. <div class='option-content'>
  455. <div class='description'>
  456. <p>
  457. You can show or hide the buttons using the <code>showButtons</code> property.
  458. If there are no buttons, the behavior will be to fire the `change` event (and update the original input) when the picker is closed.
  459. </p>
  460. </div>
  461. <pre>
  462. $("#hideButtons").spectrum({
  463. showButtons: false
  464. });
  465. </pre>
  466. <div class='example'>
  467. <input type='text' name='hideButtons' id='hideButtons' value='orangered' />
  468. </div>
  469. </div>
  470. <h3 id="options-containerClassName">Container Class Name</h3>
  471. <div class='option-content'>
  472. <div class='description'>
  473. <p>
  474. You can add an additional class name to the just the container element using the <code>containerClassName</code> property.
  475. </p>
  476. </div>
  477. <pre>
  478. $("#containerClassName").spectrum({
  479. containerClassName: 'awesome'
  480. });
  481. </pre>
  482. <pre>
  483. .awesome {
  484. background: purple;
  485. }
  486. </pre>
  487. <style type='text/css'>
  488. .awesome {
  489. background: purple;
  490. }
  491. </style>
  492. <div class='example'>
  493. <input type='text' name='containerClassName' id='containerClassName' value='orangered' />
  494. </div>
  495. </div>
  496. <h3 id="options-replacerClassName">Replacer Class Name</h3>
  497. <div class='option-content'>
  498. <div class='description'>
  499. <p>
  500. You can add an additional class name to just the replacer element using the <code>replacerClassName</code> property.
  501. </p>
  502. </div>
  503. <pre>
  504. $("#replacerClassName").spectrum({
  505. replacerClassName: 'awesome'
  506. });
  507. </pre>
  508. <pre>
  509. .awesome {
  510. background: purple;
  511. }
  512. </pre>
  513. <style type='text/css'>
  514. .awesome {
  515. background: purple;
  516. }
  517. </style>
  518. <div class='example'>
  519. <input type='text' name='replacerClassName' id='replacerClassName' value='orangered' />
  520. </div>
  521. </div>
  522. <h3 id="options-preferredFormat">Preferred Format</h3>
  523. <div class='option-content'>
  524. <div class='description'>
  525. <p>You can set the format that is displayed in the text box.</p>
  526. <p>This will also change the format that is displayed in the titles from the palette swatches.</p>
  527. </div>
  528. <pre>
  529. $("#preferredHex").spectrum({
  530. preferredFormat: "hex",
  531. showInput: true,
  532. showPalette: true,
  533. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  534. });
  535. $("#preferredHex3").spectrum({
  536. preferredFormat: "hex3",
  537. showInput: true,
  538. showPalette: true,
  539. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  540. });
  541. $("#preferredHsl").spectrum({
  542. preferredFormat: "hsl",
  543. showInput: true,
  544. showPalette: true,
  545. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  546. });
  547. $("#preferredRgb").spectrum({
  548. preferredFormat: "rgb",
  549. showInput: true,
  550. showPalette: true,
  551. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  552. });
  553. $("#preferredName").spectrum({
  554. preferredFormat: "name",
  555. showInput: true,
  556. showPalette: true,
  557. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  558. });
  559. $("#preferredNone").spectrum({
  560. showInput: true,
  561. showPalette: true,
  562. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  563. });
  564. </pre>
  565. <div class='example'>
  566. <div class='alert alert-info'>Hex</div>
  567. <input type='text' name='preferredHex' id='preferredHex' value='orangered' />
  568. <div class='alert alert-info'>Hex (3 Characters If Possible)</div>
  569. <input type='text' name='preferredHex3' id='preferredHex3' value='orangered' />
  570. <div class='alert alert-info'>Hsl</div>
  571. <input type='text' name='preferredHsl' id='preferredHsl' value='orangered' />
  572. <div class='alert alert-info'>Rgb</div>
  573. <input type='text' name='preferredRgb' id='preferredRgb' value='orangered' />
  574. <div class='alert alert-info'>Name (Falls back to hex)</div>
  575. <input type='text' name='preferredName' id='preferredName' value='orangered' />
  576. <div class='alert alert-info'>None (Depends on input - try changing formats with the text box)</div>
  577. <input type='text' name='preferredNone' id='preferredNone' value='orangered' />
  578. </div>
  579. </div>
  580. <h3 id="options-appendTo">appendTo</h3>
  581. <div class='option-content'>
  582. <div class='description'>
  583. <p>You can choose which element the colorpicker container is appended to (default is <code>"body"</code>). This can be any valid object taken into the jQuery <a href="https://api.jquery.com/appendTo/">appendTo</a> function.</p>
  584. <p>Changing this can help resolve issues with opening the colorpicker in a modal dialog or fixed position container, for instance.</p>
  585. </div>
  586. </div>
  587. <h2 id="events">Events</h2>
  588. <pre>
  589. // Events can be bound in the intialization process as options:
  590. $("#picker").spectrum({
  591. move: function(tinycolor) { },
  592. show: function(tinycolor) { },
  593. hide: function(tinycolor) { },
  594. beforeShow: function(tinycolor) { },
  595. });
  596. // Alternatively, they can be added as an event listener:
  597. $("#picker").on('move.spectrum', function(e, tinycolor) { });
  598. $("#picker").on('show.spectrum', function(e, tinycolor) { });
  599. $("#picker").on('hide.spectrum', function(e, tinycolor) { });
  600. $("#picker").on('beforeShow.spectrum', function(e, tinycolor) { });
  601. </pre>
  602. <h3 id="events-change">change</h3>
  603. <div class='option-content'>
  604. <div class='description'>
  605. <p>Called as the original input changes. Only happens when the input is closed or the 'Choose' button is clicked.</p>
  606. </div>
  607. <pre>
  608. change: function(color) {
  609. color.toHexString(); // #ff0000
  610. }
  611. </pre>
  612. <div class='example'>
  613. <input type='text' value='blanchedalmond' name='changeOnMoveNo' id='changeOnMoveNo' />
  614. <em data-label-for="changeOnMoveNo" class='em-label'></em>
  615. </div>
  616. </div>
  617. <h3 id="events-move">move</h3>
  618. <div class='option-content'>
  619. <div class='description'>
  620. <p>Called as the user moves around within the colorpicker</p>
  621. </div>
  622. <pre>
  623. move: function(color) {
  624. color.toHexString(); // #ff0000
  625. }
  626. </pre>
  627. <div class='example'>
  628. <input type='text' value='blanchedalmond' name='changeOnMove' id='changeOnMove' />
  629. <em data-label-for="changeOnMove" class='em-label'></em>
  630. </div>
  631. </div>
  632. <h3 id="events-hide">hide</h3>
  633. <div class='option-content'>
  634. <div class='description'>
  635. <p>
  636. Called after the colorpicker is hidden.
  637. This happens when clicking outside of the picker while it is open.
  638. Note, when any colorpicker on the page is shown it will hide any that are already open.
  639. This event is ignored on a flat colorpicker.
  640. </p>
  641. </div>
  642. <pre>
  643. hide: function(color) {
  644. color.toHexString(); // #ff0000
  645. }
  646. </pre>
  647. <div class='example'>
  648. <input type='text' value='blanchedalmond' name='eventhide' id='eventhide' />
  649. <em id='eventhideLabel' class='em-label'></em>
  650. </div>
  651. </div>
  652. <h3 id="events-show">show</h3>
  653. <div class='option-content'>
  654. <div class='description'>
  655. <p>
  656. Called after the colorpicker is opened.
  657. This is ignored on a flat colorpicker.
  658. Note, when any colorpicker on the page is shown it will hide any that are already open.
  659. </p>
  660. </div>
  661. <pre>
  662. show: function(color) {
  663. color.toHexString(); // #ff0000
  664. }
  665. </pre>
  666. <div class='example'>
  667. <input type='text' value='blanchedalmond' name='eventshow' id='eventshow' />
  668. <em id='eventshowLabel' class='em-label'></em>
  669. </div>
  670. </div>
  671. <h3 id="events-beforeShow">beforeShow</h3>
  672. <div class='option-content'>
  673. <div class='description'>
  674. <p>
  675. You can prevent the colorpicker from showing up if you return false in the beforeShow event.
  676. This event is ignored on a flat colorpicker.
  677. </p>
  678. </div>
  679. <pre>
  680. beforeShow: function(color) {
  681. return false; // Will never show up
  682. }
  683. </pre>
  684. <div class='example'>
  685. <input type='text' value='blanchedalmond' name='beforeShow' id='beforeShow' />
  686. </div>
  687. </div>
  688. <h3 id="events-dragstart">dragstart</h3>
  689. <div class='option-content'>
  690. <div class='description'>
  691. <p>
  692. Called at the beginning of a drag event on either
  693. hue slider, alpha slider, or main color picker areas
  694. </p>
  695. </div>
  696. <pre>
  697. $(element).on("dragstart.spectrum", function(e, color) {
  698. color.toHexString(); // #ff0000
  699. });
  700. </pre>
  701. <div class='example'>
  702. <input type='text' value='blanchedalmond' name='eventdragstart' id='eventdragstart' />
  703. <em id='eventdragstartLabel' class='em-label'></em>
  704. </div>
  705. </div>
  706. <h3 id="events-dragstop">dragstop</h3>
  707. <div class='option-content'>
  708. <div class='description'>
  709. <p>
  710. Called at the end of a drag event on either
  711. hue slider, alpha slider, or main color picker areas
  712. </p>
  713. </div>
  714. <pre>
  715. $(element).on("dragstop.spectrum", function(e, color) {
  716. color.toHexString(); // #ff0000
  717. });
  718. </pre>
  719. <div class='example'>
  720. <input type='text' value='blanchedalmond' name='eventdragstop' id='eventdragstop' />
  721. <em id='eventdragstopLabel' class='em-label'></em>
  722. </div>
  723. </div>
  724. <h2 id="methods">Methods</h2>
  725. <pre>
  726. $("#picker").spectrum("show");
  727. $("#picker").spectrum("hide");
  728. $("#picker").spectrum("toggle");
  729. $("#picker").spectrum("get");
  730. $("#picker").spectrum("set", colorString);
  731. $("#picker").spectrum("container");
  732. $("#picker").spectrum("reflow");
  733. $("#picker").spectrum("destroy");
  734. $("#picker").spectrum("enable");
  735. $("#picker").spectrum("disable");
  736. $("#picker").spectrum("option", optionName);
  737. $("#picker").spectrum("option", optionName, newOptionValue);
  738. </pre>
  739. <h3 id="methods-show">show</h3>
  740. <div class='option-content'>
  741. <div class='description'>
  742. <p>
  743. Shows the colorpicker.
  744. </p>
  745. </div>
  746. </div>
  747. <h3 id="methods-hide">hide</h3>
  748. <div class='option-content'>
  749. <div class='description'>
  750. <p>
  751. Hides the colorpicker.
  752. </p>
  753. </div>
  754. </div>
  755. <h3 id="methods-toggle">toggle</h3>
  756. <div class='option-content'>
  757. <div class='description'>
  758. <p>
  759. Toggles the colorpicker.
  760. </p>
  761. <p class="warning">
  762. <b>Warning:</b> If you are calling toggle from a click handler, make sure you <code>return false</code> to prevent the colorpicker from immediately hiding after it is toggled.
  763. </p>
  764. </div>
  765. <pre>
  766. $("#btn-toggle").click(function() {
  767. $("#toggle").spectrum("toggle");
  768. return false;
  769. });
  770. </pre>
  771. <div class='example'>
  772. <input type='text' value='blanchedalmond' name='toggle' id='toggle' />
  773. <button id='btn-toggle'>Toggle</button>
  774. </div>
  775. </div>
  776. <h3 id="methods-get">get</h3>
  777. <div class='option-content'>
  778. <div class='description'>
  779. <p>
  780. Gets the current value from the colorpicker.
  781. </p>
  782. </div>
  783. </div>
  784. <h3 id="methods-set">set</h3>
  785. <div class='option-content'>
  786. <div class='description'>
  787. <p>
  788. Setting the colorpicker programmatically will update the original input.
  789. </p>
  790. <p>
  791. Note: this will <strong>not</strong> fire the <code>change</code> event,
  792. to prevent infinite loops from calling <code>set</code> from within <code>change</code>.
  793. </p>
  794. </div>
  795. <pre>
  796. &lt;input type='text' value='blanchedalmond' name='triggerSet' id='triggerSet' /&gt;
  797. &lt;input type='text' placeholder='Enter A Color' id='enterAColor' /&gt;
  798. &lt;button id='btnEnterAColor'&gt;Trigger Set&lt;/button&gt;
  799. &lt;script&gt;
  800. $("#triggerSet").spectrum();
  801. // Show the original input to demonstrate the value changing when calling `set`
  802. $("#triggerSet").show();
  803. $("#btnEnterAColor").click(function() {
  804. $("#triggerSet").spectrum("set", $("#enterAColor").val());
  805. });
  806. &lt;/script&gt;
  807. </pre>
  808. <div class='example'>
  809. <input type='text' value='blanchedalmond' name='triggerSet' id='triggerSet' /><br /><br />
  810. <input type='text' placeholder='Enter A Color' id='enterAColor' /><button id='btnEnterAColor'>Trigger Set</button>
  811. </div>
  812. </div>
  813. <h3 id="methods-container">container</h3>
  814. <div class='option-content'>
  815. <div class='description'>
  816. <p>
  817. Retrieves the container element of the colorpicker, in case you want to manaully position it or do other things.
  818. </p>
  819. </div>
  820. </div>
  821. <h3 id="methods-reflow">reflow</h3>
  822. <div class='option-content'>
  823. <div class='description'>
  824. <p>
  825. Resets the positioning of the container element. This could be used was hidden when initialized, or if the colorpicker is inside of a moving area.
  826. </p>
  827. </div>
  828. </div>
  829. <h3 id="methods-destroy">destroy</h3>
  830. <div class='option-content'>
  831. <div class='description'>
  832. <p>
  833. Removes the colorpicker functionality and restores the element to its original state.
  834. </p>
  835. </div>
  836. </div>
  837. <h3 id="methods-enable">enable</h3>
  838. <div class='option-content'>
  839. <div class='description'>
  840. <p>
  841. Allows selection of the colorpicker component. If it is already enabled, this method does nothing.
  842. </p>
  843. <p>
  844. Additionally, this will cause the original (now hidden) input to be set as disabled.
  845. </p>
  846. </div>
  847. </div>
  848. <h3 id="methods-disable">disable</h3>
  849. <div class='option-content'>
  850. <div class='description'>
  851. <p>
  852. Disables selection of the colorpicker component. Adds the <code>sp-disabled</code> class onto the replacer element. If it is already disabled, this method does nothing.
  853. </p>
  854. <p>
  855. Additionally, this will remove the <code>disabled</code> property on the original (now hidden).
  856. </p>
  857. </div>
  858. </div>
  859. <h3 id="methods-option">option</h3>
  860. <div class='option-content'>
  861. <div class='description'>
  862. <p>
  863. Calling <code>option</code> with an option name will return the current value of that option. So, for example:
  864. </p>
  865. <pre>
  866. $("input").spectrum({
  867. showInput: true
  868. });
  869. $("input").spectrum("option", "showInput"); // true
  870. </pre>
  871. <p>
  872. Calling <code>option</code> with an option name and an option value will set the option to the new value.
  873. </p>
  874. <pre>
  875. $("input").spectrum({
  876. showInput: true
  877. });
  878. $("input").spectrum("option", "showInput", false);
  879. $("input").spectrum("option", "showInput"); // false
  880. </pre>
  881. </div>
  882. </div>
  883. <h2 id="details">Other</h2>
  884. <h3 id="skinning-nonInput" class='point'>Non-input elements</h3>
  885. <p>
  886. You can use any element you would like to trigger the colorpicker: <a href='#' id='openWithLink'>Click me to open a colorpicker</a>, though it is strongly recommended to stick with <code>&lt;input&gt;</code> tags.
  887. </p>
  888. <h3 id="modes-input" class='point'>input[type=color]</h3>
  889. <p>
  890. If you just want to provide a polyfill for the native color input,
  891. the easiest way is to create an input with the type of color.
  892. Once a user's browser supports a native color control, it will opt to use their native control instead.
  893. </p>
  894. <p>
  895. <strong>Unlike the other modes, your value must be a 6 character hex value starting with a '#'.</strong> Why? Because the spec <a href='http://dev.w3.org/html5/markup/input.color.html#input.color.attrs.value'>says so</a>, that's why.
  896. </p>
  897. <pre id='code-subheading'>
  898. &lt;input type='color' name='color' /&gt;
  899. &lt;input type='color' name='color2' value='#3355cc' /&gt;
  900. </pre>
  901. <div class='example'>
  902. <form method="get">
  903. <input type='color' name='color' />
  904. <input type='color' name='color2' value='#3355cc' />
  905. <input type='color' name='color3' value='#000000' />
  906. </form>
  907. </div>
  908. <p>
  909. <strong>That's it!</strong>
  910. The field will degrade to a text input if the user does not have JavaScript enabled,
  911. so that they will still be able to manually enter a color. You don't need to add a single line of code.
  912. </p>
  913. <h3 id="details-browserSupport" class='point'>Browser Support</h3>
  914. <p>
  915. I wanted this to work in the latest and greatest browsers, but also target backwords compatibility and <strong>mobile support</strong>.
  916. Here are the currently supported browers:
  917. <ul>
  918. <li>IE <small>6+</small></li>
  919. <li>Chrome <small>4+</small></li>
  920. <li>Firefox <small>3.6+</small></li>
  921. <li>Safari <small>4+</small></li>
  922. <li>Opera <small>11.1+</small></li>
  923. <li>iOS</li>
  924. </ul>
  925. <h3 id="details-ieImplementation" class='point'>IE Implementation</h3>
  926. <p>
  927. IE Support is provided using
  928. <a href='http://msdn.microsoft.com/en-us/library/ms532997(v=vs.85).aspx'>proprietary filters</a>.
  929. Other browsers use CSS gradients.
  930. </p>
  931. <h3 id="details-acceptedColorInputs" class='point'>Accepted Color Inputs</h3>
  932. <p>
  933. Spectrum will use the color passed in to initialize. If there is no color passed in,
  934. it will try to parse a color based on the <code>value</code> of the input. The color parsing is based on the <a href='https://github.com/bgrins/TinyColor'>TinyColor</a> plugin, and accepts many forms of input:
  935. </p>
  936. <pre>
  937. red
  938. #fff
  939. fff
  940. #ffffff
  941. ffffff
  942. rgb(255, 0, 0)
  943. rgb 255 0 0
  944. hsl(0, 100, 50)
  945. hsl(0, 100%, 50%)
  946. hsl 0 100 50
  947. hsl 0 100% 50%
  948. hsv(0, 100%, 100%)
  949. hsv(0, 100, 100)
  950. hsv 0 100% 100%
  951. hsv 0 100 100
  952. </pre>
  953. <p>It also provides the following forms of output:</p>
  954. <pre>
  955. var t = $("#element").spectrum("get");
  956. t.toHex() // "ff0000"
  957. t.toHexString() // "#ff0000"
  958. t.toRgb() // {"r":255,"g":0,"b":0}
  959. t.toRgbString() // "rgb(255, 0, 0)"
  960. t.toHsv() // {"h":0,"s":1,"v":1}
  961. t.toHsvString() // "hsv(0, 100%, 100%)"
  962. t.toHsl() // {"h":0,"s":1,"l":0.5}
  963. t.toHslString() // "hsl(0, 100%, 50%)"
  964. t.toName() // "red"
  965. </pre>
  966. <div class='footer'>
  967. <h2>Share</h2>
  968. <p>
  969. If you've made it this far, please share one of these links to help others find this project!
  970. <br />
  971. <a href='https://seballot.github.io/spectrum'>JavaScript Colorpicker</a> |
  972. <a href='https://seballot.github.io/spectrum'>jQuery Colorpicker</a> |
  973. <a href='https://seballot.github.io/spectrum'>Mobile Colorpicker</a> |
  974. <a href='https://seballot.github.io/spectrum'>Spectrum colorpicker</a>
  975. </p>
  976. <p>
  977. Thanks to all the <a href='https://github.com/seballot/spectrum/graphs/contributors'>spectrum contributors</a> for committing code, documentation, and <a href='https://github.com/seballot/spectrum/tree/master/i18n'>translations</a>.
  978. </p>
  979. </div>
  980. </div>
  981. </div>
  982. </div>
  983. </body>
  984. </html>