@fintatech/fintachart 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE.md +63 -0
  3. package/README.md +151 -0
  4. package/THIRD_PARTY_NOTICES.md +38 -0
  5. package/basic-objects.html +165 -0
  6. package/css/FintaChart.min.css +1 -0
  7. package/css/external/jqNumericField.min.css +1 -0
  8. package/css/external/spectrum.min.css +7 -0
  9. package/css/external/toastr.min.css +1 -0
  10. package/custom-indicator.html +209 -0
  11. package/d.ts/FintaChart.d.ts +24313 -0
  12. package/d.ts/frameworks/Intl.d.ts +115 -0
  13. package/d.ts/frameworks/bootstrap.d.ts +128 -0
  14. package/d.ts/frameworks/bootstrap.v3.datetimepicker.d.ts +10 -0
  15. package/d.ts/frameworks/detectizr.d.ts +27 -0
  16. package/d.ts/frameworks/dom-to-image-more.d.ts +17 -0
  17. package/d.ts/frameworks/html2canvas.d.ts +101 -0
  18. package/d.ts/frameworks/i18nextXHRBackend.d.ts +42 -0
  19. package/d.ts/frameworks/jquery-i18next.d.ts +14 -0
  20. package/d.ts/frameworks/jquery-ui.d.ts +1914 -0
  21. package/d.ts/frameworks/jquery.d.ts +3779 -0
  22. package/d.ts/frameworks/jquery.ui.touch-punch.d.ts +12 -0
  23. package/d.ts/frameworks/moment-node.d.ts +485 -0
  24. package/d.ts/frameworks/moment.d.ts +10 -0
  25. package/d.ts/frameworks/tinycolor.d.ts +377 -0
  26. package/d.ts/frameworks-modified/bootstrap-select.d.ts +18 -0
  27. package/d.ts/frameworks-modified/i18next.d.ts +148 -0
  28. package/d.ts/frameworks-modified/jquery.autocolumnlist.d.ts +17 -0
  29. package/d.ts/frameworks-modified/jquery.resizable.d.ts +20 -0
  30. package/d.ts/frameworks-modified/spectrum.d.ts +294 -0
  31. package/d.ts/frameworks-modified/switchery.d.ts +69 -0
  32. package/d.ts/frameworks-modified/toastr.d.ts +224 -0
  33. package/data/offline-market-history/EUR_CAD/Day/1.csv +2001 -0
  34. package/data/offline-market-history/EUR_CAD/Hour/1.csv +1702 -0
  35. package/data/offline-market-history/EUR_CAD/Hour/4.csv +442 -0
  36. package/data/offline-market-history/EUR_CAD/Minute/1.csv +2001 -0
  37. package/data/offline-market-history/EUR_CAD/Minute/15.csv +2001 -0
  38. package/data/offline-market-history/EUR_CAD/Minute/5.csv +2001 -0
  39. package/data/offline-market-history/EUR_CAD/Monthly/1.csv +175 -0
  40. package/data/offline-market-history/EUR_CAD/Weekly/1.csv +752 -0
  41. package/data/offline-market-history/EUR_CAD/Yearly/1.csv +16 -0
  42. package/data/offline-market-history/EUR_GBP/Day/1.csv +2001 -0
  43. package/data/offline-market-history/EUR_GBP/Hour/1.csv +1702 -0
  44. package/data/offline-market-history/EUR_GBP/Hour/4.csv +442 -0
  45. package/data/offline-market-history/EUR_GBP/Minute/1.csv +2001 -0
  46. package/data/offline-market-history/EUR_GBP/Minute/15.csv +2001 -0
  47. package/data/offline-market-history/EUR_GBP/Minute/5.csv +2001 -0
  48. package/data/offline-market-history/EUR_GBP/Monthly/1.csv +199 -0
  49. package/data/offline-market-history/EUR_GBP/Weekly/1.csv +860 -0
  50. package/data/offline-market-history/EUR_GBP/Yearly/1.csv +18 -0
  51. package/data/predefined-templates/EMAAndMACDTemplate.json +100 -0
  52. package/data/predefined-templates/bigTreeTemplate.json +137 -0
  53. package/data/predefined-templates/multiIndicator.json +136 -0
  54. package/data/predefined-templates/renkoTemplate.json +50 -0
  55. package/data/predefined-templates/standartCandleTemplate.json +73 -0
  56. package/fonts/calibri/calibri.svg +3707 -0
  57. package/fonts/calibri/calibri.ttf +0 -0
  58. package/fonts/calibri/calibri.woff +0 -0
  59. package/fonts/courier-new/courier-new.svg +633 -0
  60. package/fonts/courier-new/courier-new.ttf +0 -0
  61. package/fonts/courier-new/courier-new.woff +0 -0
  62. package/fonts/open-sans-cyrillic/open-sans-cyrillic.svg +475 -0
  63. package/fonts/open-sans-cyrillic/open-sans-cyrillic.ttf +0 -0
  64. package/fonts/open-sans-cyrillic/open-sans-cyrillic.woff +0 -0
  65. package/fonts/open-sans-cyrillic-ext/open-sans-cyrillic-ext.svg +567 -0
  66. package/fonts/open-sans-cyrillic-ext/open-sans-cyrillic-ext.ttf +0 -0
  67. package/fonts/open-sans-cyrillic-ext/open-sans-cyrillic-ext.woff +0 -0
  68. package/fonts/open-sans-greek/open-sans-greek.svg +603 -0
  69. package/fonts/open-sans-greek/open-sans-greek.ttf +0 -0
  70. package/fonts/open-sans-greek/open-sans-greek.woff +0 -0
  71. package/fonts/open-sans-greek-ext/open-sans-greek-ext.svg +42 -0
  72. package/fonts/open-sans-greek-ext/open-sans-greek-ext.ttf +0 -0
  73. package/fonts/open-sans-greek-ext/open-sans-greek-ext.woff +0 -0
  74. package/fonts/open-sans-latin/open-sans-latin.svg +1863 -0
  75. package/fonts/open-sans-latin/open-sans-latin.ttf +0 -0
  76. package/fonts/open-sans-latin/open-sans-latin.woff +0 -0
  77. package/fonts/open-sans-latin-ext/open-sans-latin-ext.svg +1686 -0
  78. package/fonts/open-sans-latin-ext/open-sans-latin-ext.ttf +0 -0
  79. package/fonts/open-sans-latin-ext/open-sans-latin-ext.woff +0 -0
  80. package/fonts/open-sans-vietnamese/open-sans-vietnamese.svg +375 -0
  81. package/fonts/open-sans-vietnamese/open-sans-vietnamese.ttf +0 -0
  82. package/fonts/open-sans-vietnamese/open-sans-vietnamese.woff +0 -0
  83. package/fonts/rubik-medium/Rubik-Medium.svg +8831 -0
  84. package/fonts/rubik-medium/Rubik-Medium.ttf +0 -0
  85. package/fonts/rubik-medium/Rubik-Medium.woff +0 -0
  86. package/fonts/rubik-regular/Rubik-Regular.svg +8885 -0
  87. package/fonts/rubik-regular/Rubik-Regular.ttf +0 -0
  88. package/fonts/rubik-regular/Rubik-Regular.woff +0 -0
  89. package/fonts/source-sans-pro-latin/source-sans-pro-latin.svg +2642 -0
  90. package/fonts/source-sans-pro-latin/source-sans-pro-latin.ttf +0 -0
  91. package/fonts/source-sans-pro-latin/source-sans-pro-latin.woff +0 -0
  92. package/fonts/source-sans-pro-latin-ext/source-sans-pro-latin-ext.svg +1572 -0
  93. package/fonts/source-sans-pro-latin-ext/source-sans-pro-latin-ext.ttf +0 -0
  94. package/fonts/source-sans-pro-latin-ext/source-sans-pro-latin-ext.woff +0 -0
  95. package/fonts/source-sans-pro-vietnamese/source-sans-pro-vietnamese.svg +428 -0
  96. package/fonts/source-sans-pro-vietnamese/source-sans-pro-vietnamese.ttf +0 -0
  97. package/fonts/source-sans-pro-vietnamese/source-sans-pro-vietnamese.woff +0 -0
  98. package/htmldialogs/ChartContextMenu.html +3 -0
  99. package/htmldialogs/ChartTypeSettingsDialog.html +231 -0
  100. package/htmldialogs/CheckboxIndicatorParameterControl.html +9 -0
  101. package/htmldialogs/CompareInstrumentSettings.html +61 -0
  102. package/htmldialogs/ComparingContextMenu.html +8 -0
  103. package/htmldialogs/ConfirmDialog.html +28 -0
  104. package/htmldialogs/DemoModePopup.html +24 -0
  105. package/htmldialogs/FillPlotStyleControl.html +28 -0
  106. package/htmldialogs/HotkeysSettings.html +28 -0
  107. package/htmldialogs/IndicatorContextMenu.html +18 -0
  108. package/htmldialogs/IndicatorSettingsDialog.html +38 -0
  109. package/htmldialogs/IndicatorsDialog.html +39 -0
  110. package/htmldialogs/IndicatorsOverview_en.html +1694 -0
  111. package/htmldialogs/IndicatorsOverview_ua.html +9 -0
  112. package/htmldialogs/InstrumentSearchDialog.html +22 -0
  113. package/htmldialogs/LinePlotStyleControl.html +33 -0
  114. package/htmldialogs/MainSettings.html +292 -0
  115. package/htmldialogs/MarketEventPopup.html +27 -0
  116. package/htmldialogs/MarketEventsSettingsDialog.html +22 -0
  117. package/htmldialogs/NumericIndicatorParameter.html +8 -0
  118. package/htmldialogs/OpenChart.html +6 -0
  119. package/htmldialogs/PatternSettingsControl.html +26 -0
  120. package/htmldialogs/PatternsIndicatorSettingsDialog.html +30 -0
  121. package/htmldialogs/PatternsSettingsParameterControl.html +12 -0
  122. package/htmldialogs/PositionShapeContextMenu.html +9 -0
  123. package/htmldialogs/QuantityPopup.html +7 -0
  124. package/htmldialogs/Scrollbar.html +6 -0
  125. package/htmldialogs/SelectableIndicatorParameter.html +9 -0
  126. package/htmldialogs/ShapeContextMenu.html +7 -0
  127. package/htmldialogs/ShapeFibonacciSettingsDialog.html +261 -0
  128. package/htmldialogs/ShapePositionSettingsDialog.html +351 -0
  129. package/htmldialogs/ShapeSettingsDialog.html +521 -0
  130. package/htmldialogs/TimeFrameChangePopup.html +11 -0
  131. package/htmldialogs/TimeIndicatorParameterControl.html +89 -0
  132. package/htmldialogs/Toolbar.html +1710 -0
  133. package/htmldialogs/TooltipView.html +151 -0
  134. package/htmldialogs/TradingContextMenu.html +2 -0
  135. package/img/ContextMenuCheckbox.png +0 -0
  136. package/img/cross-hairs.cur +0 -0
  137. package/img/eu.png +0 -0
  138. package/img/favicon/favicon.ico +0 -0
  139. package/img/fist.cur +0 -0
  140. package/img/point.cur +0 -0
  141. package/img/svg-icons/Illustration-License-b.svg +1 -0
  142. package/img/svg-icons/Illustration-License-w.svg +1 -0
  143. package/img/svg-icons/abcd-label-pattern.svg +1 -0
  144. package/img/svg-icons/abcd-pattern.svg +1 -0
  145. package/img/svg-icons/add.svg +1 -0
  146. package/img/svg-icons/adjust-OHLC.svg +1 -0
  147. package/img/svg-icons/adjust-all.svg +1 -0
  148. package/img/svg-icons/andrews-pitchfork.svg +1 -0
  149. package/img/svg-icons/arrow-down.svg +1 -0
  150. package/img/svg-icons/arrow-left.svg +3 -0
  151. package/img/svg-icons/arrow-right.svg +3 -0
  152. package/img/svg-icons/arrow-type-type.svg +3 -0
  153. package/img/svg-icons/arrow-up.svg +1 -0
  154. package/img/svg-icons/arrow.svg +1 -0
  155. package/img/svg-icons/balloon.svg +1 -0
  156. package/img/svg-icons/brand-x.svg +1 -0
  157. package/img/svg-icons/calculator.svg +15 -0
  158. package/img/svg-icons/chartType-area.svg +1 -0
  159. package/img/svg-icons/chartType-bars.svg +1 -0
  160. package/img/svg-icons/chartType-candles-volume.svg +1 -0
  161. package/img/svg-icons/chartType-candles.svg +1 -0
  162. package/img/svg-icons/chartType-colored-bars.svg +1 -0
  163. package/img/svg-icons/chartType-equi-volume-shadow.svg +1 -0
  164. package/img/svg-icons/chartType-equi-volume.svg +1 -0
  165. package/img/svg-icons/chartType-heikin-ashi.svg +1 -0
  166. package/img/svg-icons/chartType-hollow-candles.svg +1 -0
  167. package/img/svg-icons/chartType-kagi.svg +1 -0
  168. package/img/svg-icons/chartType-line-break.svg +1 -0
  169. package/img/svg-icons/chartType-line.svg +1 -0
  170. package/img/svg-icons/chartType-point-figure.svg +1 -0
  171. package/img/svg-icons/chartType-range-bars.svg +1 -0
  172. package/img/svg-icons/chartType-renko.svg +1 -0
  173. package/img/svg-icons/chevron-right-double.svg +3 -0
  174. package/img/svg-icons/chevron.svg +3 -0
  175. package/img/svg-icons/circle.svg +1 -0
  176. package/img/svg-icons/close-floating-toolbar.svg +1 -0
  177. package/img/svg-icons/close-pane.svg +1 -0
  178. package/img/svg-icons/close-rect.svg +4 -0
  179. package/img/svg-icons/close-windows.svg +1 -0
  180. package/img/svg-icons/close.svg +4 -0
  181. package/img/svg-icons/compare.svg +1 -0
  182. package/img/svg-icons/copy.svg +1 -0
  183. package/img/svg-icons/cursorType-arrow-with-labels.svg +1 -0
  184. package/img/svg-icons/cursorType-arrow.svg +3 -0
  185. package/img/svg-icons/cursorType-crosshairs.svg +1 -0
  186. package/img/svg-icons/cursorType-point.svg +1 -0
  187. package/img/svg-icons/cyclic-lines.svg +1 -0
  188. package/img/svg-icons/default-screen.svg +11 -0
  189. package/img/svg-icons/demo-popup-bg.svg +1 -0
  190. package/img/svg-icons/diamond.svg +1 -0
  191. package/img/svg-icons/dot.svg +1 -0
  192. package/img/svg-icons/drag.svg +1 -0
  193. package/img/svg-icons/elliott-wave-pattern.svg +1 -0
  194. package/img/svg-icons/ellipse.svg +1 -0
  195. package/img/svg-icons/error-channel.svg +1 -0
  196. package/img/svg-icons/export.svg +1 -0
  197. package/img/svg-icons/extended-line.svg +3 -0
  198. package/img/svg-icons/fibonacci-arcs.svg +1 -0
  199. package/img/svg-icons/fibonacci-ellipses.svg +1 -0
  200. package/img/svg-icons/fibonacci-extensions.svg +1 -0
  201. package/img/svg-icons/fibonacci-fan.svg +1 -0
  202. package/img/svg-icons/fibonacci-retracements.svg +1 -0
  203. package/img/svg-icons/fibonacci-time-zones.svg +1 -0
  204. package/img/svg-icons/fintatech.svg +1 -0
  205. package/img/svg-icons/free-hand.svg +1 -0
  206. package/img/svg-icons/full-screen.svg +11 -0
  207. package/img/svg-icons/full-windows.svg +12 -0
  208. package/img/svg-icons/gann-fan.svg +1 -0
  209. package/img/svg-icons/general-delete.svg +3 -0
  210. package/img/svg-icons/head-shoulders-pattern.svg +1 -0
  211. package/img/svg-icons/horizontal-line.svg +1 -0
  212. package/img/svg-icons/horizontal-ray.svg +3 -0
  213. package/img/svg-icons/html-code.svg +1 -0
  214. package/img/svg-icons/image.svg +5 -0
  215. package/img/svg-icons/images.svg +1 -0
  216. package/img/svg-icons/in-shape-mode.svg +1 -0
  217. package/img/svg-icons/insert-indicator.svg +1 -0
  218. package/img/svg-icons/kings-crown-pattern.svg +1 -0
  219. package/img/svg-icons/latest-position.svg +1 -0
  220. package/img/svg-icons/line-segment.svg +1 -0
  221. package/img/svg-icons/link.svg +5 -0
  222. package/img/svg-icons/lock.svg +3 -0
  223. package/img/svg-icons/magnet-mode.svg +1 -0
  224. package/img/svg-icons/measure.svg +1 -0
  225. package/img/svg-icons/multiply-link.svg +5 -0
  226. package/img/svg-icons/note.svg +1 -0
  227. package/img/svg-icons/number-label-pattern.svg +1 -0
  228. package/img/svg-icons/open-OHLC-pane.svg +1 -0
  229. package/img/svg-icons/options.svg +1 -0
  230. package/img/svg-icons/period.svg +1 -0
  231. package/img/svg-icons/polygon.svg +1 -0
  232. package/img/svg-icons/polyline.svg +1 -0
  233. package/img/svg-icons/position-long.svg +90 -0
  234. package/img/svg-icons/position-long_og.svg +81 -0
  235. package/img/svg-icons/position-short.svg +90 -0
  236. package/img/svg-icons/position-short_og.svg +89 -0
  237. package/img/svg-icons/quadrant-lines.svg +1 -0
  238. package/img/svg-icons/raff-regression.svg +1 -0
  239. package/img/svg-icons/ray.svg +3 -0
  240. package/img/svg-icons/rectangle.svg +1 -0
  241. package/img/svg-icons/redo-new.svg +3 -0
  242. package/img/svg-icons/redo.svg +1 -0
  243. package/img/svg-icons/remove-all-indicators.svg +1 -0
  244. package/img/svg-icons/remove-all-shapes.svg +1 -0
  245. package/img/svg-icons/replay-jump.svg +1 -0
  246. package/img/svg-icons/replay-pause.svg +1 -0
  247. package/img/svg-icons/replay-play.svg +1 -0
  248. package/img/svg-icons/replay-skip-end.svg +1 -0
  249. package/img/svg-icons/replay-skip-one.svg +1 -0
  250. package/img/svg-icons/save-as-image.svg +1 -0
  251. package/img/svg-icons/screenshot.svg +5 -0
  252. package/img/svg-icons/scroll-bottom.svg +1 -0
  253. package/img/svg-icons/scroll-left.svg +1 -0
  254. package/img/svg-icons/scroll-right.svg +1 -0
  255. package/img/svg-icons/scroll-top.svg +1 -0
  256. package/img/svg-icons/search.svg +1 -0
  257. package/img/svg-icons/speed-lines.svg +1 -0
  258. package/img/svg-icons/square.svg +1 -0
  259. package/img/svg-icons/star.svg +4 -0
  260. package/img/svg-icons/stash.svg +4 -0
  261. package/img/svg-icons/stick-to-bar.svg +1 -0
  262. package/img/svg-icons/stick-to-close.svg +1 -0
  263. package/img/svg-icons/stick-to-high.svg +1 -0
  264. package/img/svg-icons/stick-to-low.svg +1 -0
  265. package/img/svg-icons/stick-to-open.svg +1 -0
  266. package/img/svg-icons/sticky-mode-off.svg +1 -0
  267. package/img/svg-icons/tcdPane-alert-indicator.svg +1 -0
  268. package/img/svg-icons/tcdPane-close.svg +1 -0
  269. package/img/svg-icons/tcdPane-down.svg +1 -0
  270. package/img/svg-icons/tcdPane-expand-closed.svg +1 -0
  271. package/img/svg-icons/tcdPane-expand.svg +1 -0
  272. package/img/svg-icons/tcdPane-maximize.svg +1 -0
  273. package/img/svg-icons/tcdPane-options.svg +1 -0
  274. package/img/svg-icons/tcdPane-remove-indicator.svg +1 -0
  275. package/img/svg-icons/tcdPane-restore.svg +1 -0
  276. package/img/svg-icons/tcdPane-toggle.svg +1 -0
  277. package/img/svg-icons/tcdPane-up.svg +1 -0
  278. package/img/svg-icons/template-delete.svg +1 -0
  279. package/img/svg-icons/template-edit.svg +1 -0
  280. package/img/svg-icons/template-ok.svg +1 -0
  281. package/img/svg-icons/template.svg +1 -0
  282. package/img/svg-icons/text-editor-b.svg +1 -0
  283. package/img/svg-icons/text-editor-i.svg +1 -0
  284. package/img/svg-icons/text-editor-u.svg +1 -0
  285. package/img/svg-icons/text.svg +1 -0
  286. package/img/svg-icons/tirone-levels.svg +1 -0
  287. package/img/svg-icons/toggle-shapes.svg +1 -0
  288. package/img/svg-icons/trade-manager.svg +1 -0
  289. package/img/svg-icons/trend-angle.svg +1 -0
  290. package/img/svg-icons/trend-channel.svg +1 -0
  291. package/img/svg-icons/triangle-pattern.svg +1 -0
  292. package/img/svg-icons/triangle.svg +1 -0
  293. package/img/svg-icons/undo-new.svg +3 -0
  294. package/img/svg-icons/undo.svg +1 -0
  295. package/img/svg-icons/unlock.svg +3 -0
  296. package/img/svg-icons/vertical-line.svg +1 -0
  297. package/img/svg-icons/visibleProfile.svg +1 -0
  298. package/img/svg-icons/web-link.svg +1 -0
  299. package/img/svg-icons/x.svg +3 -0
  300. package/img/svg-icons/xabcd-pattern.svg +1 -0
  301. package/img/svg-icons/zoom-by-area.svg +1 -0
  302. package/img/svg-icons/zoom.svg +1 -0
  303. package/img/usa.png +0 -0
  304. package/index-dark.html +132 -0
  305. package/index.html +229 -0
  306. package/localization/en.json +1646 -0
  307. package/localization/uk.json +1597 -0
  308. package/multiple-charts.html +162 -0
  309. package/package.json +62 -0
  310. package/scripts/FintaChart.min.js +70 -0
  311. package/scripts/frameworks/Intl.min.js +4 -0
  312. package/scripts/frameworks/bootstrap.v3.datetimepicker.min.js +2605 -0
  313. package/scripts/frameworks/detectizr.min.js +1 -0
  314. package/scripts/frameworks/dom-to-image-more.min.js +3 -0
  315. package/scripts/frameworks/i18nextXHRBackend.min.js +1 -0
  316. package/scripts/frameworks/jquery-i18next.min.js +1 -0
  317. package/scripts/frameworks/jquery-ui.min.js +8 -0
  318. package/scripts/frameworks/jquery.min.js +3 -0
  319. package/scripts/frameworks/jquery.ui.touch-punch.min.js +1 -0
  320. package/scripts/frameworks/moment.min.js +1216 -0
  321. package/scripts/frameworks-modified/bootstrap-select.js +1024 -0
  322. package/scripts/frameworks-modified/i18next.js +2075 -0
  323. package/scripts/frameworks-modified/jquery.autocolumnlist.js +48 -0
  324. package/scripts/frameworks-modified/jquery.resizable.js +229 -0
  325. package/scripts/frameworks-modified/spectrum.js +2279 -0
  326. package/scripts/frameworks-modified/switchery.js +1957 -0
  327. package/scripts/frameworks-modified/toastr.js +414 -0
  328. package/scripts/jsdataadapters/fileDataAdapter.js +129 -0
  329. package/scripts/jsdataadapters/restDataAdapter.js +149 -0
  330. package/scripts/jsdataadapters/webSocketDataAdapter.js +114 -0
  331. package/scripts/miscs/templateFileDataAdapter.js +17 -0
  332. package/scripts/themes/beetTheme.js +2999 -0
  333. package/scripts/themes/darkTheme.js +3004 -0
  334. package/scripts/themes/defaultTheme.js +3095 -0
  335. package/scripts/themes/fintatechDarkTheme.js +3005 -0
  336. package/scripts/themes/grayTheme.js +3004 -0
  337. package/scripts/themes/oliveTheme.js +3004 -0
  338. package/scripts/themes/orangeTheme.js +3004 -0
  339. package/scripts/themes/purpleTheme.js +3004 -0
  340. package/scripts/themes/skyTheme.js +3009 -0
  341. package/scripts/themes/tealTheme.js +3004 -0
@@ -0,0 +1,2279 @@
1
+ 'use strict';
2
+
3
+ var FintaChart;
4
+ (function (FintaChart) {
5
+ var External;
6
+ var HtmlContainer = FintaChart.HtmlContainer;
7
+ (function (External) {
8
+ (function (window, $, undefined) {
9
+ var defaultOpts = {
10
+
11
+ // Callbacks
12
+ beforeShow: noop,
13
+ move: noop,
14
+ change: noop,
15
+ show: noop,
16
+ hide: noop,
17
+
18
+ // Options
19
+ color: false,
20
+ flat: false,
21
+ showInput: true,
22
+ allowEmpty: true,
23
+ showButtons: true,
24
+ clickoutFiresChange: false,
25
+ showInitial: false,
26
+ showPalette: false,
27
+ showPaletteOnly: false,
28
+ togglePaletteOnly: false,
29
+ showSelectionPalette: true,
30
+ localStorageKey: false,
31
+ appendTo: "body",
32
+ maxSelectionSize: 7,
33
+ cancelText: "cancel",
34
+ chooseText: "choose",
35
+ togglePaletteMoreText: "more",
36
+ togglePaletteLessText: "less",
37
+ clearText: "Clear Color Selection",
38
+ noColorSelectedText: "No Color Selected",
39
+ preferredFormat: false,
40
+ className: "", // Deprecated - use containerClassName and replacerClassName instead.
41
+ containerClassName: "",
42
+ replacerClassName: "",
43
+ showAlpha: false,
44
+ theme: "sp-light",
45
+ palette: [["#ffffff", "#000000", "#ff0000", "#ff8000", "#ffff00", "#008000", "#0000ff", "#4b0082", "#9400d3"]],
46
+ selectionPalette: [],
47
+ disabled: false
48
+ },
49
+ spectrums = [],
50
+ IE = !!/msie/i.exec( window.navigator.userAgent ),
51
+ rgbaSupport = (function() {
52
+ function contains( str, substr ) {
53
+ return !!~('' + str).indexOf(substr);
54
+ }
55
+
56
+ var elem = document.createElement('div');
57
+ var style = elem.style;
58
+ style.cssText = 'background-color:rgba(0,0,0,.5)';
59
+ return contains(style.backgroundColor, 'rgba') || contains(style.backgroundColor, 'hsla');
60
+ })(),
61
+ inputTypeColorSupport = (function() {
62
+ var colorInput = $("<input type='color' value='#000001' />")[0];
63
+ return colorInput.type === "color" && colorInput.value !== "#000001";
64
+ })(),
65
+ replaceInput = [
66
+ "<div class='sp-replacer'>",
67
+ "<div class='sp-preview'><div class='sp-preview-inner'></div></div>",
68
+ "<div class='sp-dd'>&#9660;</div>",
69
+ "</div>"
70
+ ].join(''),
71
+ markup = (function () {
72
+
73
+ // IE does not support gradients with multiple stops, so we need to simulate
74
+ // that for the rainbow slider with 8 divs that each have a single gradient
75
+ var gradientFix = "";
76
+ if (IE) {
77
+ for (var i = 1; i <= 6; i++) {
78
+ gradientFix += "<div class='sp-" + i + "'></div>";
79
+ }
80
+ }
81
+
82
+ return [
83
+ "<div class='tcdSpectrum sp-container sp-hidden'>",
84
+ "<div class='sp-palette-container'>",
85
+ "<div class='sp-palette sp-thumb sp-cf'></div>",
86
+ "<div class='sp-palette-button-container sp-cf'>",
87
+ '<a href="#" class="tcd-btn tcd-btn-default tcd-btn-info tcd-btn-sm sp-palette-toggle">More</a>',
88
+ "</div>",
89
+ "</div>",
90
+ "<div class='sp-picker-container'>",
91
+ "<div class='sp-top sp-cf'>",
92
+ "<div class='sp-fill'></div>",
93
+ "<div class='sp-top-inner'>",
94
+ "<div class='sp-color'>",
95
+ "<div class='sp-sat'>",
96
+ "<div class='sp-val'>",
97
+ "<div class='sp-dragger'></div>",
98
+ "</div>",
99
+ "</div>",
100
+ "</div>",
101
+ "<div class='sp-clear sp-clear-display'>",
102
+ "</div>",
103
+ "<div class='sp-hue'>",
104
+ "<div class='sp-slider'></div>",
105
+ gradientFix,
106
+ "</div>",
107
+ "</div>",
108
+ "<div class='sp-alpha'><div class='sp-alpha-inner'><div class='sp-alpha-handle'></div></div></div>",
109
+ "</div>",
110
+ "<div class='sp-input-container sp-cf'>",
111
+ "<input class='sp-input' type='text' spellcheck='false' />",
112
+ "</div>",
113
+ "<div class='sp-initial sp-thumb sp-cf'></div>",
114
+ "<div class='sp-button-container sp-cf'>",
115
+ '<a href="#" class="tcd-btn tcd-btn-default tcd-btn-sm sp-cancel"><span class="glyphicon glyphicon-remove"></span> Cancel</a>',
116
+ '<a href="#" class="tcd-btn tcd-btn-default tcd-btn-success tcd-btn-sm sp-choose"><span class="glyphicon glyphicon-ok"></span> Choose</a>',
117
+ "</div>",
118
+ "</div>",
119
+ "</div>"
120
+ ].join("");
121
+ })();
122
+
123
+ function paletteTemplate (p, color, className, opts) {
124
+ var html = [];
125
+ for (var i = 0; i < p.length; i++) {
126
+ var current = p[i];
127
+ if(current) {
128
+ var tiny = tinycolor(current);
129
+ var c = tiny.toHsl().l < 0.5 ? "sp-thumb-el sp-thumb-dark" : "sp-thumb-el sp-thumb-light";
130
+ c += (tinycolor.equals(color, current)) ? " sp-thumb-active" : "";
131
+ var formattedString = tiny.toString(opts.preferredFormat || "rgb");
132
+ var swatchStyle = rgbaSupport ? ("background-color:" + tiny.toRgbString()) : "filter:" + tiny.toFilter();
133
+ html.push('<span title="' + formattedString + '" data-color="' + tiny.toRgbString() + '" class="' + c + '"><span class="sp-thumb-inner" style="' + swatchStyle + ';" /></span>');
134
+ } else {
135
+ var cls = 'sp-clear-display';
136
+ html.push($('<div />')
137
+ .append($('<span data-color="" style="background-color:transparent;" class="' + cls + '"></span>')
138
+ .attr('title', opts.noColorSelectedText)
139
+ )
140
+ .html()
141
+ );
142
+ }
143
+ }
144
+ return "<div class='sp-cf " + className + "'>" + html.join('') + "</div>";
145
+ }
146
+
147
+ function hideAll() {
148
+ for (var i = 0; i < spectrums.length; i++) {
149
+ if (spectrums[i]) {
150
+ spectrums[i].hide();
151
+ }
152
+ }
153
+ }
154
+
155
+ function instanceOptions(o, callbackContext) {
156
+ var opts = $.extend({}, defaultOpts, o);
157
+ opts.callbacks = {
158
+ 'move': bind(opts.move, callbackContext),
159
+ 'change': bind(opts.change, callbackContext),
160
+ 'show': bind(opts.show, callbackContext),
161
+ 'hide': bind(opts.hide, callbackContext),
162
+ 'beforeShow': bind(opts.beforeShow, callbackContext)
163
+ };
164
+
165
+ return opts;
166
+ }
167
+
168
+ function spectrum(element, o) {
169
+
170
+ var opts = instanceOptions(o, element),
171
+ flat = opts.flat,
172
+ showSelectionPalette = opts.showSelectionPalette,
173
+ localStorageKey = opts.localStorageKey,
174
+ theme = opts.theme,
175
+ callbacks = opts.callbacks,
176
+ resize = throttle(reflow, 10),
177
+ visible = false,
178
+ dragWidth = 0,
179
+ dragHeight = 0,
180
+ dragHelperHeight = 0,
181
+ slideHeight = 0,
182
+ slideWidth = 0,
183
+ alphaWidth = 0,
184
+ alphaSlideHelperWidth = 0,
185
+ slideHelperHeight = 0,
186
+ currentHue = 0,
187
+ currentSaturation = 0,
188
+ currentValue = 0,
189
+ currentAlpha = 1,
190
+ palette = [],
191
+ paletteArray = [],
192
+ paletteLookup = {},
193
+ selectionPalette = opts.selectionPalette.slice(0),
194
+ maxSelectionSize = opts.maxSelectionSize,
195
+ draggingClass = "sp-dragging",
196
+ shiftMovementDirection = null;
197
+
198
+ var doc = element.ownerDocument,
199
+ body = doc.body,
200
+ boundElement = $(element),
201
+ disabled = false,
202
+ container = $(markup, doc).addClass(theme),
203
+ pickerContainer = container.find(".sp-picker-container"),
204
+ dragger = container.find(".sp-color"),
205
+ dragHelper = container.find(".sp-dragger"),
206
+ slider = container.find(".sp-hue"),
207
+ slideHelper = container.find(".sp-slider"),
208
+ alphaSliderInner = container.find(".sp-alpha-inner"),
209
+ alphaSlider = container.find(".sp-alpha"),
210
+ alphaSlideHelper = container.find(".sp-alpha-handle"),
211
+ textInput = container.find(".sp-input"),
212
+ paletteContainer = container.find(".sp-palette"),
213
+ initialColorContainer = container.find(".sp-initial"),
214
+ cancelButton = container.find(".sp-cancel"),
215
+ clearButton = container.find(".sp-clear"),
216
+ chooseButton = container.find(".sp-choose"),
217
+ toggleButton = container.find(".sp-palette-toggle"),
218
+ isInput = boundElement.is("input"),
219
+ isInputTypeColor = isInput && inputTypeColorSupport && boundElement.attr("type") === "color",
220
+ shouldReplace = isInput && !flat,
221
+ replacer = (shouldReplace) ? $(replaceInput).addClass(theme).addClass(opts.instanceTypeName).addClass(opts.replacerClassName) : $([]),
222
+ offsetElement = (shouldReplace) ? replacer : boundElement,
223
+ previewElement = replacer.find(".sp-preview-inner"),
224
+ initialColor = opts.color || (isInput && boundElement.val()),
225
+ colorOnShow = false,
226
+ preferredFormat = opts.preferredFormat,
227
+ currentPreferredFormat = preferredFormat,
228
+ clickoutFiresChange = !opts.showButtons || opts.clickoutFiresChange,
229
+ isEmpty = !initialColor,
230
+ allowEmpty = opts.allowEmpty && !isInputTypeColor;
231
+
232
+ function applyOptions() {
233
+
234
+ if (opts.showPaletteOnly) {
235
+ opts.showPalette = true;
236
+ }
237
+
238
+ toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
239
+
240
+ if (opts.palette) {
241
+ palette = opts.palette.slice(0);
242
+ paletteArray = $.isArray(palette[0]) ? palette : [palette];
243
+ paletteLookup = {};
244
+ for (var i = 0; i < paletteArray.length; i++) {
245
+ for (var j = 0; j < paletteArray[i].length; j++) {
246
+ var rgb = tinycolor(paletteArray[i][j]).toRgbString();
247
+ paletteLookup[rgb] = true;
248
+ }
249
+ }
250
+ }
251
+
252
+ container.toggleClass("sp-flat", flat);
253
+ container.toggleClass("sp-input-disabled", !opts.showInput);
254
+ container.toggleClass("sp-alpha-enabled", opts.showAlpha);
255
+ container.toggleClass("sp-clear-enabled", allowEmpty);
256
+ container.toggleClass("sp-buttons-disabled", !opts.showButtons);
257
+ container.toggleClass("sp-palette-buttons-disabled", !opts.togglePaletteOnly);
258
+ container.toggleClass("sp-palette-disabled", !opts.showPalette);
259
+ container.toggleClass("sp-palette-only", opts.showPaletteOnly);
260
+ container.toggleClass("sp-initial-disabled", !opts.showInitial);
261
+ container.addClass(opts.instanceTypeName).addClass(opts.containerClassName);
262
+
263
+ reflow();
264
+ }
265
+
266
+ function initialize() {
267
+
268
+ if (IE) {
269
+ container.find("*:not(input)").attr("unselectable", "on");
270
+ }
271
+
272
+ applyOptions();
273
+
274
+ if (shouldReplace) {
275
+ boundElement.after(replacer).hide();
276
+ }
277
+
278
+ if (!allowEmpty) {
279
+ clearButton.hide();
280
+ }
281
+
282
+ if (flat) {
283
+ boundElement.after(container).hide();
284
+ }
285
+ else {
286
+
287
+ // var appendTo = opts.appendTo === "parent" ? boundElement.parent() : $(opts.appendTo);
288
+ // if (appendTo.length !== 1) {
289
+ // appendTo = $("body");
290
+ // }
291
+ //
292
+ // appendTo.append(container);
293
+
294
+ //FIX: issue with change of root container in full screen mode
295
+ HtmlContainer.add('spectrum', container);
296
+ }
297
+
298
+ updateSelectionPaletteFromStorage();
299
+
300
+ offsetElement.bind("click.spectrum touchstart.spectrum", function (e) {
301
+ if (!disabled) {
302
+ toggle();
303
+ }
304
+
305
+ e.stopPropagation();
306
+
307
+ if (!$(e.target).is("input")) {
308
+ e.preventDefault();
309
+ }
310
+ });
311
+
312
+ if(boundElement.is(":disabled") || (opts.disabled === true)) {
313
+ disable();
314
+ }
315
+
316
+ // Prevent clicks from bubbling up to document. This would cause it to be hidden.
317
+ container.click(stopPropagation);
318
+
319
+ // Handle user typed input
320
+ textInput.change(setFromTextInput);
321
+ textInput.bind("paste", function () {
322
+ setTimeout(setFromTextInput, 1);
323
+ });
324
+ textInput.keydown(function (e) { if (e.keyCode == 13) { setFromTextInput(); } });
325
+
326
+ cancelButton.text(opts.cancelText);
327
+ cancelButton.bind("click.spectrum", function (e) {
328
+ e.stopPropagation();
329
+ e.preventDefault();
330
+ hide("cancel");
331
+ });
332
+
333
+ clearButton.attr("title", opts.clearText);
334
+ clearButton.bind("click.spectrum", function (e) {
335
+ e.stopPropagation();
336
+ e.preventDefault();
337
+ // isEmpty = true;
338
+ set("rgba(255, 255, 255, 0)");
339
+ move();
340
+
341
+ if(flat) {
342
+ //for the flat style, this is a change event
343
+ updateOriginalInput(true);
344
+ }
345
+ });
346
+
347
+ chooseButton.text(opts.chooseText);
348
+ chooseButton.bind("click.spectrum", function (e) {
349
+ e.stopPropagation();
350
+ e.preventDefault();
351
+
352
+ if (isValid()) {
353
+ updateOriginalInput(true);
354
+ hide();
355
+ }
356
+ });
357
+
358
+ toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
359
+ toggleButton.parent().bind("click.spectrum", function (e) {
360
+ e.stopPropagation();
361
+ e.preventDefault();
362
+
363
+ opts.showPaletteOnly = !opts.showPaletteOnly;
364
+
365
+ // To make sure the Picker area is drawn on the right, next to the
366
+ // Palette area (and not below the palette), first move the Palette
367
+ // to the left to make space for the picker, plus 5px extra.
368
+ // The 'applyOptions' function puts the whole container back into place
369
+ // and takes care of the button-text and the sp-palette-only CSS class.
370
+ if (!opts.showPaletteOnly && !flat) {
371
+ container.css('left', '-=' + (pickerContainer.outerWidth(true) + 5));
372
+ }
373
+ applyOptions();
374
+ });
375
+
376
+ draggable(alphaSlider, function (dragX, dragY, e) {
377
+ currentAlpha = (dragX / alphaWidth);
378
+ isEmpty = false;
379
+ if (e.shiftKey) {
380
+ currentAlpha = Math.round(currentAlpha * 10) / 10;
381
+ }
382
+
383
+ move();
384
+ }, dragStart, dragStop);
385
+
386
+ draggable(slider, function (dragX, dragY) {
387
+ currentHue = parseFloat(dragY / slideHeight);
388
+ isEmpty = false;
389
+ if (!opts.showAlpha) {
390
+ currentAlpha = 1;
391
+ }
392
+ move();
393
+ }, dragStart, dragStop);
394
+
395
+ draggable(dragger, function (dragX, dragY, e) {
396
+
397
+ // shift+drag should snap the movement to either the x or y axis.
398
+ if (!e.shiftKey) {
399
+ shiftMovementDirection = null;
400
+ }
401
+ else if (!shiftMovementDirection) {
402
+ var oldDragX = currentSaturation * dragWidth;
403
+ var oldDragY = dragHeight - (currentValue * dragHeight);
404
+ var furtherFromX = Math.abs(dragX - oldDragX) > Math.abs(dragY - oldDragY);
405
+
406
+ shiftMovementDirection = furtherFromX ? "x" : "y";
407
+ }
408
+
409
+ var setSaturation = !shiftMovementDirection || shiftMovementDirection === "x";
410
+ var setValue = !shiftMovementDirection || shiftMovementDirection === "y";
411
+
412
+ if (setSaturation) {
413
+ currentSaturation = parseFloat(dragX / dragWidth);
414
+ }
415
+ if (setValue) {
416
+ currentValue = parseFloat((dragHeight - dragY) / dragHeight);
417
+ }
418
+
419
+ isEmpty = false;
420
+ if (!opts.showAlpha) {
421
+ currentAlpha = 1;
422
+ }
423
+
424
+ move();
425
+
426
+ }, dragStart, dragStop);
427
+
428
+ if (!!initialColor) {
429
+ set(initialColor);
430
+
431
+ // In case color was black - update the preview UI and set the format
432
+ // since the set function will not run (default color is black).
433
+ updateUI();
434
+ currentPreferredFormat = preferredFormat || tinycolor(initialColor).format;
435
+
436
+ addColorToSelectionPalette(initialColor);
437
+ }
438
+ else {
439
+ updateUI();
440
+ }
441
+
442
+ if (flat) {
443
+ show();
444
+ }
445
+
446
+ function paletteElementClick(e) {
447
+ if (e.data && e.data.ignore) {
448
+ set($(e.target).closest(".sp-thumb-el").data("color"));
449
+ move();
450
+ }
451
+ else {
452
+ set($(e.target).closest(".sp-thumb-el").data("color"));
453
+ move();
454
+ updateOriginalInput(true);
455
+ hide();
456
+ }
457
+
458
+ return false;
459
+ }
460
+
461
+ var paletteEvent = IE ? "mousedown.spectrum" : "click.spectrum touchstart.spectrum";
462
+ paletteContainer.delegate(".sp-thumb-el", paletteEvent, paletteElementClick);
463
+ initialColorContainer.delegate(".sp-thumb-el:nth-child(1)", paletteEvent, { ignore: true }, paletteElementClick);
464
+ }
465
+
466
+ function updateSelectionPaletteFromStorage() {
467
+
468
+ if (localStorageKey && window.localStorage) {
469
+
470
+ // Migrate old palettes over to new format. May want to remove this eventually.
471
+ try {
472
+ var oldPalette = window.localStorage[localStorageKey].split(",#");
473
+ if (oldPalette.length > 1) {
474
+ delete window.localStorage[localStorageKey];
475
+ $.each(oldPalette, function(i, c) {
476
+ addColorToSelectionPalette(c);
477
+ });
478
+ }
479
+ }
480
+ catch(e) { }
481
+
482
+ try {
483
+ selectionPalette = window.localStorage[localStorageKey].split(";");
484
+ }
485
+ catch (e) { }
486
+ }
487
+ }
488
+
489
+ function addColorToSelectionPalette(color) {
490
+ if (showSelectionPalette) {
491
+ var rgb = tinycolor(color).toRgbString();
492
+ if (!paletteLookup[rgb] && $.inArray(rgb, selectionPalette) === -1) {
493
+ selectionPalette.push(rgb);
494
+ while(selectionPalette.length > maxSelectionSize) {
495
+ selectionPalette.shift();
496
+ }
497
+ }
498
+
499
+ if (localStorageKey && window.localStorage) {
500
+ try {
501
+ window.localStorage[localStorageKey] = selectionPalette.join(";");
502
+ }
503
+ catch(e) { }
504
+ }
505
+ }
506
+ }
507
+
508
+ function getUniqueSelectionPalette() {
509
+ var unique = [];
510
+ if (opts.showPalette) {
511
+ for (var i = 0; i < selectionPalette.length; i++) {
512
+ var rgb = tinycolor(selectionPalette[i]).toRgbString();
513
+
514
+ if (!paletteLookup[rgb]) {
515
+ unique.push(selectionPalette[i]);
516
+ }
517
+ }
518
+ }
519
+
520
+ return unique.reverse().slice(0, opts.maxSelectionSize);
521
+ }
522
+
523
+ function drawPalette() {
524
+
525
+ var currentColor = get();
526
+
527
+ var html = $.map(paletteArray, function (palette, i) {
528
+ return paletteTemplate(palette, currentColor, "sp-palette-row sp-palette-row-" + i, opts);
529
+ });
530
+
531
+ updateSelectionPaletteFromStorage();
532
+
533
+ if (selectionPalette) {
534
+ html.push(paletteTemplate(getUniqueSelectionPalette(), currentColor, "sp-palette-row sp-palette-row-selection", opts));
535
+ }
536
+
537
+ paletteContainer.html(html.join(""));
538
+ }
539
+
540
+ function drawInitial() {
541
+ if (opts.showInitial) {
542
+ var initial = colorOnShow;
543
+ var current = get();
544
+ initialColorContainer.html(paletteTemplate([initial, current], current, "sp-palette-row-initial", opts));
545
+ }
546
+ }
547
+
548
+ function dragStart() {
549
+ if (dragHeight <= 0 || dragWidth <= 0 || slideHeight <= 0) {
550
+ reflow();
551
+ }
552
+ container.addClass(draggingClass);
553
+ shiftMovementDirection = null;
554
+ boundElement.trigger('dragstart.spectrum', [ get() ]);
555
+ }
556
+
557
+ function dragStop() {
558
+ container.removeClass(draggingClass);
559
+ boundElement.trigger('dragstop.spectrum', [ get() ]);
560
+ }
561
+
562
+ function setFromTextInput() {
563
+
564
+ var value = textInput.val();
565
+
566
+ if ((value === null || value === "") && allowEmpty) {
567
+ set(null);
568
+ updateOriginalInput(true);
569
+ }
570
+ else {
571
+ var tiny = tinycolor(value);
572
+ if (tiny.isValid()) {
573
+ set(tiny);
574
+ updateOriginalInput(true);
575
+ }
576
+ else {
577
+ textInput.addClass("sp-validation-error");
578
+ }
579
+ }
580
+ }
581
+
582
+ function toggle() {
583
+ if (visible) {
584
+ hide();
585
+ }
586
+ else {
587
+ show();
588
+ }
589
+ }
590
+
591
+ function show() {
592
+ var event = $.Event('beforeShow.spectrum');
593
+
594
+ if (visible) {
595
+ reflow();
596
+ return;
597
+ }
598
+
599
+ boundElement.trigger(event, [ get() ]);
600
+
601
+ if (callbacks.beforeShow(get()) === false || event.isDefaultPrevented()) {
602
+ return;
603
+ }
604
+
605
+ hideAll();
606
+ visible = true;
607
+
608
+ $(doc).bind("click.spectrum", hide);
609
+ $(window).bind("resize.spectrum", resize);
610
+ $(window).bind("resize.spectrum", hide);
611
+ replacer.addClass("sp-active");
612
+ container.removeClass("sp-hidden");
613
+
614
+ reflow();
615
+ updateUI();
616
+
617
+ colorOnShow = get();
618
+
619
+ drawInitial();
620
+ callbacks.show(colorOnShow);
621
+ boundElement.trigger('show.spectrum', [ colorOnShow ]);
622
+
623
+ $('html').on('mousedown', function (e) {
624
+ if (container.has(e.target).length === 0)
625
+ container.addClass('sp-hidden');
626
+ });
627
+ $('html').on('DOMMouseScroll mousewheel', function (e) {
628
+ if (container.has(e.target).length === 0)
629
+ container.addClass('sp-hidden');
630
+ });
631
+
632
+ if (!opts.showPaletteOnly && !flat) {
633
+ container.css('left', '-=' + (pickerContainer.outerWidth(true) + 5));
634
+ }
635
+
636
+ applyOptions();
637
+ }
638
+
639
+ function hide(e) {
640
+
641
+ // Return on right click
642
+ if (e && e.type == "click" && e.button == 2) { return; }
643
+
644
+ // Return if hiding is unnecessary
645
+ if (!visible || flat) { return; }
646
+ visible = false;
647
+
648
+ $(doc).unbind("click.spectrum", hide);
649
+ $(window).unbind("resize.spectrum", resize);
650
+
651
+ replacer.removeClass("sp-active");
652
+ container.addClass("sp-hidden");
653
+
654
+ var colorHasChanged = !tinycolor.equals(get(), colorOnShow);
655
+
656
+ if (colorHasChanged) {
657
+ if (clickoutFiresChange && e !== "cancel") {
658
+ updateOriginalInput(true);
659
+ }
660
+ else {
661
+ revert();
662
+ }
663
+ }
664
+
665
+ callbacks.hide(get());
666
+ boundElement.trigger('hide.spectrum', [ get() ]);
667
+ }
668
+
669
+ function revert() {
670
+ set(colorOnShow, true);
671
+ }
672
+
673
+ function set(color, ignoreFormatChange) {
674
+ if (tinycolor.equals(color, get())) {
675
+ // Update UI just in case a validation error needs
676
+ // to be cleared.
677
+ updateUI();
678
+ return;
679
+ }
680
+
681
+ var newColor, newHsv;
682
+ if (!color && allowEmpty) {
683
+ isEmpty = true;
684
+ } else {
685
+ isEmpty = false;
686
+ newColor = tinycolor(color);
687
+ newHsv = newColor.toHsv();
688
+
689
+ currentHue = (newHsv.h % 360) / 360;
690
+ currentSaturation = newHsv.s;
691
+ currentValue = newHsv.v;
692
+ currentAlpha = newHsv.a;
693
+ }
694
+ updateUI();
695
+
696
+ if (newColor && newColor.isValid() && !ignoreFormatChange) {
697
+ currentPreferredFormat = preferredFormat || newColor.getFormat();
698
+ }
699
+ }
700
+
701
+ function get(opts) {
702
+ opts = opts || { };
703
+
704
+ if (allowEmpty && isEmpty) {
705
+ return null;
706
+ }
707
+
708
+ return tinycolor.fromRatio({
709
+ h: currentHue,
710
+ s: currentSaturation,
711
+ v: currentValue,
712
+ a: Math.round(currentAlpha * 100) / 100
713
+ }, { format: opts.format || currentPreferredFormat });
714
+ }
715
+
716
+ function isValid() {
717
+ return !textInput.hasClass("sp-validation-error");
718
+ }
719
+
720
+ function move() {
721
+ updateUI();
722
+
723
+ callbacks.move(get());
724
+ boundElement.trigger('move.spectrum', [ get() ]);
725
+ }
726
+
727
+ function updateUI() {
728
+
729
+ textInput.removeClass("sp-validation-error");
730
+
731
+ updateHelperLocations();
732
+
733
+ // Update dragger background color (gradients take care of saturation and value).
734
+ var flatColor = tinycolor.fromRatio({ h: currentHue, s: 1, v: 1 });
735
+ dragger.css("background-color", flatColor.toHexString());
736
+
737
+ // Get a format that alpha will be included in (hex and names ignore alpha)
738
+ var format = currentPreferredFormat;
739
+ if (currentAlpha < 1 && !(currentAlpha === 0 && format === "name")) {
740
+ if (format === "hex" || format === "hex3" || format === "hex6" || format === "name") {
741
+ format = "rgb";
742
+ }
743
+ }
744
+
745
+ var realColor = get({ format: format }),
746
+ displayColor = '';
747
+
748
+ //reset background info for preview element
749
+ previewElement.removeClass("sp-clear-display");
750
+ previewElement.css('background-color', 'transparent');
751
+
752
+ if (!realColor && allowEmpty) {
753
+ // Update the replaced elements background with icon indicating no color selection
754
+ previewElement.addClass("sp-clear-display");
755
+ }
756
+ else {
757
+ var realHex = realColor.toHexString(),
758
+ realRgb = realColor.toRgbString();
759
+
760
+ // Update the replaced elements background color (with actual selected color)
761
+ if (rgbaSupport || realColor.alpha === 1) {
762
+ previewElement.css("background-color", realRgb);
763
+ }
764
+ else {
765
+ previewElement.css("background-color", "transparent");
766
+ previewElement.css("filter", realColor.toFilter());
767
+ }
768
+
769
+ if (opts.showAlpha) {
770
+ var rgb = realColor.toRgb();
771
+ rgb.a = 0;
772
+ var realAlpha = tinycolor(rgb).toRgbString();
773
+ var gradient = "linear-gradient(left, " + realAlpha + ", " + realHex + ")";
774
+
775
+ if (IE) {
776
+ alphaSliderInner.css("filter", tinycolor(realAlpha).toFilter({ gradientType: 1 }, realHex));
777
+ }
778
+ else {
779
+ alphaSliderInner.css("background", "-webkit-" + gradient);
780
+ alphaSliderInner.css("background", "-moz-" + gradient);
781
+ alphaSliderInner.css("background", "-ms-" + gradient);
782
+ // Use current syntax gradient on unprefixed property.
783
+ alphaSliderInner.css("background",
784
+ "linear-gradient(to right, " + realAlpha + ", " + realHex + ")");
785
+ }
786
+ }
787
+
788
+ displayColor = realColor.toString(format);
789
+ }
790
+
791
+ // Update the text entry input as it changes happen
792
+ if (opts.showInput) {
793
+ textInput.val(displayColor);
794
+ }
795
+
796
+ if (opts.showPalette) {
797
+ drawPalette();
798
+ }
799
+
800
+ drawInitial();
801
+ }
802
+
803
+ function updateHelperLocations() {
804
+ var s = currentSaturation;
805
+ var v = currentValue;
806
+
807
+ if(allowEmpty && isEmpty) {
808
+ //if selected color is empty, hide the helpers
809
+ alphaSlideHelper.hide();
810
+ slideHelper.hide();
811
+ dragHelper.hide();
812
+ }
813
+ else {
814
+ //make sure helpers are visible
815
+ alphaSlideHelper.show();
816
+ slideHelper.show();
817
+ dragHelper.show();
818
+
819
+ // Where to show the little circle in that displays your current selected color
820
+ var dragX = s * dragWidth;
821
+ var dragY = dragHeight - (v * dragHeight);
822
+ dragX = Math.max(
823
+ -dragHelperHeight,
824
+ Math.min(dragWidth - dragHelperHeight, dragX - dragHelperHeight)
825
+ );
826
+ dragY = Math.max(
827
+ -dragHelperHeight,
828
+ Math.min(dragHeight - dragHelperHeight, dragY - dragHelperHeight)
829
+ );
830
+ dragHelper.css({
831
+ "top": dragY + "px",
832
+ "left": dragX + "px"
833
+ });
834
+
835
+ var alphaX = currentAlpha * alphaWidth;
836
+ alphaSlideHelper.css({
837
+ "left": (alphaX - (alphaSlideHelperWidth / 2)) + "px"
838
+ });
839
+
840
+ // Where to show the bar that displays your current selected hue
841
+ var slideY = (currentHue) * slideHeight;
842
+ slideHelper.css({
843
+ "top": (slideY - slideHelperHeight) + "px"
844
+ });
845
+ }
846
+ }
847
+
848
+ function updateOriginalInput(fireCallback) {
849
+ var color = get(),
850
+ displayColor = '',
851
+ hasChanged = !tinycolor.equals(color, colorOnShow);
852
+
853
+ if (color) {
854
+ displayColor = color.toString(currentPreferredFormat);
855
+ // Update the selection palette with the current color
856
+ addColorToSelectionPalette(color);
857
+ }
858
+
859
+ if (isInput) {
860
+ boundElement.val(displayColor);
861
+ }
862
+
863
+ colorOnShow = color;
864
+
865
+ if (fireCallback && hasChanged) {
866
+ callbacks.change(color);
867
+ boundElement.trigger('change', [ color ]);
868
+ }
869
+ }
870
+
871
+ function reflow() {
872
+ dragWidth = dragger.width();
873
+ dragHeight = dragger.height();
874
+ dragHelperHeight = dragHelper.height();
875
+ slideWidth = slider.width();
876
+ slideHeight = slider.height();
877
+ slideHelperHeight = slideHelper.height();
878
+ alphaWidth = alphaSlider.width();
879
+ alphaSlideHelperWidth = alphaSlideHelper.width();
880
+
881
+ if (!flat) {
882
+ container.css("position", "absolute");
883
+ container.offset(getOffset(container, offsetElement));
884
+ }
885
+
886
+ updateHelperLocations();
887
+
888
+ if (opts.showPalette) {
889
+ drawPalette();
890
+ }
891
+
892
+ boundElement.trigger('reflow.spectrum');
893
+ }
894
+
895
+ function destroy() {
896
+ boundElement.show();
897
+ offsetElement.unbind("click.spectrum touchstart.spectrum");
898
+ container.remove();
899
+ replacer.remove();
900
+ spectrums[spect.id] = null;
901
+ }
902
+
903
+ function option(optionName, optionValue) {
904
+ if (optionName === undefined) {
905
+ return $.extend({}, opts);
906
+ }
907
+ if (optionValue === undefined) {
908
+ return opts[optionName];
909
+ }
910
+
911
+ opts[optionName] = optionValue;
912
+ applyOptions();
913
+ }
914
+
915
+ function enable() {
916
+ disabled = false;
917
+ boundElement.attr("disabled", false);
918
+ offsetElement.removeClass("sp-disabled");
919
+ }
920
+
921
+ function disable() {
922
+ hide();
923
+ disabled = true;
924
+ boundElement.attr("disabled", true);
925
+ offsetElement.addClass("sp-disabled");
926
+ }
927
+
928
+ initialize();
929
+
930
+ var spect = {
931
+ show: show,
932
+ hide: hide,
933
+ toggle: toggle,
934
+ reflow: reflow,
935
+ option: option,
936
+ enable: enable,
937
+ disable: disable,
938
+ set: function (c) {
939
+ set(c);
940
+ updateOriginalInput();
941
+ },
942
+ get: get,
943
+ destroy: destroy,
944
+ container: container
945
+ };
946
+
947
+ spect.id = spectrums.push(spect) - 1;
948
+
949
+ return spect;
950
+ }
951
+
952
+ /**
953
+ * checkOffset - get the offset below/above and left/right element depending on screen position
954
+ * Thanks https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js
955
+ */
956
+ function getOffset(picker, input) {
957
+ var extraY = 0;
958
+ var dpWidth = picker.outerWidth();
959
+ var dpHeight = picker.outerHeight();
960
+ var inputHeight = input.outerHeight();
961
+ var doc = picker[0].ownerDocument;
962
+ var docElem = doc.documentElement;
963
+ var viewWidth = docElem.clientWidth + $(doc).scrollLeft();
964
+ var viewHeight = docElem.clientHeight + $(doc).scrollTop();
965
+ var offset = input.offset();
966
+ offset.top += inputHeight;
967
+
968
+ offset.left -=
969
+ Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
970
+ Math.abs(offset.left + dpWidth - viewWidth) : 0);
971
+
972
+ offset.top -=
973
+ Math.min(offset.top, ((offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
974
+ Math.abs(dpHeight + inputHeight - extraY) : extraY));
975
+
976
+ return offset;
977
+ }
978
+
979
+ /**
980
+ * noop - do nothing
981
+ */
982
+ function noop() {
983
+
984
+ }
985
+
986
+ /**
987
+ * stopPropagation - makes the code only doing this a little easier to read in line
988
+ */
989
+ function stopPropagation(e) {
990
+ e.stopPropagation();
991
+ }
992
+
993
+ /**
994
+ * Create a function bound to a given object
995
+ * Thanks to underscore.js
996
+ */
997
+ function bind(func, obj) {
998
+ var slice = Array.prototype.slice;
999
+ var args = slice.call(arguments, 2);
1000
+ return function () {
1001
+ return func.apply(obj, args.concat(slice.call(arguments)));
1002
+ };
1003
+ }
1004
+
1005
+ /**
1006
+ * Lightweight drag helper. Handles containment within the element, so that
1007
+ * when dragging, the x is within [0,element.width] and y is within [0,element.height]
1008
+ */
1009
+ function draggable(element, onmove, onstart, onstop) {
1010
+ onmove = onmove || function () { };
1011
+ onstart = onstart || function () { };
1012
+ onstop = onstop || function () { };
1013
+ var doc = element.ownerDocument || document;
1014
+ var dragging = false;
1015
+ var offset = {};
1016
+ var maxHeight = 0;
1017
+ var maxWidth = 0;
1018
+ var hasTouch = ('ontouchstart' in window);
1019
+
1020
+ var duringDragEvents = {};
1021
+ duringDragEvents["selectstart"] = prevent;
1022
+ duringDragEvents["dragstart"] = prevent;
1023
+ duringDragEvents["touchmove mousemove"] = move;
1024
+ duringDragEvents["touchend mouseup"] = stop;
1025
+
1026
+ function prevent(e) {
1027
+ if (e.stopPropagation) {
1028
+ e.stopPropagation();
1029
+ }
1030
+ if (e.preventDefault) {
1031
+ e.preventDefault();
1032
+ }
1033
+ e.returnValue = false;
1034
+ }
1035
+
1036
+ function move(e) {
1037
+ if (dragging) {
1038
+ // Mouseup happened outside of window
1039
+ if (IE && document.documentMode < 9 && !e.button) {
1040
+ return stop();
1041
+ }
1042
+
1043
+ var touches = e.originalEvent.touches;
1044
+ var pageX = touches ? touches[0].pageX : e.pageX;
1045
+ var pageY = touches ? touches[0].pageY : e.pageY;
1046
+
1047
+ var dragX = Math.max(0, Math.min(pageX - offset.left, maxWidth));
1048
+ var dragY = Math.max(0, Math.min(pageY - offset.top, maxHeight));
1049
+
1050
+ if (hasTouch) {
1051
+ // Stop scrolling in iOS
1052
+ prevent(e);
1053
+ }
1054
+
1055
+ onmove.apply(element, [dragX, dragY, e]);
1056
+ }
1057
+ }
1058
+
1059
+ function start(e) {
1060
+ var rightclick = (e.which) ? (e.which == 3) : (e.button == 2);
1061
+ var touches = e.originalEvent.touches;
1062
+
1063
+ if (!rightclick && !dragging) {
1064
+ if (onstart.apply(element, arguments) !== false) {
1065
+ dragging = true;
1066
+ maxHeight = $(element).height();
1067
+ maxWidth = $(element).width();
1068
+ offset = $(element).offset();
1069
+
1070
+ $(doc).bind(duringDragEvents);
1071
+ $(doc.body).addClass("sp-dragging");
1072
+
1073
+ if (!hasTouch) {
1074
+ move(e);
1075
+ }
1076
+
1077
+ prevent(e);
1078
+ }
1079
+ }
1080
+ }
1081
+
1082
+ function stop() {
1083
+ if (dragging) {
1084
+ $(doc).unbind(duringDragEvents);
1085
+ $(doc.body).removeClass("sp-dragging");
1086
+ onstop.apply(element, arguments);
1087
+ }
1088
+ dragging = false;
1089
+ }
1090
+
1091
+ $(element).bind("touchstart mousedown", start);
1092
+ }
1093
+
1094
+ function throttle(func, wait, debounce) {
1095
+ var timeout;
1096
+ return function () {
1097
+ var context = this, args = arguments;
1098
+ var throttler = function () {
1099
+ timeout = null;
1100
+ func.apply(context, args);
1101
+ };
1102
+ if (debounce) clearTimeout(timeout);
1103
+ if (debounce || !timeout) timeout = setTimeout(throttler, wait);
1104
+ };
1105
+ }
1106
+
1107
+ /**
1108
+ * Define a jQuery plugin
1109
+ */
1110
+ var dataID = "spectrum.id";
1111
+ $.fn.spectrum = function (opts, extra) {
1112
+
1113
+ if (typeof opts == "string") {
1114
+
1115
+ var returnValue = this;
1116
+ var args = Array.prototype.slice.call( arguments, 1 );
1117
+
1118
+ this.each(function () {
1119
+ var spect = spectrums[$(this).data(dataID)];
1120
+ if (spect) {
1121
+ var method = spect[opts];
1122
+ if (!method) {
1123
+ throw new Error( "Spectrum: no such method: '" + opts + "'" );
1124
+ }
1125
+
1126
+ if (opts == "get") {
1127
+ returnValue = spect.get();
1128
+ }
1129
+ else if (opts == "container") {
1130
+ returnValue = spect.container;
1131
+ }
1132
+ else if (opts == "option") {
1133
+ returnValue = spect.option.apply(spect, args);
1134
+ }
1135
+ else if (opts == "destroy") {
1136
+ spect.destroy();
1137
+ $(this).removeData(dataID);
1138
+ }
1139
+ else {
1140
+ method.apply(spect, args);
1141
+ }
1142
+ }
1143
+ });
1144
+
1145
+ return returnValue;
1146
+ }
1147
+
1148
+ // Initializing a new instance of spectrum
1149
+ return this.spectrum("destroy").each(function () {
1150
+ var options = $.extend({}, opts, $(this).data());
1151
+ var spect = spectrum(this, options);
1152
+ $(this).data(dataID, spect.id);
1153
+ });
1154
+ };
1155
+
1156
+ $.fn.spectrum.load = true;
1157
+ $.fn.spectrum.loadOpts = {};
1158
+ $.fn.spectrum.draggable = draggable;
1159
+ $.fn.spectrum.defaults = defaultOpts;
1160
+
1161
+ $.spectrum = { };
1162
+ $.spectrum.localization = { };
1163
+ $.spectrum.palettes = { };
1164
+
1165
+ $.fn.spectrum.processNativeColorInputs = function () {
1166
+ if (!inputTypeColorSupport) {
1167
+ $("input[type=color]").spectrum({
1168
+ preferredFormat: "hex6"
1169
+ });
1170
+ }
1171
+ };
1172
+
1173
+ // TinyColor v1.0.0
1174
+ // https://github.com/bgrins/TinyColor
1175
+ // Brian Grinstead, MIT License
1176
+
1177
+ (function() {
1178
+
1179
+ var trimLeft = /^[\s,#]+/,
1180
+ trimRight = /\s+$/,
1181
+ tinyCounter = 0,
1182
+ math = Math,
1183
+ mathRound = math.round,
1184
+ mathMin = math.min,
1185
+ mathMax = math.max,
1186
+ mathRandom = math.random;
1187
+
1188
+ var tinycolor = function tinycolor (color, opts) {
1189
+
1190
+ color = (color) ? color : '';
1191
+ opts = opts || { };
1192
+
1193
+ // If input is already a tinycolor, return itself
1194
+ if (color instanceof tinycolor) {
1195
+ return color;
1196
+ }
1197
+ // If we are called as a function, call using new instead
1198
+ if (!(this instanceof tinycolor)) {
1199
+ return new tinycolor(color, opts);
1200
+ }
1201
+
1202
+ var rgb = inputToRGB(color);
1203
+ this._r = rgb.r,
1204
+ this._g = rgb.g,
1205
+ this._b = rgb.b,
1206
+ this._a = rgb.a,
1207
+ this._roundA = mathRound(100*this._a) / 100,
1208
+ this._format = opts.format || rgb.format;
1209
+ this._gradientType = opts.gradientType;
1210
+
1211
+ // Don't let the range of [0,255] come back in [0,1].
1212
+ // Potentially lose a little bit of precision here, but will fix issues where
1213
+ // .5 gets interpreted as half of the total, instead of half of 1
1214
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
1215
+ if (this._r < 1) { this._r = mathRound(this._r); }
1216
+ if (this._g < 1) { this._g = mathRound(this._g); }
1217
+ if (this._b < 1) { this._b = mathRound(this._b); }
1218
+
1219
+ this._ok = rgb.ok;
1220
+ this._tc_id = tinyCounter++;
1221
+ };
1222
+
1223
+ tinycolor.prototype = {
1224
+ isDark: function() {
1225
+ return this.getBrightness() < 128;
1226
+ },
1227
+ isLight: function() {
1228
+ return !this.isDark();
1229
+ },
1230
+ isValid: function() {
1231
+ return this._ok;
1232
+ },
1233
+ getFormat: function() {
1234
+ return this._format;
1235
+ },
1236
+ getAlpha: function() {
1237
+ return this._a;
1238
+ },
1239
+ getBrightness: function() {
1240
+ var rgb = this.toRgb();
1241
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
1242
+ },
1243
+ setAlpha: function(value) {
1244
+ this._a = boundAlpha(value);
1245
+ this._roundA = mathRound(100*this._a) / 100;
1246
+ return this;
1247
+ },
1248
+ toHsv: function() {
1249
+ var hsv = rgbToHsv(this._r, this._g, this._b);
1250
+ return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
1251
+ },
1252
+ toHsvString: function() {
1253
+ var hsv = rgbToHsv(this._r, this._g, this._b);
1254
+ var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
1255
+ return (this._a == 1) ?
1256
+ "hsv(" + h + ", " + s + "%, " + v + "%)" :
1257
+ "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
1258
+ },
1259
+ toHsl: function() {
1260
+ var hsl = rgbToHsl(this._r, this._g, this._b);
1261
+ return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
1262
+ },
1263
+ toHslString: function() {
1264
+ var hsl = rgbToHsl(this._r, this._g, this._b);
1265
+ var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
1266
+ return (this._a == 1) ?
1267
+ "hsl(" + h + ", " + s + "%, " + l + "%)" :
1268
+ "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
1269
+ },
1270
+ toHex: function(allow3Char) {
1271
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
1272
+ },
1273
+ toHexString: function(allow3Char) {
1274
+ return '#' + this.toHex(allow3Char);
1275
+ },
1276
+ toHex8: function() {
1277
+ return rgbaToHex(this._r, this._g, this._b, this._a);
1278
+ },
1279
+ toHex8String: function() {
1280
+ return '#' + this.toHex8();
1281
+ },
1282
+ toRgb: function() {
1283
+ return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
1284
+ },
1285
+ toRgbString: function() {
1286
+ return (this._a == 1) ?
1287
+ "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
1288
+ "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
1289
+ },
1290
+ toPercentageRgb: function() {
1291
+ 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 };
1292
+ },
1293
+ toPercentageRgbString: function() {
1294
+ return (this._a == 1) ?
1295
+ "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
1296
+ "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
1297
+ },
1298
+ toName: function() {
1299
+ if (this._a === 0) {
1300
+ return "transparent";
1301
+ }
1302
+
1303
+ if (this._a < 1) {
1304
+ return false;
1305
+ }
1306
+
1307
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
1308
+ },
1309
+ toFilter: function(secondColor) {
1310
+ var hex8String = '#' + rgbaToHex(this._r, this._g, this._b, this._a);
1311
+ var secondHex8String = hex8String;
1312
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
1313
+
1314
+ if (secondColor) {
1315
+ var s = tinycolor(secondColor);
1316
+ secondHex8String = s.toHex8String();
1317
+ }
1318
+
1319
+ return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
1320
+ },
1321
+ toString: function(format) {
1322
+ var formatSet = !!format;
1323
+ format = format || this._format;
1324
+
1325
+ var formattedString = false;
1326
+ var hasAlpha = this._a < 1 && this._a >= 0;
1327
+ var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "name");
1328
+
1329
+ if (needsAlphaFormat) {
1330
+ // Special case for "transparent", all other non-alpha formats
1331
+ // will return rgba when there is transparency.
1332
+ if (format === "name" && this._a === 0) {
1333
+ return this.toName();
1334
+ }
1335
+ return this.toRgbString();
1336
+ }
1337
+ if (format === "rgb") {
1338
+ formattedString = this.toRgbString();
1339
+ }
1340
+ if (format === "prgb") {
1341
+ formattedString = this.toPercentageRgbString();
1342
+ }
1343
+ if (format === "hex" || format === "hex6") {
1344
+ formattedString = this.toHexString();
1345
+ }
1346
+ if (format === "hex3") {
1347
+ formattedString = this.toHexString(true);
1348
+ }
1349
+ if (format === "hex8") {
1350
+ formattedString = this.toHex8String();
1351
+ }
1352
+ if (format === "name") {
1353
+ formattedString = this.toName();
1354
+ }
1355
+ if (format === "hsl") {
1356
+ formattedString = this.toHslString();
1357
+ }
1358
+ if (format === "hsv") {
1359
+ formattedString = this.toHsvString();
1360
+ }
1361
+
1362
+ return formattedString || this.toHexString();
1363
+ },
1364
+
1365
+ _applyModification: function(fn, args) {
1366
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
1367
+ this._r = color._r;
1368
+ this._g = color._g;
1369
+ this._b = color._b;
1370
+ this.setAlpha(color._a);
1371
+ return this;
1372
+ },
1373
+ lighten: function() {
1374
+ return this._applyModification(lighten, arguments);
1375
+ },
1376
+ brighten: function() {
1377
+ return this._applyModification(brighten, arguments);
1378
+ },
1379
+ darken: function() {
1380
+ return this._applyModification(darken, arguments);
1381
+ },
1382
+ desaturate: function() {
1383
+ return this._applyModification(desaturate, arguments);
1384
+ },
1385
+ saturate: function() {
1386
+ return this._applyModification(saturate, arguments);
1387
+ },
1388
+ greyscale: function() {
1389
+ return this._applyModification(greyscale, arguments);
1390
+ },
1391
+ spin: function() {
1392
+ return this._applyModification(spin, arguments);
1393
+ },
1394
+
1395
+ _applyCombination: function(fn, args) {
1396
+ return fn.apply(null, [this].concat([].slice.call(args)));
1397
+ },
1398
+ analogous: function() {
1399
+ return this._applyCombination(analogous, arguments);
1400
+ },
1401
+ complement: function() {
1402
+ return this._applyCombination(complement, arguments);
1403
+ },
1404
+ monochromatic: function() {
1405
+ return this._applyCombination(monochromatic, arguments);
1406
+ },
1407
+ splitcomplement: function() {
1408
+ return this._applyCombination(splitcomplement, arguments);
1409
+ },
1410
+ triad: function() {
1411
+ return this._applyCombination(triad, arguments);
1412
+ },
1413
+ tetrad: function() {
1414
+ return this._applyCombination(tetrad, arguments);
1415
+ }
1416
+ };
1417
+
1418
+ // If input is an object, force 1 into "1.0" to handle ratios properly
1419
+ // String input requires "1.0" as input, so 1 will be treated as 1
1420
+ tinycolor.fromRatio = function(color, opts) {
1421
+ if (typeof color == "object") {
1422
+ var newColor = {};
1423
+ for (var i in color) {
1424
+ if (color.hasOwnProperty(i)) {
1425
+ if (i === "a") {
1426
+ newColor[i] = color[i];
1427
+ }
1428
+ else {
1429
+ newColor[i] = convertToPercentage(color[i]);
1430
+ }
1431
+ }
1432
+ }
1433
+ color = newColor;
1434
+ }
1435
+
1436
+ return tinycolor(color, opts);
1437
+ };
1438
+
1439
+ // Given a string or object, convert that input to RGB
1440
+ // Possible string inputs:
1441
+ //
1442
+ // "red"
1443
+ // "#f00" or "f00"
1444
+ // "#ff0000" or "ff0000"
1445
+ // "#ff000000" or "ff000000"
1446
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
1447
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
1448
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
1449
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
1450
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
1451
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
1452
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
1453
+ //
1454
+ function inputToRGB(color) {
1455
+
1456
+ var rgb = { r: 0, g: 0, b: 0 };
1457
+ var a = 1;
1458
+ var ok = false;
1459
+ var format = false;
1460
+
1461
+ if (typeof color == "string") {
1462
+ color = stringInputToObject(color);
1463
+ }
1464
+
1465
+ if (typeof color == "object") {
1466
+ if (color.hasOwnProperty("r") && color.hasOwnProperty("g") && color.hasOwnProperty("b")) {
1467
+ rgb = rgbToRgb(color.r, color.g, color.b);
1468
+ ok = true;
1469
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
1470
+ }
1471
+ else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("v")) {
1472
+ color.s = convertToPercentage(color.s);
1473
+ color.v = convertToPercentage(color.v);
1474
+ rgb = hsvToRgb(color.h, color.s, color.v);
1475
+ ok = true;
1476
+ format = "hsv";
1477
+ }
1478
+ else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("l")) {
1479
+ color.s = convertToPercentage(color.s);
1480
+ color.l = convertToPercentage(color.l);
1481
+ rgb = hslToRgb(color.h, color.s, color.l);
1482
+ ok = true;
1483
+ format = "hsl";
1484
+ }
1485
+
1486
+ if (color.hasOwnProperty("a")) {
1487
+ a = color.a;
1488
+ }
1489
+ }
1490
+
1491
+ a = boundAlpha(a);
1492
+
1493
+ return {
1494
+ ok: ok,
1495
+ format: color.format || format,
1496
+ r: mathMin(255, mathMax(rgb.r, 0)),
1497
+ g: mathMin(255, mathMax(rgb.g, 0)),
1498
+ b: mathMin(255, mathMax(rgb.b, 0)),
1499
+ a: a
1500
+ };
1501
+ }
1502
+
1503
+
1504
+ // Conversion Functions
1505
+ // --------------------
1506
+
1507
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
1508
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
1509
+
1510
+ // `rgbToRgb`
1511
+ // Handle bounds / percentage checking to conform to CSS color spec
1512
+ // <http://www.w3.org/TR/css3-color/>
1513
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
1514
+ // *Returns:* { r, g, b } in [0, 255]
1515
+ function rgbToRgb(r, g, b){
1516
+ return {
1517
+ r: bound01(r, 255) * 255,
1518
+ g: bound01(g, 255) * 255,
1519
+ b: bound01(b, 255) * 255
1520
+ };
1521
+ }
1522
+
1523
+ // `rgbToHsl`
1524
+ // Converts an RGB color value to HSL.
1525
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
1526
+ // *Returns:* { h, s, l } in [0,1]
1527
+ function rgbToHsl(r, g, b) {
1528
+
1529
+ r = bound01(r, 255);
1530
+ g = bound01(g, 255);
1531
+ b = bound01(b, 255);
1532
+
1533
+ var max = mathMax(r, g, b), min = mathMin(r, g, b);
1534
+ var h, s, l = (max + min) / 2;
1535
+
1536
+ if(max == min) {
1537
+ h = s = 0; // achromatic
1538
+ }
1539
+ else {
1540
+ var d = max - min;
1541
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1542
+ switch(max) {
1543
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
1544
+ case g: h = (b - r) / d + 2; break;
1545
+ case b: h = (r - g) / d + 4; break;
1546
+ }
1547
+
1548
+ h /= 6;
1549
+ }
1550
+
1551
+ return { h: h, s: s, l: l };
1552
+ }
1553
+
1554
+ // `hslToRgb`
1555
+ // Converts an HSL color value to RGB.
1556
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
1557
+ // *Returns:* { r, g, b } in the set [0, 255]
1558
+ function hslToRgb(h, s, l) {
1559
+ var r, g, b;
1560
+
1561
+ h = bound01(h, 360);
1562
+ s = bound01(s, 100);
1563
+ l = bound01(l, 100);
1564
+
1565
+ function hue2rgb(p, q, t) {
1566
+ if(t < 0) t += 1;
1567
+ if(t > 1) t -= 1;
1568
+ if(t < 1/6) return p + (q - p) * 6 * t;
1569
+ if(t < 1/2) return q;
1570
+ if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
1571
+ return p;
1572
+ }
1573
+
1574
+ if(s === 0) {
1575
+ r = g = b = l; // achromatic
1576
+ }
1577
+ else {
1578
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
1579
+ var p = 2 * l - q;
1580
+ r = hue2rgb(p, q, h + 1/3);
1581
+ g = hue2rgb(p, q, h);
1582
+ b = hue2rgb(p, q, h - 1/3);
1583
+ }
1584
+
1585
+ return { r: r * 255, g: g * 255, b: b * 255 };
1586
+ }
1587
+
1588
+ // `rgbToHsv`
1589
+ // Converts an RGB color value to HSV
1590
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
1591
+ // *Returns:* { h, s, v } in [0,1]
1592
+ function rgbToHsv(r, g, b) {
1593
+
1594
+ r = bound01(r, 255);
1595
+ g = bound01(g, 255);
1596
+ b = bound01(b, 255);
1597
+
1598
+ var max = mathMax(r, g, b), min = mathMin(r, g, b);
1599
+ var h, s, v = max;
1600
+
1601
+ var d = max - min;
1602
+ s = max === 0 ? 0 : d / max;
1603
+
1604
+ if(max == min) {
1605
+ h = 0; // achromatic
1606
+ }
1607
+ else {
1608
+ switch(max) {
1609
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
1610
+ case g: h = (b - r) / d + 2; break;
1611
+ case b: h = (r - g) / d + 4; break;
1612
+ }
1613
+ h /= 6;
1614
+ }
1615
+ return { h: h, s: s, v: v };
1616
+ }
1617
+
1618
+ // `hsvToRgb`
1619
+ // Converts an HSV color value to RGB.
1620
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
1621
+ // *Returns:* { r, g, b } in the set [0, 255]
1622
+ function hsvToRgb(h, s, v) {
1623
+
1624
+ h = bound01(h, 360) * 6;
1625
+ s = bound01(s, 100);
1626
+ v = bound01(v, 100);
1627
+
1628
+ var i = math.floor(h),
1629
+ f = h - i,
1630
+ p = v * (1 - s),
1631
+ q = v * (1 - f * s),
1632
+ t = v * (1 - (1 - f) * s),
1633
+ mod = i % 6,
1634
+ r = [v, q, p, p, t, v][mod],
1635
+ g = [t, v, v, q, p, p][mod],
1636
+ b = [p, p, t, v, v, q][mod];
1637
+
1638
+ return { r: r * 255, g: g * 255, b: b * 255 };
1639
+ }
1640
+
1641
+ // `rgbToHex`
1642
+ // Converts an RGB color to hex
1643
+ // Assumes r, g, and b are contained in the set [0, 255]
1644
+ // Returns a 3 or 6 character hex
1645
+ function rgbToHex(r, g, b, allow3Char) {
1646
+
1647
+ var hex = [
1648
+ pad2(mathRound(r).toString(16)),
1649
+ pad2(mathRound(g).toString(16)),
1650
+ pad2(mathRound(b).toString(16))
1651
+ ];
1652
+
1653
+ // Return a 3 character hex if possible
1654
+ 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)) {
1655
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
1656
+ }
1657
+
1658
+ return hex.join("");
1659
+ }
1660
+ // `rgbaToHex`
1661
+ // Converts an RGBA color plus alpha transparency to hex
1662
+ // Assumes r, g, b and a are contained in the set [0, 255]
1663
+ // Returns an 8 character hex
1664
+ function rgbaToHex(r, g, b, a) {
1665
+
1666
+ var hex = [
1667
+ pad2(convertDecimalToHex(a)),
1668
+ pad2(mathRound(r).toString(16)),
1669
+ pad2(mathRound(g).toString(16)),
1670
+ pad2(mathRound(b).toString(16))
1671
+ ];
1672
+
1673
+ return hex.join("");
1674
+ }
1675
+
1676
+ // `equals`
1677
+ // Can be called with any tinycolor input
1678
+ tinycolor.equals = function (color1, color2) {
1679
+ if (!color1 || !color2) { return false; }
1680
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
1681
+ };
1682
+ tinycolor.random = function() {
1683
+ return tinycolor.fromRatio({
1684
+ r: mathRandom(),
1685
+ g: mathRandom(),
1686
+ b: mathRandom()
1687
+ });
1688
+ };
1689
+
1690
+
1691
+ // Modification Functions
1692
+ // ----------------------
1693
+ // Thanks to less.js for some of the basics here
1694
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
1695
+
1696
+ function desaturate(color, amount) {
1697
+ amount = (amount === 0) ? 0 : (amount || 10);
1698
+ var hsl = tinycolor(color).toHsl();
1699
+ hsl.s -= amount / 100;
1700
+ hsl.s = clamp01(hsl.s);
1701
+ return tinycolor(hsl);
1702
+ }
1703
+
1704
+ function saturate(color, amount) {
1705
+ amount = (amount === 0) ? 0 : (amount || 10);
1706
+ var hsl = tinycolor(color).toHsl();
1707
+ hsl.s += amount / 100;
1708
+ hsl.s = clamp01(hsl.s);
1709
+ return tinycolor(hsl);
1710
+ }
1711
+
1712
+ function greyscale(color) {
1713
+ return tinycolor(color).desaturate(100);
1714
+ }
1715
+
1716
+ function lighten (color, amount) {
1717
+ amount = (amount === 0) ? 0 : (amount || 10);
1718
+ var hsl = tinycolor(color).toHsl();
1719
+ hsl.l += amount / 100;
1720
+ hsl.l = clamp01(hsl.l);
1721
+ return tinycolor(hsl);
1722
+ }
1723
+
1724
+ function brighten(color, amount) {
1725
+ amount = (amount === 0) ? 0 : (amount || 10);
1726
+ var rgb = tinycolor(color).toRgb();
1727
+ rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
1728
+ rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
1729
+ rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
1730
+ return tinycolor(rgb);
1731
+ }
1732
+
1733
+ function darken (color, amount) {
1734
+ amount = (amount === 0) ? 0 : (amount || 10);
1735
+ var hsl = tinycolor(color).toHsl();
1736
+ hsl.l -= amount / 100;
1737
+ hsl.l = clamp01(hsl.l);
1738
+ return tinycolor(hsl);
1739
+ }
1740
+
1741
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
1742
+ // Values outside of this range will be wrapped into this range.
1743
+ function spin(color, amount) {
1744
+ var hsl = tinycolor(color).toHsl();
1745
+ var hue = (mathRound(hsl.h) + amount) % 360;
1746
+ hsl.h = hue < 0 ? 360 + hue : hue;
1747
+ return tinycolor(hsl);
1748
+ }
1749
+
1750
+ // Combination Functions
1751
+ // ---------------------
1752
+ // Thanks to jQuery xColor for some of the ideas behind these
1753
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
1754
+
1755
+ function complement(color) {
1756
+ var hsl = tinycolor(color).toHsl();
1757
+ hsl.h = (hsl.h + 180) % 360;
1758
+ return tinycolor(hsl);
1759
+ }
1760
+
1761
+ function triad(color) {
1762
+ var hsl = tinycolor(color).toHsl();
1763
+ var h = hsl.h;
1764
+ return [
1765
+ tinycolor(color),
1766
+ tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
1767
+ tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
1768
+ ];
1769
+ }
1770
+
1771
+ function tetrad(color) {
1772
+ var hsl = tinycolor(color).toHsl();
1773
+ var h = hsl.h;
1774
+ return [
1775
+ tinycolor(color),
1776
+ tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
1777
+ tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
1778
+ tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
1779
+ ];
1780
+ }
1781
+
1782
+ function splitcomplement(color) {
1783
+ var hsl = tinycolor(color).toHsl();
1784
+ var h = hsl.h;
1785
+ return [
1786
+ tinycolor(color),
1787
+ tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
1788
+ tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
1789
+ ];
1790
+ }
1791
+
1792
+ function analogous(color, results, slices) {
1793
+ results = results || 6;
1794
+ slices = slices || 30;
1795
+
1796
+ var hsl = tinycolor(color).toHsl();
1797
+ var part = 360 / slices;
1798
+ var ret = [tinycolor(color)];
1799
+
1800
+ for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
1801
+ hsl.h = (hsl.h + part) % 360;
1802
+ ret.push(tinycolor(hsl));
1803
+ }
1804
+ return ret;
1805
+ }
1806
+
1807
+ function monochromatic(color, results) {
1808
+ results = results || 6;
1809
+ var hsv = tinycolor(color).toHsv();
1810
+ var h = hsv.h, s = hsv.s, v = hsv.v;
1811
+ var ret = [];
1812
+ var modification = 1 / results;
1813
+
1814
+ while (results--) {
1815
+ ret.push(tinycolor({ h: h, s: s, v: v}));
1816
+ v = (v + modification) % 1;
1817
+ }
1818
+
1819
+ return ret;
1820
+ }
1821
+
1822
+ // Utility Functions
1823
+ // ---------------------
1824
+
1825
+ tinycolor.mix = function(color1, color2, amount) {
1826
+ amount = (amount === 0) ? 0 : (amount || 50);
1827
+
1828
+ var rgb1 = tinycolor(color1).toRgb();
1829
+ var rgb2 = tinycolor(color2).toRgb();
1830
+
1831
+ var p = amount / 100;
1832
+ var w = p * 2 - 1;
1833
+ var a = rgb2.a - rgb1.a;
1834
+
1835
+ var w1;
1836
+
1837
+ if (w * a == -1) {
1838
+ w1 = w;
1839
+ } else {
1840
+ w1 = (w + a) / (1 + w * a);
1841
+ }
1842
+
1843
+ w1 = (w1 + 1) / 2;
1844
+
1845
+ var w2 = 1 - w1;
1846
+
1847
+ var rgba = {
1848
+ r: rgb2.r * w1 + rgb1.r * w2,
1849
+ g: rgb2.g * w1 + rgb1.g * w2,
1850
+ b: rgb2.b * w1 + rgb1.b * w2,
1851
+ a: rgb2.a * p + rgb1.a * (1 - p)
1852
+ };
1853
+
1854
+ return tinycolor(rgba);
1855
+ };
1856
+
1857
+
1858
+ // Readability Functions
1859
+ // ---------------------
1860
+ // <http://www.w3.org/TR/AERT#color-contrast>
1861
+
1862
+ // `readability`
1863
+ // Analyze the 2 colors and returns an object with the following properties:
1864
+ // `brightness`: difference in brightness between the two colors
1865
+ // `color`: difference in color/hue between the two colors
1866
+ tinycolor.readability = function(color1, color2) {
1867
+ var c1 = tinycolor(color1);
1868
+ var c2 = tinycolor(color2);
1869
+ var rgb1 = c1.toRgb();
1870
+ var rgb2 = c2.toRgb();
1871
+ var brightnessA = c1.getBrightness();
1872
+ var brightnessB = c2.getBrightness();
1873
+ var colorDiff = (
1874
+ Math.max(rgb1.r, rgb2.r) - Math.min(rgb1.r, rgb2.r) +
1875
+ Math.max(rgb1.g, rgb2.g) - Math.min(rgb1.g, rgb2.g) +
1876
+ Math.max(rgb1.b, rgb2.b) - Math.min(rgb1.b, rgb2.b)
1877
+ );
1878
+
1879
+ return {
1880
+ brightness: Math.abs(brightnessA - brightnessB),
1881
+ color: colorDiff
1882
+ };
1883
+ };
1884
+
1885
+ // `readable`
1886
+ // http://www.w3.org/TR/AERT#color-contrast
1887
+ // Ensure that foreground and background color combinations provide sufficient contrast.
1888
+ // *Example*
1889
+ // tinycolor.isReadable("#000", "#111") => false
1890
+ tinycolor.isReadable = function(color1, color2) {
1891
+ var readability = tinycolor.readability(color1, color2);
1892
+ return readability.brightness > 125 && readability.color > 500;
1893
+ };
1894
+
1895
+ // `mostReadable`
1896
+ // Given a base color and a list of possible foreground or background
1897
+ // colors for that base, returns the most readable color.
1898
+ // *Example*
1899
+ // tinycolor.mostReadable("#123", ["#fff", "#000"]) => "#000"
1900
+ tinycolor.mostReadable = function(baseColor, colorList) {
1901
+ var bestColor = null;
1902
+ var bestScore = 0;
1903
+ var bestIsReadable = false;
1904
+ for (var i=0; i < colorList.length; i++) {
1905
+
1906
+ // We createTicks both around the "acceptable" breaking point,
1907
+ // but rank brightness constrast higher than hue.
1908
+
1909
+ var readability = tinycolor.readability(baseColor, colorList[i]);
1910
+ var readable = readability.brightness > 125 && readability.color > 500;
1911
+ var score = 3 * (readability.brightness / 125) + (readability.color / 500);
1912
+
1913
+ if ((readable && ! bestIsReadable) ||
1914
+ (readable && bestIsReadable && score > bestScore) ||
1915
+ ((! readable) && (! bestIsReadable) && score > bestScore)) {
1916
+ bestIsReadable = readable;
1917
+ bestScore = score;
1918
+ bestColor = tinycolor(colorList[i]);
1919
+ }
1920
+ }
1921
+ return bestColor;
1922
+ };
1923
+
1924
+
1925
+ // Big List of Colors
1926
+ // ------------------
1927
+ // <http://www.w3.org/TR/css3-color/#svg-color>
1928
+ var names = tinycolor.names = {
1929
+ aliceblue: "f0f8ff",
1930
+ antiquewhite: "faebd7",
1931
+ aqua: "0ff",
1932
+ aquamarine: "7fffd4",
1933
+ azure: "f0ffff",
1934
+ beige: "f5f5dc",
1935
+ bisque: "ffe4c4",
1936
+ black: "000",
1937
+ blanchedalmond: "ffebcd",
1938
+ blue: "00f",
1939
+ blueviolet: "8a2be2",
1940
+ brown: "a52a2a",
1941
+ burlywood: "deb887",
1942
+ burntsienna: "ea7e5d",
1943
+ cadetblue: "5f9ea0",
1944
+ chartreuse: "7fff00",
1945
+ chocolate: "d2691e",
1946
+ coral: "ff7f50",
1947
+ cornflowerblue: "6495ed",
1948
+ cornsilk: "fff8dc",
1949
+ crimson: "dc143c",
1950
+ cyan: "0ff",
1951
+ darkblue: "00008b",
1952
+ darkcyan: "008b8b",
1953
+ darkgoldenrod: "b8860b",
1954
+ darkgray: "a9a9a9",
1955
+ darkgreen: "006400",
1956
+ darkgrey: "a9a9a9",
1957
+ darkkhaki: "bdb76b",
1958
+ darkmagenta: "8b008b",
1959
+ darkolivegreen: "556b2f",
1960
+ darkorange: "ff8c00",
1961
+ darkorchid: "9932cc",
1962
+ darkred: "8b0000",
1963
+ darksalmon: "e9967a",
1964
+ darkseagreen: "8fbc8f",
1965
+ darkslateblue: "483d8b",
1966
+ darkslategray: "2f4f4f",
1967
+ darkslategrey: "2f4f4f",
1968
+ darkturquoise: "00ced1",
1969
+ darkviolet: "9400d3",
1970
+ deeppink: "ff1493",
1971
+ deepskyblue: "00bfff",
1972
+ dimgray: "696969",
1973
+ dimgrey: "696969",
1974
+ dodgerblue: "1e90ff",
1975
+ firebrick: "b22222",
1976
+ floralwhite: "fffaf0",
1977
+ forestgreen: "228b22",
1978
+ fuchsia: "f0f",
1979
+ gainsboro: "dcdcdc",
1980
+ ghostwhite: "f8f8ff",
1981
+ gold: "ffd700",
1982
+ goldenrod: "daa520",
1983
+ gray: "808080",
1984
+ green: "008000",
1985
+ greenyellow: "adff2f",
1986
+ grey: "808080",
1987
+ honeydew: "f0fff0",
1988
+ hotpink: "ff69b4",
1989
+ indianred: "cd5c5c",
1990
+ indigo: "4b0082",
1991
+ ivory: "fffff0",
1992
+ khaki: "f0e68c",
1993
+ lavender: "e6e6fa",
1994
+ lavenderblush: "fff0f5",
1995
+ lawngreen: "7cfc00",
1996
+ lemonchiffon: "fffacd",
1997
+ lightblue: "add8e6",
1998
+ lightcoral: "f08080",
1999
+ lightcyan: "e0ffff",
2000
+ lightgoldenrodyellow: "fafad2",
2001
+ lightgray: "d3d3d3",
2002
+ lightgreen: "90ee90",
2003
+ lightgrey: "d3d3d3",
2004
+ lightpink: "ffb6c1",
2005
+ lightsalmon: "ffa07a",
2006
+ lightseagreen: "20b2aa",
2007
+ lightskyblue: "87cefa",
2008
+ lightslategray: "789",
2009
+ lightslategrey: "789",
2010
+ lightsteelblue: "b0c4de",
2011
+ lightyellow: "ffffe0",
2012
+ lime: "0f0",
2013
+ limegreen: "32cd32",
2014
+ linen: "faf0e6",
2015
+ magenta: "f0f",
2016
+ maroon: "800000",
2017
+ mediumaquamarine: "66cdaa",
2018
+ mediumblue: "0000cd",
2019
+ mediumorchid: "ba55d3",
2020
+ mediumpurple: "9370db",
2021
+ mediumseagreen: "3cb371",
2022
+ mediumslateblue: "7b68ee",
2023
+ mediumspringgreen: "00fa9a",
2024
+ mediumturquoise: "48d1cc",
2025
+ mediumvioletred: "c71585",
2026
+ midnightblue: "191970",
2027
+ mintcream: "f5fffa",
2028
+ mistyrose: "ffe4e1",
2029
+ moccasin: "ffe4b5",
2030
+ navajowhite: "ffdead",
2031
+ navy: "000080",
2032
+ oldlace: "fdf5e6",
2033
+ olive: "808000",
2034
+ olivedrab: "6b8e23",
2035
+ orange: "ffa500",
2036
+ orangered: "ff4500",
2037
+ orchid: "da70d6",
2038
+ palegoldenrod: "eee8aa",
2039
+ palegreen: "98fb98",
2040
+ paleturquoise: "afeeee",
2041
+ palevioletred: "db7093",
2042
+ papayawhip: "ffefd5",
2043
+ peachpuff: "ffdab9",
2044
+ peru: "cd853f",
2045
+ pink: "ffc0cb",
2046
+ plum: "dda0dd",
2047
+ powderblue: "b0e0e6",
2048
+ purple: "800080",
2049
+ red: "f00",
2050
+ rosybrown: "bc8f8f",
2051
+ royalblue: "4169e1",
2052
+ saddlebrown: "8b4513",
2053
+ salmon: "fa8072",
2054
+ sandybrown: "f4a460",
2055
+ seagreen: "2e8b57",
2056
+ seashell: "fff5ee",
2057
+ sienna: "a0522d",
2058
+ silver: "c0c0c0",
2059
+ skyblue: "87ceeb",
2060
+ slateblue: "6a5acd",
2061
+ slategray: "708090",
2062
+ slategrey: "708090",
2063
+ snow: "fffafa",
2064
+ springgreen: "00ff7f",
2065
+ steelblue: "4682b4",
2066
+ tan: "d2b48c",
2067
+ teal: "008080",
2068
+ thistle: "d8bfd8",
2069
+ tomato: "ff6347",
2070
+ turquoise: "40e0d0",
2071
+ violet: "ee82ee",
2072
+ wheat: "f5deb3",
2073
+ white: "fff",
2074
+ whitesmoke: "f5f5f5",
2075
+ yellow: "ff0",
2076
+ yellowgreen: "9acd32"
2077
+ };
2078
+
2079
+ // Make it easy to access colors via `hexNames[hex]`
2080
+ var hexNames = tinycolor.hexNames = flip(names);
2081
+
2082
+
2083
+ // Utilities
2084
+ // ---------
2085
+
2086
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
2087
+ function flip(o) {
2088
+ var flipped = { };
2089
+ for (var i in o) {
2090
+ if (o.hasOwnProperty(i)) {
2091
+ flipped[o[i]] = i;
2092
+ }
2093
+ }
2094
+ return flipped;
2095
+ }
2096
+
2097
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
2098
+ function boundAlpha(a) {
2099
+ a = parseFloat(a);
2100
+
2101
+ if (isNaN(a) || a < 0 || a > 1) {
2102
+ a = 1;
2103
+ }
2104
+
2105
+ return a;
2106
+ }
2107
+
2108
+ // Take input from [0, n] and return it as [0, 1]
2109
+ function bound01(n, max) {
2110
+ if (isOnePointZero(n)) { n = "100%"; }
2111
+
2112
+ var processPercent = isPercentage(n);
2113
+ n = mathMin(max, mathMax(0, parseFloat(n)));
2114
+
2115
+ // Automatically convert percentage into number
2116
+ if (processPercent) {
2117
+ n = parseInt(n * max, 10) / 100;
2118
+ }
2119
+
2120
+ // Handle floating point rounding errors
2121
+ if ((math.abs(n - max) < 0.000001)) {
2122
+ return 1;
2123
+ }
2124
+
2125
+ // Convert into [0, 1] range if it isn't already
2126
+ return (n % max) / parseFloat(max);
2127
+ }
2128
+
2129
+ // Force a number between 0 and 1
2130
+ function clamp01(val) {
2131
+ return mathMin(1, mathMax(0, val));
2132
+ }
2133
+
2134
+ // Parse a base-16 hex value into a base-10 integer
2135
+ function parseIntFromHex(val) {
2136
+ return parseInt(val, 16);
2137
+ }
2138
+
2139
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
2140
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
2141
+ function isOnePointZero(n) {
2142
+ return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
2143
+ }
2144
+
2145
+ // Check to see if string passed in is a percentage
2146
+ function isPercentage(n) {
2147
+ return typeof n === "string" && n.indexOf('%') != -1;
2148
+ }
2149
+
2150
+ // Force a hex value to have 2 characters
2151
+ function pad2(c) {
2152
+ return c.length == 1 ? '0' + c : '' + c;
2153
+ }
2154
+
2155
+ // Replace a decimal with it's percentage value
2156
+ function convertToPercentage(n) {
2157
+ if (n <= 1) {
2158
+ n = (n * 100) + "%";
2159
+ }
2160
+
2161
+ return n;
2162
+ }
2163
+
2164
+ // Converts a decimal to a hex value
2165
+ function convertDecimalToHex(d) {
2166
+ return Math.round(parseFloat(d) * 255).toString(16);
2167
+ }
2168
+ // Converts a hex value to a decimal
2169
+ function convertHexToDecimal(h) {
2170
+ return (parseIntFromHex(h) / 255);
2171
+ }
2172
+
2173
+ var matchers = (function() {
2174
+
2175
+ // <http://www.w3.org/TR/css3-values/#integers>
2176
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
2177
+
2178
+ // <http://www.w3.org/TR/css3-values/#number-value>
2179
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
2180
+
2181
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
2182
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
2183
+
2184
+ // Actual matching.
2185
+ // Parentheses and commas are optional, but not required.
2186
+ // Whitespace can take the place of commas or opening paren
2187
+ var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
2188
+ var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
2189
+
2190
+ return {
2191
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
2192
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
2193
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
2194
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
2195
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
2196
+ hex3: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
2197
+ hex6: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
2198
+ hex8: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
2199
+ };
2200
+ })();
2201
+
2202
+ // `stringInputToObject`
2203
+ // Permissive string parsing. Take in a number of formats, and output an object
2204
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
2205
+ function stringInputToObject(color) {
2206
+
2207
+ color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
2208
+ var named = false;
2209
+ if (names[color]) {
2210
+ color = names[color];
2211
+ named = true;
2212
+ }
2213
+ else if (color == 'transparent') {
2214
+ return { r: 0, g: 0, b: 0, a: 0, format: "name" };
2215
+ }
2216
+
2217
+ // Try to match string input using regular expressions.
2218
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
2219
+ // Just return an object and let the conversion functions handle that.
2220
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
2221
+ var match;
2222
+ if ((match = matchers.rgb.exec(color))) {
2223
+ return { r: match[1], g: match[2], b: match[3] };
2224
+ }
2225
+ if ((match = matchers.rgba.exec(color))) {
2226
+ return { r: match[1], g: match[2], b: match[3], a: match[4] };
2227
+ }
2228
+ if ((match = matchers.hsl.exec(color))) {
2229
+ return { h: match[1], s: match[2], l: match[3] };
2230
+ }
2231
+ if ((match = matchers.hsla.exec(color))) {
2232
+ return { h: match[1], s: match[2], l: match[3], a: match[4] };
2233
+ }
2234
+ if ((match = matchers.hsv.exec(color))) {
2235
+ return { h: match[1], s: match[2], v: match[3] };
2236
+ }
2237
+ if ((match = matchers.hex8.exec(color))) {
2238
+ return {
2239
+ a: convertHexToDecimal(match[1]),
2240
+ r: parseIntFromHex(match[2]),
2241
+ g: parseIntFromHex(match[3]),
2242
+ b: parseIntFromHex(match[4]),
2243
+ format: named ? "name" : "hex8"
2244
+ };
2245
+ }
2246
+ if ((match = matchers.hex6.exec(color))) {
2247
+ return {
2248
+ r: parseIntFromHex(match[1]),
2249
+ g: parseIntFromHex(match[2]),
2250
+ b: parseIntFromHex(match[3]),
2251
+ format: named ? "name" : "hex"
2252
+ };
2253
+ }
2254
+ if ((match = matchers.hex3.exec(color))) {
2255
+ return {
2256
+ r: parseIntFromHex(match[1] + '' + match[1]),
2257
+ g: parseIntFromHex(match[2] + '' + match[2]),
2258
+ b: parseIntFromHex(match[3] + '' + match[3]),
2259
+ format: named ? "name" : "hex"
2260
+ };
2261
+ }
2262
+
2263
+ return false;
2264
+ }
2265
+
2266
+ window.tinycolor = tinycolor;
2267
+ })();
2268
+
2269
+ $(function () {
2270
+ if ($.fn.spectrum.load) {
2271
+ $.fn.spectrum.processNativeColorInputs();
2272
+ }
2273
+ });
2274
+
2275
+ })(window, jQuery);
2276
+ })(External = FintaChart.External || (FintaChart.External = {}));
2277
+ })(FintaChart || (FintaChart = {}));
2278
+
2279
+