Skip to content
Snippets Groups Projects
bootstrap-slider.js 64.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • Laura Cappelli's avatar
    Laura Cappelli committed
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    /*! =======================================================
                          VERSION  9.8.0              
    ========================================================= */
    "use strict";
    
    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; };
    
    /*! =========================================================
     * bootstrap-slider.js
     *
     * Maintainers:
     *		Kyle Kemp
     *			- Twitter: @seiyria
     *			- Github:  seiyria
     *		Rohit Kalkur
     *			- Twitter: @Rovolutionary
     *			- Github:  rovolution
     *
     * =========================================================
     *
     * bootstrap-slider is released under the MIT License
     * Copyright (c) 2017 Kyle Kemp, Rohit Kalkur, and contributors
     *
     * Permission is hereby granted, free of charge, to any person
     * obtaining a copy of this software and associated documentation
     * files (the "Software"), to deal in the Software without
     * restriction, including without limitation the rights to use,
     * copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the
     * Software is furnished to do so, subject to the following
     * conditions:
     *
     * The above copyright notice and this permission notice shall be
     * included in all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
     * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     * OTHER DEALINGS IN THE SOFTWARE.
     *
     * ========================================================= */
    
    /**
     * Bridget makes jQuery widgets
     * v1.0.1
     * MIT license
     */
    var windowIsDefined = (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object";
    
    (function (factory) {
    	if (typeof define === "function" && define.amd) {
    		define(["jquery"], factory);
    	} else if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === "object" && module.exports) {
    		var jQuery;
    		try {
    			jQuery = require("jquery");
    		} catch (err) {
    			jQuery = null;
    		}
    		module.exports = factory(jQuery);
    	} else if (window) {
    		window.Slider = factory(window.jQuery);
    	}
    })(function ($) {
    	// Constants
    	var NAMESPACE_MAIN = 'slider';
    	var NAMESPACE_ALTERNATE = 'bootstrapSlider';
    
    	// Polyfill console methods
    	if (windowIsDefined && !window.console) {
    		window.console = {};
    	}
    	if (windowIsDefined && !window.console.log) {
    		window.console.log = function () {};
    	}
    	if (windowIsDefined && !window.console.warn) {
    		window.console.warn = function () {};
    	}
    
    	// Reference to Slider constructor
    	var Slider;
    
    	(function ($) {
    
    		'use strict';
    
    		// -------------------------- utils -------------------------- //
    
    		var slice = Array.prototype.slice;
    
    		function noop() {}
    
    		// -------------------------- definition -------------------------- //
    
    		function defineBridget($) {
    
    			// bail if no jQuery
    			if (!$) {
    				return;
    			}
    
    			// -------------------------- addOptionMethod -------------------------- //
    
    			/**
        * adds option method -> $().plugin('option', {...})
        * @param {Function} PluginClass - constructor class
        */
    			function addOptionMethod(PluginClass) {
    				// don't overwrite original option method
    				if (PluginClass.prototype.option) {
    					return;
    				}
    
    				// option setter
    				PluginClass.prototype.option = function (opts) {
    					// bail out if not an object
    					if (!$.isPlainObject(opts)) {
    						return;
    					}
    					this.options = $.extend(true, this.options, opts);
    				};
    			}
    
    			// -------------------------- plugin bridge -------------------------- //
    
    			// helper function for logging errors
    			// $.error breaks jQuery chaining
    			var logError = typeof console === 'undefined' ? noop : function (message) {
    				console.error(message);
    			};
    
    			/**
        * jQuery plugin bridge, access methods like $elem.plugin('method')
        * @param {String} namespace - plugin name
        * @param {Function} PluginClass - constructor class
        */
    			function bridge(namespace, PluginClass) {
    				// add to jQuery fn namespace
    				$.fn[namespace] = function (options) {
    					if (typeof options === 'string') {
    						// call plugin method when first argument is a string
    						// get arguments for method
    						var args = slice.call(arguments, 1);
    
    						for (var i = 0, len = this.length; i < len; i++) {
    							var elem = this[i];
    							var instance = $.data(elem, namespace);
    							if (!instance) {
    								logError("cannot call methods on " + namespace + " prior to initialization; " + "attempted to call '" + options + "'");
    								continue;
    							}
    							if (!$.isFunction(instance[options]) || options.charAt(0) === '_') {
    								logError("no such method '" + options + "' for " + namespace + " instance");
    								continue;
    							}
    
    							// trigger method with arguments
    							var returnValue = instance[options].apply(instance, args);
    
    							// break look and return first value if provided
    							if (returnValue !== undefined && returnValue !== instance) {
    								return returnValue;
    							}
    						}
    						// return this if no return value
    						return this;
    					} else {
    						var objects = this.map(function () {
    							var instance = $.data(this, namespace);
    							if (instance) {
    								// apply options & init
    								instance.option(options);
    								instance._init();
    							} else {
    								// initialize new instance
    								instance = new PluginClass(this, options);
    								$.data(this, namespace, instance);
    							}
    							return $(this);
    						});
    
    						if (!objects || objects.length > 1) {
    							return objects;
    						} else {
    							return objects[0];
    						}
    					}
    				};
    			}
    
    			// -------------------------- bridget -------------------------- //
    
    			/**
        * converts a Prototypical class into a proper jQuery plugin
        *   the class must have a ._init method
        * @param {String} namespace - plugin name, used in $().pluginName
        * @param {Function} PluginClass - constructor class
        */
    			$.bridget = function (namespace, PluginClass) {
    				addOptionMethod(PluginClass);
    				bridge(namespace, PluginClass);
    			};
    
    			return $.bridget;
    		}
    
    		// get jquery from browser global
    		defineBridget($);
    	})($);
    
    	/*************************************************
     			BOOTSTRAP-SLIDER SOURCE CODE
     	**************************************************/
    
    	(function ($) {
    
    		var ErrorMsgs = {
    			formatInvalidInputErrorMsg: function formatInvalidInputErrorMsg(input) {
    				return "Invalid input value '" + input + "' passed in";
    			},
    			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"
    		};
    
    		var SliderScale = {
    			linear: {
    				toValue: function toValue(percentage) {
    					var rawValue = percentage / 100 * (this.options.max - this.options.min);
    					var shouldAdjustWithBase = true;
    					if (this.options.ticks_positions.length > 0) {
    						var minv,
    						    maxv,
    						    minp,
    						    maxp = 0;
    						for (var i = 1; i < this.options.ticks_positions.length; i++) {
    							if (percentage <= this.options.ticks_positions[i]) {
    								minv = this.options.ticks[i - 1];
    								minp = this.options.ticks_positions[i - 1];
    								maxv = this.options.ticks[i];
    								maxp = this.options.ticks_positions[i];
    
    								break;
    							}
    						}
    						var partialPercentage = (percentage - minp) / (maxp - minp);
    						rawValue = minv + partialPercentage * (maxv - minv);
    						shouldAdjustWithBase = false;
    					}
    
    					var adjustment = shouldAdjustWithBase ? this.options.min : 0;
    					var value = adjustment + Math.round(rawValue / this.options.step) * this.options.step;
    					if (value < this.options.min) {
    						return this.options.min;
    					} else if (value > this.options.max) {
    						return this.options.max;
    					} else {
    						return value;
    					}
    				},
    				toPercentage: function toPercentage(value) {
    					if (this.options.max === this.options.min) {
    						return 0;
    					}
    
    					if (this.options.ticks_positions.length > 0) {
    						var minv,
    						    maxv,
    						    minp,
    						    maxp = 0;
    						for (var i = 0; i < this.options.ticks.length; i++) {
    							if (value <= this.options.ticks[i]) {
    								minv = i > 0 ? this.options.ticks[i - 1] : 0;
    								minp = i > 0 ? this.options.ticks_positions[i - 1] : 0;
    								maxv = this.options.ticks[i];
    								maxp = this.options.ticks_positions[i];
    
    								break;
    							}
    						}
    						if (i > 0) {
    							var partialPercentage = (value - minv) / (maxv - minv);
    							return minp + partialPercentage * (maxp - minp);
    						}
    					}
    
    					return 100 * (value - this.options.min) / (this.options.max - this.options.min);
    				}
    			},
    
    			logarithmic: {
    				/* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */
    				toValue: function toValue(percentage) {
    					var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
    					var max = Math.log(this.options.max);
    					var value = Math.exp(min + (max - min) * percentage / 100);
    					value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step;
    					/* Rounding to the nearest step could exceed the min or
          * max, so clip to those values. */
    					if (value < this.options.min) {
    						return this.options.min;
    					} else if (value > this.options.max) {
    						return this.options.max;
    					} else {
    						return value;
    					}
    				},
    				toPercentage: function toPercentage(value) {
    					if (this.options.max === this.options.min) {
    						return 0;
    					} else {
    						var max = Math.log(this.options.max);
    						var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
    						var v = value === 0 ? 0 : Math.log(value);
    						return 100 * (v - min) / (max - min);
    					}
    				}
    			}
    		};
    
    		/*************************************************
      						CONSTRUCTOR
      	**************************************************/
    		Slider = function Slider(element, options) {
    			createNewSlider.call(this, element, options);
    			return this;
    		};
    
    		function createNewSlider(element, options) {
    
    			/*
       	The internal state object is used to store data about the current 'state' of slider.
       	This includes values such as the `value`, `enabled`, etc...
       */
    			this._state = {
    				value: null,
    				enabled: null,
    				offset: null,
    				size: null,
    				percentage: null,
    				inDrag: false,
    				over: false
    			};
    
    			// The objects used to store the reference to the tick methods if ticks_tooltip is on
    			this.ticksCallbackMap = {};
    			this.handleCallbackMap = {};
    
    			if (typeof element === "string") {
    				this.element = document.querySelector(element);
    			} else if (element instanceof HTMLElement) {
    				this.element = element;
    			}
    
    			/*************************************************
       					Process Options
       	**************************************************/
    			options = options ? options : {};
    			var optionTypes = Object.keys(this.defaultOptions);
    
    			for (var i = 0; i < optionTypes.length; i++) {
    				var optName = optionTypes[i];
    
    				// First check if an option was passed in via the constructor
    				var val = options[optName];
    				// If no data attrib, then check data atrributes
    				val = typeof val !== 'undefined' ? val : getDataAttrib(this.element, optName);
    				// Finally, if nothing was specified, use the defaults
    				val = val !== null ? val : this.defaultOptions[optName];
    
    				// Set all options on the instance of the Slider
    				if (!this.options) {
    					this.options = {};
    				}
    				this.options[optName] = val;
    			}
    
    			// Check options.rtl
    			if (this.options.rtl === 'auto') {
    				this.options.rtl = window.getComputedStyle(this.element).direction === 'rtl';
    			}
    
    			/*
       	Validate `tooltip_position` against 'orientation`
       	- if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation`
       		-- default for "vertical" -> "right", "left" if rtl
       		-- default for "horizontal" -> "top"
       */
    			if (this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) {
    				if (this.options.rtl) {
    					this.options.tooltip_position = "left";
    				} else {
    					this.options.tooltip_position = "right";
    				}
    			} else if (this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) {
    
    				this.options.tooltip_position = "top";
    			}
    
    			function getDataAttrib(element, optName) {
    				var dataName = "data-slider-" + optName.replace(/_/g, '-');
    				var dataValString = element.getAttribute(dataName);
    
    				try {
    					return JSON.parse(dataValString);
    				} catch (err) {
    					return dataValString;
    				}
    			}
    
    			/*************************************************
       					Create Markup
       	**************************************************/
    
    			var origWidth = this.element.style.width;
    			var updateSlider = false;
    			var parent = this.element.parentNode;
    			var sliderTrackSelection;
    			var sliderTrackLow, sliderTrackHigh;
    			var sliderMinHandle;
    			var sliderMaxHandle;
    
    			if (this.sliderElem) {
    				updateSlider = true;
    			} else {
    				/* Create elements needed for slider */
    				this.sliderElem = document.createElement("div");
    				this.sliderElem.className = "slider";
    
    				/* Create slider track elements */
    				var sliderTrack = document.createElement("div");
    				sliderTrack.className = "slider-track";
    
    				sliderTrackLow = document.createElement("div");
    				sliderTrackLow.className = "slider-track-low";
    
    				sliderTrackSelection = document.createElement("div");
    				sliderTrackSelection.className = "slider-selection";
    
    				sliderTrackHigh = document.createElement("div");
    				sliderTrackHigh.className = "slider-track-high";
    
    				sliderMinHandle = document.createElement("div");
    				sliderMinHandle.className = "slider-handle min-slider-handle";
    				sliderMinHandle.setAttribute('role', 'slider');
    				sliderMinHandle.setAttribute('aria-valuemin', this.options.min);
    				sliderMinHandle.setAttribute('aria-valuemax', this.options.max);
    
    				sliderMaxHandle = document.createElement("div");
    				sliderMaxHandle.className = "slider-handle max-slider-handle";
    				sliderMaxHandle.setAttribute('role', 'slider');
    				sliderMaxHandle.setAttribute('aria-valuemin', this.options.min);
    				sliderMaxHandle.setAttribute('aria-valuemax', this.options.max);
    
    				sliderTrack.appendChild(sliderTrackLow);
    				sliderTrack.appendChild(sliderTrackSelection);
    				sliderTrack.appendChild(sliderTrackHigh);
    
    				/* Create highlight range elements */
    				this.rangeHighlightElements = [];
    				var rangeHighlightsOpts = this.options.rangeHighlights;
    				if (Array.isArray(rangeHighlightsOpts) && rangeHighlightsOpts.length > 0) {
    					for (var j = 0; j < rangeHighlightsOpts.length; j++) {
    						var rangeHighlightElement = document.createElement("div");
    						var customClassString = rangeHighlightsOpts[j].class || "";
    						rangeHighlightElement.className = "slider-rangeHighlight slider-selection " + customClassString;
    						this.rangeHighlightElements.push(rangeHighlightElement);
    						sliderTrack.appendChild(rangeHighlightElement);
    					}
    				}
    
    				/* Add aria-labelledby to handle's */
    				var isLabelledbyArray = Array.isArray(this.options.labelledby);
    				if (isLabelledbyArray && this.options.labelledby[0]) {
    					sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby[0]);
    				}
    				if (isLabelledbyArray && this.options.labelledby[1]) {
    					sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby[1]);
    				}
    				if (!isLabelledbyArray && this.options.labelledby) {
    					sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby);
    					sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby);
    				}
    
    				/* Create ticks */
    				this.ticks = [];
    				if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
    					this.ticksContainer = document.createElement('div');
    					this.ticksContainer.className = 'slider-tick-container';
    
    					for (i = 0; i < this.options.ticks.length; i++) {
    						var tick = document.createElement('div');
    						tick.className = 'slider-tick';
    						if (this.options.ticks_tooltip) {
    							var tickListenerReference = this._addTickListener();
    							var enterCallback = tickListenerReference.addMouseEnter(this, tick, i);
    							var leaveCallback = tickListenerReference.addMouseLeave(this, tick);
    
    							this.ticksCallbackMap[i] = {
    								mouseEnter: enterCallback,
    								mouseLeave: leaveCallback
    							};
    						}
    						this.ticks.push(tick);
    						this.ticksContainer.appendChild(tick);
    					}
    
    					sliderTrackSelection.className += " tick-slider-selection";
    				}
    
    				this.tickLabels = [];
    				if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
    					this.tickLabelContainer = document.createElement('div');
    					this.tickLabelContainer.className = 'slider-tick-label-container';
    
    					for (i = 0; i < this.options.ticks_labels.length; i++) {
    						var label = document.createElement('div');
    						var noTickPositionsSpecified = this.options.ticks_positions.length === 0;
    						var tickLabelsIndex = this.options.reversed && noTickPositionsSpecified ? this.options.ticks_labels.length - (i + 1) : i;
    						label.className = 'slider-tick-label';
    						label.innerHTML = this.options.ticks_labels[tickLabelsIndex];
    
    						this.tickLabels.push(label);
    						this.tickLabelContainer.appendChild(label);
    					}
    				}
    
    				var createAndAppendTooltipSubElements = function createAndAppendTooltipSubElements(tooltipElem) {
    					var arrow = document.createElement("div");
    					arrow.className = "tooltip-arrow";
    
    					var inner = document.createElement("div");
    					inner.className = "tooltip-inner";
    
    					tooltipElem.appendChild(arrow);
    					tooltipElem.appendChild(inner);
    				};
    
    				/* Create tooltip elements */
    				var sliderTooltip = document.createElement("div");
    				sliderTooltip.className = "tooltip tooltip-main";
    				sliderTooltip.setAttribute('role', 'presentation');
    				createAndAppendTooltipSubElements(sliderTooltip);
    
    				var sliderTooltipMin = document.createElement("div");
    				sliderTooltipMin.className = "tooltip tooltip-min";
    				sliderTooltipMin.setAttribute('role', 'presentation');
    				createAndAppendTooltipSubElements(sliderTooltipMin);
    
    				var sliderTooltipMax = document.createElement("div");
    				sliderTooltipMax.className = "tooltip tooltip-max";
    				sliderTooltipMax.setAttribute('role', 'presentation');
    				createAndAppendTooltipSubElements(sliderTooltipMax);
    
    				/* Append components to sliderElem */
    				this.sliderElem.appendChild(sliderTrack);
    				this.sliderElem.appendChild(sliderTooltip);
    				this.sliderElem.appendChild(sliderTooltipMin);
    				this.sliderElem.appendChild(sliderTooltipMax);
    
    				if (this.tickLabelContainer) {
    					this.sliderElem.appendChild(this.tickLabelContainer);
    				}
    				if (this.ticksContainer) {
    					this.sliderElem.appendChild(this.ticksContainer);
    				}
    
    				this.sliderElem.appendChild(sliderMinHandle);
    				this.sliderElem.appendChild(sliderMaxHandle);
    
    				/* Append slider element to parent container, right before the original <input> element */
    				parent.insertBefore(this.sliderElem, this.element);
    
    				/* Hide original <input> element */
    				this.element.style.display = "none";
    			}
    			/* If JQuery exists, cache JQ references */
    			if ($) {
    				this.$element = $(this.element);
    				this.$sliderElem = $(this.sliderElem);
    			}
    
    			/*************************************************
       						Setup
       	**************************************************/
    			this.eventToCallbackMap = {};
    			this.sliderElem.id = this.options.id;
    
    			this.touchCapable = 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch;
    
    			this.touchX = 0;
    			this.touchY = 0;
    
    			this.tooltip = this.sliderElem.querySelector('.tooltip-main');
    			this.tooltipInner = this.tooltip.querySelector('.tooltip-inner');
    
    			this.tooltip_min = this.sliderElem.querySelector('.tooltip-min');
    			this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner');
    
    			this.tooltip_max = this.sliderElem.querySelector('.tooltip-max');
    			this.tooltipInner_max = this.tooltip_max.querySelector('.tooltip-inner');
    
    			if (SliderScale[this.options.scale]) {
    				this.options.scale = SliderScale[this.options.scale];
    			}
    
    			if (updateSlider === true) {
    				// Reset classes
    				this._removeClass(this.sliderElem, 'slider-horizontal');
    				this._removeClass(this.sliderElem, 'slider-vertical');
    				this._removeClass(this.sliderElem, 'slider-rtl');
    				this._removeClass(this.tooltip, 'hide');
    				this._removeClass(this.tooltip_min, 'hide');
    				this._removeClass(this.tooltip_max, 'hide');
    
    				// Undo existing inline styles for track
    				["left", "right", "top", "width", "height"].forEach(function (prop) {
    					this._removeProperty(this.trackLow, prop);
    					this._removeProperty(this.trackSelection, prop);
    					this._removeProperty(this.trackHigh, prop);
    				}, this);
    
    				// Undo inline styles on handles
    				[this.handle1, this.handle2].forEach(function (handle) {
    					this._removeProperty(handle, 'left');
    					this._removeProperty(handle, 'right');
    					this._removeProperty(handle, 'top');
    				}, this);
    
    				// Undo inline styles and classes on tooltips
    				[this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function (tooltip) {
    					this._removeProperty(tooltip, 'left');
    					this._removeProperty(tooltip, 'right');
    					this._removeProperty(tooltip, 'top');
    					this._removeProperty(tooltip, 'margin-left');
    					this._removeProperty(tooltip, 'margin-right');
    					this._removeProperty(tooltip, 'margin-top');
    
    					this._removeClass(tooltip, 'right');
    					this._removeClass(tooltip, 'left');
    					this._removeClass(tooltip, 'top');
    				}, this);
    			}
    
    			if (this.options.orientation === 'vertical') {
    				this._addClass(this.sliderElem, 'slider-vertical');
    				this.stylePos = 'top';
    				this.mousePos = 'pageY';
    				this.sizePos = 'offsetHeight';
    			} else {
    				this._addClass(this.sliderElem, 'slider-horizontal');
    				this.sliderElem.style.width = origWidth;
    				this.options.orientation = 'horizontal';
    				if (this.options.rtl) {
    					this.stylePos = 'right';
    				} else {
    					this.stylePos = 'left';
    				}
    				this.mousePos = 'pageX';
    				this.sizePos = 'offsetWidth';
    			}
    			// specific rtl class
    			if (this.options.rtl) {
    				this._addClass(this.sliderElem, 'slider-rtl');
    			}
    			this._setTooltipPosition();
    			/* In case ticks are specified, overwrite the min and max bounds */
    			if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
    				this.options.max = Math.max.apply(Math, this.options.ticks);
    				this.options.min = Math.min.apply(Math, this.options.ticks);
    			}
    
    			if (Array.isArray(this.options.value)) {
    				this.options.range = true;
    				this._state.value = this.options.value;
    			} else if (this.options.range) {
    				// User wants a range, but value is not an array
    				this._state.value = [this.options.value, this.options.max];
    			} else {
    				this._state.value = this.options.value;
    			}
    
    			this.trackLow = sliderTrackLow || this.trackLow;
    			this.trackSelection = sliderTrackSelection || this.trackSelection;
    			this.trackHigh = sliderTrackHigh || this.trackHigh;
    
    			if (this.options.selection === 'none') {
    				this._addClass(this.trackLow, 'hide');
    				this._addClass(this.trackSelection, 'hide');
    				this._addClass(this.trackHigh, 'hide');
    			} else if (this.options.selection === 'after' || this.options.selection === 'before') {
    				this._removeClass(this.trackLow, 'hide');
    				this._removeClass(this.trackSelection, 'hide');
    				this._removeClass(this.trackHigh, 'hide');
    			}
    
    			this.handle1 = sliderMinHandle || this.handle1;
    			this.handle2 = sliderMaxHandle || this.handle2;
    
    			if (updateSlider === true) {
    				// Reset classes
    				this._removeClass(this.handle1, 'round triangle');
    				this._removeClass(this.handle2, 'round triangle hide');
    
    				for (i = 0; i < this.ticks.length; i++) {
    					this._removeClass(this.ticks[i], 'round triangle hide');
    				}
    			}
    
    			var availableHandleModifiers = ['round', 'triangle', 'custom'];
    			var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1;
    			if (isValidHandleType) {
    				this._addClass(this.handle1, this.options.handle);
    				this._addClass(this.handle2, this.options.handle);
    
    				for (i = 0; i < this.ticks.length; i++) {
    					this._addClass(this.ticks[i], this.options.handle);
    				}
    			}
    
    			this._state.offset = this._offset(this.sliderElem);
    			this._state.size = this.sliderElem[this.sizePos];
    			this.setValue(this._state.value);
    
    			/******************************************
       				Bind Event Listeners
       	******************************************/
    
    			// Bind keyboard handlers
    			this.handle1Keydown = this._keydown.bind(this, 0);
    			this.handle1.addEventListener("keydown", this.handle1Keydown, false);
    
    			this.handle2Keydown = this._keydown.bind(this, 1);
    			this.handle2.addEventListener("keydown", this.handle2Keydown, false);
    
    			this.mousedown = this._mousedown.bind(this);
    			this.touchstart = this._touchstart.bind(this);
    			this.touchmove = this._touchmove.bind(this);
    
    			if (this.touchCapable) {
    				// Test for passive event support
    				var supportsPassive = false;
    				try {
    					var opts = Object.defineProperty({}, 'passive', {
    						get: function get() {
    							supportsPassive = true;
    						}
    					});
    					window.addEventListener("test", null, opts);
    				} catch (e) {}
    				// Use our detect's results. passive applied if supported, capture will be false either way.
    				var eventOptions = supportsPassive ? { passive: true } : false;
    				// Bind touch handlers
    				this.sliderElem.addEventListener("touchstart", this.touchstart, eventOptions);
    				this.sliderElem.addEventListener("touchmove", this.touchmove, eventOptions);
    			}
    			this.sliderElem.addEventListener("mousedown", this.mousedown, false);
    
    			// Bind window handlers
    			this.resize = this._resize.bind(this);
    			window.addEventListener("resize", this.resize, false);
    
    			// Bind tooltip-related handlers
    			if (this.options.tooltip === 'hide') {
    				this._addClass(this.tooltip, 'hide');
    				this._addClass(this.tooltip_min, 'hide');
    				this._addClass(this.tooltip_max, 'hide');
    			} else if (this.options.tooltip === 'always') {
    				this._showTooltip();
    				this._alwaysShowTooltip = true;
    			} else {
    				this.showTooltip = this._showTooltip.bind(this);
    				this.hideTooltip = this._hideTooltip.bind(this);
    
    				if (this.options.ticks_tooltip) {
    					var callbackHandle = this._addTickListener();
    					//create handle1 listeners and store references in map
    					var mouseEnter = callbackHandle.addMouseEnter(this, this.handle1);
    					var mouseLeave = callbackHandle.addMouseLeave(this, this.handle1);
    					this.handleCallbackMap.handle1 = {
    						mouseEnter: mouseEnter,
    						mouseLeave: mouseLeave
    					};
    					//create handle2 listeners and store references in map
    					mouseEnter = callbackHandle.addMouseEnter(this, this.handle2);
    					mouseLeave = callbackHandle.addMouseLeave(this, this.handle2);
    					this.handleCallbackMap.handle2 = {
    						mouseEnter: mouseEnter,
    						mouseLeave: mouseLeave
    					};
    				} else {
    					this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
    					this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
    				}
    
    				this.handle1.addEventListener("focus", this.showTooltip, false);
    				this.handle1.addEventListener("blur", this.hideTooltip, false);
    
    				this.handle2.addEventListener("focus", this.showTooltip, false);
    				this.handle2.addEventListener("blur", this.hideTooltip, false);
    			}
    
    			if (this.options.enabled) {
    				this.enable();
    			} else {
    				this.disable();
    			}
    		}
    
    		/*************************************************
      				INSTANCE PROPERTIES/METHODS
      	- Any methods bound to the prototype are considered
      part of the plugin's `public` interface
      	**************************************************/
    		Slider.prototype = {
    			_init: function _init() {}, // NOTE: Must exist to support bridget
    
    			constructor: Slider,
    
    			defaultOptions: {
    				id: "",
    				min: 0,
    				max: 10,
    				step: 1,
    				precision: 0,
    				orientation: 'horizontal',
    				value: 5,
    				range: false,
    				selection: 'before',
    				tooltip: 'show',
    				tooltip_split: false,
    				handle: 'round',
    				reversed: false,
    				rtl: 'auto',
    				enabled: true,
    				formatter: function formatter(val) {
    					if (Array.isArray(val)) {
    						return val[0] + " : " + val[1];
    					} else {
    						return val;
    					}
    				},
    				natural_arrow_keys: false,
    				ticks: [],
    				ticks_positions: [],
    				ticks_labels: [],
    				ticks_snap_bounds: 0,
    				ticks_tooltip: false,
    				scale: 'linear',
    				focus: false,
    				tooltip_position: null,
    				labelledby: null,
    				rangeHighlights: []
    			},
    
    			getElement: function getElement() {
    				return this.sliderElem;
    			},
    
    			getValue: function getValue() {
    				if (this.options.range) {
    					return this._state.value;
    				} else {
    					return this._state.value[0];
    				}
    			},
    
    			setValue: function setValue(val, triggerSlideEvent, triggerChangeEvent) {
    				if (!val) {
    					val = 0;
    				}
    				var oldValue = this.getValue();
    				this._state.value = this._validateInputValue(val);
    				var applyPrecision = this._applyPrecision.bind(this);
    
    				if (this.options.range) {
    					this._state.value[0] = applyPrecision(this._state.value[0]);
    					this._state.value[1] = applyPrecision(this._state.value[1]);
    
    					this._state.value[0] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[0]));
    					this._state.value[1] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[1]));
    				} else {
    					this._state.value = applyPrecision(this._state.value);
    					this._state.value = [Math.max(this.options.min, Math.min(this.options.max, this._state.value))];
    					this._addClass(this.handle2, 'hide');
    					if (this.options.selection === 'after') {
    						this._state.value[1] = this.options.max;
    					} else {
    						this._state.value[1] = this.options.min;
    					}
    				}
    
    				if (this.options.max > this.options.min) {
    					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)];
    				} else {
    					this._state.percentage = [0, 0, 100];
    				}
    
    				this._layout();
    				var newValue = this.options.range ? this._state.value : this._state.value[0];
    
    				this._setDataVal(newValue);
    				if (triggerSlideEvent === true) {
    					this._trigger('slide', newValue);
    				}
    				if (oldValue !== newValue && triggerChangeEvent === true) {
    					this._trigger('change', {
    						oldValue: oldValue,
    						newValue: newValue
    					});
    				}
    
    				return this;
    			},
    
    			destroy: function destroy() {
    				// Remove event handlers on slider elements
    				this._removeSliderEventHandlers();
    
    				// Remove the slider from the DOM
    				this.sliderElem.parentNode.removeChild(this.sliderElem);
    				/* Show original <input> element */
    				this.element.style.display = "";
    
    				// Clear out custom event bindings
    				this._cleanUpEventCallbacksMap();
    
    				// Remove data values
    				this.element.removeAttribute("data");
    
    				// Remove JQuery handlers/data
    				if ($) {
    					this._unbindJQueryEventHandlers();
    					this.$element.removeData('slider');
    				}
    			},
    
    			disable: function disable() {
    				this._state.enabled = false;
    				this.handle1.removeAttribute("tabindex");
    				this.handle2.removeAttribute("tabindex");
    				this._addClass(this.sliderElem, 'slider-disabled');
    				this._trigger('slideDisabled');
    
    				return this;
    			},
    
    			enable: function enable() {
    				this._state.enabled = true;
    				this.handle1.setAttribute("tabindex", 0);
    				this.handle2.setAttribute("tabindex", 0);
    				this._removeClass(this.sliderElem, 'slider-disabled');
    				this._trigger('slideEnabled');
    
    				return this;
    			},
    
    			toggle: function toggle() {
    				if (this._state.enabled) {
    					this.disable();
    				} else {
    					this.enable();
    				}
    				return this;
    			},
    
    			isEnabled: function isEnabled() {
    				return this._state.enabled;
    			},
    
    			on: function on(evt, callback) {
    				this._bindNonQueryEventHandler(evt, callback);
    				return this;
    			},
    
    			off: function off(evt, callback) {
    				if ($) {
    					this.$element.off(evt, callback);
    					this.$sliderElem.off(evt, callback);
    				} else {
    					this._unbindNonQueryEventHandler(evt, callback);
    				}
    			},
    
    			getAttribute: function getAttribute(attribute) {
    				if (attribute) {
    					return this.options[attribute];
    				} else {
    					return this.options;
    				}
    			},
    
    			setAttribute: function setAttribute(attribute, value) {
    				this.options[attribute] = value;
    				return this;
    			},
    
    			refresh: function refresh() {