docs.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. function updateBorders(color) {
  2. var hexColor = "transparent";
  3. if(color) {
  4. hexColor = color.toHexString();
  5. }
  6. $("#docs-content").css("border-color", hexColor);
  7. }
  8. $(function() {
  9. $("#full").spectrum({
  10. allowEmpty:true,
  11. color: "#ECC",
  12. showInput: true,
  13. containerClassName: "full-spectrum",
  14. showInitial: true,
  15. showPalette: true,
  16. showSelectionPalette: true,
  17. showAlpha: true,
  18. maxPaletteSize: 10,
  19. preferredFormat: "hex",
  20. localStorageKey: "spectrum.demo",
  21. move: function (color) {
  22. updateBorders(color);
  23. },
  24. show: function () {
  25. },
  26. beforeShow: function () {
  27. },
  28. hide: function (color) {
  29. updateBorders(color);
  30. },
  31. palette: [
  32. ["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", /*"rgb(153, 153, 153)","rgb(183, 183, 183)",*/
  33. "rgb(204, 204, 204)", "rgb(217, 217, 217)", /*"rgb(239, 239, 239)", "rgb(243, 243, 243)",*/ "rgb(255, 255, 255)"],
  34. ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)",
  35. "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"],
  36. ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)",
  37. "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)",
  38. "rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)",
  39. "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)",
  40. "rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)",
  41. "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)",
  42. "rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)",
  43. "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)",
  44. /*"rgb(133, 32, 12)", "rgb(153, 0, 0)", "rgb(180, 95, 6)", "rgb(191, 144, 0)", "rgb(56, 118, 29)",
  45. "rgb(19, 79, 92)", "rgb(17, 85, 204)", "rgb(11, 83, 148)", "rgb(53, 28, 117)", "rgb(116, 27, 71)",*/
  46. "rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)",
  47. "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"]
  48. ]
  49. });
  50. $("#hideButtons").spectrum({
  51. showButtons: false,
  52. change: updateBorders
  53. });
  54. var isDisabled = true;
  55. $("#toggle-disabled").click(function() {
  56. if (isDisabled) {
  57. $("#disabled").spectrum("enable");
  58. }
  59. else {
  60. $("#disabled").spectrum("disable");
  61. }
  62. isDisabled = !isDisabled;
  63. return false;
  64. });
  65. $("input:disabled").spectrum({
  66. });
  67. $("#disabled").spectrum({
  68. disabled: true
  69. });
  70. $("#pick1").spectrum({
  71. flat: true,
  72. change: function(color) {
  73. var hsv = color.toHsv();
  74. var rgb = color.toRgbString();
  75. var hex = color.toHexString();
  76. //console.log("callback",color.toHslString(), color.toHsl().h, color.toHsl().s, color.toHsl().l)
  77. $("#docs-content").css({
  78. 'background-color': color.toRgbString()
  79. }).toggleClass("dark", hsv.v < .5);
  80. $("#switch-current-rgb").text(rgb);
  81. $("#switch-current-hex").text(hex);
  82. },
  83. show: function() {
  84. },
  85. hide: function() {
  86. },
  87. showInput: true,
  88. showPalette: true,
  89. palette: ['white', '#306', '#c5c88d', '#ac5c5c', '#344660']
  90. });
  91. $("#collapsed").spectrum({
  92. color: "#dd3333",
  93. change: updateBorders,
  94. show: function() {
  95. },
  96. hide: function() {
  97. }
  98. });
  99. $("#flat").spectrum({
  100. flat: true,
  101. showInput: true,
  102. move: updateBorders
  103. });
  104. $("#flatClearable").spectrum({
  105. flat: true,
  106. move: updateBorders,
  107. change: updateBorders,
  108. allowEmpty:true,
  109. showInput: true
  110. });
  111. $("#showInput").spectrum({
  112. color: "#dd33dd",
  113. showInput: true,
  114. change: updateBorders,
  115. show: function() {
  116. },
  117. hide: function() {
  118. }
  119. });
  120. $("#showAlpha").spectrum({
  121. color: "rgba(255, 128, 0, .5)",
  122. showAlpha: true,
  123. change: updateBorders
  124. });
  125. $("#showAlphaWithInput").spectrum({
  126. color: "rgba(255, 128, 0, .5)",
  127. showAlpha: true,
  128. showInput: true,
  129. showPalette: true,
  130. palette: [
  131. ["rgba(255, 128, 0, .9)", "rgba(255, 128, 0, .5)"],
  132. ["red", "green", "blue"],
  133. ["hsla(25, 50, 75, .5)", "rgba(100, .5, .5, .8)"]
  134. ],
  135. change: updateBorders
  136. });
  137. $("#showAlphaWithInputAndEmpty").spectrum({
  138. color: "rgba(255, 128, 0, .5)",
  139. allowEmpty:true,
  140. showAlpha: true,
  141. showInput: true,
  142. showPalette: true,
  143. palette: [
  144. ["rgba(255, 128, 0, .9)", "rgba(255, 128, 0, .5)"],
  145. ["red", "green", "blue"],
  146. ["hsla(25, 50, 75, .5)", "rgba(100, .5, .5, .8)"]
  147. ],
  148. change: updateBorders
  149. });
  150. $("#showInputWithClear").spectrum({
  151. allowEmpty:true,
  152. color: "",
  153. showInput: true,
  154. change: updateBorders,
  155. show: function() {
  156. },
  157. hide: function() {
  158. }
  159. });
  160. $("#openWithLink").spectrum({
  161. color: "#dd3333",
  162. change: updateBorders,
  163. show: function() {
  164. },
  165. hide: function() {
  166. }
  167. });
  168. $("#className").spectrum({
  169. className: 'awesome'
  170. });
  171. $("#replacerClassName").spectrum({
  172. replacerClassName: 'awesome'
  173. });
  174. $("#containerClassName").spectrum({
  175. containerClassName: 'awesome'
  176. });
  177. $("#showPalette").spectrum({
  178. showPalette: true,
  179. palette: [
  180. ['black', 'white', 'blanchedalmond'],
  181. ['rgb(255, 128, 0);', 'hsv 100 70 50', 'lightyellow']
  182. ],
  183. change: updateBorders
  184. });
  185. var textPalette = ["rgb(255, 255, 255)", "rgb(204, 204, 204)", "rgb(192, 192, 192)", "rgb(153, 153, 153)", "rgb(102, 102, 102)", "rgb(51, 51, 51)", "rgb(0, 0, 0)", "rgb(255, 204, 204)", "rgb(255, 102, 102)", "rgb(255, 0, 0)", "rgb(204, 0, 0)", "rgb(153, 0, 0)", "rgb(102, 0, 0)", "rgb(51, 0, 0)", "rgb(255, 204, 153)", "rgb(255, 153, 102)", "rgb(255, 153, 0)", "rgb(255, 102, 0)", "rgb(204, 102, 0)", "rgb(153, 51, 0)", "rgb(102, 51, 0)", "rgb(255, 255, 153)", "rgb(255, 255, 102)", "rgb(255, 204, 102)", "rgb(255, 204, 51)", "rgb(204, 153, 51)", "rgb(153, 102, 51)", "rgb(102, 51, 51)", "rgb(255, 255, 204)", "rgb(255, 255, 51)", "rgb(255, 255, 0)", "rgb(255, 204, 0)", "rgb(153, 153, 0)", "rgb(102, 102, 0)", "rgb(51, 51, 0)", "rgb(153, 255, 153)", "rgb(102, 255, 153)", "rgb(51, 255, 51)", "rgb(51, 204, 0)", "rgb(0, 153, 0)", "rgb(0, 102, 0)", "rgb(0, 51, 0)", "rgb(153, 255, 255)", "rgb(51, 255, 255)", "rgb(102, 204, 204)", "rgb(0, 204, 204)", "rgb(51, 153, 153)", "rgb(51, 102, 102)", "rgb(0, 51, 51)", "rgb(204, 255, 255)", "rgb(102, 255, 255)", "rgb(51, 204, 255)", "rgb(51, 102, 255)", "rgb(51, 51, 255)", "rgb(0, 0, 153)", "rgb(0, 0, 102)", "rgb(204, 204, 255)", "rgb(153, 153, 255)", "rgb(102, 102, 204)", "rgb(102, 51, 255)", "rgb(102, 0, 204)", "rgb(51, 51, 153)", "rgb(51, 0, 153)", "rgb(255, 204, 255)", "rgb(255, 153, 255)", "rgb(204, 102, 204)", "rgb(204, 51, 204)", "rgb(153, 51, 153)", "rgb(102, 51, 102)", "rgb(51, 0, 51)"];
  186. $("#showPaletteOnly").spectrum({
  187. color: 'blanchedalmond',
  188. showPaletteOnly: true,
  189. showPalette:true,
  190. palette: [
  191. ['black', 'white', 'blanchedalmond',
  192. 'rgb(255, 128, 0);', 'hsv 100 70 50'],
  193. ['red', 'yellow', 'green', 'blue', 'violet']
  194. ]
  195. });
  196. $("#clickoutFiresChange").spectrum({
  197. clickoutFiresChange: true,
  198. change: updateBorders
  199. });
  200. $("#clickoutDoesntFireChange").spectrum({
  201. change: updateBorders
  202. });
  203. $("#showInitial").spectrum({
  204. showInitial: true
  205. });
  206. $("#showInputAndInitial").spectrum({
  207. showInitial: true,
  208. showInput: true
  209. });
  210. $("#showInputInitialClear").spectrum({
  211. allowEmpty:true,
  212. showInitial: true,
  213. showInput: true
  214. });
  215. $("#changeOnMove").spectrum({
  216. move: function(c) {
  217. var label = $("#changeOnMoveLabel");
  218. label.text("Move called: " + c.toHexString());
  219. }
  220. });
  221. $("#changeOnMoveNo").spectrum({
  222. showInput: true,
  223. change: function(c) {
  224. var label = $("#changeOnMoveNoLabel");
  225. label.text("Change called: " + c.toHexString());
  226. }
  227. });
  228. function prettyTime() {
  229. var date = new Date();
  230. return date.toLocaleTimeString();
  231. }
  232. $("#eventshow").spectrum({
  233. show: function(c) {
  234. var label = $("#eventshowLabel");
  235. label.text("show called at " + prettyTime() + " (color is " + c.toHexString() + ")");
  236. }
  237. });
  238. $("#eventhide").spectrum({
  239. hide: function(c) {
  240. var label = $("#eventhideLabel");
  241. label.text("hide called at " + prettyTime() + " (color is " + c.toHexString() + ")");
  242. }
  243. });
  244. $("#eventdragstart").spectrum({
  245. showAlpha: true
  246. }).on("dragstart.spectrum", function(e, c) {
  247. var label = $("#eventdragstartLabel");
  248. label.text("dragstart called at " + prettyTime() + " (color is " + c.toHexString() + ")");
  249. });
  250. $("#eventdragstop").spectrum({
  251. showAlpha: true
  252. }).on("dragstop.spectrum", function(e, c) {
  253. var label = $("#eventdragstopLabel");
  254. label.text("dragstop called at " + prettyTime() + " (color is " + c.toHexString() + ")");
  255. });
  256. $(".basic").spectrum({ change: updateBorders });
  257. $(".override").spectrum({
  258. color: "yellow",
  259. change: updateBorders
  260. });
  261. $(".startEmpty").spectrum({
  262. allowEmpty:true,
  263. change: updateBorders});
  264. $("#beforeShow").spectrum({
  265. beforeShow: function() {
  266. return false;
  267. }
  268. });
  269. $("#custom").spectrum({
  270. color: "#f00"
  271. });
  272. $("#buttonText").spectrum({
  273. allowEmpty:true,
  274. chooseText: "Alright",
  275. cancelText: "No way"
  276. });
  277. $("#showSelectionPalette").spectrum({
  278. showPalette: true,
  279. showSelectionPalette: true, // true by default
  280. palette: [ ]
  281. });
  282. $("#showSelectionPaletteStorage").spectrum({
  283. showPalette: true,
  284. localStorageKey: "spectrum.homepage", // Any picker with the same string will share selection
  285. showSelectionPalette: true,
  286. palette: [ ]
  287. });
  288. $("#showSelectionPaletteStorage2").spectrum({
  289. showPalette: true,
  290. localStorageKey: "spectrum.homepage", // Any picker with the same string will share selection
  291. showSelectionPalette: true,
  292. palette: [ ]
  293. });
  294. $("#preferredHex").spectrum({
  295. preferredFormat: "hex",
  296. showInput: true,
  297. showPalette: true,
  298. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  299. });
  300. $("#preferredHex3").spectrum({
  301. preferredFormat: "hex3",
  302. showInput: true,
  303. showPalette: true,
  304. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  305. });
  306. $("#preferredHsl").spectrum({
  307. preferredFormat: "hsl",
  308. showInput: true,
  309. showPalette: true,
  310. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  311. });
  312. $("#preferredRgb").spectrum({
  313. preferredFormat: "rgb",
  314. showInput: true,
  315. showPalette: true,
  316. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  317. });
  318. $("#preferredName").spectrum({
  319. preferredFormat: "name",
  320. showInput: true,
  321. showPalette: true,
  322. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  323. });
  324. $("#preferredNone").spectrum({
  325. showInput: true,
  326. showPalette: true,
  327. palette: [["red", "rgba(0, 255, 0, .5)", "rgb(0, 0, 255)"]]
  328. });
  329. $("#triggerSet").spectrum({
  330. change: updateBorders
  331. });
  332. // Show the original input to demonstrate the value changing when calling `set`
  333. $("#triggerSet").show();
  334. $("#btnEnterAColor").click(function() {
  335. $("#triggerSet").spectrum("set", $("#enterAColor").val());
  336. });
  337. $("#toggle").spectrum();
  338. $("#btn-toggle").click(function() {
  339. $("#toggle").spectrum("toggle");
  340. return false;
  341. });
  342. $('#toc').toc({
  343. 'selectors': 'h2,h3', //elements to use as headings
  344. 'container': '#docs', //element to find all selectors in
  345. 'smoothScrolling': true, //enable or disable smooth scrolling on click
  346. 'prefix': 'toc', //prefix for anchor tags and class names
  347. 'highlightOnScroll': true, //add class to heading that is currently in focus
  348. 'highlightOffset': 100, //offset to trigger the next headline
  349. 'anchorName': function(i, heading, prefix) { //custom function for anchor name
  350. return heading.id || prefix+i;
  351. }
  352. });
  353. prettyPrint();
  354. });