Commit 7d5a6dae306442a3e9b495fcd03eb193054e63b4

Authored by Zambom
1 parent 7049a800

Adding range slider to goals form

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