Dashboard sipadu mbip
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.

bootstrap-slider.js 64KB

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