bootstrap-slider-rails 1.9.0 → 9.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de07875d169d068b9ae5663bc3480b783a7b0f05
4
+ data.tar.gz: 8e9ccb27822b1d218354f59df3cdc1d039ba21fc
5
+ SHA512:
6
+ metadata.gz: 496116b305bc13d8488958a33da9fbcb8e5a20027aba690d471be8cd1d5333431ba48cdedf69150d029a2efff53d4512b7c47612b1e2e8a329ee717f5e806f44
7
+ data.tar.gz: 9f23e5316abb908da020d3d53d8425d65feba8c3cc1acb1b9a42ecf93066405840bc659471484fde4938160e2681d525998e28cbdd460fd41df37e425ac55b9c
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
@@ -0,0 +1,37 @@
1
+ # How to use it
2
+ # =============
3
+ #
4
+ # Visit http://blog.zedroot.org/using-docker-to-maintain-a-ruby-gem/
5
+
6
+ # ~~~~ Image base ~~~~
7
+ # Base image with the latest Ruby only
8
+ FROM ruby:2.3.0-slim
9
+ MAINTAINER Guillaume Hain zedtux@zedroot.org
10
+
11
+
12
+ # ~~~~ Set up the environment ~~~~
13
+ ENV DEBIAN_FRONTEND noninteractive
14
+
15
+ RUN mkdir -p /gem/
16
+ WORKDIR /gem/
17
+ ADD . /gem/
18
+
19
+ # ~~~~ OS Maintenance & Rails Preparation ~~~~
20
+ # Rubygems and Bundler
21
+ RUN apt-get update && \
22
+ apt-get install -y git build-essential && \
23
+ touch ~/.gemrc && \
24
+ echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \
25
+ gem install rubygems-update && \
26
+ update_rubygems && \
27
+ gem install bundler && \
28
+ bundle install && \
29
+ apt-get remove --purge -y build-essential && \
30
+ apt-get autoclean -y && \
31
+ apt-get clean
32
+
33
+ # Import the gem source code
34
+ VOLUME .:/gem/
35
+
36
+ ENTRYPOINT ["bundle", "exec"]
37
+ CMD ["rake", "-T"]
data/README.md CHANGED
@@ -34,6 +34,26 @@ Require the CSS files from your `application.scss` or wherever needed using:
34
34
  *= require bootstrap-slider
35
35
  ```
36
36
 
37
+ ## Gem release
38
+
39
+ In the case you'd like to create a new release when [seiyria](https://github.com/seiyria) release a new version of his bootstrap-slider library, you just need to run the following:
40
+
41
+ ```
42
+ $ ./make_new_release.sh
43
+ Ensuring Docker image zedtux/bootstrap-slider-rails exists ...
44
+ Updating library code to version 5.3.3 ...
45
+ Downlading Bootstrap-slider 5.3.3 ...
46
+ % Total % Received % Xferd Average Speed Time Time Time Current
47
+ Dload Upload Total Spent Left Speed
48
+ 100 51140 100 51140 0 0 124k 0 --:--:-- --:--:-- --:--:-- 124k
49
+ % Total % Received % Xferd Average Speed Time Time Time Current
50
+ Dload Upload Total Spent Left Speed
51
+ 100 8238 100 8238 0 0 28698 0 --:--:-- --:--:-- --:--:-- 28703
52
+ Done!
53
+ Committing new version ...
54
+ Releasing gem ...
55
+ ```
56
+
37
57
  ## Contributing
38
58
 
39
59
  1. Fork it
data/Rakefile CHANGED
@@ -1 +1,23 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'fileutils'
3
+
4
+ desc 'Update the Bootstrap-slider Javascript and CSS files'
5
+ task :update do
6
+ def download(version)
7
+ base_url = 'https://raw.githubusercontent.com/seiyria/bootstrap-slider'
8
+ puts "Downlading Bootstrap-slider #{version} ..."
9
+ js = system("curl -fo vendor/assets/javascripts/bootstrap-slider.js " \
10
+ "#{base_url}/v#{version}/dist/bootstrap-slider.js")
11
+ css = system("curl -fo vendor/assets/stylesheets/bootstrap-slider.css " \
12
+ "#{base_url}/v#{version}/dist/css/bootstrap-slider.css")
13
+
14
+ puts 'ERROR: Unable to fetch the Javascript file !' unless js
15
+ puts 'ERROR: Unable to fetch the CSS file !' unless css
16
+ exit 1 unless js || css
17
+ end
18
+
19
+ FileUtils.mkdir_p('vendor/assets/javascripts')
20
+ FileUtils.mkdir_p('vendor/assets/stylesheets')
21
+ download(BootstrapSlider::Rails::VERSION)
22
+ puts "\e[32mDone!\e[0m"
23
+ end
@@ -4,21 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'bootstrap-slider-rails/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "bootstrap-slider-rails"
7
+ spec.name = 'bootstrap-slider-rails'
8
8
  spec.version = BootstrapSlider::Rails::VERSION
9
- spec.authors = ["Pedr Browne"]
10
- spec.email = ["pedr.browne@gmail.com"]
11
- spec.description = %q{Make Bootstrap Slider available to Rails}
12
- spec.summary = %q{This Gem integrates Seiyara's fork of Bootstrap Slider with Rails, exposing its JavaScript and CSS assets via a Rails Engine.
13
- }
14
- spec.homepage = "http://github.com/stationkeeping/bootstrap-slider-rails"
15
- spec.license = "MIT"
9
+ spec.authors = ['Pedr Browne']
10
+ spec.email = ['pedr.browne@gmail.com']
11
+ spec.description = 'Make Bootstrap Slider available to Rails'
12
+ spec.summary = "This Gem integrates Seiyara's fork of Bootstrap " \
13
+ 'Slider with Rails, exposing its JavaScript and CSS ' \
14
+ 'assets via a Rails Engine.'
15
+ spec.homepage = 'https://github.com/YourCursus/bootstrap-slider-rails'
16
+ spec.license = 'MIT'
16
17
 
17
- spec.files = `git ls-files`.split($/)
18
+ spec.files = `git ls-files`.split($RS)
18
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_dependency "railties", ">= 3.2", "< 5.0"
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
22
+ spec.add_dependency 'railties', '>= 3.2', '< 6.0'
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
24
25
  end
@@ -1,4 +1,4 @@
1
- require "bootstrap-slider-rails/version"
1
+ require 'bootstrap-slider-rails/version'
2
2
 
3
3
  module BootstrapSlider
4
4
  module Rails
@@ -6,4 +6,4 @@ module BootstrapSlider
6
6
  # Make assets avaiable
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module BootstrapSlider
2
- module Rails
3
- VERSION = "1.9.0"
4
- end
2
+ module Rails
3
+ VERSION = '9.8.0'
4
+ end
5
5
  end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env bash
2
+
3
+ DOCKER_IMAGE_NAME="$USER/bootstrap-slider-rails"
4
+ LIBRARY_NEW_VERSION=`cat lib/**/*.rb | grep VERSION | awk '{ print $3 }' | tr -d "'"`
5
+
6
+ LIBRARY_UPDATED=`git status --porcelain | grep -v "lib/bootstrap-slider-rails/version.rb"`
7
+ if [[ -n "$LIBRARY_UPDATED" ]]; then
8
+ echo "Your repository is not clean !"
9
+ exit 1
10
+ fi
11
+
12
+ echo "Ensuring Docker image $DOCKER_IMAGE_NAME exists ..."
13
+ EXISTING_DOCKER_IMAGE=`docker images | grep "$DOCKER_IMAGE_NAME"`
14
+ if [[ -z "$EXISTING_DOCKER_IMAGE" ]]; then
15
+ echo "Building the Docker image ..."
16
+ docker build -t "$DOCKER_IMAGE_NAME" .
17
+ fi
18
+
19
+ echo "Updating library code to version $LIBRARY_NEW_VERSION ..."
20
+ docker run --rm -v `pwd`:/gem/ "$DOCKER_IMAGE_NAME" rake update
21
+
22
+ LIBRARY_UPDATED=`git status --porcelain | grep -v make_new_release.sh`
23
+ if [[ -z "$LIBRARY_UPDATED" ]]; then
24
+ echo "No update found, stopping release creation."
25
+ exit 1
26
+ elif [[ "$LIBRARY_UPDATED" == " M lib/bootstrap-slider-rails/version.rb" ]]; then
27
+ echo "None of the JS or CSS files have been updated."
28
+ exit 1
29
+ fi
30
+
31
+ echo "Committing new version ..."
32
+ git commit -am "Import version $LIBRARY_NEW_VERSION"
33
+
34
+ echo "Releasing gem ..."
35
+ docker run --rm -v ~/.gitconfig:/root/.gitconfig \
36
+ -v ~/.ssh/:/root/.ssh/ \
37
+ -v ~/.gem/:/root/.gem/ \
38
+ -v `pwd`:/gem/ "$DOCKER_IMAGE_NAME" rake release
@@ -1,538 +1,1902 @@
1
- /* =========================================================
2
- * bootstrap-slider.js v2.0.0
3
- * http://www.eyecon.ro/bootstrap-slider
1
+ /*! =======================================================
2
+ VERSION 9.8.0
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
+ *
4
19
  * =========================================================
5
- * Copyright 2012 Stefan Petre
6
20
  *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
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.
10
35
  *
11
- * http://www.apache.org/licenses/LICENSE-2.0
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.
12
44
  *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
45
  * ========================================================= */
19
-
20
- (function( $ ) {
21
-
22
- var ErrorMsgs = {
23
- formatInvalidInputErrorMsg : function(input) {
24
- return "Invalid input value '" + input + "' passed in";
25
- },
26
- 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"
27
- };
28
-
29
- var Slider = function(element, options) {
30
- var el = this.element = $(element).hide();
31
- var origWidth = el.outerWidth();
32
-
33
- var updateSlider = false;
34
- var parent = this.element.parent();
35
-
36
-
37
- if (parent.hasClass('slider') === true) {
38
- updateSlider = true;
39
- this.picker = parent;
40
- } else {
41
- this.picker = $('<div class="slider">'+
42
- '<div class="slider-track">'+
43
- '<div class="slider-selection"></div>'+
44
- '<div class="slider-handle"></div>'+
45
- '<div class="slider-handle"></div>'+
46
- '</div>'+
47
- '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'+
48
- '</div>')
49
- .insertBefore(this.element)
50
- .append(this.element);
51
- }
52
46
 
53
- this.id = this.element.data('slider-id')||options.id;
54
- if (this.id) {
55
- this.picker[0].id = this.id;
56
- }
47
+ /**
48
+ * Bridget makes jQuery widgets
49
+ * v1.0.1
50
+ * MIT license
51
+ */
52
+ var windowIsDefined = (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object";
57
53
 
58
- if (typeof Modernizr !== 'undefined' && Modernizr.touch) {
59
- this.touchCapable = true;
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;
60
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
+ }
61
83
 
62
- var tooltip = this.element.data('slider-tooltip')||options.tooltip;
84
+ // Reference to Slider constructor
85
+ var Slider;
63
86
 
64
- this.tooltip = this.picker.find('.tooltip');
65
- this.tooltipInner = this.tooltip.find('div.tooltip-inner');
87
+ (function ($) {
66
88
 
67
- this.orientation = this.element.data('slider-orientation')||options.orientation;
68
- switch(this.orientation) {
69
- case 'vertical':
70
- this.picker.addClass('slider-vertical');
71
- this.stylePos = 'top';
72
- this.mousePos = 'pageY';
73
- this.sizePos = 'offsetHeight';
74
- this.tooltip.addClass('right')[0].style.left = '100%';
75
- break;
76
- default:
77
- this.picker
78
- .addClass('slider-horizontal')
79
- .css('width', origWidth);
80
- this.orientation = 'horizontal';
81
- this.stylePos = 'left';
82
- this.mousePos = 'pageX';
83
- this.sizePos = 'offsetWidth';
84
- this.tooltip.addClass('top')[0].style.top = -this.tooltip.outerHeight() - 14 + 'px';
85
- break;
86
- }
89
+ 'use strict';
87
90
 
88
- ['min', 'max', 'step', 'value'].forEach(function(attr) {
89
- this[attr] = el.data('slider-' + attr) || options[attr] || el.prop(attr);
90
- }, this);
91
+ // -------------------------- utils -------------------------- //
91
92
 
92
- if (this.value instanceof Array) {
93
- this.range = true;
94
- }
93
+ var slice = Array.prototype.slice;
95
94
 
96
- this.selection = this.element.data('slider-selection')||options.selection;
97
- this.selectionEl = this.picker.find('.slider-selection');
98
- if (this.selection === 'none') {
99
- this.selectionEl.addClass('hide');
100
- }
95
+ function noop() {}
101
96
 
102
- this.selectionElStyle = this.selectionEl[0].style;
103
-
104
- this.handle1 = this.picker.find('.slider-handle:first');
105
- this.handle1Stype = this.handle1[0].style;
106
- this.handle2 = this.picker.find('.slider-handle:last');
107
- this.handle2Stype = this.handle2[0].style;
108
-
109
- var handle = this.element.data('slider-handle')||options.handle;
110
- switch(handle) {
111
- case 'round':
112
- this.handle1.addClass('round');
113
- this.handle2.addClass('round');
114
- break;
115
- case 'triangle':
116
- this.handle1.addClass('triangle');
117
- this.handle2.addClass('triangle');
118
- break;
119
- }
97
+ // -------------------------- definition -------------------------- //
120
98
 
121
- if (this.range) {
122
- this.value[0] = Math.max(this.min, Math.min(this.max, this.value[0]));
123
- this.value[1] = Math.max(this.min, Math.min(this.max, this.value[1]));
124
- } else {
125
- this.value = [ Math.max(this.min, Math.min(this.max, this.value))];
126
- this.handle2.addClass('hide');
127
- if (this.selection === 'after') {
128
- this.value[1] = this.max;
129
- } else {
130
- this.value[1] = this.min;
99
+ function defineBridget($) {
100
+
101
+ // bail if no jQuery
102
+ if (!$) {
103
+ return;
131
104
  }
132
- }
133
- this.diff = this.max - this.min;
134
- this.percentage = [
135
- (this.value[0]-this.min)*100/this.diff,
136
- (this.value[1]-this.min)*100/this.diff,
137
- this.step*100/this.diff
138
- ];
139
105
 
140
- this.offset = this.picker.offset();
141
- this.size = this.picker[0][this.sizePos];
106
+ // -------------------------- addOptionMethod -------------------------- //
142
107
 
143
- this.formater = options.formater;
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
+ }
144
117
 
145
- this.reversed = this.element.data('slider-reversed')||options.reversed;
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
+ }
146
127
 
147
- this.layout();
128
+ // -------------------------- plugin bridge -------------------------- //
148
129
 
149
- if (this.touchCapable) {
150
- // Touch: Bind touch events:
151
- this.picker.on({
152
- touchstart: $.proxy(this.mousedown, this)
153
- });
154
- } else {
155
- this.picker.on({
156
- mousedown: $.proxy(this.mousedown, this)
157
- });
158
- }
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
+ };
159
135
 
160
- if (tooltip === 'show') {
161
- this.picker.on({
162
- mouseenter: $.proxy(this.showTooltip, this),
163
- mouseleave: $.proxy(this.hideTooltip, this)
164
- });
165
- } else {
166
- this.tooltip.addClass('hide');
167
- }
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);
168
148
 
169
- if (updateSlider === true) {
170
- var old = this.getValue();
171
- var val = this.calculateValue();
172
- this.element
173
- .trigger({
174
- type: 'slide',
175
- value: val
176
- })
177
- .data('value', val)
178
- .prop('value', val);
179
-
180
- if (old !== val) {
181
- this.element
182
- .trigger({
183
- type: 'slideChange',
184
- new: val,
185
- old: old
186
- })
187
- .data('value', val)
188
- .prop('value', val);
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
+ };
189
193
  }
190
- }
191
194
 
192
- this.enabled = options.enabled &&
193
- (this.element.data('slider-enabled') === undefined || this.element.data('slider-enabled') === true);
194
- if(!this.enabled)
195
- {
196
- this.disable();
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;
197
209
  }
198
- };
199
-
200
- Slider.prototype = {
201
- constructor: Slider,
202
-
203
- over: false,
204
- inDrag: false,
205
-
206
- showTooltip: function(){
207
- this.tooltip.addClass('in');
208
- this.over = true;
209
- },
210
-
211
- hideTooltip: function(){
212
- if (this.inDrag === false) {
213
- this.tooltip.removeClass('in');
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
+ }
214
320
  }
215
- this.over = false;
216
- },
321
+ };
217
322
 
218
- layout: function(){
219
- var positionPercentages;
323
+ /*************************************************
324
+ CONSTRUCTOR
325
+ **************************************************/
326
+ Slider = function Slider(element, options) {
327
+ createNewSlider.call(this, element, options);
328
+ return this;
329
+ };
220
330
 
221
- if(this.reversed) {
222
- positionPercentages = [ 100 - this.percentage[0], this.percentage[1] ];
223
- } else {
224
- positionPercentages = [ this.percentage[0], this.percentage[1] ];
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;
225
355
  }
226
356
 
227
- this.handle1Stype[this.stylePos] = positionPercentages[0]+'%';
228
- this.handle2Stype[this.stylePos] = positionPercentages[1]+'%';
357
+ /*************************************************
358
+ Process Options
359
+ **************************************************/
360
+ options = options ? options : {};
361
+ var optionTypes = Object.keys(this.defaultOptions);
229
362
 
230
- if (this.orientation === 'vertical') {
231
- this.selectionElStyle.top = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
232
- this.selectionElStyle.height = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
233
- } else {
234
- this.selectionElStyle.left = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
235
- this.selectionElStyle.width = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
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;
236
378
  }
237
379
 
238
- if (this.range) {
239
- this.tooltipInner.text(
240
- this.formater(this.value[0]) + ' : ' + this.formater(this.value[1])
241
- );
242
- this.tooltip[0].style[this.stylePos] = this.size * (positionPercentages[0] + (positionPercentages[1] - positionPercentages[0])/2)/100 - (this.orientation === 'vertical' ? this.tooltip.outerHeight()/2 : this.tooltip.outerWidth()/2) +'px';
243
- } else {
244
- this.tooltipInner.text(
245
- this.formater(this.value[0])
246
- );
247
- this.tooltip[0].style[this.stylePos] = this.size * positionPercentages[0]/100 - (this.orientation === 'vertical' ? this.tooltip.outerHeight()/2 : this.tooltip.outerWidth()/2) +'px';
380
+ // Check options.rtl
381
+ if (this.options.rtl === 'auto') {
382
+ this.options.rtl = window.getComputedStyle(this.element).direction === 'rtl';
248
383
  }
249
- },
250
384
 
251
- mousedown: function(ev) {
252
- if(!this.isEnabled()) {
253
- return false;
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";
254
400
  }
255
- // Touch: Get the original event:
256
- if (this.touchCapable && ev.type === 'touchstart') {
257
- ev = ev.originalEvent;
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
+ }
258
411
  }
259
412
 
260
- this.offset = this.picker.offset();
261
- this.size = this.picker[0][this.sizePos];
413
+ /*************************************************
414
+ Create Markup
415
+ **************************************************/
262
416
 
263
- var percentage = this.getPercentage(ev);
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;
264
424
 
265
- if (this.range) {
266
- var diff1 = Math.abs(this.percentage[0] - percentage);
267
- var diff2 = Math.abs(this.percentage[1] - percentage);
268
- this.dragged = (diff1 < diff2) ? 0 : 1;
425
+ if (this.sliderElem) {
426
+ updateSlider = true;
269
427
  } else {
270
- this.dragged = 0;
271
- }
428
+ /* Create elements needed for slider */
429
+ this.sliderElem = document.createElement("div");
430
+ this.sliderElem.className = "slider";
272
431
 
273
- this.percentage[this.dragged] = this.reversed ? 100 - percentage : percentage;
274
- this.layout();
432
+ /* Create slider track elements */
433
+ var sliderTrack = document.createElement("div");
434
+ sliderTrack.className = "slider-track";
275
435
 
276
- if (this.touchCapable) {
277
- // Touch: Bind touch events:
278
- $(document).on({
279
- touchmove: $.proxy(this.mousemove, this),
280
- touchend: $.proxy(this.mouseup, this)
281
- });
282
- } else {
283
- $(document).on({
284
- mousemove: $.proxy(this.mousemove, this),
285
- mouseup: $.proxy(this.mouseup, this)
286
- });
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
+ var rangeHighlightsOpts = this.options.rangeHighlights;
464
+ if (Array.isArray(rangeHighlightsOpts) && rangeHighlightsOpts.length > 0) {
465
+ for (var j = 0; j < rangeHighlightsOpts.length; j++) {
466
+ var rangeHighlightElement = document.createElement("div");
467
+ var customClassString = rangeHighlightsOpts[j].class || "";
468
+ rangeHighlightElement.className = "slider-rangeHighlight slider-selection " + customClassString;
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);
287
583
  }
288
584
 
289
- this.inDrag = true;
290
- var val = this.calculateValue();
291
- this.setValue(val);
292
- this.element.trigger({
293
- type: 'slideStart',
294
- value: val
295
- }).trigger({
296
- type: 'slide',
297
- value: val
298
- });
299
- return false;
300
- },
585
+ /*************************************************
586
+ Setup
587
+ **************************************************/
588
+ this.eventToCallbackMap = {};
589
+ this.sliderElem.id = this.options.id;
301
590
 
302
- mousemove: function(ev) {
303
- if(!this.isEnabled()) {
304
- return false;
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];
305
607
  }
306
- // Touch: Get the original event:
307
- if (this.touchCapable && ev.type === 'touchmove') {
308
- ev = ev.originalEvent;
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);
309
645
  }
310
646
 
311
- var percentage = this.getPercentage(ev);
312
- if (this.range) {
313
- if (this.dragged === 0 && this.percentage[1] < percentage) {
314
- this.percentage[0] = this.percentage[1];
315
- this.dragged = 1;
316
- } else if (this.dragged === 1 && this.percentage[0] > percentage) {
317
- this.percentage[1] = this.percentage[0];
318
- this.dragged = 0;
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';
319
660
  }
661
+ this.mousePos = 'pageX';
662
+ this.sizePos = 'offsetWidth';
320
663
  }
321
- this.percentage[this.dragged] = this.reversed ? 100 - percentage : percentage;
322
- this.layout();
323
- var val = this.calculateValue();
324
- this.setValue(val);
325
- this.element
326
- .trigger({
327
- type: 'slide',
328
- value: val
329
- })
330
- .data('value', val)
331
- .prop('value', val);
332
- return false;
333
- },
334
-
335
- mouseup: function() {
336
- if(!this.isEnabled()) {
337
- return false;
664
+ // specific rtl class
665
+ if (this.options.rtl) {
666
+ this._addClass(this.sliderElem, 'slider-rtl');
338
667
  }
339
- if (this.touchCapable) {
340
- // Touch: Bind touch events:
341
- $(document).off({
342
- touchmove: this.mousemove,
343
- touchend: this.mouseup
344
- });
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];
345
681
  } else {
346
- $(document).off({
347
- mousemove: this.mousemove,
348
- mouseup: this.mouseup
349
- });
682
+ this._state.value = this.options.value;
350
683
  }
351
684
 
352
- this.inDrag = false;
353
- if (this.over === false) {
354
- this.hideTooltip();
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');
355
697
  }
356
- var val = this.calculateValue();
357
- this.layout();
358
- this.element
359
- .trigger({
360
- type: 'slideStop',
361
- value: val
362
- })
363
- .data('value', val)
364
- .prop('value', val);
365
- return false;
366
- },
367
-
368
- calculateValue: function() {
369
- var val;
370
- if (this.range) {
371
- val = [
372
- (Math.max(this.min, this.min + Math.round((this.diff * this.percentage[0]/100)/this.step)*this.step)),
373
- (Math.min(this.max, this.min + Math.round((this.diff * this.percentage[1]/100)/this.step)*this.step))
374
- ];
375
- this.value = val;
376
- } else {
377
- val = (this.min + Math.round((this.diff * this.percentage[0]/100)/this.step)*this.step);
378
- if (val < this.min) {
379
- val = this.min;
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');
380
709
  }
381
- else if (val > this.max) {
382
- val = this.max;
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);
383
720
  }
384
- val = parseFloat(val);
385
- this.value = [val, this.value[1]];
386
721
  }
387
- return val;
388
- },
389
722
 
390
- getPercentage: function(ev) {
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
+
391
742
  if (this.touchCapable) {
392
- ev = ev.touches[0];
393
- }
394
- var percentage = (ev[this.mousePos] - this.offset[this.stylePos])*100/this.size;
395
- percentage = Math.round(percentage/this.percentage[2])*this.percentage[2];
396
- return Math.max(0, Math.min(100, percentage));
397
- },
398
-
399
- getValue: function() {
400
- if (this.range) {
401
- return this.value;
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);
402
758
  }
403
- return this.value[0];
404
- },
759
+ this.sliderElem.addEventListener("mousedown", this.mousedown, false);
405
760
 
406
- setValue: function(val) {
407
- this.value = this.validateInputValue(val);
761
+ // Bind window handlers
762
+ this.resize = this._resize.bind(this);
763
+ window.addEventListener("resize", this.resize, false);
408
764
 
409
- if (this.range) {
410
- this.value[0] = Math.max(this.min, Math.min(this.max, this.value[0]));
411
- this.value[1] = Math.max(this.min, Math.min(this.max, this.value[1]));
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;
412
773
  } else {
413
- this.value = [ Math.max(this.min, Math.min(this.max, this.value))];
414
- this.handle2.addClass('hide');
415
- if (this.selection === 'after') {
416
- this.value[1] = this.max;
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
+ };
417
793
  } else {
418
- this.value[1] = this.min;
794
+ this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
795
+ this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
419
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);
420
803
  }
421
- this.diff = this.max - this.min;
422
- this.percentage = [
423
- (this.value[0]-this.min)*100/this.diff,
424
- (this.value[1]-this.min)*100/this.diff,
425
- this.step*100/this.diff
426
- ];
427
- this.layout();
428
- },
429
-
430
- validateInputValue : function(val) {
431
- if(typeof val === 'number') {
432
- return val;
433
- } else if(val instanceof Array) {
434
- val.forEach(function(input) { if (typeof input !== 'number') { throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(input) ); }});
435
- return val;
804
+
805
+ if (this.options.enabled) {
806
+ this.enable();
436
807
  } else {
437
- throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(val) );
438
- }
439
- },
440
-
441
- destroy: function(){
442
- this.element.show().insertBefore(this.picker);
443
- this.picker.remove();
444
- $(this.element).removeData('slider');
445
- $(this.element).off();
446
- },
447
-
448
- disable: function() {
449
- this.enabled = false;
450
- this.picker.addClass('slider-disabled');
451
- this.element.trigger('slideDisabled');
452
- },
453
-
454
- enable: function() {
455
- this.enabled = true;
456
- this.picker.removeClass('slider-disabled');
457
- this.element.trigger('slideEnabled');
458
- },
459
-
460
- toggle: function() {
461
- if(this.enabled) {
462
808
  this.disable();
463
- } else {
464
- this.enable();
465
809
  }
466
- },
467
-
468
- isEnabled: function() {
469
- return this.enabled;
470
- }
471
- };
472
-
473
- var publicMethods = {
474
- getValue : Slider.prototype.getValue,
475
- setValue : Slider.prototype.setValue,
476
- destroy : Slider.prototype.destroy,
477
- disable : Slider.prototype.disable,
478
- enable : Slider.prototype.enable,
479
- toggle : Slider.prototype.toggle,
480
- isEnabled: Slider.prototype.isEnabled
481
- };
482
-
483
- $.fn.slider = function (option) {
484
- if (typeof option === 'string') {
485
- var args = Array.prototype.slice.call(arguments, 1);
486
- return invokePublicMethod.call(this, option, args);
487
- } else {
488
- return createNewSliderInstance.call(this, option);
489
- }
490
- };
491
-
492
- function invokePublicMethod(methodName, args) {
493
- if(publicMethods[methodName]) {
494
- var sliderObject = retrieveSliderObjectFromElement(this);
495
- return publicMethods[methodName].apply(sliderObject, args);
496
- } else {
497
- throw new Error("method '" + methodName + "()' does not exist for slider.");
498
810
  }
499
- }
500
811
 
501
- function retrieveSliderObjectFromElement(element) {
502
- var sliderObject = $(element).data('slider');
503
- if(sliderObject && sliderObject instanceof Slider) {
504
- return sliderObject;
505
- } else {
506
- throw new Error(ErrorMsgs.callingContextNotSliderInstance);
507
- }
508
- }
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
509
819
 
510
- function createNewSliderInstance(opts) {
511
- var $this = $(this),
512
- data = $this.data('slider'),
513
- options = typeof opts === 'object' && opts;
514
- if (!data) {
515
- $this.data('slider', (data = new Slider(this, $.extend({}, $.fn.slider.defaults,options))));
516
- }
517
- return $this;
518
- }
820
+ constructor: Slider,
519
821
 
520
- $.fn.slider.defaults = {
521
- min: 0,
522
- max: 10,
523
- step: 1,
524
- orientation: 'horizontal',
525
- value: 5,
526
- selection: 'before',
527
- tooltip: 'show',
528
- handle: 'round',
529
- reversed : false,
530
- enabled: true,
531
- formater: function(value) {
532
- return value;
533
- }
534
- };
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
+ },
535
949
 
536
- $.fn.slider.Constructor = Slider;
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
+ var autoRegisterNamespace = void 0;
1882
+
1883
+ if (!$.fn.slider) {
1884
+ $.bridget(NAMESPACE_MAIN, Slider);
1885
+ autoRegisterNamespace = NAMESPACE_MAIN;
1886
+ } else {
1887
+ if (windowIsDefined) {
1888
+ window.console.warn("bootstrap-slider.js - WARNING: $.fn.slider namespace is already bound. Use the $.fn.bootstrapSlider namespace instead.");
1889
+ }
1890
+ autoRegisterNamespace = NAMESPACE_ALTERNATE;
1891
+ }
1892
+ $.bridget(NAMESPACE_ALTERNATE, Slider);
1893
+
1894
+ // Auto-Register data-provide="slider" Elements
1895
+ $(function () {
1896
+ $("input[data-provide=slider]")[autoRegisterNamespace]();
1897
+ });
1898
+ }
1899
+ })($);
537
1900
 
538
- })( window.jQuery );
1901
+ return Slider;
1902
+ });