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

1916 lines
64 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*! =======================================================
  2. VERSION 10.3.2
  3. ========================================================= */
  4. "use strict";
  5. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  6. /*! =========================================================
  7. * bootstrap-slider.js
  8. *
  9. * Maintainers:
  10. * Kyle Kemp
  11. * - Twitter: @seiyria
  12. * - Github: seiyria
  13. * Rohit Kalkur
  14. * - Twitter: @Rovolutionary
  15. * - Github: rovolution
  16. *
  17. * =========================================================
  18. *
  19. * bootstrap-slider is released under the MIT License
  20. * Copyright (c) 2017 Kyle Kemp, Rohit Kalkur, and contributors
  21. *
  22. * Permission is hereby granted, free of charge, to any person
  23. * obtaining a copy of this software and associated documentation
  24. * files (the "Software"), to deal in the Software without
  25. * restriction, including without limitation the rights to use,
  26. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  27. * copies of the Software, and to permit persons to whom the
  28. * Software is furnished to do so, subject to the following
  29. * conditions:
  30. *
  31. * The above copyright notice and this permission notice shall be
  32. * included in all copies or substantial portions of the Software.
  33. *
  34. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  35. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  36. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  37. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  38. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  39. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  40. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  41. * OTHER DEALINGS IN THE SOFTWARE.
  42. *
  43. * ========================================================= */
  44. /**
  45. * Bridget makes jQuery widgets
  46. * v1.0.1
  47. * MIT license
  48. */
  49. var windowIsDefined = (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object";
  50. (function (factory) {
  51. if (typeof define === "function" && define.amd) {
  52. define(["jquery"], factory);
  53. } else if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === "object" && module.exports) {
  54. var jQuery;
  55. try {
  56. jQuery = require("jquery");
  57. } catch (err) {
  58. jQuery = null;
  59. }
  60. module.exports = factory(jQuery);
  61. } else if (window) {
  62. window.Slider = factory(window.jQuery);
  63. }
  64. })(function ($) {
  65. // Constants
  66. var NAMESPACE_MAIN = 'slider';
  67. var NAMESPACE_ALTERNATE = 'bootstrapSlider';
  68. // Polyfill console methods
  69. if (windowIsDefined && !window.console) {
  70. window.console = {};
  71. }
  72. if (windowIsDefined && !window.console.log) {
  73. window.console.log = function () {};
  74. }
  75. if (windowIsDefined && !window.console.warn) {
  76. window.console.warn = function () {};
  77. }
  78. // Reference to Slider constructor
  79. var Slider;
  80. (function ($) {
  81. 'use strict';
  82. // -------------------------- utils -------------------------- //
  83. var slice = Array.prototype.slice;
  84. function noop() {}
  85. // -------------------------- definition -------------------------- //
  86. function defineBridget($) {
  87. // bail if no jQuery
  88. if (!$) {
  89. return;
  90. }
  91. // -------------------------- addOptionMethod -------------------------- //
  92. /**
  93. * adds option method -> $().plugin('option', {...})
  94. * @param {Function} PluginClass - constructor class
  95. */
  96. function addOptionMethod(PluginClass) {
  97. // don't overwrite original option method
  98. if (PluginClass.prototype.option) {
  99. return;
  100. }
  101. // option setter
  102. PluginClass.prototype.option = function (opts) {
  103. // bail out if not an object
  104. if (!$.isPlainObject(opts)) {
  105. return;
  106. }
  107. this.options = $.extend(true, this.options, opts);
  108. };
  109. }
  110. // -------------------------- plugin bridge -------------------------- //
  111. // helper function for logging errors
  112. // $.error breaks jQuery chaining
  113. var logError = typeof console === 'undefined' ? noop : function (message) {
  114. console.error(message);
  115. };
  116. /**
  117. * jQuery plugin bridge, access methods like $elem.plugin('method')
  118. * @param {String} namespace - plugin name
  119. * @param {Function} PluginClass - constructor class
  120. */
  121. function bridge(namespace, PluginClass) {
  122. // add to jQuery fn namespace
  123. $.fn[namespace] = function (options) {
  124. if (typeof options === 'string') {
  125. // call plugin method when first argument is a string
  126. // get arguments for method
  127. var args = slice.call(arguments, 1);
  128. for (var i = 0, len = this.length; i < len; i++) {
  129. var elem = this[i];
  130. var instance = $.data(elem, namespace);
  131. if (!instance) {
  132. logError("cannot call methods on " + namespace + " prior to initialization; " + "attempted to call '" + options + "'");
  133. continue;
  134. }
  135. if (!$.isFunction(instance[options]) || options.charAt(0) === '_') {
  136. logError("no such method '" + options + "' for " + namespace + " instance");
  137. continue;
  138. }
  139. // trigger method with arguments
  140. var returnValue = instance[options].apply(instance, args);
  141. // break look and return first value if provided
  142. if (returnValue !== undefined && returnValue !== instance) {
  143. return returnValue;
  144. }
  145. }
  146. // return this if no return value
  147. return this;
  148. } else {
  149. var objects = this.map(function () {
  150. var instance = $.data(this, namespace);
  151. if (instance) {
  152. // apply options & init
  153. instance.option(options);
  154. instance._init();
  155. } else {
  156. // initialize new instance
  157. instance = new PluginClass(this, options);
  158. $.data(this, namespace, instance);
  159. }
  160. return $(this);
  161. });
  162. if (!objects || objects.length > 1) {
  163. return objects;
  164. } else {
  165. return objects[0];
  166. }
  167. }
  168. };
  169. }
  170. // -------------------------- bridget -------------------------- //
  171. /**
  172. * converts a Prototypical class into a proper jQuery plugin
  173. * the class must have a ._init method
  174. * @param {String} namespace - plugin name, used in $().pluginName
  175. * @param {Function} PluginClass - constructor class
  176. */
  177. $.bridget = function (namespace, PluginClass) {
  178. addOptionMethod(PluginClass);
  179. bridge(namespace, PluginClass);
  180. };
  181. return $.bridget;
  182. }
  183. // get jquery from browser global
  184. defineBridget($);
  185. })($);
  186. /*************************************************
  187. BOOTSTRAP-SLIDER SOURCE CODE
  188. **************************************************/
  189. (function ($) {
  190. var ErrorMsgs = {
  191. formatInvalidInputErrorMsg: function formatInvalidInputErrorMsg(input) {
  192. return "Invalid input value '" + input + "' passed in";
  193. },
  194. callingContextNotSliderInstance: "Calling context element does not have instance of Slider bound to it. Check your code to make sure the JQuery object returned from the call to the slider() initializer is calling the method"
  195. };
  196. var SliderScale = {
  197. linear: {
  198. toValue: function toValue(percentage) {
  199. var rawValue = percentage / 100 * (this.options.max - this.options.min);
  200. var shouldAdjustWithBase = true;
  201. if (this.options.ticks_positions.length > 0) {
  202. var minv,
  203. maxv,
  204. minp,
  205. maxp = 0;
  206. for (var i = 1; i < this.options.ticks_positions.length; i++) {
  207. if (percentage <= this.options.ticks_positions[i]) {
  208. minv = this.options.ticks[i - 1];
  209. minp = this.options.ticks_positions[i - 1];
  210. maxv = this.options.ticks[i];
  211. maxp = this.options.ticks_positions[i];
  212. break;
  213. }
  214. }
  215. var partialPercentage = (percentage - minp) / (maxp - minp);
  216. rawValue = minv + partialPercentage * (maxv - minv);
  217. shouldAdjustWithBase = false;
  218. }
  219. var adjustment = shouldAdjustWithBase ? this.options.min : 0;
  220. var value = adjustment + Math.round(rawValue / this.options.step) * this.options.step;
  221. if (value < this.options.min) {
  222. return this.options.min;
  223. } else if (value > this.options.max) {
  224. return this.options.max;
  225. } else {
  226. return value;
  227. }
  228. },
  229. toPercentage: function toPercentage(value) {
  230. if (this.options.max === this.options.min) {
  231. return 0;
  232. }
  233. if (this.options.ticks_positions.length > 0) {
  234. var minv,
  235. maxv,
  236. minp,
  237. maxp = 0;
  238. for (var i = 0; i < this.options.ticks.length; i++) {
  239. if (value <= this.options.ticks[i]) {
  240. minv = i > 0 ? this.options.ticks[i - 1] : 0;
  241. minp = i > 0 ? this.options.ticks_positions[i - 1] : 0;
  242. maxv = this.options.ticks[i];
  243. maxp = this.options.ticks_positions[i];
  244. break;
  245. }
  246. }
  247. if (i > 0) {
  248. var partialPercentage = (value - minv) / (maxv - minv);
  249. return minp + partialPercentage * (maxp - minp);
  250. }
  251. }
  252. return 100 * (value - this.options.min) / (this.options.max - this.options.min);
  253. }
  254. },
  255. logarithmic: {
  256. /* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */
  257. toValue: function toValue(percentage) {
  258. var offset = 1 - this.options.min;
  259. var min = Math.log(this.options.min + offset);
  260. var max = Math.log(this.options.max + offset);
  261. var value = Math.exp(min + (max - min) * percentage / 100) - offset;
  262. if (Math.round(value) === max) {
  263. return max;
  264. }
  265. value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step;
  266. /* Rounding to the nearest step could exceed the min or
  267. * max, so clip to those values. */
  268. if (value < this.options.min) {
  269. return this.options.min;
  270. } else if (value > this.options.max) {
  271. return this.options.max;
  272. } else {
  273. return value;
  274. }
  275. },
  276. toPercentage: function toPercentage(value) {
  277. if (this.options.max === this.options.min) {
  278. return 0;
  279. } else {
  280. var offset = 1 - this.options.min;
  281. var max = Math.log(this.options.max + offset);
  282. var min = Math.log(this.options.min + offset);
  283. var v = Math.log(value + offset);
  284. return 100 * (v - min) / (max - min);
  285. }
  286. }
  287. }
  288. };
  289. /*************************************************
  290. CONSTRUCTOR
  291. **************************************************/
  292. Slider = function Slider(element, options) {
  293. createNewSlider.call(this, element, options);
  294. return this;
  295. };
  296. function createNewSlider(element, options) {
  297. /*
  298. The internal state object is used to store data about the current 'state' of slider.
  299. This includes values such as the `value`, `enabled`, etc...
  300. */
  301. this._state = {
  302. value: null,
  303. enabled: null,
  304. offset: null,
  305. size: null,
  306. percentage: null,
  307. inDrag: false,
  308. over: false
  309. };
  310. // The objects used to store the reference to the tick methods if ticks_tooltip is on
  311. this.ticksCallbackMap = {};
  312. this.handleCallbackMap = {};
  313. if (typeof element === "string") {
  314. this.element = document.querySelector(element);
  315. } else if (element instanceof HTMLElement) {
  316. this.element = element;
  317. }
  318. /*************************************************
  319. Process Options
  320. **************************************************/
  321. options = options ? options : {};
  322. var optionTypes = Object.keys(this.defaultOptions);
  323. for (var i = 0; i < optionTypes.length; i++) {
  324. var optName = optionTypes[i];
  325. // First check if an option was passed in via the constructor
  326. var val = options[optName];
  327. // If no data attrib, then check data atrributes
  328. val = typeof val !== 'undefined' ? val : getDataAttrib(this.element, optName);
  329. // Finally, if nothing was specified, use the defaults
  330. val = val !== null ? val : this.defaultOptions[optName];
  331. // Set all options on the instance of the Slider
  332. if (!this.options) {
  333. this.options = {};
  334. }
  335. this.options[optName] = val;
  336. }
  337. // Check options.rtl
  338. if (this.options.rtl === 'auto') {
  339. var computedStyle = window.getComputedStyle(this.element);
  340. if (computedStyle != null) {
  341. this.options.rtl = computedStyle.direction === 'rtl';
  342. } else {
  343. // Fix for Firefox bug in versions less than 62:
  344. // https://bugzilla.mozilla.org/show_bug.cgi?id=548397
  345. // https://bugzilla.mozilla.org/show_bug.cgi?id=1467722
  346. this.options.rtl = this.element.style.direction === 'rtl';
  347. }
  348. }
  349. /*
  350. Validate `tooltip_position` against 'orientation`
  351. - if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation`
  352. -- default for "vertical" -> "right", "left" if rtl
  353. -- default for "horizontal" -> "top"
  354. */
  355. if (this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) {
  356. if (this.options.rtl) {
  357. this.options.tooltip_position = "left";
  358. } else {
  359. this.options.tooltip_position = "right";
  360. }
  361. } else if (this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) {
  362. this.options.tooltip_position = "top";
  363. }
  364. function getDataAttrib(element, optName) {
  365. var dataName = "data-slider-" + optName.replace(/_/g, '-');
  366. var dataValString = element.getAttribute(dataName);
  367. try {
  368. return JSON.parse(dataValString);
  369. } catch (err) {
  370. return dataValString;
  371. }
  372. }
  373. /*************************************************
  374. Create Markup
  375. **************************************************/
  376. var origWidth = this.element.style.width;
  377. var updateSlider = false;
  378. var parent = this.element.parentNode;
  379. var sliderTrackSelection;
  380. var sliderTrackLow, sliderTrackHigh;
  381. var sliderMinHandle;
  382. var sliderMaxHandle;
  383. if (this.sliderElem) {
  384. updateSlider = true;
  385. } else {
  386. /* Create elements needed for slider */
  387. this.sliderElem = document.createElement("div");
  388. this.sliderElem.className = "slider";
  389. /* Create slider track elements */
  390. var sliderTrack = document.createElement("div");
  391. sliderTrack.className = "slider-track";
  392. sliderTrackLow = document.createElement("div");
  393. sliderTrackLow.className = "slider-track-low";
  394. sliderTrackSelection = document.createElement("div");
  395. sliderTrackSelection.className = "slider-selection";
  396. sliderTrackHigh = document.createElement("div");
  397. sliderTrackHigh.className = "slider-track-high";
  398. sliderMinHandle = document.createElement("div");
  399. sliderMinHandle.className = "slider-handle min-slider-handle";
  400. sliderMinHandle.setAttribute('role', 'slider');
  401. sliderMinHandle.setAttribute('aria-valuemin', this.options.min);
  402. sliderMinHandle.setAttribute('aria-valuemax', this.options.max);
  403. sliderMaxHandle = document.createElement("div");
  404. sliderMaxHandle.className = "slider-handle max-slider-handle";
  405. sliderMaxHandle.setAttribute('role', 'slider');
  406. sliderMaxHandle.setAttribute('aria-valuemin', this.options.min);
  407. sliderMaxHandle.setAttribute('aria-valuemax', this.options.max);
  408. sliderTrack.appendChild(sliderTrackLow);
  409. sliderTrack.appendChild(sliderTrackSelection);
  410. sliderTrack.appendChild(sliderTrackHigh);
  411. /* Create highlight range elements */
  412. this.rangeHighlightElements = [];
  413. var rangeHighlightsOpts = this.options.rangeHighlights;
  414. if (Array.isArray(rangeHighlightsOpts) && rangeHighlightsOpts.length > 0) {
  415. for (var j = 0; j < rangeHighlightsOpts.length; j++) {
  416. var rangeHighlightElement = document.createElement("div");
  417. var customClassString = rangeHighlightsOpts[j].class || "";
  418. rangeHighlightElement.className = "slider-rangeHighlight slider-selection " + customClassString;
  419. this.rangeHighlightElements.push(rangeHighlightElement);
  420. sliderTrack.appendChild(rangeHighlightElement);
  421. }
  422. }
  423. /* Add aria-labelledby to handle's */
  424. var isLabelledbyArray = Array.isArray(this.options.labelledby);
  425. if (isLabelledbyArray && this.options.labelledby[0]) {
  426. sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby[0]);
  427. }
  428. if (isLabelledbyArray && this.options.labelledby[1]) {
  429. sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby[1]);
  430. }
  431. if (!isLabelledbyArray && this.options.labelledby) {
  432. sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby);
  433. sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby);
  434. }
  435. /* Create ticks */
  436. this.ticks = [];
  437. if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
  438. this.ticksContainer = document.createElement('div');
  439. this.ticksContainer.className = 'slider-tick-container';
  440. for (i = 0; i < this.options.ticks.length; i++) {
  441. var tick = document.createElement('div');
  442. tick.className = 'slider-tick';
  443. if (this.options.ticks_tooltip) {
  444. var tickListenerReference = this._addTickListener();
  445. var enterCallback = tickListenerReference.addMouseEnter(this, tick, i);
  446. var leaveCallback = tickListenerReference.addMouseLeave(this, tick);
  447. this.ticksCallbackMap[i] = {
  448. mouseEnter: enterCallback,
  449. mouseLeave: leaveCallback
  450. };
  451. }
  452. this.ticks.push(tick);
  453. this.ticksContainer.appendChild(tick);
  454. }
  455. sliderTrackSelection.className += " tick-slider-selection";
  456. }
  457. this.tickLabels = [];
  458. if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
  459. this.tickLabelContainer = document.createElement('div');
  460. this.tickLabelContainer.className = 'slider-tick-label-container';
  461. for (i = 0; i < this.options.ticks_labels.length; i++) {
  462. var label = document.createElement('div');
  463. var noTickPositionsSpecified = this.options.ticks_positions.length === 0;
  464. var tickLabelsIndex = this.options.reversed && noTickPositionsSpecified ? this.options.ticks_labels.length - (i + 1) : i;
  465. label.className = 'slider-tick-label';
  466. label.innerHTML = this.options.ticks_labels[tickLabelsIndex];
  467. this.tickLabels.push(label);
  468. this.tickLabelContainer.appendChild(label);
  469. }
  470. }
  471. var createAndAppendTooltipSubElements = function createAndAppendTooltipSubElements(tooltipElem) {
  472. var arrow = document.createElement("div");
  473. arrow.className = "tooltip-arrow";
  474. var inner = document.createElement("div");
  475. inner.className = "tooltip-inner";
  476. tooltipElem.appendChild(arrow);
  477. tooltipElem.appendChild(inner);
  478. };
  479. /* Create tooltip elements */
  480. var sliderTooltip = document.createElement("div");
  481. sliderTooltip.className = "tooltip tooltip-main";
  482. sliderTooltip.setAttribute('role', 'presentation');
  483. createAndAppendTooltipSubElements(sliderTooltip);
  484. var sliderTooltipMin = document.createElement("div");
  485. sliderTooltipMin.className = "tooltip tooltip-min";
  486. sliderTooltipMin.setAttribute('role', 'presentation');
  487. createAndAppendTooltipSubElements(sliderTooltipMin);
  488. var sliderTooltipMax = document.createElement("div");
  489. sliderTooltipMax.className = "tooltip tooltip-max";
  490. sliderTooltipMax.setAttribute('role', 'presentation');
  491. createAndAppendTooltipSubElements(sliderTooltipMax);
  492. /* Append components to sliderElem */
  493. this.sliderElem.appendChild(sliderTrack);
  494. this.sliderElem.appendChild(sliderTooltip);
  495. this.sliderElem.appendChild(sliderTooltipMin);
  496. this.sliderElem.appendChild(sliderTooltipMax);
  497. if (this.tickLabelContainer) {
  498. this.sliderElem.appendChild(this.tickLabelContainer);
  499. }
  500. if (this.ticksContainer) {
  501. this.sliderElem.appendChild(this.ticksContainer);
  502. }
  503. this.sliderElem.appendChild(sliderMinHandle);
  504. this.sliderElem.appendChild(sliderMaxHandle);
  505. /* Append slider element to parent container, right before the original <input> element */
  506. parent.insertBefore(this.sliderElem, this.element);
  507. /* Hide original <input> element */
  508. this.element.style.display = "none";
  509. }
  510. /* If JQuery exists, cache JQ references */
  511. if ($) {
  512. this.$element = $(this.element);
  513. this.$sliderElem = $(this.sliderElem);
  514. }
  515. /*************************************************
  516. Setup
  517. **************************************************/
  518. this.eventToCallbackMap = {};
  519. this.sliderElem.id = this.options.id;
  520. this.touchCapable = 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch;
  521. this.touchX = 0;
  522. this.touchY = 0;
  523. this.tooltip = this.sliderElem.querySelector('.tooltip-main');
  524. this.tooltipInner = this.tooltip.querySelector('.tooltip-inner');
  525. this.tooltip_min = this.sliderElem.querySelector('.tooltip-min');
  526. this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner');
  527. this.tooltip_max = this.sliderElem.querySelector('.tooltip-max');
  528. this.tooltipInner_max = this.tooltip_max.querySelector('.tooltip-inner');
  529. if (SliderScale[this.options.scale]) {
  530. this.options.scale = SliderScale[this.options.scale];
  531. }
  532. if (updateSlider === true) {
  533. // Reset classes
  534. this._removeClass(this.sliderElem, 'slider-horizontal');
  535. this._removeClass(this.sliderElem, 'slider-vertical');
  536. this._removeClass(this.sliderElem, 'slider-rtl');
  537. this._removeClass(this.tooltip, 'hide');
  538. this._removeClass(this.tooltip_min, 'hide');
  539. this._removeClass(this.tooltip_max, 'hide');
  540. // Undo existing inline styles for track
  541. ["left", "right", "top", "width", "height"].forEach(function (prop) {
  542. this._removeProperty(this.trackLow, prop);
  543. this._removeProperty(this.trackSelection, prop);
  544. this._removeProperty(this.trackHigh, prop);
  545. }, this);
  546. // Undo inline styles on handles
  547. [this.handle1, this.handle2].forEach(function (handle) {
  548. this._removeProperty(handle, 'left');
  549. this._removeProperty(handle, 'right');
  550. this._removeProperty(handle, 'top');
  551. }, this);
  552. // Undo inline styles and classes on tooltips
  553. [this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function (tooltip) {
  554. this._removeProperty(tooltip, 'left');
  555. this._removeProperty(tooltip, 'right');
  556. this._removeProperty(tooltip, 'top');
  557. this._removeClass(tooltip, 'right');
  558. this._removeClass(tooltip, 'left');
  559. this._removeClass(tooltip, 'top');
  560. }, this);
  561. }
  562. if (this.options.orientation === 'vertical') {
  563. this._addClass(this.sliderElem, 'slider-vertical');
  564. this.stylePos = 'top';
  565. this.mousePos = 'pageY';
  566. this.sizePos = 'offsetHeight';
  567. } else {
  568. this._addClass(this.sliderElem, 'slider-horizontal');
  569. this.sliderElem.style.width = origWidth;
  570. this.options.orientation = 'horizontal';
  571. if (this.options.rtl) {
  572. this.stylePos = 'right';
  573. } else {
  574. this.stylePos = 'left';
  575. }
  576. this.mousePos = 'clientX';
  577. this.sizePos = 'offsetWidth';
  578. }
  579. // specific rtl class
  580. if (this.options.rtl) {
  581. this._addClass(this.sliderElem, 'slider-rtl');
  582. }
  583. this._setTooltipPosition();
  584. /* In case ticks are specified, overwrite the min and max bounds */
  585. if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
  586. this.options.max = Math.max.apply(Math, this.options.ticks);
  587. this.options.min = Math.min.apply(Math, this.options.ticks);
  588. }
  589. if (Array.isArray(this.options.value)) {
  590. this.options.range = true;
  591. this._state.value = this.options.value;
  592. } else if (this.options.range) {
  593. // User wants a range, but value is not an array
  594. this._state.value = [this.options.value, this.options.max];
  595. } else {
  596. this._state.value = this.options.value;
  597. }
  598. this.trackLow = sliderTrackLow || this.trackLow;
  599. this.trackSelection = sliderTrackSelection || this.trackSelection;
  600. this.trackHigh = sliderTrackHigh || this.trackHigh;
  601. if (this.options.selection === 'none') {
  602. this._addClass(this.trackLow, 'hide');
  603. this._addClass(this.trackSelection, 'hide');
  604. this._addClass(this.trackHigh, 'hide');
  605. } else if (this.options.selection === 'after' || this.options.selection === 'before') {
  606. this._removeClass(this.trackLow, 'hide');
  607. this._removeClass(this.trackSelection, 'hide');
  608. this._removeClass(this.trackHigh, 'hide');
  609. }
  610. this.handle1 = sliderMinHandle || this.handle1;
  611. this.handle2 = sliderMaxHandle || this.handle2;
  612. if (updateSlider === true) {
  613. // Reset classes
  614. this._removeClass(this.handle1, 'round triangle');
  615. this._removeClass(this.handle2, 'round triangle hide');
  616. for (i = 0; i < this.ticks.length; i++) {
  617. this._removeClass(this.ticks[i], 'round triangle hide');
  618. }
  619. }
  620. var availableHandleModifiers = ['round', 'triangle', 'custom'];
  621. var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1;
  622. if (isValidHandleType) {
  623. this._addClass(this.handle1, this.options.handle);
  624. this._addClass(this.handle2, this.options.handle);
  625. for (i = 0; i < this.ticks.length; i++) {
  626. this._addClass(this.ticks[i], this.options.handle);
  627. }
  628. }
  629. this._state.offset = this._offset(this.sliderElem);
  630. this._state.size = this.sliderElem[this.sizePos];
  631. this.setValue(this._state.value);
  632. /******************************************
  633. Bind Event Listeners
  634. ******************************************/
  635. // Bind keyboard handlers
  636. this.handle1Keydown = this._keydown.bind(this, 0);
  637. this.handle1.addEventListener("keydown", this.handle1Keydown, false);
  638. this.handle2Keydown = this._keydown.bind(this, 1);
  639. this.handle2.addEventListener("keydown", this.handle2Keydown, false);
  640. this.mousedown = this._mousedown.bind(this);
  641. this.touchstart = this._touchstart.bind(this);
  642. this.touchmove = this._touchmove.bind(this);
  643. if (this.touchCapable) {
  644. // Test for passive event support
  645. var supportsPassive = false;
  646. try {
  647. var opts = Object.defineProperty({}, 'passive', {
  648. get: function get() {
  649. supportsPassive = true;
  650. }
  651. });
  652. window.addEventListener("test", null, opts);
  653. } catch (e) {}
  654. // Use our detect's results. passive applied if supported, capture will be false either way.
  655. var eventOptions = supportsPassive ? { passive: true } : false;
  656. // Bind touch handlers
  657. this.sliderElem.addEventListener("touchstart", this.touchstart, eventOptions);
  658. this.sliderElem.addEventListener("touchmove", this.touchmove, eventOptions);
  659. }
  660. this.sliderElem.addEventListener("mousedown", this.mousedown, false);
  661. // Bind window handlers
  662. this.resize = this._resize.bind(this);
  663. window.addEventListener("resize", this.resize, false);
  664. // Bind tooltip-related handlers
  665. if (this.options.tooltip === 'hide') {
  666. this._addClass(this.tooltip, 'hide');
  667. this._addClass(this.tooltip_min, 'hide');
  668. this._addClass(this.tooltip_max, 'hide');
  669. } else if (this.options.tooltip === 'always') {
  670. this._showTooltip();
  671. this._alwaysShowTooltip = true;
  672. } else {
  673. this.showTooltip = this._showTooltip.bind(this);
  674. this.hideTooltip = this._hideTooltip.bind(this);
  675. if (this.options.ticks_tooltip) {
  676. var callbackHandle = this._addTickListener();
  677. //create handle1 listeners and store references in map
  678. var mouseEnter = callbackHandle.addMouseEnter(this, this.handle1);
  679. var mouseLeave = callbackHandle.addMouseLeave(this, this.handle1);
  680. this.handleCallbackMap.handle1 = {
  681. mouseEnter: mouseEnter,
  682. mouseLeave: mouseLeave
  683. };
  684. //create handle2 listeners and store references in map
  685. mouseEnter = callbackHandle.addMouseEnter(this, this.handle2);
  686. mouseLeave = callbackHandle.addMouseLeave(this, this.handle2);
  687. this.handleCallbackMap.handle2 = {
  688. mouseEnter: mouseEnter,
  689. mouseLeave: mouseLeave
  690. };
  691. } else {
  692. this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
  693. this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
  694. }
  695. this.handle1.addEventListener("focus", this.showTooltip, false);
  696. this.handle1.addEventListener("blur", this.hideTooltip, false);
  697. this.handle2.addEventListener("focus", this.showTooltip, false);
  698. this.handle2.addEventListener("blur", this.hideTooltip, false);
  699. }
  700. if (this.options.enabled) {
  701. this.enable();
  702. } else {
  703. this.disable();
  704. }
  705. }
  706. /*************************************************
  707. INSTANCE PROPERTIES/METHODS
  708. - Any methods bound to the prototype are considered
  709. part of the plugin's `public` interface
  710. **************************************************/
  711. Slider.prototype = {
  712. _init: function _init() {}, // NOTE: Must exist to support bridget
  713. constructor: Slider,
  714. defaultOptions: {
  715. id: "",
  716. min: 0,
  717. max: 10,
  718. step: 1,
  719. precision: 0,
  720. orientation: 'horizontal',
  721. value: 5,
  722. range: false,
  723. selection: 'before',
  724. tooltip: 'show',
  725. tooltip_split: false,
  726. handle: 'round',
  727. reversed: false,
  728. rtl: 'auto',
  729. enabled: true,
  730. formatter: function formatter(val) {
  731. if (Array.isArray(val)) {
  732. return val[0] + " : " + val[1];
  733. } else {
  734. return val;
  735. }
  736. },
  737. natural_arrow_keys: false,
  738. ticks: [],
  739. ticks_positions: [],
  740. ticks_labels: [],
  741. ticks_snap_bounds: 0,
  742. ticks_tooltip: false,
  743. scale: 'linear',
  744. focus: false,
  745. tooltip_position: null,
  746. labelledby: null,
  747. rangeHighlights: []
  748. },
  749. getElement: function getElement() {
  750. return this.sliderElem;
  751. },
  752. getValue: function getValue() {
  753. if (this.options.range) {
  754. return this._state.value;
  755. } else {
  756. return this._state.value[0];
  757. }
  758. },
  759. setValue: function setValue(val, triggerSlideEvent, triggerChangeEvent) {
  760. if (!val) {
  761. val = 0;
  762. }
  763. var oldValue = this.getValue();
  764. this._state.value = this._validateInputValue(val);
  765. var applyPrecision = this._applyPrecision.bind(this);
  766. if (this.options.range) {
  767. this._state.value[0] = applyPrecision(this._state.value[0]);
  768. this._state.value[1] = applyPrecision(this._state.value[1]);
  769. this._state.value[0] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[0]));
  770. this._state.value[1] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[1]));
  771. } else {
  772. this._state.value = applyPrecision(this._state.value);
  773. this._state.value = [Math.max(this.options.min, Math.min(this.options.max, this._state.value))];
  774. this._addClass(this.handle2, 'hide');
  775. if (this.options.selection === 'after') {
  776. this._state.value[1] = this.options.max;
  777. } else {
  778. this._state.value[1] = this.options.min;
  779. }
  780. }
  781. if (this.options.max > this.options.min) {
  782. this._state.percentage = [this._toPercentage(this._state.value[0]), this._toPercentage(this._state.value[1]), this.options.step * 100 / (this.options.max - this.options.min)];
  783. } else {
  784. this._state.percentage = [0, 0, 100];
  785. }
  786. this._layout();
  787. var newValue = this.options.range ? this._state.value : this._state.value[0];
  788. this._setDataVal(newValue);
  789. if (triggerSlideEvent === true) {
  790. this._trigger('slide', newValue);
  791. }
  792. if (oldValue !== newValue && triggerChangeEvent === true) {
  793. this._trigger('change', {
  794. oldValue: oldValue,
  795. newValue: newValue
  796. });
  797. }
  798. return this;
  799. },
  800. destroy: function destroy() {
  801. // Remove event handlers on slider elements
  802. this._removeSliderEventHandlers();
  803. // Remove the slider from the DOM
  804. this.sliderElem.parentNode.removeChild(this.sliderElem);
  805. /* Show original <input> element */
  806. this.element.style.display = "";
  807. // Clear out custom event bindings
  808. this._cleanUpEventCallbacksMap();
  809. // Remove data values
  810. this.element.removeAttribute("data");
  811. // Remove JQuery handlers/data
  812. if ($) {
  813. this._unbindJQueryEventHandlers();
  814. this.$element.removeData('slider');
  815. }
  816. },
  817. disable: function disable() {
  818. this._state.enabled = false;
  819. this.handle1.removeAttribute("tabindex");
  820. this.handle2.removeAttribute("tabindex");
  821. this._addClass(this.sliderElem, 'slider-disabled');
  822. this._trigger('slideDisabled');
  823. return this;
  824. },
  825. enable: function enable() {
  826. this._state.enabled = true;
  827. this.handle1.setAttribute("tabindex", 0);
  828. this.handle2.setAttribute("tabindex", 0);
  829. this._removeClass(this.sliderElem, 'slider-disabled');
  830. this._trigger('slideEnabled');
  831. return this;
  832. },
  833. toggle: function toggle() {
  834. if (this._state.enabled) {
  835. this.disable();
  836. } else {
  837. this.enable();
  838. }
  839. return this;
  840. },
  841. isEnabled: function isEnabled() {
  842. return this._state.enabled;
  843. },
  844. on: function on(evt, callback) {
  845. this._bindNonQueryEventHandler(evt, callback);
  846. return this;
  847. },
  848. off: function off(evt, callback) {
  849. if ($) {
  850. this.$element.off(evt, callback);
  851. this.$sliderElem.off(evt, callback);
  852. } else {
  853. this._unbindNonQueryEventHandler(evt, callback);
  854. }
  855. },
  856. getAttribute: function getAttribute(attribute) {
  857. if (attribute) {
  858. return this.options[attribute];
  859. } else {
  860. return this.options;
  861. }
  862. },
  863. setAttribute: function setAttribute(attribute, value) {
  864. this.options[attribute] = value;
  865. return this;
  866. },
  867. refresh: function refresh() {
  868. this._removeSliderEventHandlers();
  869. createNewSlider.call(this, this.element, this.options);
  870. if ($) {
  871. // Bind new instance of slider to the element
  872. $.data(this.element, 'slider', this);
  873. }
  874. return this;
  875. },
  876. relayout: function relayout() {
  877. this._resize();
  878. return this;
  879. },
  880. /******************************+
  881. HELPERS
  882. - Any method that is not part of the public interface.
  883. - Place it underneath this comment block and write its signature like so:
  884. _fnName : function() {...}
  885. ********************************/
  886. _removeSliderEventHandlers: function _removeSliderEventHandlers() {
  887. // Remove keydown event listeners
  888. this.handle1.removeEventListener("keydown", this.handle1Keydown, false);
  889. this.handle2.removeEventListener("keydown", this.handle2Keydown, false);
  890. //remove the listeners from the ticks and handles if they had their own listeners
  891. if (this.options.ticks_tooltip) {
  892. var ticks = this.ticksContainer.getElementsByClassName('slider-tick');
  893. for (var i = 0; i < ticks.length; i++) {
  894. ticks[i].removeEventListener('mouseenter', this.ticksCallbackMap[i].mouseEnter, false);
  895. ticks[i].removeEventListener('mouseleave', this.ticksCallbackMap[i].mouseLeave, false);
  896. }
  897. this.handle1.removeEventListener('mouseenter', this.handleCallbackMap.handle1.mouseEnter, false);
  898. this.handle2.removeEventListener('mouseenter', this.handleCallbackMap.handle2.mouseEnter, false);
  899. this.handle1.removeEventListener('mouseleave', this.handleCallbackMap.handle1.mouseLeave, false);
  900. this.handle2.removeEventListener('mouseleave', this.handleCallbackMap.handle2.mouseLeave, false);
  901. }
  902. this.handleCallbackMap = null;
  903. this.ticksCallbackMap = null;
  904. if (this.showTooltip) {
  905. this.handle1.removeEventListener("focus", this.showTooltip, false);
  906. this.handle2.removeEventListener("focus", this.showTooltip, false);
  907. }
  908. if (this.hideTooltip) {
  909. this.handle1.removeEventListener("blur", this.hideTooltip, false);
  910. this.handle2.removeEventListener("blur", this.hideTooltip, false);
  911. }
  912. // Remove event listeners from sliderElem
  913. if (this.showTooltip) {
  914. this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false);
  915. }
  916. if (this.hideTooltip) {
  917. this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false);
  918. }
  919. this.sliderElem.removeEventListener("touchstart", this.touchstart, false);
  920. this.sliderElem.removeEventListener("touchmove", this.touchmove, false);
  921. this.sliderElem.removeEventListener("mousedown", this.mousedown, false);
  922. // Remove window event listener
  923. window.removeEventListener("resize", this.resize, false);
  924. },
  925. _bindNonQueryEventHandler: function _bindNonQueryEventHandler(evt, callback) {
  926. if (this.eventToCallbackMap[evt] === undefined) {
  927. this.eventToCallbackMap[evt] = [];
  928. }
  929. this.eventToCallbackMap[evt].push(callback);
  930. },
  931. _unbindNonQueryEventHandler: function _unbindNonQueryEventHandler(evt, callback) {
  932. var callbacks = this.eventToCallbackMap[evt];
  933. if (callbacks !== undefined) {
  934. for (var i = 0; i < callbacks.length; i++) {
  935. if (callbacks[i] === callback) {
  936. callbacks.splice(i, 1);
  937. break;
  938. }
  939. }
  940. }
  941. },
  942. _cleanUpEventCallbacksMap: function _cleanUpEventCallbacksMap() {
  943. var eventNames = Object.keys(this.eventToCallbackMap);
  944. for (var i = 0; i < eventNames.length; i++) {
  945. var eventName = eventNames[i];
  946. delete this.eventToCallbackMap[eventName];
  947. }
  948. },
  949. _showTooltip: function _showTooltip() {
  950. if (this.options.tooltip_split === false) {
  951. this._addClass(this.tooltip, 'in');
  952. this.tooltip_min.style.display = 'none';
  953. this.tooltip_max.style.display = 'none';
  954. } else {
  955. this._addClass(this.tooltip_min, 'in');
  956. this._addClass(this.tooltip_max, 'in');
  957. this.tooltip.style.display = 'none';
  958. }
  959. this._state.over = true;
  960. },
  961. _hideTooltip: function _hideTooltip() {
  962. if (this._state.inDrag === false && this.alwaysShowTooltip !== true) {
  963. this._removeClass(this.tooltip, 'in');
  964. this._removeClass(this.tooltip_min, 'in');
  965. this._removeClass(this.tooltip_max, 'in');
  966. }
  967. this._state.over = false;
  968. },
  969. _setToolTipOnMouseOver: function _setToolTipOnMouseOver(tempState) {
  970. var formattedTooltipVal = this.options.formatter(!tempState ? this._state.value[0] : tempState.value[0]);
  971. var positionPercentages = !tempState ? getPositionPercentages(this._state, this.options.reversed) : getPositionPercentages(tempState, this.options.reversed);
  972. this._setText(this.tooltipInner, formattedTooltipVal);
  973. this.tooltip.style[this.stylePos] = positionPercentages[0] + "%";
  974. function getPositionPercentages(state, reversed) {
  975. if (reversed) {
  976. return [100 - state.percentage[0], this.options.range ? 100 - state.percentage[1] : state.percentage[1]];
  977. }
  978. return [state.percentage[0], state.percentage[1]];
  979. }
  980. },
  981. _addTickListener: function _addTickListener() {
  982. return {
  983. addMouseEnter: function addMouseEnter(reference, tick, index) {
  984. var enter = function enter() {
  985. var tempState = reference._state;
  986. var idString = index >= 0 ? index : this.attributes['aria-valuenow'].value;
  987. var hoverIndex = parseInt(idString, 10);
  988. tempState.value[0] = hoverIndex;
  989. tempState.percentage[0] = reference.options.ticks_positions[hoverIndex];
  990. reference._setToolTipOnMouseOver(tempState);
  991. reference._showTooltip();
  992. };
  993. tick.addEventListener("mouseenter", enter, false);
  994. return enter;
  995. },
  996. addMouseLeave: function addMouseLeave(reference, tick) {
  997. var leave = function leave() {
  998. reference._hideTooltip();
  999. };
  1000. tick.addEventListener("mouseleave", leave, false);
  1001. return leave;
  1002. }
  1003. };
  1004. },
  1005. _layout: function _layout() {
  1006. var positionPercentages;
  1007. if (this.options.reversed) {
  1008. positionPercentages = [100 - this._state.percentage[0], this.options.range ? 100 - this._state.percentage[1] : this._state.percentage[1]];
  1009. } else {
  1010. positionPercentages = [this._state.percentage[0], this._state.percentage[1]];
  1011. }
  1012. this.handle1.style[this.stylePos] = positionPercentages[0] + "%";
  1013. this.handle1.setAttribute('aria-valuenow', this._state.value[0]);
  1014. if (isNaN(this.options.formatter(this._state.value[0]))) {
  1015. this.handle1.setAttribute('aria-valuetext', this.options.formatter(this._state.value[0]));
  1016. }
  1017. this.handle2.style[this.stylePos] = positionPercentages[1] + "%";
  1018. this.handle2.setAttribute('aria-valuenow', this._state.value[1]);
  1019. if (isNaN(this.options.formatter(this._state.value[1]))) {
  1020. this.handle2.setAttribute('aria-valuetext', this.options.formatter(this._state.value[1]));
  1021. }
  1022. /* Position highlight range elements */
  1023. if (this.rangeHighlightElements.length > 0 && Array.isArray(this.options.rangeHighlights) && this.options.rangeHighlights.length > 0) {
  1024. for (var _i = 0; _i < this.options.rangeHighlights.length; _i++) {
  1025. var startPercent = this._toPercentage(this.options.rangeHighlights[_i].start);
  1026. var endPercent = this._toPercentage(this.options.rangeHighlights[_i].end);
  1027. if (this.options.reversed) {
  1028. var sp = 100 - endPercent;
  1029. endPercent = 100 - startPercent;
  1030. startPercent = sp;
  1031. }
  1032. var currentRange = this._createHighlightRange(startPercent, endPercent);
  1033. if (currentRange) {
  1034. if (this.options.orientation === 'vertical') {
  1035. this.rangeHighlightElements[_i].style.top = currentRange.start + "%";
  1036. this.rangeHighlightElements[_i].style.height = currentRange.size + "%";
  1037. } else {
  1038. if (this.options.rtl) {
  1039. this.rangeHighlightElements[_i].style.right = currentRange.start + "%";
  1040. } else {
  1041. this.rangeHighlightElements[_i].style.left = currentRange.start + "%";
  1042. }
  1043. this.rangeHighlightElements[_i].style.width = currentRange.size + "%";
  1044. }
  1045. } else {
  1046. this.rangeHighlightElements[_i].style.display = "none";
  1047. }
  1048. }
  1049. }
  1050. /* Position ticks and labels */
  1051. if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
  1052. var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width';
  1053. var styleMargin;
  1054. if (this.options.orientation === 'vertical') {
  1055. styleMargin = 'marginTop';
  1056. } else {
  1057. if (this.options.rtl) {
  1058. styleMargin = 'marginRight';
  1059. } else {
  1060. styleMargin = 'marginLeft';
  1061. }
  1062. }
  1063. var labelSize = this._state.size / (this.options.ticks.length - 1);
  1064. if (this.tickLabelContainer) {
  1065. var extraMargin = 0;
  1066. if (this.options.ticks_positions.length === 0) {
  1067. if (this.options.orientation !== 'vertical') {
  1068. this.tickLabelContainer.style[styleMargin] = -labelSize / 2 + "px";
  1069. }
  1070. extraMargin = this.tickLabelContainer.offsetHeight;
  1071. } else {
  1072. /* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */
  1073. for (i = 0; i < this.tickLabelContainer.childNodes.length; i++) {
  1074. if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) {
  1075. extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight;
  1076. }
  1077. }
  1078. }
  1079. if (this.options.orientation === 'horizontal') {
  1080. this.sliderElem.style.marginBottom = extraMargin + "px";
  1081. }
  1082. }
  1083. for (var i = 0; i < this.options.ticks.length; i++) {
  1084. var percentage = this.options.ticks_positions[i] || this._toPercentage(this.options.ticks[i]);
  1085. if (this.options.reversed) {
  1086. percentage = 100 - percentage;
  1087. }
  1088. this.ticks[i].style[this.stylePos] = percentage + "%";
  1089. /* Set class labels to denote whether ticks are in the selection */
  1090. this._removeClass(this.ticks[i], 'in-selection');
  1091. if (!this.options.range) {
  1092. if (this.options.selection === 'after' && percentage >= positionPercentages[0]) {
  1093. this._addClass(this.ticks[i], 'in-selection');
  1094. } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) {
  1095. this._addClass(this.ticks[i], 'in-selection');
  1096. }
  1097. } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) {
  1098. this._addClass(this.ticks[i], 'in-selection');
  1099. }
  1100. if (this.tickLabels[i]) {
  1101. this.tickLabels[i].style[styleSize] = labelSize + "px";
  1102. if (this.options.orientation !== 'vertical' && this.options.ticks_positions[i] !== undefined) {
  1103. this.tickLabels[i].style.position = 'absolute';
  1104. this.tickLabels[i].style[this.stylePos] = percentage + "%";
  1105. this.tickLabels[i].style[styleMargin] = -labelSize / 2 + 'px';
  1106. } else if (this.options.orientation === 'vertical') {
  1107. if (this.options.rtl) {
  1108. this.tickLabels[i].style['marginRight'] = this.sliderElem.offsetWidth + "px";
  1109. } else {
  1110. this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + "px";
  1111. }
  1112. this.tickLabelContainer.style[styleMargin] = this.sliderElem.offsetWidth / 2 * -1 + 'px';
  1113. }
  1114. /* Set class labels to indicate tick labels are in the selection or selected */
  1115. this._removeClass(this.tickLabels[i], 'label-in-selection label-is-selection');
  1116. if (!this.options.range) {
  1117. if (this.options.selection === 'after' && percentage >= positionPercentages[0]) {
  1118. this._addClass(this.tickLabels[i], 'label-in-selection');
  1119. } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) {
  1120. this._addClass(this.tickLabels[i], 'label-in-selection');
  1121. }
  1122. if (percentage === positionPercentages[0]) {
  1123. this._addClass(this.tickLabels[i], 'label-is-selection');
  1124. }
  1125. } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) {
  1126. this._addClass(this.tickLabels[i], 'label-in-selection');
  1127. if (percentage === positionPercentages[0] || positionPercentages[1]) {
  1128. this._addClass(this.tickLabels[i], 'label-is-selection');
  1129. }
  1130. }
  1131. }
  1132. }
  1133. }
  1134. var formattedTooltipVal;
  1135. if (this.options.range) {
  1136. formattedTooltipVal = this.options.formatter(this._state.value);
  1137. this._setText(this.tooltipInner, formattedTooltipVal);
  1138. this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0]) / 2 + "%";
  1139. var innerTooltipMinText = this.options.formatter(this._state.value[0]);
  1140. this._setText(this.tooltipInner_min, innerTooltipMinText);
  1141. var innerTooltipMaxText = this.options.formatter(this._state.value[1]);
  1142. this._setText(this.tooltipInner_max, innerTooltipMaxText);
  1143. this.tooltip_min.style[this.stylePos] = positionPercentages[0] + "%";
  1144. this.tooltip_max.style[this.stylePos] = positionPercentages[1] + "%";
  1145. } else {
  1146. formattedTooltipVal = this.options.formatter(this._state.value[0]);
  1147. this._setText(this.tooltipInner, formattedTooltipVal);
  1148. this.tooltip.style[this.stylePos] = positionPercentages[0] + "%";
  1149. }
  1150. if (this.options.orientation === 'vertical') {
  1151. this.trackLow.style.top = '0';
  1152. this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1153. this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1154. this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
  1155. this.trackHigh.style.bottom = '0';
  1156. this.trackHigh.style.height = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
  1157. } else {
  1158. if (this.stylePos === 'right') {
  1159. this.trackLow.style.right = '0';
  1160. } else {
  1161. this.trackLow.style.left = '0';
  1162. }
  1163. this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1164. if (this.stylePos === 'right') {
  1165. this.trackSelection.style.right = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1166. } else {
  1167. this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1168. }
  1169. this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
  1170. if (this.stylePos === 'right') {
  1171. this.trackHigh.style.left = '0';
  1172. } else {
  1173. this.trackHigh.style.right = '0';
  1174. }
  1175. this.trackHigh.style.width = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
  1176. var offset_min = this.tooltip_min.getBoundingClientRect();
  1177. var offset_max = this.tooltip_max.getBoundingClientRect();
  1178. if (this.options.tooltip_position === 'bottom') {
  1179. if (offset_min.right > offset_max.left) {
  1180. this._removeClass(this.tooltip_max, 'bottom');
  1181. this._addClass(this.tooltip_max, 'top');
  1182. this.tooltip_max.style.top = '';
  1183. this.tooltip_max.style.bottom = 22 + 'px';
  1184. } else {
  1185. this._removeClass(this.tooltip_max, 'top');
  1186. this._addClass(this.tooltip_max, 'bottom');
  1187. this.tooltip_max.style.top = this.tooltip_min.style.top;
  1188. this.tooltip_max.style.bottom = '';
  1189. }
  1190. } else {
  1191. if (offset_min.right > offset_max.left) {
  1192. this._removeClass(this.tooltip_max, 'top');
  1193. this._addClass(this.tooltip_max, 'bottom');
  1194. this.tooltip_max.style.top = 18 + 'px';
  1195. } else {
  1196. this._removeClass(this.tooltip_max, 'bottom');
  1197. this._addClass(this.tooltip_max, 'top');
  1198. this.tooltip_max.style.top = this.tooltip_min.style.top;
  1199. }
  1200. }
  1201. }
  1202. },
  1203. _createHighlightRange: function _createHighlightRange(start, end) {
  1204. if (this._isHighlightRange(start, end)) {
  1205. if (start > end) {
  1206. return { 'start': end, 'size': start - end };
  1207. }
  1208. return { 'start': start, 'size': end - start };
  1209. }
  1210. return null;
  1211. },
  1212. _isHighlightRange: function _isHighlightRange(start, end) {
  1213. if (0 <= start && start <= 100 && 0 <= end && end <= 100) {
  1214. return true;
  1215. } else {
  1216. return false;
  1217. }
  1218. },
  1219. _resize: function _resize(ev) {
  1220. /*jshint unused:false*/
  1221. this._state.offset = this._offset(this.sliderElem);
  1222. this._state.size = this.sliderElem[this.sizePos];
  1223. this._layout();
  1224. },
  1225. _removeProperty: function _removeProperty(element, prop) {
  1226. if (element.style.removeProperty) {
  1227. element.style.removeProperty(prop);
  1228. } else {
  1229. element.style.removeAttribute(prop);
  1230. }
  1231. },
  1232. _mousedown: function _mousedown(ev) {
  1233. if (!this._state.enabled) {
  1234. return false;
  1235. }
  1236. if (ev.preventDefault) {
  1237. ev.preventDefault();
  1238. }
  1239. this._state.offset = this._offset(this.sliderElem);
  1240. this._state.size = this.sliderElem[this.sizePos];
  1241. var percentage = this._getPercentage(ev);
  1242. if (this.options.range) {
  1243. var diff1 = Math.abs(this._state.percentage[0] - percentage);
  1244. var diff2 = Math.abs(this._state.percentage[1] - percentage);
  1245. this._state.dragged = diff1 < diff2 ? 0 : 1;
  1246. this._adjustPercentageForRangeSliders(percentage);
  1247. } else {
  1248. this._state.dragged = 0;
  1249. }
  1250. this._state.percentage[this._state.dragged] = percentage;
  1251. this._layout();
  1252. if (this.touchCapable) {
  1253. document.removeEventListener("touchmove", this.mousemove, false);
  1254. document.removeEventListener("touchend", this.mouseup, false);
  1255. }
  1256. if (this.mousemove) {
  1257. document.removeEventListener("mousemove", this.mousemove, false);
  1258. }
  1259. if (this.mouseup) {
  1260. document.removeEventListener("mouseup", this.mouseup, false);
  1261. }
  1262. this.mousemove = this._mousemove.bind(this);
  1263. this.mouseup = this._mouseup.bind(this);
  1264. if (this.touchCapable) {
  1265. // Touch: Bind touch events:
  1266. document.addEventListener("touchmove", this.mousemove, false);
  1267. document.addEventListener("touchend", this.mouseup, false);
  1268. }
  1269. // Bind mouse events:
  1270. document.addEventListener("mousemove", this.mousemove, false);
  1271. document.addEventListener("mouseup", this.mouseup, false);
  1272. this._state.inDrag = true;
  1273. var newValue = this._calculateValue();
  1274. this._trigger('slideStart', newValue);
  1275. this._setDataVal(newValue);
  1276. this.setValue(newValue, false, true);
  1277. ev.returnValue = false;
  1278. if (this.options.focus) {
  1279. this._triggerFocusOnHandle(this._state.dragged);
  1280. }
  1281. return true;
  1282. },
  1283. _touchstart: function _touchstart(ev) {
  1284. if (ev.changedTouches === undefined) {
  1285. this._mousedown(ev);
  1286. return;
  1287. }
  1288. var touch = ev.changedTouches[0];
  1289. this.touchX = touch.pageX;
  1290. this.touchY = touch.pageY;
  1291. },
  1292. _triggerFocusOnHandle: function _triggerFocusOnHandle(handleIdx) {
  1293. if (handleIdx === 0) {
  1294. this.handle1.focus();
  1295. }
  1296. if (handleIdx === 1) {
  1297. this.handle2.focus();
  1298. }
  1299. },
  1300. _keydown: function _keydown(handleIdx, ev) {
  1301. if (!this._state.enabled) {
  1302. return false;
  1303. }
  1304. var dir;
  1305. switch (ev.keyCode) {
  1306. case 37: // left
  1307. case 40:
  1308. // down
  1309. dir = -1;
  1310. break;
  1311. case 39: // right
  1312. case 38:
  1313. // up
  1314. dir = 1;
  1315. break;
  1316. }
  1317. if (!dir) {
  1318. return;
  1319. }
  1320. // use natural arrow keys instead of from min to max
  1321. if (this.options.natural_arrow_keys) {
  1322. var ifVerticalAndNotReversed = this.options.orientation === 'vertical' && !this.options.reversed;
  1323. var ifHorizontalAndReversed = this.options.orientation === 'horizontal' && this.options.reversed; // @todo control with rtl
  1324. if (ifVerticalAndNotReversed || ifHorizontalAndReversed) {
  1325. dir = -dir;
  1326. }
  1327. }
  1328. var val = this._state.value[handleIdx] + dir * this.options.step;
  1329. var percentage = val / this.options.max * 100;
  1330. this._state.keyCtrl = handleIdx;
  1331. if (this.options.range) {
  1332. this._adjustPercentageForRangeSliders(percentage);
  1333. var val1 = !this._state.keyCtrl ? val : this._state.value[0];
  1334. var val2 = this._state.keyCtrl ? val : this._state.value[1];
  1335. val = [val1, val2];
  1336. }
  1337. this._trigger('slideStart', val);
  1338. this._setDataVal(val);
  1339. this.setValue(val, true, true);
  1340. this._setDataVal(val);
  1341. this._trigger('slideStop', val);
  1342. this._layout();
  1343. this._pauseEvent(ev);
  1344. delete this._state.keyCtrl;
  1345. return false;
  1346. },
  1347. _pauseEvent: function _pauseEvent(ev) {
  1348. if (ev.stopPropagation) {
  1349. ev.stopPropagation();
  1350. }
  1351. if (ev.preventDefault) {
  1352. ev.preventDefault();
  1353. }
  1354. ev.cancelBubble = true;
  1355. ev.returnValue = false;
  1356. },
  1357. _mousemove: function _mousemove(ev) {
  1358. if (!this._state.enabled) {
  1359. return false;
  1360. }
  1361. var percentage = this._getPercentage(ev);
  1362. this._adjustPercentageForRangeSliders(percentage);
  1363. this._state.percentage[this._state.dragged] = percentage;
  1364. this._layout();
  1365. var val = this._calculateValue(true);
  1366. this.setValue(val, true, true);
  1367. return false;
  1368. },
  1369. _touchmove: function _touchmove(ev) {
  1370. if (ev.changedTouches === undefined) {
  1371. return;
  1372. }
  1373. var touch = ev.changedTouches[0];
  1374. var xDiff = touch.pageX - this.touchX;
  1375. var yDiff = touch.pageY - this.touchY;
  1376. if (!this._state.inDrag) {
  1377. // Vertical Slider
  1378. if (this.options.orientation === 'vertical' && xDiff <= 5 && xDiff >= -5 && (yDiff >= 15 || yDiff <= -15)) {
  1379. this._mousedown(ev);
  1380. }
  1381. // Horizontal slider.
  1382. else if (yDiff <= 5 && yDiff >= -5 && (xDiff >= 15 || xDiff <= -15)) {
  1383. this._mousedown(ev);
  1384. }
  1385. }
  1386. },
  1387. _adjustPercentageForRangeSliders: function _adjustPercentageForRangeSliders(percentage) {
  1388. if (this.options.range) {
  1389. var precision = this._getNumDigitsAfterDecimalPlace(percentage);
  1390. precision = precision ? precision - 1 : 0;
  1391. var percentageWithAdjustedPrecision = this._applyToFixedAndParseFloat(percentage, precision);
  1392. if (this._state.dragged === 0 && this._applyToFixedAndParseFloat(this._state.percentage[1], precision) < percentageWithAdjustedPrecision) {
  1393. this._state.percentage[0] = this._state.percentage[1];
  1394. this._state.dragged = 1;
  1395. } else if (this._state.dragged === 1 && this._applyToFixedAndParseFloat(this._state.percentage[0], precision) > percentageWithAdjustedPrecision) {
  1396. this._state.percentage[1] = this._state.percentage[0];
  1397. this._state.dragged = 0;
  1398. } else if (this._state.keyCtrl === 0 && this._state.value[1] / this.options.max * 100 < percentage) {
  1399. this._state.percentage[0] = this._state.percentage[1];
  1400. this._state.keyCtrl = 1;
  1401. this.handle2.focus();
  1402. } else if (this._state.keyCtrl === 1 && this._state.value[0] / this.options.max * 100 > percentage) {
  1403. this._state.percentage[1] = this._state.percentage[0];
  1404. this._state.keyCtrl = 0;
  1405. this.handle1.focus();
  1406. }
  1407. }
  1408. },
  1409. _mouseup: function _mouseup() {
  1410. if (!this._state.enabled) {
  1411. return false;
  1412. }
  1413. if (this.touchCapable) {
  1414. // Touch: Unbind touch event handlers:
  1415. document.removeEventListener("touchmove", this.mousemove, false);
  1416. document.removeEventListener("touchend", this.mouseup, false);
  1417. }
  1418. // Unbind mouse event handlers:
  1419. document.removeEventListener("mousemove", this.mousemove, false);
  1420. document.removeEventListener("mouseup", this.mouseup, false);
  1421. this._state.inDrag = false;
  1422. if (this._state.over === false) {
  1423. this._hideTooltip();
  1424. }
  1425. var val = this._calculateValue(true);
  1426. this._layout();
  1427. this._setDataVal(val);
  1428. this._trigger('slideStop', val);
  1429. // No longer need 'dragged' after mouse up
  1430. this._state.dragged = null;
  1431. return false;
  1432. },
  1433. _calculateValue: function _calculateValue(snapToClosestTick) {
  1434. var val;
  1435. if (this.options.range) {
  1436. val = [this.options.min, this.options.max];
  1437. if (this._state.percentage[0] !== 0) {
  1438. val[0] = this._toValue(this._state.percentage[0]);
  1439. val[0] = this._applyPrecision(val[0]);
  1440. }
  1441. if (this._state.percentage[1] !== 100) {
  1442. val[1] = this._toValue(this._state.percentage[1]);
  1443. val[1] = this._applyPrecision(val[1]);
  1444. }
  1445. if (snapToClosestTick) {
  1446. val[0] = this._snapToClosestTick(val[0]);
  1447. val[1] = this._snapToClosestTick(val[1]);
  1448. }
  1449. } else {
  1450. val = this._toValue(this._state.percentage[0]);
  1451. val = parseFloat(val);
  1452. val = this._applyPrecision(val);
  1453. if (snapToClosestTick) {
  1454. val = this._snapToClosestTick(val);
  1455. }
  1456. }
  1457. return val;
  1458. },
  1459. _snapToClosestTick: function _snapToClosestTick(val) {
  1460. var min = [val, Infinity];
  1461. for (var i = 0; i < this.options.ticks.length; i++) {
  1462. var diff = Math.abs(this.options.ticks[i] - val);
  1463. if (diff <= min[1]) {
  1464. min = [this.options.ticks[i], diff];
  1465. }
  1466. }
  1467. if (min[1] <= this.options.ticks_snap_bounds) {
  1468. return min[0];
  1469. }
  1470. return val;
  1471. },
  1472. _applyPrecision: function _applyPrecision(val) {
  1473. var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step);
  1474. return this._applyToFixedAndParseFloat(val, precision);
  1475. },
  1476. _getNumDigitsAfterDecimalPlace: function _getNumDigitsAfterDecimalPlace(num) {
  1477. var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
  1478. if (!match) {
  1479. return 0;
  1480. }
  1481. return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
  1482. },
  1483. _applyToFixedAndParseFloat: function _applyToFixedAndParseFloat(num, toFixedInput) {
  1484. var truncatedNum = num.toFixed(toFixedInput);
  1485. return parseFloat(truncatedNum);
  1486. },
  1487. /*
  1488. Credits to Mike Samuel for the following method!
  1489. Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number
  1490. */
  1491. _getPercentage: function _getPercentage(ev) {
  1492. if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) {
  1493. ev = ev.touches[0];
  1494. }
  1495. var eventPosition = ev[this.mousePos];
  1496. var sliderOffset = this._state.offset[this.stylePos];
  1497. var distanceToSlide = eventPosition - sliderOffset;
  1498. if (this.stylePos === 'right') {
  1499. distanceToSlide = -distanceToSlide;
  1500. }
  1501. // Calculate what percent of the length the slider handle has slid
  1502. var percentage = distanceToSlide / this._state.size * 100;
  1503. percentage = Math.round(percentage / this._state.percentage[2]) * this._state.percentage[2];
  1504. if (this.options.reversed) {
  1505. percentage = 100 - percentage;
  1506. }
  1507. // Make sure the percent is within the bounds of the slider.
  1508. // 0% corresponds to the 'min' value of the slide
  1509. // 100% corresponds to the 'max' value of the slide
  1510. return Math.max(0, Math.min(100, percentage));
  1511. },
  1512. _validateInputValue: function _validateInputValue(val) {
  1513. if (!isNaN(+val)) {
  1514. return +val;
  1515. } else if (Array.isArray(val)) {
  1516. this._validateArray(val);
  1517. return val;
  1518. } else {
  1519. throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(val));
  1520. }
  1521. },
  1522. _validateArray: function _validateArray(val) {
  1523. for (var i = 0; i < val.length; i++) {
  1524. var input = val[i];
  1525. if (typeof input !== 'number') {
  1526. throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(input));
  1527. }
  1528. }
  1529. },
  1530. _setDataVal: function _setDataVal(val) {
  1531. this.element.setAttribute('data-value', val);
  1532. this.element.setAttribute('value', val);
  1533. this.element.value = val;
  1534. },
  1535. _trigger: function _trigger(evt, val) {
  1536. val = val || val === 0 ? val : undefined;
  1537. var callbackFnArray = this.eventToCallbackMap[evt];
  1538. if (callbackFnArray && callbackFnArray.length) {
  1539. for (var i = 0; i < callbackFnArray.length; i++) {
  1540. var callbackFn = callbackFnArray[i];
  1541. callbackFn(val);
  1542. }
  1543. }
  1544. /* If JQuery exists, trigger JQuery events */
  1545. if ($) {
  1546. this._triggerJQueryEvent(evt, val);
  1547. }
  1548. },
  1549. _triggerJQueryEvent: function _triggerJQueryEvent(evt, val) {
  1550. var eventData = {
  1551. type: evt,
  1552. value: val
  1553. };
  1554. this.$element.trigger(eventData);
  1555. this.$sliderElem.trigger(eventData);
  1556. },
  1557. _unbindJQueryEventHandlers: function _unbindJQueryEventHandlers() {
  1558. this.$element.off();
  1559. this.$sliderElem.off();
  1560. },
  1561. _setText: function _setText(element, text) {
  1562. if (typeof element.textContent !== "undefined") {
  1563. element.textContent = text;
  1564. } else if (typeof element.innerText !== "undefined") {
  1565. element.innerText = text;
  1566. }
  1567. },
  1568. _removeClass: function _removeClass(element, classString) {
  1569. var classes = classString.split(" ");
  1570. var newClasses = element.className;
  1571. for (var i = 0; i < classes.length; i++) {
  1572. var classTag = classes[i];
  1573. var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
  1574. newClasses = newClasses.replace(regex, " ");
  1575. }
  1576. element.className = newClasses.trim();
  1577. },
  1578. _addClass: function _addClass(element, classString) {
  1579. var classes = classString.split(" ");
  1580. var newClasses = element.className;
  1581. for (var i = 0; i < classes.length; i++) {
  1582. var classTag = classes[i];
  1583. var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
  1584. var ifClassExists = regex.test(newClasses);
  1585. if (!ifClassExists) {
  1586. newClasses += " " + classTag;
  1587. }
  1588. }
  1589. element.className = newClasses.trim();
  1590. },
  1591. _offsetLeft: function _offsetLeft(obj) {
  1592. return obj.getBoundingClientRect().left;
  1593. },
  1594. _offsetRight: function _offsetRight(obj) {
  1595. return obj.getBoundingClientRect().right;
  1596. },
  1597. _offsetTop: function _offsetTop(obj) {
  1598. var offsetTop = obj.offsetTop;
  1599. while ((obj = obj.offsetParent) && !isNaN(obj.offsetTop)) {
  1600. offsetTop += obj.offsetTop;
  1601. if (obj.tagName !== 'BODY') {
  1602. offsetTop -= obj.scrollTop;
  1603. }
  1604. }
  1605. return offsetTop;
  1606. },
  1607. _offset: function _offset(obj) {
  1608. return {
  1609. left: this._offsetLeft(obj),
  1610. right: this._offsetRight(obj),
  1611. top: this._offsetTop(obj)
  1612. };
  1613. },
  1614. _css: function _css(elementRef, styleName, value) {
  1615. if ($) {
  1616. $.style(elementRef, styleName, value);
  1617. } else {
  1618. var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) {
  1619. return letter.toUpperCase();
  1620. });
  1621. elementRef.style[style] = value;
  1622. }
  1623. },
  1624. _toValue: function _toValue(percentage) {
  1625. return this.options.scale.toValue.apply(this, [percentage]);
  1626. },
  1627. _toPercentage: function _toPercentage(value) {
  1628. return this.options.scale.toPercentage.apply(this, [value]);
  1629. },
  1630. _setTooltipPosition: function _setTooltipPosition() {
  1631. var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max];
  1632. if (this.options.orientation === 'vertical') {
  1633. var tooltipPos;
  1634. if (this.options.tooltip_position) {
  1635. tooltipPos = this.options.tooltip_position;
  1636. } else {
  1637. if (this.options.rtl) {
  1638. tooltipPos = 'left';
  1639. } else {
  1640. tooltipPos = 'right';
  1641. }
  1642. }
  1643. var oppositeSide = tooltipPos === 'left' ? 'right' : 'left';
  1644. tooltips.forEach(function (tooltip) {
  1645. this._addClass(tooltip, tooltipPos);
  1646. tooltip.style[oppositeSide] = '100%';
  1647. }.bind(this));
  1648. } else if (this.options.tooltip_position === 'bottom') {
  1649. tooltips.forEach(function (tooltip) {
  1650. this._addClass(tooltip, 'bottom');
  1651. tooltip.style.top = 22 + 'px';
  1652. }.bind(this));
  1653. } else {
  1654. tooltips.forEach(function (tooltip) {
  1655. this._addClass(tooltip, 'top');
  1656. tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px';
  1657. }.bind(this));
  1658. }
  1659. }
  1660. };
  1661. /*********************************
  1662. Attach to global namespace
  1663. *********************************/
  1664. if ($ && $.fn) {
  1665. var autoRegisterNamespace = void 0;
  1666. if (!$.fn.slider) {
  1667. $.bridget(NAMESPACE_MAIN, Slider);
  1668. autoRegisterNamespace = NAMESPACE_MAIN;
  1669. } else {
  1670. if (windowIsDefined) {
  1671. window.console.warn("bootstrap-slider.js - WARNING: $.fn.slider namespace is already bound. Use the $.fn.bootstrapSlider namespace instead.");
  1672. }
  1673. autoRegisterNamespace = NAMESPACE_ALTERNATE;
  1674. }
  1675. $.bridget(NAMESPACE_ALTERNATE, Slider);
  1676. // Auto-Register data-provide="slider" Elements
  1677. $(function () {
  1678. $("input[data-provide=slider]")[autoRegisterNamespace]();
  1679. });
  1680. }
  1681. })($);
  1682. return Slider;
  1683. });