bootstrap-slider.js 61KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818
  1. /*! =======================================================
  2. VERSION 9.5.1
  3. ========================================================= */
  4. "use strict";
  5. function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "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) 2016 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 min = this.options.min === 0 ? 0 : Math.log(this.options.min);
  259. var max = Math.log(this.options.max);
  260. var value = Math.exp(min + (max - min) * percentage / 100);
  261. value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step;
  262. /* Rounding to the nearest step could exceed the min or
  263. * max, so clip to those values. */
  264. if (value < this.options.min) {
  265. return this.options.min;
  266. } else if (value > this.options.max) {
  267. return this.options.max;
  268. } else {
  269. return value;
  270. }
  271. },
  272. toPercentage: function toPercentage(value) {
  273. if (this.options.max === this.options.min) {
  274. return 0;
  275. } else {
  276. var max = Math.log(this.options.max);
  277. var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
  278. var v = value === 0 ? 0 : Math.log(value);
  279. return 100 * (v - min) / (max - min);
  280. }
  281. }
  282. }
  283. };
  284. /*************************************************
  285. CONSTRUCTOR
  286. **************************************************/
  287. Slider = function (element, options) {
  288. createNewSlider.call(this, element, options);
  289. return this;
  290. };
  291. function createNewSlider(element, options) {
  292. /*
  293. The internal state object is used to store data about the current 'state' of slider.
  294. This includes values such as the `value`, `enabled`, etc...
  295. */
  296. this._state = {
  297. value: null,
  298. enabled: null,
  299. offset: null,
  300. size: null,
  301. percentage: null,
  302. inDrag: false,
  303. over: false
  304. };
  305. // The objects used to store the reference to the tick methods if ticks_tooltip is on
  306. this.ticksCallbackMap = {};
  307. this.handleCallbackMap = {};
  308. if (typeof element === "string") {
  309. this.element = document.querySelector(element);
  310. } else if (element instanceof HTMLElement) {
  311. this.element = element;
  312. }
  313. /*************************************************
  314. Process Options
  315. **************************************************/
  316. options = options ? options : {};
  317. var optionTypes = Object.keys(this.defaultOptions);
  318. for (var i = 0; i < optionTypes.length; i++) {
  319. var optName = optionTypes[i];
  320. // First check if an option was passed in via the constructor
  321. var val = options[optName];
  322. // If no data attrib, then check data atrributes
  323. val = typeof val !== 'undefined' ? val : getDataAttrib(this.element, optName);
  324. // Finally, if nothing was specified, use the defaults
  325. val = val !== null ? val : this.defaultOptions[optName];
  326. // Set all options on the instance of the Slider
  327. if (!this.options) {
  328. this.options = {};
  329. }
  330. this.options[optName] = val;
  331. }
  332. /*
  333. Validate `tooltip_position` against 'orientation`
  334. - if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation`
  335. -- default for "vertical" -> "right"
  336. -- default for "horizontal" -> "left"
  337. */
  338. if (this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) {
  339. this.options.tooltip_position = "right";
  340. } else if (this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) {
  341. this.options.tooltip_position = "top";
  342. }
  343. function getDataAttrib(element, optName) {
  344. var dataName = "data-slider-" + optName.replace(/_/g, '-');
  345. var dataValString = element.getAttribute(dataName);
  346. try {
  347. return JSON.parse(dataValString);
  348. } catch (err) {
  349. return dataValString;
  350. }
  351. }
  352. /*************************************************
  353. Create Markup
  354. **************************************************/
  355. var origWidth = this.element.style.width;
  356. var updateSlider = false;
  357. var parent = this.element.parentNode;
  358. var sliderTrackSelection;
  359. var sliderTrackLow, sliderTrackHigh;
  360. var sliderMinHandle;
  361. var sliderMaxHandle;
  362. if (this.sliderElem) {
  363. updateSlider = true;
  364. } else {
  365. /* Create elements needed for slider */
  366. this.sliderElem = document.createElement("div");
  367. this.sliderElem.className = "slider";
  368. /* Create slider track elements */
  369. var sliderTrack = document.createElement("div");
  370. sliderTrack.className = "slider-track";
  371. sliderTrackLow = document.createElement("div");
  372. sliderTrackLow.className = "slider-track-low";
  373. sliderTrackSelection = document.createElement("div");
  374. sliderTrackSelection.className = "slider-selection";
  375. sliderTrackHigh = document.createElement("div");
  376. sliderTrackHigh.className = "slider-track-high";
  377. sliderMinHandle = document.createElement("div");
  378. sliderMinHandle.className = "slider-handle min-slider-handle";
  379. sliderMinHandle.setAttribute('role', 'slider');
  380. sliderMinHandle.setAttribute('aria-valuemin', this.options.min);
  381. sliderMinHandle.setAttribute('aria-valuemax', this.options.max);
  382. sliderMaxHandle = document.createElement("div");
  383. sliderMaxHandle.className = "slider-handle max-slider-handle";
  384. sliderMaxHandle.setAttribute('role', 'slider');
  385. sliderMaxHandle.setAttribute('aria-valuemin', this.options.min);
  386. sliderMaxHandle.setAttribute('aria-valuemax', this.options.max);
  387. sliderTrack.appendChild(sliderTrackLow);
  388. sliderTrack.appendChild(sliderTrackSelection);
  389. sliderTrack.appendChild(sliderTrackHigh);
  390. /* Create highlight range elements */
  391. this.rangeHighlightElements = [];
  392. if (Array.isArray(this.options.rangeHighlights) && this.options.rangeHighlights.length > 0) {
  393. for (var j = 0; j < this.options.rangeHighlights.length; j++) {
  394. var rangeHighlightElement = document.createElement("div");
  395. rangeHighlightElement.className = "slider-rangeHighlight slider-selection";
  396. this.rangeHighlightElements.push(rangeHighlightElement);
  397. sliderTrack.appendChild(rangeHighlightElement);
  398. }
  399. }
  400. /* Add aria-labelledby to handle's */
  401. var isLabelledbyArray = Array.isArray(this.options.labelledby);
  402. if (isLabelledbyArray && this.options.labelledby[0]) {
  403. sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby[0]);
  404. }
  405. if (isLabelledbyArray && this.options.labelledby[1]) {
  406. sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby[1]);
  407. }
  408. if (!isLabelledbyArray && this.options.labelledby) {
  409. sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby);
  410. sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby);
  411. }
  412. /* Create ticks */
  413. this.ticks = [];
  414. if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
  415. this.ticksContainer = document.createElement('div');
  416. this.ticksContainer.className = 'slider-tick-container';
  417. for (i = 0; i < this.options.ticks.length; i++) {
  418. var tick = document.createElement('div');
  419. tick.className = 'slider-tick';
  420. if (this.options.ticks_tooltip) {
  421. var tickListenerReference = this._addTickListener();
  422. var enterCallback = tickListenerReference.addMouseEnter(this, tick, i);
  423. var leaveCallback = tickListenerReference.addMouseLeave(this, tick);
  424. this.ticksCallbackMap[i] = {
  425. mouseEnter: enterCallback,
  426. mouseLeave: leaveCallback
  427. };
  428. }
  429. this.ticks.push(tick);
  430. this.ticksContainer.appendChild(tick);
  431. }
  432. sliderTrackSelection.className += " tick-slider-selection";
  433. }
  434. this.tickLabels = [];
  435. if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
  436. this.tickLabelContainer = document.createElement('div');
  437. this.tickLabelContainer.className = 'slider-tick-label-container';
  438. for (i = 0; i < this.options.ticks_labels.length; i++) {
  439. var label = document.createElement('div');
  440. var noTickPositionsSpecified = this.options.ticks_positions.length === 0;
  441. var tickLabelsIndex = this.options.reversed && noTickPositionsSpecified ? this.options.ticks_labels.length - (i + 1) : i;
  442. label.className = 'slider-tick-label';
  443. label.innerHTML = this.options.ticks_labels[tickLabelsIndex];
  444. this.tickLabels.push(label);
  445. this.tickLabelContainer.appendChild(label);
  446. }
  447. }
  448. var createAndAppendTooltipSubElements = function createAndAppendTooltipSubElements(tooltipElem) {
  449. var arrow = document.createElement("div");
  450. arrow.className = "tooltip-arrow";
  451. var inner = document.createElement("div");
  452. inner.className = "tooltip-inner";
  453. tooltipElem.appendChild(arrow);
  454. tooltipElem.appendChild(inner);
  455. };
  456. /* Create tooltip elements */
  457. var sliderTooltip = document.createElement("div");
  458. sliderTooltip.className = "tooltip tooltip-main";
  459. sliderTooltip.setAttribute('role', 'presentation');
  460. createAndAppendTooltipSubElements(sliderTooltip);
  461. var sliderTooltipMin = document.createElement("div");
  462. sliderTooltipMin.className = "tooltip tooltip-min";
  463. sliderTooltipMin.setAttribute('role', 'presentation');
  464. createAndAppendTooltipSubElements(sliderTooltipMin);
  465. var sliderTooltipMax = document.createElement("div");
  466. sliderTooltipMax.className = "tooltip tooltip-max";
  467. sliderTooltipMax.setAttribute('role', 'presentation');
  468. createAndAppendTooltipSubElements(sliderTooltipMax);
  469. /* Append components to sliderElem */
  470. this.sliderElem.appendChild(sliderTrack);
  471. this.sliderElem.appendChild(sliderTooltip);
  472. this.sliderElem.appendChild(sliderTooltipMin);
  473. this.sliderElem.appendChild(sliderTooltipMax);
  474. if (this.tickLabelContainer) {
  475. this.sliderElem.appendChild(this.tickLabelContainer);
  476. }
  477. if (this.ticksContainer) {
  478. this.sliderElem.appendChild(this.ticksContainer);
  479. }
  480. this.sliderElem.appendChild(sliderMinHandle);
  481. this.sliderElem.appendChild(sliderMaxHandle);
  482. /* Append slider element to parent container, right before the original <input> element */
  483. parent.insertBefore(this.sliderElem, this.element);
  484. /* Hide original <input> element */
  485. this.element.style.display = "none";
  486. }
  487. /* If JQuery exists, cache JQ references */
  488. if ($) {
  489. this.$element = $(this.element);
  490. this.$sliderElem = $(this.sliderElem);
  491. }
  492. /*************************************************
  493. Setup
  494. **************************************************/
  495. this.eventToCallbackMap = {};
  496. this.sliderElem.id = this.options.id;
  497. this.touchCapable = 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch;
  498. this.touchX = 0;
  499. this.touchY = 0;
  500. this.tooltip = this.sliderElem.querySelector('.tooltip-main');
  501. this.tooltipInner = this.tooltip.querySelector('.tooltip-inner');
  502. this.tooltip_min = this.sliderElem.querySelector('.tooltip-min');
  503. this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner');
  504. this.tooltip_max = this.sliderElem.querySelector('.tooltip-max');
  505. this.tooltipInner_max = this.tooltip_max.querySelector('.tooltip-inner');
  506. if (SliderScale[this.options.scale]) {
  507. this.options.scale = SliderScale[this.options.scale];
  508. }
  509. if (updateSlider === true) {
  510. // Reset classes
  511. this._removeClass(this.sliderElem, 'slider-horizontal');
  512. this._removeClass(this.sliderElem, 'slider-vertical');
  513. this._removeClass(this.tooltip, 'hide');
  514. this._removeClass(this.tooltip_min, 'hide');
  515. this._removeClass(this.tooltip_max, 'hide');
  516. // Undo existing inline styles for track
  517. ["left", "top", "width", "height"].forEach(function (prop) {
  518. this._removeProperty(this.trackLow, prop);
  519. this._removeProperty(this.trackSelection, prop);
  520. this._removeProperty(this.trackHigh, prop);
  521. }, this);
  522. // Undo inline styles on handles
  523. [this.handle1, this.handle2].forEach(function (handle) {
  524. this._removeProperty(handle, 'left');
  525. this._removeProperty(handle, 'top');
  526. }, this);
  527. // Undo inline styles and classes on tooltips
  528. [this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function (tooltip) {
  529. this._removeProperty(tooltip, 'left');
  530. this._removeProperty(tooltip, 'top');
  531. this._removeProperty(tooltip, 'margin-left');
  532. this._removeProperty(tooltip, 'margin-top');
  533. this._removeClass(tooltip, 'right');
  534. this._removeClass(tooltip, 'top');
  535. }, this);
  536. }
  537. if (this.options.orientation === 'vertical') {
  538. this._addClass(this.sliderElem, 'slider-vertical');
  539. this.stylePos = 'top';
  540. this.mousePos = 'pageY';
  541. this.sizePos = 'offsetHeight';
  542. } else {
  543. this._addClass(this.sliderElem, 'slider-horizontal');
  544. this.sliderElem.style.width = origWidth;
  545. this.options.orientation = 'horizontal';
  546. this.stylePos = 'left';
  547. this.mousePos = 'pageX';
  548. this.sizePos = 'offsetWidth';
  549. }
  550. this._setTooltipPosition();
  551. /* In case ticks are specified, overwrite the min and max bounds */
  552. if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
  553. this.options.max = Math.max.apply(Math, this.options.ticks);
  554. this.options.min = Math.min.apply(Math, this.options.ticks);
  555. }
  556. if (Array.isArray(this.options.value)) {
  557. this.options.range = true;
  558. this._state.value = this.options.value;
  559. } else if (this.options.range) {
  560. // User wants a range, but value is not an array
  561. this._state.value = [this.options.value, this.options.max];
  562. } else {
  563. this._state.value = this.options.value;
  564. }
  565. this.trackLow = sliderTrackLow || this.trackLow;
  566. this.trackSelection = sliderTrackSelection || this.trackSelection;
  567. this.trackHigh = sliderTrackHigh || this.trackHigh;
  568. if (this.options.selection === 'none') {
  569. this._addClass(this.trackLow, 'hide');
  570. this._addClass(this.trackSelection, 'hide');
  571. this._addClass(this.trackHigh, 'hide');
  572. } else if (this.options.selection === 'after' || this.options.selection === 'before') {
  573. this._removeClass(this.trackLow, 'hide');
  574. this._removeClass(this.trackSelection, 'hide');
  575. this._removeClass(this.trackHigh, 'hide');
  576. }
  577. this.handle1 = sliderMinHandle || this.handle1;
  578. this.handle2 = sliderMaxHandle || this.handle2;
  579. if (updateSlider === true) {
  580. // Reset classes
  581. this._removeClass(this.handle1, 'round triangle');
  582. this._removeClass(this.handle2, 'round triangle hide');
  583. for (i = 0; i < this.ticks.length; i++) {
  584. this._removeClass(this.ticks[i], 'round triangle hide');
  585. }
  586. }
  587. var availableHandleModifiers = ['round', 'triangle', 'custom'];
  588. var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1;
  589. if (isValidHandleType) {
  590. this._addClass(this.handle1, this.options.handle);
  591. this._addClass(this.handle2, this.options.handle);
  592. for (i = 0; i < this.ticks.length; i++) {
  593. this._addClass(this.ticks[i], this.options.handle);
  594. }
  595. }
  596. this._state.offset = this._offset(this.sliderElem);
  597. this._state.size = this.sliderElem[this.sizePos];
  598. this.setValue(this._state.value);
  599. /******************************************
  600. Bind Event Listeners
  601. ******************************************/
  602. // Bind keyboard handlers
  603. this.handle1Keydown = this._keydown.bind(this, 0);
  604. this.handle1.addEventListener("keydown", this.handle1Keydown, false);
  605. this.handle2Keydown = this._keydown.bind(this, 1);
  606. this.handle2.addEventListener("keydown", this.handle2Keydown, false);
  607. this.mousedown = this._mousedown.bind(this);
  608. this.touchstart = this._touchstart.bind(this);
  609. this.touchmove = this._touchmove.bind(this);
  610. if (this.touchCapable) {
  611. // Bind touch handlers
  612. this.sliderElem.addEventListener("touchstart", this.touchstart, false);
  613. this.sliderElem.addEventListener("touchmove", this.touchmove, false);
  614. }
  615. this.sliderElem.addEventListener("mousedown", this.mousedown, false);
  616. // Bind window handlers
  617. this.resize = this._resize.bind(this);
  618. window.addEventListener("resize", this.resize, false);
  619. // Bind tooltip-related handlers
  620. if (this.options.tooltip === 'hide') {
  621. this._addClass(this.tooltip, 'hide');
  622. this._addClass(this.tooltip_min, 'hide');
  623. this._addClass(this.tooltip_max, 'hide');
  624. } else if (this.options.tooltip === 'always') {
  625. this._showTooltip();
  626. this._alwaysShowTooltip = true;
  627. } else {
  628. this.showTooltip = this._showTooltip.bind(this);
  629. this.hideTooltip = this._hideTooltip.bind(this);
  630. if (this.options.ticks_tooltip) {
  631. var callbackHandle = this._addTickListener();
  632. //create handle1 listeners and store references in map
  633. var mouseEnter = callbackHandle.addMouseEnter(this, this.handle1);
  634. var mouseLeave = callbackHandle.addMouseLeave(this, this.handle1);
  635. this.handleCallbackMap.handle1 = {
  636. mouseEnter: mouseEnter,
  637. mouseLeave: mouseLeave
  638. };
  639. //create handle2 listeners and store references in map
  640. mouseEnter = callbackHandle.addMouseEnter(this, this.handle2);
  641. mouseLeave = callbackHandle.addMouseLeave(this, this.handle2);
  642. this.handleCallbackMap.handle2 = {
  643. mouseEnter: mouseEnter,
  644. mouseLeave: mouseLeave
  645. };
  646. } else {
  647. this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
  648. this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
  649. }
  650. this.handle1.addEventListener("focus", this.showTooltip, false);
  651. this.handle1.addEventListener("blur", this.hideTooltip, false);
  652. this.handle2.addEventListener("focus", this.showTooltip, false);
  653. this.handle2.addEventListener("blur", this.hideTooltip, false);
  654. }
  655. if (this.options.enabled) {
  656. this.enable();
  657. } else {
  658. this.disable();
  659. }
  660. }
  661. /*************************************************
  662. INSTANCE PROPERTIES/METHODS
  663. - Any methods bound to the prototype are considered
  664. part of the plugin's `public` interface
  665. **************************************************/
  666. Slider.prototype = {
  667. _init: function _init() {}, // NOTE: Must exist to support bridget
  668. constructor: Slider,
  669. defaultOptions: {
  670. id: "",
  671. min: 0,
  672. max: 10,
  673. step: 1,
  674. precision: 0,
  675. orientation: 'horizontal',
  676. value: 5,
  677. range: false,
  678. selection: 'before',
  679. tooltip: 'show',
  680. tooltip_split: false,
  681. handle: 'round',
  682. reversed: false,
  683. enabled: true,
  684. formatter: function formatter(val) {
  685. if (Array.isArray(val)) {
  686. return val[0] + " : " + val[1];
  687. } else {
  688. return val;
  689. }
  690. },
  691. natural_arrow_keys: false,
  692. ticks: [],
  693. ticks_positions: [],
  694. ticks_labels: [],
  695. ticks_snap_bounds: 0,
  696. ticks_tooltip: false,
  697. scale: 'linear',
  698. focus: false,
  699. tooltip_position: null,
  700. labelledby: null,
  701. rangeHighlights: []
  702. },
  703. getElement: function getElement() {
  704. return this.sliderElem;
  705. },
  706. getValue: function getValue() {
  707. if (this.options.range) {
  708. return this._state.value;
  709. } else {
  710. return this._state.value[0];
  711. }
  712. },
  713. setValue: function setValue(val, triggerSlideEvent, triggerChangeEvent) {
  714. if (!val) {
  715. val = 0;
  716. }
  717. var oldValue = this.getValue();
  718. this._state.value = this._validateInputValue(val);
  719. var applyPrecision = this._applyPrecision.bind(this);
  720. if (this.options.range) {
  721. this._state.value[0] = applyPrecision(this._state.value[0]);
  722. this._state.value[1] = applyPrecision(this._state.value[1]);
  723. this._state.value[0] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[0]));
  724. this._state.value[1] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[1]));
  725. } else {
  726. this._state.value = applyPrecision(this._state.value);
  727. this._state.value = [Math.max(this.options.min, Math.min(this.options.max, this._state.value))];
  728. this._addClass(this.handle2, 'hide');
  729. if (this.options.selection === 'after') {
  730. this._state.value[1] = this.options.max;
  731. } else {
  732. this._state.value[1] = this.options.min;
  733. }
  734. }
  735. if (this.options.max > this.options.min) {
  736. 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)];
  737. } else {
  738. this._state.percentage = [0, 0, 100];
  739. }
  740. this._layout();
  741. var newValue = this.options.range ? this._state.value : this._state.value[0];
  742. this._setDataVal(newValue);
  743. if (triggerSlideEvent === true) {
  744. this._trigger('slide', newValue);
  745. }
  746. if (oldValue !== newValue && triggerChangeEvent === true) {
  747. this._trigger('change', {
  748. oldValue: oldValue,
  749. newValue: newValue
  750. });
  751. }
  752. return this;
  753. },
  754. destroy: function destroy() {
  755. // Remove event handlers on slider elements
  756. this._removeSliderEventHandlers();
  757. // Remove the slider from the DOM
  758. this.sliderElem.parentNode.removeChild(this.sliderElem);
  759. /* Show original <input> element */
  760. this.element.style.display = "";
  761. // Clear out custom event bindings
  762. this._cleanUpEventCallbacksMap();
  763. // Remove data values
  764. this.element.removeAttribute("data");
  765. // Remove JQuery handlers/data
  766. if ($) {
  767. this._unbindJQueryEventHandlers();
  768. this.$element.removeData('slider');
  769. }
  770. },
  771. disable: function disable() {
  772. this._state.enabled = false;
  773. this.handle1.removeAttribute("tabindex");
  774. this.handle2.removeAttribute("tabindex");
  775. this._addClass(this.sliderElem, 'slider-disabled');
  776. this._trigger('slideDisabled');
  777. return this;
  778. },
  779. enable: function enable() {
  780. this._state.enabled = true;
  781. this.handle1.setAttribute("tabindex", 0);
  782. this.handle2.setAttribute("tabindex", 0);
  783. this._removeClass(this.sliderElem, 'slider-disabled');
  784. this._trigger('slideEnabled');
  785. return this;
  786. },
  787. toggle: function toggle() {
  788. if (this._state.enabled) {
  789. this.disable();
  790. } else {
  791. this.enable();
  792. }
  793. return this;
  794. },
  795. isEnabled: function isEnabled() {
  796. return this._state.enabled;
  797. },
  798. on: function on(evt, callback) {
  799. this._bindNonQueryEventHandler(evt, callback);
  800. return this;
  801. },
  802. off: function off(evt, callback) {
  803. if ($) {
  804. this.$element.off(evt, callback);
  805. this.$sliderElem.off(evt, callback);
  806. } else {
  807. this._unbindNonQueryEventHandler(evt, callback);
  808. }
  809. },
  810. getAttribute: function getAttribute(attribute) {
  811. if (attribute) {
  812. return this.options[attribute];
  813. } else {
  814. return this.options;
  815. }
  816. },
  817. setAttribute: function setAttribute(attribute, value) {
  818. this.options[attribute] = value;
  819. return this;
  820. },
  821. refresh: function refresh() {
  822. this._removeSliderEventHandlers();
  823. createNewSlider.call(this, this.element, this.options);
  824. if ($) {
  825. // Bind new instance of slider to the element
  826. $.data(this.element, 'slider', this);
  827. }
  828. return this;
  829. },
  830. relayout: function relayout() {
  831. this._resize();
  832. this._layout();
  833. return this;
  834. },
  835. /******************************+
  836. HELPERS
  837. - Any method that is not part of the public interface.
  838. - Place it underneath this comment block and write its signature like so:
  839. _fnName : function() {...}
  840. ********************************/
  841. _removeSliderEventHandlers: function _removeSliderEventHandlers() {
  842. // Remove keydown event listeners
  843. this.handle1.removeEventListener("keydown", this.handle1Keydown, false);
  844. this.handle2.removeEventListener("keydown", this.handle2Keydown, false);
  845. //remove the listeners from the ticks and handles if they had their own listeners
  846. if (this.options.ticks_tooltip) {
  847. var ticks = this.ticksContainer.getElementsByClassName('slider-tick');
  848. for (var i = 0; i < ticks.length; i++) {
  849. ticks[i].removeEventListener('mouseenter', this.ticksCallbackMap[i].mouseEnter, false);
  850. ticks[i].removeEventListener('mouseleave', this.ticksCallbackMap[i].mouseLeave, false);
  851. }
  852. this.handle1.removeEventListener('mouseenter', this.handleCallbackMap.handle1.mouseEnter, false);
  853. this.handle2.removeEventListener('mouseenter', this.handleCallbackMap.handle2.mouseEnter, false);
  854. this.handle1.removeEventListener('mouseleave', this.handleCallbackMap.handle1.mouseLeave, false);
  855. this.handle2.removeEventListener('mouseleave', this.handleCallbackMap.handle2.mouseLeave, false);
  856. }
  857. this.handleCallbackMap = null;
  858. this.ticksCallbackMap = null;
  859. if (this.showTooltip) {
  860. this.handle1.removeEventListener("focus", this.showTooltip, false);
  861. this.handle2.removeEventListener("focus", this.showTooltip, false);
  862. }
  863. if (this.hideTooltip) {
  864. this.handle1.removeEventListener("blur", this.hideTooltip, false);
  865. this.handle2.removeEventListener("blur", this.hideTooltip, false);
  866. }
  867. // Remove event listeners from sliderElem
  868. if (this.showTooltip) {
  869. this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false);
  870. }
  871. if (this.hideTooltip) {
  872. this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false);
  873. }
  874. this.sliderElem.removeEventListener("touchstart", this.touchstart, false);
  875. this.sliderElem.removeEventListener("touchmove", this.touchmove, false);
  876. this.sliderElem.removeEventListener("mousedown", this.mousedown, false);
  877. // Remove window event listener
  878. window.removeEventListener("resize", this.resize, false);
  879. },
  880. _bindNonQueryEventHandler: function _bindNonQueryEventHandler(evt, callback) {
  881. if (this.eventToCallbackMap[evt] === undefined) {
  882. this.eventToCallbackMap[evt] = [];
  883. }
  884. this.eventToCallbackMap[evt].push(callback);
  885. },
  886. _unbindNonQueryEventHandler: function _unbindNonQueryEventHandler(evt, callback) {
  887. var callbacks = this.eventToCallbackMap[evt];
  888. if (callbacks !== undefined) {
  889. for (var i = 0; i < callbacks.length; i++) {
  890. if (callbacks[i] === callback) {
  891. callbacks.splice(i, 1);
  892. break;
  893. }
  894. }
  895. }
  896. },
  897. _cleanUpEventCallbacksMap: function _cleanUpEventCallbacksMap() {
  898. var eventNames = Object.keys(this.eventToCallbackMap);
  899. for (var i = 0; i < eventNames.length; i++) {
  900. var eventName = eventNames[i];
  901. delete this.eventToCallbackMap[eventName];
  902. }
  903. },
  904. _showTooltip: function _showTooltip() {
  905. if (this.options.tooltip_split === false) {
  906. this._addClass(this.tooltip, 'in');
  907. this.tooltip_min.style.display = 'none';
  908. this.tooltip_max.style.display = 'none';
  909. } else {
  910. this._addClass(this.tooltip_min, 'in');
  911. this._addClass(this.tooltip_max, 'in');
  912. this.tooltip.style.display = 'none';
  913. }
  914. this._state.over = true;
  915. },
  916. _hideTooltip: function _hideTooltip() {
  917. if (this._state.inDrag === false && this.alwaysShowTooltip !== true) {
  918. this._removeClass(this.tooltip, 'in');
  919. this._removeClass(this.tooltip_min, 'in');
  920. this._removeClass(this.tooltip_max, 'in');
  921. }
  922. this._state.over = false;
  923. },
  924. _setToolTipOnMouseOver: function _setToolTipOnMouseOver(tempState) {
  925. var formattedTooltipVal = this.options.formatter(!tempState ? this._state.value[0] : tempState.value[0]);
  926. var positionPercentages = !tempState ? getPositionPercentages(this._state, this.options.reversed) : getPositionPercentages(tempState, this.options.reversed);
  927. this._setText(this.tooltipInner, formattedTooltipVal);
  928. this.tooltip.style[this.stylePos] = positionPercentages[0] + '%';
  929. if (this.options.orientation === 'vertical') {
  930. this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
  931. } else {
  932. this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
  933. }
  934. function getPositionPercentages(state, reversed) {
  935. if (reversed) {
  936. return [100 - state.percentage[0], this.options.range ? 100 - state.percentage[1] : state.percentage[1]];
  937. }
  938. return [state.percentage[0], state.percentage[1]];
  939. }
  940. },
  941. _addTickListener: function _addTickListener() {
  942. return {
  943. addMouseEnter: function addMouseEnter(reference, tick, index) {
  944. var enter = function enter() {
  945. var tempState = reference._state;
  946. var idString = index >= 0 ? index : this.attributes['aria-valuenow'].value;
  947. var hoverIndex = parseInt(idString, 10);
  948. tempState.value[0] = hoverIndex;
  949. tempState.percentage[0] = reference.options.ticks_positions[hoverIndex];
  950. reference._setToolTipOnMouseOver(tempState);
  951. reference._showTooltip();
  952. };
  953. tick.addEventListener("mouseenter", enter, false);
  954. return enter;
  955. },
  956. addMouseLeave: function addMouseLeave(reference, tick) {
  957. var leave = function leave() {
  958. reference._hideTooltip();
  959. };
  960. tick.addEventListener("mouseleave", leave, false);
  961. return leave;
  962. }
  963. };
  964. },
  965. _layout: function _layout() {
  966. var positionPercentages;
  967. if (this.options.reversed) {
  968. positionPercentages = [100 - this._state.percentage[0], this.options.range ? 100 - this._state.percentage[1] : this._state.percentage[1]];
  969. } else {
  970. positionPercentages = [this._state.percentage[0], this._state.percentage[1]];
  971. }
  972. this.handle1.style[this.stylePos] = positionPercentages[0] + '%';
  973. this.handle1.setAttribute('aria-valuenow', this._state.value[0]);
  974. if (isNaN(this.options.formatter(this._state.value[0]))) {
  975. this.handle1.setAttribute('aria-valuetext', this.options.formatter(this._state.value[0]));
  976. }
  977. this.handle2.style[this.stylePos] = positionPercentages[1] + '%';
  978. this.handle2.setAttribute('aria-valuenow', this._state.value[1]);
  979. if (isNaN(this.options.formatter(this._state.value[1]))) {
  980. this.handle2.setAttribute('aria-valuetext', this.options.formatter(this._state.value[1]));
  981. }
  982. /* Position highlight range elements */
  983. if (this.rangeHighlightElements.length > 0 && Array.isArray(this.options.rangeHighlights) && this.options.rangeHighlights.length > 0) {
  984. for (var _i = 0; _i < this.options.rangeHighlights.length; _i++) {
  985. var startPercent = this._toPercentage(this.options.rangeHighlights[_i].start);
  986. var endPercent = this._toPercentage(this.options.rangeHighlights[_i].end);
  987. if (this.options.reversed) {
  988. var sp = 100 - endPercent;
  989. endPercent = 100 - startPercent;
  990. startPercent = sp;
  991. }
  992. var currentRange = this._createHighlightRange(startPercent, endPercent);
  993. if (currentRange) {
  994. if (this.options.orientation === 'vertical') {
  995. this.rangeHighlightElements[_i].style.top = currentRange.start + "%";
  996. this.rangeHighlightElements[_i].style.height = currentRange.size + "%";
  997. } else {
  998. this.rangeHighlightElements[_i].style.left = currentRange.start + "%";
  999. this.rangeHighlightElements[_i].style.width = currentRange.size + "%";
  1000. }
  1001. } else {
  1002. this.rangeHighlightElements[_i].style.display = "none";
  1003. }
  1004. }
  1005. }
  1006. /* Position ticks and labels */
  1007. if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
  1008. var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width';
  1009. var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft';
  1010. var labelSize = this._state.size / (this.options.ticks.length - 1);
  1011. if (this.tickLabelContainer) {
  1012. var extraMargin = 0;
  1013. if (this.options.ticks_positions.length === 0) {
  1014. if (this.options.orientation !== 'vertical') {
  1015. this.tickLabelContainer.style[styleMargin] = -labelSize / 2 + 'px';
  1016. }
  1017. extraMargin = this.tickLabelContainer.offsetHeight;
  1018. } else {
  1019. /* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */
  1020. for (i = 0; i < this.tickLabelContainer.childNodes.length; i++) {
  1021. if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) {
  1022. extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight;
  1023. }
  1024. }
  1025. }
  1026. if (this.options.orientation === 'horizontal') {
  1027. this.sliderElem.style.marginBottom = extraMargin + 'px';
  1028. }
  1029. }
  1030. for (var i = 0; i < this.options.ticks.length; i++) {
  1031. var percentage = this.options.ticks_positions[i] || this._toPercentage(this.options.ticks[i]);
  1032. if (this.options.reversed) {
  1033. percentage = 100 - percentage;
  1034. }
  1035. this.ticks[i].style[this.stylePos] = percentage + '%';
  1036. /* Set class labels to denote whether ticks are in the selection */
  1037. this._removeClass(this.ticks[i], 'in-selection');
  1038. if (!this.options.range) {
  1039. if (this.options.selection === 'after' && percentage >= positionPercentages[0]) {
  1040. this._addClass(this.ticks[i], 'in-selection');
  1041. } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) {
  1042. this._addClass(this.ticks[i], 'in-selection');
  1043. }
  1044. } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) {
  1045. this._addClass(this.ticks[i], 'in-selection');
  1046. }
  1047. if (this.tickLabels[i]) {
  1048. this.tickLabels[i].style[styleSize] = labelSize + 'px';
  1049. if (this.options.orientation !== 'vertical' && this.options.ticks_positions[i] !== undefined) {
  1050. this.tickLabels[i].style.position = 'absolute';
  1051. this.tickLabels[i].style[this.stylePos] = percentage + '%';
  1052. this.tickLabels[i].style[styleMargin] = -labelSize / 2 + 'px';
  1053. } else if (this.options.orientation === 'vertical') {
  1054. this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px';
  1055. this.tickLabelContainer.style['marginTop'] = this.sliderElem.offsetWidth / 2 * -1 + 'px';
  1056. }
  1057. }
  1058. }
  1059. }
  1060. var formattedTooltipVal;
  1061. if (this.options.range) {
  1062. formattedTooltipVal = this.options.formatter(this._state.value);
  1063. this._setText(this.tooltipInner, formattedTooltipVal);
  1064. this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0]) / 2 + '%';
  1065. if (this.options.orientation === 'vertical') {
  1066. this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
  1067. } else {
  1068. this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
  1069. }
  1070. if (this.options.orientation === 'vertical') {
  1071. this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
  1072. } else {
  1073. this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
  1074. }
  1075. var innerTooltipMinText = this.options.formatter(this._state.value[0]);
  1076. this._setText(this.tooltipInner_min, innerTooltipMinText);
  1077. var innerTooltipMaxText = this.options.formatter(this._state.value[1]);
  1078. this._setText(this.tooltipInner_max, innerTooltipMaxText);
  1079. this.tooltip_min.style[this.stylePos] = positionPercentages[0] + '%';
  1080. if (this.options.orientation === 'vertical') {
  1081. this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px');
  1082. } else {
  1083. this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px');
  1084. }
  1085. this.tooltip_max.style[this.stylePos] = positionPercentages[1] + '%';
  1086. if (this.options.orientation === 'vertical') {
  1087. this._css(this.tooltip_max, 'margin-top', -this.tooltip_max.offsetHeight / 2 + 'px');
  1088. } else {
  1089. this._css(this.tooltip_max, 'margin-left', -this.tooltip_max.offsetWidth / 2 + 'px');
  1090. }
  1091. } else {
  1092. formattedTooltipVal = this.options.formatter(this._state.value[0]);
  1093. this._setText(this.tooltipInner, formattedTooltipVal);
  1094. this.tooltip.style[this.stylePos] = positionPercentages[0] + '%';
  1095. if (this.options.orientation === 'vertical') {
  1096. this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
  1097. } else {
  1098. this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
  1099. }
  1100. }
  1101. if (this.options.orientation === 'vertical') {
  1102. this.trackLow.style.top = '0';
  1103. this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1104. this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1105. this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
  1106. this.trackHigh.style.bottom = '0';
  1107. this.trackHigh.style.height = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
  1108. } else {
  1109. this.trackLow.style.left = '0';
  1110. this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1111. this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
  1112. this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
  1113. this.trackHigh.style.right = '0';
  1114. this.trackHigh.style.width = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
  1115. var offset_min = this.tooltip_min.getBoundingClientRect();
  1116. var offset_max = this.tooltip_max.getBoundingClientRect();
  1117. if (this.options.tooltip_position === 'bottom') {
  1118. if (offset_min.right > offset_max.left) {
  1119. this._removeClass(this.tooltip_max, 'bottom');
  1120. this._addClass(this.tooltip_max, 'top');
  1121. this.tooltip_max.style.top = '';
  1122. this.tooltip_max.style.bottom = 22 + 'px';
  1123. } else {
  1124. this._removeClass(this.tooltip_max, 'top');
  1125. this._addClass(this.tooltip_max, 'bottom');
  1126. this.tooltip_max.style.top = this.tooltip_min.style.top;
  1127. this.tooltip_max.style.bottom = '';
  1128. }
  1129. } else {
  1130. if (offset_min.right > offset_max.left) {
  1131. this._removeClass(this.tooltip_max, 'top');
  1132. this._addClass(this.tooltip_max, 'bottom');
  1133. this.tooltip_max.style.top = 18 + 'px';
  1134. } else {
  1135. this._removeClass(this.tooltip_max, 'bottom');
  1136. this._addClass(this.tooltip_max, 'top');
  1137. this.tooltip_max.style.top = this.tooltip_min.style.top;
  1138. }
  1139. }
  1140. }
  1141. },
  1142. _createHighlightRange: function _createHighlightRange(start, end) {
  1143. if (this._isHighlightRange(start, end)) {
  1144. if (start > end) {
  1145. return { 'start': end, 'size': start - end };
  1146. }
  1147. return { 'start': start, 'size': end - start };
  1148. }
  1149. return null;
  1150. },
  1151. _isHighlightRange: function _isHighlightRange(start, end) {
  1152. if (0 <= start && start <= 100 && 0 <= end && end <= 100) {
  1153. return true;
  1154. } else {
  1155. return false;
  1156. }
  1157. },
  1158. _resize: function _resize(ev) {
  1159. /*jshint unused:false*/
  1160. this._state.offset = this._offset(this.sliderElem);
  1161. this._state.size = this.sliderElem[this.sizePos];
  1162. this._layout();
  1163. },
  1164. _removeProperty: function _removeProperty(element, prop) {
  1165. if (element.style.removeProperty) {
  1166. element.style.removeProperty(prop);
  1167. } else {
  1168. element.style.removeAttribute(prop);
  1169. }
  1170. },
  1171. _mousedown: function _mousedown(ev) {
  1172. if (!this._state.enabled) {
  1173. return false;
  1174. }
  1175. this._state.offset = this._offset(this.sliderElem);
  1176. this._state.size = this.sliderElem[this.sizePos];
  1177. var percentage = this._getPercentage(ev);
  1178. if (this.options.range) {
  1179. var diff1 = Math.abs(this._state.percentage[0] - percentage);
  1180. var diff2 = Math.abs(this._state.percentage[1] - percentage);
  1181. this._state.dragged = diff1 < diff2 ? 0 : 1;
  1182. this._adjustPercentageForRangeSliders(percentage);
  1183. } else {
  1184. this._state.dragged = 0;
  1185. }
  1186. this._state.percentage[this._state.dragged] = percentage;
  1187. this._layout();
  1188. if (this.touchCapable) {
  1189. document.removeEventListener("touchmove", this.mousemove, false);
  1190. document.removeEventListener("touchend", this.mouseup, false);
  1191. }
  1192. if (this.mousemove) {
  1193. document.removeEventListener("mousemove", this.mousemove, false);
  1194. }
  1195. if (this.mouseup) {
  1196. document.removeEventListener("mouseup", this.mouseup, false);
  1197. }
  1198. this.mousemove = this._mousemove.bind(this);
  1199. this.mouseup = this._mouseup.bind(this);
  1200. if (this.touchCapable) {
  1201. // Touch: Bind touch events:
  1202. document.addEventListener("touchmove", this.mousemove, false);
  1203. document.addEventListener("touchend", this.mouseup, false);
  1204. }
  1205. // Bind mouse events:
  1206. document.addEventListener("mousemove", this.mousemove, false);
  1207. document.addEventListener("mouseup", this.mouseup, false);
  1208. this._state.inDrag = true;
  1209. var newValue = this._calculateValue();
  1210. this._trigger('slideStart', newValue);
  1211. this._setDataVal(newValue);
  1212. this.setValue(newValue, false, true);
  1213. this._pauseEvent(ev);
  1214. if (this.options.focus) {
  1215. this._triggerFocusOnHandle(this._state.dragged);
  1216. }
  1217. return true;
  1218. },
  1219. _touchstart: function _touchstart(ev) {
  1220. if (ev.changedTouches === undefined) {
  1221. this._mousedown(ev);
  1222. return;
  1223. }
  1224. var touch = ev.changedTouches[0];
  1225. this.touchX = touch.pageX;
  1226. this.touchY = touch.pageY;
  1227. },
  1228. _triggerFocusOnHandle: function _triggerFocusOnHandle(handleIdx) {
  1229. if (handleIdx === 0) {
  1230. this.handle1.focus();
  1231. }
  1232. if (handleIdx === 1) {
  1233. this.handle2.focus();
  1234. }
  1235. },
  1236. _keydown: function _keydown(handleIdx, ev) {
  1237. if (!this._state.enabled) {
  1238. return false;
  1239. }
  1240. var dir;
  1241. switch (ev.keyCode) {
  1242. case 37: // left
  1243. case 40:
  1244. // down
  1245. dir = -1;
  1246. break;
  1247. case 39: // right
  1248. case 38:
  1249. // up
  1250. dir = 1;
  1251. break;
  1252. }
  1253. if (!dir) {
  1254. return;
  1255. }
  1256. // use natural arrow keys instead of from min to max
  1257. if (this.options.natural_arrow_keys) {
  1258. var ifVerticalAndNotReversed = this.options.orientation === 'vertical' && !this.options.reversed;
  1259. var ifHorizontalAndReversed = this.options.orientation === 'horizontal' && this.options.reversed;
  1260. if (ifVerticalAndNotReversed || ifHorizontalAndReversed) {
  1261. dir = -dir;
  1262. }
  1263. }
  1264. var val = this._state.value[handleIdx] + dir * this.options.step;
  1265. if (this.options.range) {
  1266. val = [!handleIdx ? val : this._state.value[0], handleIdx ? val : this._state.value[1]];
  1267. }
  1268. this._trigger('slideStart', val);
  1269. this._setDataVal(val);
  1270. this.setValue(val, true, true);
  1271. this._setDataVal(val);
  1272. this._trigger('slideStop', val);
  1273. this._layout();
  1274. this._pauseEvent(ev);
  1275. return false;
  1276. },
  1277. _pauseEvent: function _pauseEvent(ev) {
  1278. if (ev.stopPropagation) {
  1279. ev.stopPropagation();
  1280. }
  1281. if (ev.preventDefault) {
  1282. ev.preventDefault();
  1283. }
  1284. ev.cancelBubble = true;
  1285. ev.returnValue = false;
  1286. },
  1287. _mousemove: function _mousemove(ev) {
  1288. if (!this._state.enabled) {
  1289. return false;
  1290. }
  1291. var percentage = this._getPercentage(ev);
  1292. this._adjustPercentageForRangeSliders(percentage);
  1293. this._state.percentage[this._state.dragged] = percentage;
  1294. this._layout();
  1295. var val = this._calculateValue(true);
  1296. this.setValue(val, true, true);
  1297. return false;
  1298. },
  1299. _touchmove: function _touchmove(ev) {
  1300. if (ev.changedTouches === undefined) {
  1301. return;
  1302. }
  1303. var touch = ev.changedTouches[0];
  1304. var xDiff = touch.pageX - this.touchX;
  1305. var yDiff = touch.pageY - this.touchY;
  1306. if (!this._state.inDrag) {
  1307. // Vertical Slider
  1308. if (this.options.orientation === 'vertical' && xDiff <= 5 && xDiff >= -5 && (yDiff >= 15 || yDiff <= -15)) {
  1309. this._mousedown(ev);
  1310. }
  1311. // Horizontal slider.
  1312. else if (yDiff <= 5 && yDiff >= -5 && (xDiff >= 15 || xDiff <= -15)) {
  1313. this._mousedown(ev);
  1314. }
  1315. }
  1316. },
  1317. _adjustPercentageForRangeSliders: function _adjustPercentageForRangeSliders(percentage) {
  1318. if (this.options.range) {
  1319. var precision = this._getNumDigitsAfterDecimalPlace(percentage);
  1320. precision = precision ? precision - 1 : 0;
  1321. var percentageWithAdjustedPrecision = this._applyToFixedAndParseFloat(percentage, precision);
  1322. if (this._state.dragged === 0 && this._applyToFixedAndParseFloat(this._state.percentage[1], precision) < percentageWithAdjustedPrecision) {
  1323. this._state.percentage[0] = this._state.percentage[1];
  1324. this._state.dragged = 1;
  1325. } else if (this._state.dragged === 1 && this._applyToFixedAndParseFloat(this._state.percentage[0], precision) > percentageWithAdjustedPrecision) {
  1326. this._state.percentage[1] = this._state.percentage[0];
  1327. this._state.dragged = 0;
  1328. }
  1329. }
  1330. },
  1331. _mouseup: function _mouseup() {
  1332. if (!this._state.enabled) {
  1333. return false;
  1334. }
  1335. if (this.touchCapable) {
  1336. // Touch: Unbind touch event handlers:
  1337. document.removeEventListener("touchmove", this.mousemove, false);
  1338. document.removeEventListener("touchend", this.mouseup, false);
  1339. }
  1340. // Unbind mouse event handlers:
  1341. document.removeEventListener("mousemove", this.mousemove, false);
  1342. document.removeEventListener("mouseup", this.mouseup, false);
  1343. this._state.inDrag = false;
  1344. if (this._state.over === false) {
  1345. this._hideTooltip();
  1346. }
  1347. var val = this._calculateValue(true);
  1348. this._layout();
  1349. this._setDataVal(val);
  1350. this._trigger('slideStop', val);
  1351. return false;
  1352. },
  1353. _calculateValue: function _calculateValue(snapToClosestTick) {
  1354. var val;
  1355. if (this.options.range) {
  1356. val = [this.options.min, this.options.max];
  1357. if (this._state.percentage[0] !== 0) {
  1358. val[0] = this._toValue(this._state.percentage[0]);
  1359. val[0] = this._applyPrecision(val[0]);
  1360. }
  1361. if (this._state.percentage[1] !== 100) {
  1362. val[1] = this._toValue(this._state.percentage[1]);
  1363. val[1] = this._applyPrecision(val[1]);
  1364. }
  1365. } else {
  1366. val = this._toValue(this._state.percentage[0]);
  1367. val = parseFloat(val);
  1368. val = this._applyPrecision(val);
  1369. }
  1370. if (snapToClosestTick) {
  1371. var min = [val, Infinity];
  1372. for (var i = 0; i < this.options.ticks.length; i++) {
  1373. var diff = Math.abs(this.options.ticks[i] - val);
  1374. if (diff <= min[1]) {
  1375. min = [this.options.ticks[i], diff];
  1376. }
  1377. }
  1378. if (min[1] <= this.options.ticks_snap_bounds) {
  1379. return min[0];
  1380. }
  1381. }
  1382. return val;
  1383. },
  1384. _applyPrecision: function _applyPrecision(val) {
  1385. var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step);
  1386. return this._applyToFixedAndParseFloat(val, precision);
  1387. },
  1388. _getNumDigitsAfterDecimalPlace: function _getNumDigitsAfterDecimalPlace(num) {
  1389. var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
  1390. if (!match) {
  1391. return 0;
  1392. }
  1393. return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
  1394. },
  1395. _applyToFixedAndParseFloat: function _applyToFixedAndParseFloat(num, toFixedInput) {
  1396. var truncatedNum = num.toFixed(toFixedInput);
  1397. return parseFloat(truncatedNum);
  1398. },
  1399. /*
  1400. Credits to Mike Samuel for the following method!
  1401. Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number
  1402. */
  1403. _getPercentage: function _getPercentage(ev) {
  1404. if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) {
  1405. ev = ev.touches[0];
  1406. }
  1407. var eventPosition = ev[this.mousePos];
  1408. var sliderOffset = this._state.offset[this.stylePos];
  1409. var distanceToSlide = eventPosition - sliderOffset;
  1410. // Calculate what percent of the length the slider handle has slid
  1411. var percentage = distanceToSlide / this._state.size * 100;
  1412. percentage = Math.round(percentage / this._state.percentage[2]) * this._state.percentage[2];
  1413. if (this.options.reversed) {
  1414. percentage = 100 - percentage;
  1415. }
  1416. // Make sure the percent is within the bounds of the slider.
  1417. // 0% corresponds to the 'min' value of the slide
  1418. // 100% corresponds to the 'max' value of the slide
  1419. return Math.max(0, Math.min(100, percentage));
  1420. },
  1421. _validateInputValue: function _validateInputValue(val) {
  1422. if (!isNaN(+val)) {
  1423. return +val;
  1424. } else if (Array.isArray(val)) {
  1425. this._validateArray(val);
  1426. return val;
  1427. } else {
  1428. throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(val));
  1429. }
  1430. },
  1431. _validateArray: function _validateArray(val) {
  1432. for (var i = 0; i < val.length; i++) {
  1433. var input = val[i];
  1434. if (typeof input !== 'number') {
  1435. throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(input));
  1436. }
  1437. }
  1438. },
  1439. _setDataVal: function _setDataVal(val) {
  1440. this.element.setAttribute('data-value', val);
  1441. this.element.setAttribute('value', val);
  1442. this.element.value = val;
  1443. },
  1444. _trigger: function _trigger(evt, val) {
  1445. val = val || val === 0 ? val : undefined;
  1446. var callbackFnArray = this.eventToCallbackMap[evt];
  1447. if (callbackFnArray && callbackFnArray.length) {
  1448. for (var i = 0; i < callbackFnArray.length; i++) {
  1449. var callbackFn = callbackFnArray[i];
  1450. callbackFn(val);
  1451. }
  1452. }
  1453. /* If JQuery exists, trigger JQuery events */
  1454. if ($) {
  1455. this._triggerJQueryEvent(evt, val);
  1456. }
  1457. },
  1458. _triggerJQueryEvent: function _triggerJQueryEvent(evt, val) {
  1459. var eventData = {
  1460. type: evt,
  1461. value: val
  1462. };
  1463. this.$element.trigger(eventData);
  1464. this.$sliderElem.trigger(eventData);
  1465. },
  1466. _unbindJQueryEventHandlers: function _unbindJQueryEventHandlers() {
  1467. this.$element.off();
  1468. this.$sliderElem.off();
  1469. },
  1470. _setText: function _setText(element, text) {
  1471. if (typeof element.textContent !== "undefined") {
  1472. element.textContent = text;
  1473. } else if (typeof element.innerText !== "undefined") {
  1474. element.innerText = text;
  1475. }
  1476. },
  1477. _removeClass: function _removeClass(element, classString) {
  1478. var classes = classString.split(" ");
  1479. var newClasses = element.className;
  1480. for (var i = 0; i < classes.length; i++) {
  1481. var classTag = classes[i];
  1482. var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
  1483. newClasses = newClasses.replace(regex, " ");
  1484. }
  1485. element.className = newClasses.trim();
  1486. },
  1487. _addClass: function _addClass(element, classString) {
  1488. var classes = classString.split(" ");
  1489. var newClasses = element.className;
  1490. for (var i = 0; i < classes.length; i++) {
  1491. var classTag = classes[i];
  1492. var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
  1493. var ifClassExists = regex.test(newClasses);
  1494. if (!ifClassExists) {
  1495. newClasses += " " + classTag;
  1496. }
  1497. }
  1498. element.className = newClasses.trim();
  1499. },
  1500. _offsetLeft: function _offsetLeft(obj) {
  1501. return obj.getBoundingClientRect().left;
  1502. },
  1503. _offsetTop: function _offsetTop(obj) {
  1504. var offsetTop = obj.offsetTop;
  1505. while ((obj = obj.offsetParent) && !isNaN(obj.offsetTop)) {
  1506. offsetTop += obj.offsetTop;
  1507. if (obj.tagName !== 'BODY') {
  1508. offsetTop -= obj.scrollTop;
  1509. }
  1510. }
  1511. return offsetTop;
  1512. },
  1513. _offset: function _offset(obj) {
  1514. return {
  1515. left: this._offsetLeft(obj),
  1516. top: this._offsetTop(obj)
  1517. };
  1518. },
  1519. _css: function _css(elementRef, styleName, value) {
  1520. if ($) {
  1521. $.style(elementRef, styleName, value);
  1522. } else {
  1523. var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) {
  1524. return letter.toUpperCase();
  1525. });
  1526. elementRef.style[style] = value;
  1527. }
  1528. },
  1529. _toValue: function _toValue(percentage) {
  1530. return this.options.scale.toValue.apply(this, [percentage]);
  1531. },
  1532. _toPercentage: function _toPercentage(value) {
  1533. return this.options.scale.toPercentage.apply(this, [value]);
  1534. },
  1535. _setTooltipPosition: function _setTooltipPosition() {
  1536. var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max];
  1537. if (this.options.orientation === 'vertical') {
  1538. var tooltipPos = this.options.tooltip_position || 'right';
  1539. var oppositeSide = tooltipPos === 'left' ? 'right' : 'left';
  1540. tooltips.forEach((function (tooltip) {
  1541. this._addClass(tooltip, tooltipPos);
  1542. tooltip.style[oppositeSide] = '100%';
  1543. }).bind(this));
  1544. } else if (this.options.tooltip_position === 'bottom') {
  1545. tooltips.forEach((function (tooltip) {
  1546. this._addClass(tooltip, 'bottom');
  1547. tooltip.style.top = 22 + 'px';
  1548. }).bind(this));
  1549. } else {
  1550. tooltips.forEach((function (tooltip) {
  1551. this._addClass(tooltip, 'top');
  1552. tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px';
  1553. }).bind(this));
  1554. }
  1555. }
  1556. };
  1557. /*********************************
  1558. Attach to global namespace
  1559. *********************************/
  1560. if ($) {
  1561. (function () {
  1562. var autoRegisterNamespace = undefined;
  1563. if (!$.fn.slider) {
  1564. $.bridget(NAMESPACE_MAIN, Slider);
  1565. autoRegisterNamespace = NAMESPACE_MAIN;
  1566. } else {
  1567. if (windowIsDefined) {
  1568. window.console.warn("bootstrap-slider.js - WARNING: $.fn.slider namespace is already bound. Use the $.fn.bootstrapSlider namespace instead.");
  1569. }
  1570. autoRegisterNamespace = NAMESPACE_ALTERNATE;
  1571. }
  1572. $.bridget(NAMESPACE_ALTERNATE, Slider);
  1573. // Auto-Register data-provide="slider" Elements
  1574. $(function () {
  1575. $("input[data-provide=slider]")[autoRegisterNamespace]();
  1576. });
  1577. })();
  1578. }
  1579. })($);
  1580. return Slider;
  1581. });