bootstrap-slider-rails 1.9.0 → 4.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d98f6d9098949f6905bd100b53ecfee56601f18b
4
+ data.tar.gz: 7390bda2d0b068b8cbb5f01c37f6ecdcd08a6e30
5
+ SHA512:
6
+ metadata.gz: 7f158cdef06ad1faf262c14a3a1738d7c85878bc696dba44fd15874f18df9b2230952157f273f1f3fbc9770a73bcb0b31695bad03bd2fc88913a67b7abe09bde
7
+ data.tar.gz: 91475175a91e23ece5dc5a57c095e913fdc858eb3b0eb459b79e1a1f004791668c26a6a632444d127efb626c30d5f20a4c3d2c18ffdb8c0a94e12db4cb3e9c61
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
data/Dockerfile ADDED
@@ -0,0 +1,35 @@
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 litaio/ruby:2.2.2
9
+ MAINTAINER Guillaume Hain zedtux@zedroot.org
10
+
11
+
12
+ # ~~~~ Set up the environment ~~~~
13
+ ENV DEBIAN_FRONTEND noninteractive
14
+
15
+ # ~~~~ OS Maintenance ~~~~
16
+ RUN apt-get update && apt-get install -y git
17
+
18
+ # ~~~~ Rails Preparation ~~~~
19
+ # Rubygems and Bundler
20
+ RUN touch ~/.gemrc && \
21
+ echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \
22
+ gem install rubygems-update && \
23
+ update_rubygems && \
24
+ gem install bundler && \
25
+ mkdir -p /gem/
26
+
27
+ WORKDIR /gem/
28
+ ADD . /gem/
29
+ RUN bundle install
30
+
31
+ # Import the gem source code
32
+ VOLUME .:/gem/
33
+
34
+ ENTRYPOINT ["bundle", "exec"]
35
+ CMD ["rake", "-T"]
data/Rakefile CHANGED
@@ -1 +1,19 @@
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_slider do
6
+ def download_slider(version)
7
+ base_url = 'https://raw.githubusercontent.com/seiyria/bootstrap-slider'
8
+ puts "Downlading Bootstrap-slider #{version} ..."
9
+ `curl -o vendor/assets/javascripts/bootstrap-slider.js \
10
+ #{base_url}/v#{version}/js/bootstrap-slider.js`
11
+ `curl -o vendor/assets/stylesheets/bootstrap-slider.css \
12
+ #{base_url}/v#{version}/dist/css/bootstrap-slider.css`
13
+ end
14
+
15
+ FileUtils.mkdir_p('vendor/assets/javascripts')
16
+ FileUtils.mkdir_p('vendor/assets/stylesheets')
17
+ download_slider(BootstrapSlider::Rails::VERSION)
18
+ puts "\e[32mDone!\e[0m"
19
+ 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"]
9
+ spec.authors = ['Pedr Browne']
10
+ spec.email = ['pedr.browne@gmail.com']
11
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"
12
+ spec.summary = %q{This Gem integrates Seiyara's fork of Bootstrap Slider
13
+ with Rails, exposing its JavaScript and CSS assets via
14
+ a Rails Engine.}
15
+ spec.homepage = 'http://github.com/stationkeeping/bootstrap-slider-rails'
16
+ spec.license = 'MIT'
16
17
 
17
18
  spec.files = `git ls-files`.split($/)
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', '< 5.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 = '4.8.1'
4
+ end
5
5
  end
@@ -1,8 +1,15 @@
1
- /* =========================================================
2
- * bootstrap-slider.js v2.0.0
3
- * http://www.eyecon.ro/bootstrap-slider
1
+ /*! =========================================================
2
+ * bootstrap-slider.js
3
+ *
4
+ * Maintainers:
5
+ * Kyle Kemp
6
+ * - Twitter: @seiyria
7
+ * - Github: seiyria
8
+ * Rohit Kalkur
9
+ * - Twitter: @Rovolutionary
10
+ * - Github: rovolution
11
+ *
4
12
  * =========================================================
5
- * Copyright 2012 Stefan Petre
6
13
  *
7
14
  * Licensed under the Apache License, Version 2.0 (the "License");
8
15
  * you may not use this file except in compliance with the License.
@@ -16,523 +23,1441 @@
16
23
  * See the License for the specific language governing permissions and
17
24
  * limitations under the License.
18
25
  * ========================================================= */
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
26
 
53
- this.id = this.element.data('slider-id')||options.id;
54
- if (this.id) {
55
- this.picker[0].id = this.id;
56
- }
57
27
 
58
- if (typeof Modernizr !== 'undefined' && Modernizr.touch) {
59
- this.touchCapable = true;
28
+ /**
29
+ * Bridget makes jQuery widgets
30
+ * v1.0.1
31
+ * MIT license
32
+ */
33
+
34
+ (function(root, factory) {
35
+ if(typeof define === "function" && define.amd) {
36
+ define(["jquery"], factory);
37
+ }
38
+ else if(typeof module === "object" && module.exports) {
39
+ var jQuery;
40
+ try {
41
+ jQuery = require("jquery");
60
42
  }
43
+ catch (err) {
44
+ jQuery = null;
45
+ }
46
+ module.exports = factory(jQuery);
47
+ }
48
+ else {
49
+ root.Slider = factory(root.jQuery);
50
+ }
51
+ }(this, function($) {
52
+ // Reference to Slider constructor
53
+ var Slider;
61
54
 
62
- var tooltip = this.element.data('slider-tooltip')||options.tooltip;
63
55
 
64
- this.tooltip = this.picker.find('.tooltip');
65
- this.tooltipInner = this.tooltip.find('div.tooltip-inner');
56
+ (function( $ ) {
66
57
 
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
- }
58
+ 'use strict';
87
59
 
88
- ['min', 'max', 'step', 'value'].forEach(function(attr) {
89
- this[attr] = el.data('slider-' + attr) || options[attr] || el.prop(attr);
90
- }, this);
60
+ // -------------------------- utils -------------------------- //
91
61
 
92
- if (this.value instanceof Array) {
93
- this.range = true;
94
- }
62
+ var slice = Array.prototype.slice;
95
63
 
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
- }
64
+ function noop() {}
101
65
 
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
- }
66
+ // -------------------------- definition -------------------------- //
120
67
 
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;
68
+ function defineBridget( $ ) {
69
+
70
+ // bail if no jQuery
71
+ if ( !$ ) {
72
+ return;
131
73
  }
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
-
140
- this.offset = this.picker.offset();
141
- this.size = this.picker[0][this.sizePos];
142
-
143
- this.formater = options.formater;
144
-
145
- this.reversed = this.element.data('slider-reversed')||options.reversed;
146
-
147
- this.layout();
148
-
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
- }
159
74
 
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
- }
75
+ // -------------------------- addOptionMethod -------------------------- //
168
76
 
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);
77
+ /**
78
+ * adds option method -> $().plugin('option', {...})
79
+ * @param {Function} PluginClass - constructor class
80
+ */
81
+ function addOptionMethod( PluginClass ) {
82
+ // don't overwrite original option method
83
+ if ( PluginClass.prototype.option ) {
84
+ return;
85
+ }
86
+
87
+ // option setter
88
+ PluginClass.prototype.option = function( opts ) {
89
+ // bail out if not an object
90
+ if ( !$.isPlainObject( opts ) ){
91
+ return;
92
+ }
93
+ this.options = $.extend( true, this.options, opts );
94
+ };
189
95
  }
190
- }
191
96
 
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();
97
+
98
+ // -------------------------- plugin bridge -------------------------- //
99
+
100
+ // helper function for logging errors
101
+ // $.error breaks jQuery chaining
102
+ var logError = typeof console === 'undefined' ? noop :
103
+ function( message ) {
104
+ console.error( message );
105
+ };
106
+
107
+ /**
108
+ * jQuery plugin bridge, access methods like $elem.plugin('method')
109
+ * @param {String} namespace - plugin name
110
+ * @param {Function} PluginClass - constructor class
111
+ */
112
+ function bridge( namespace, PluginClass ) {
113
+ // add to jQuery fn namespace
114
+ $.fn[ namespace ] = function( options ) {
115
+ if ( typeof options === 'string' ) {
116
+ // call plugin method when first argument is a string
117
+ // get arguments for method
118
+ var args = slice.call( arguments, 1 );
119
+
120
+ for ( var i=0, len = this.length; i < len; i++ ) {
121
+ var elem = this[i];
122
+ var instance = $.data( elem, namespace );
123
+ if ( !instance ) {
124
+ logError( "cannot call methods on " + namespace + " prior to initialization; " +
125
+ "attempted to call '" + options + "'" );
126
+ continue;
127
+ }
128
+ if ( !$.isFunction( instance[options] ) || options.charAt(0) === '_' ) {
129
+ logError( "no such method '" + options + "' for " + namespace + " instance" );
130
+ continue;
131
+ }
132
+
133
+ // trigger method with arguments
134
+ var returnValue = instance[ options ].apply( instance, args);
135
+
136
+ // break look and return first value if provided
137
+ if ( returnValue !== undefined && returnValue !== instance) {
138
+ return returnValue;
139
+ }
140
+ }
141
+ // return this if no return value
142
+ return this;
143
+ } else {
144
+ var objects = this.map( function() {
145
+ var instance = $.data( this, namespace );
146
+ if ( instance ) {
147
+ // apply options & init
148
+ instance.option( options );
149
+ instance._init();
150
+ } else {
151
+ // initialize new instance
152
+ instance = new PluginClass( this, options );
153
+ $.data( this, namespace, instance );
154
+ }
155
+ return $(this);
156
+ });
157
+
158
+ if(!objects || objects.length > 1) {
159
+ return objects;
160
+ } else {
161
+ return objects[0];
162
+ }
163
+ }
164
+ };
165
+
166
+ }
167
+
168
+ // -------------------------- bridget -------------------------- //
169
+
170
+ /**
171
+ * converts a Prototypical class into a proper jQuery plugin
172
+ * the class must have a ._init method
173
+ * @param {String} namespace - plugin name, used in $().pluginName
174
+ * @param {Function} PluginClass - constructor class
175
+ */
176
+ $.bridget = function( namespace, PluginClass ) {
177
+ addOptionMethod( PluginClass );
178
+ bridge( namespace, PluginClass );
179
+ };
180
+
181
+ return $.bridget;
182
+
197
183
  }
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');
184
+
185
+ // get jquery from browser global
186
+ defineBridget( $ );
187
+
188
+ })( $ );
189
+
190
+
191
+ /*************************************************
192
+
193
+ BOOTSTRAP-SLIDER SOURCE CODE
194
+
195
+ **************************************************/
196
+
197
+ (function($) {
198
+
199
+ var ErrorMsgs = {
200
+ formatInvalidInputErrorMsg : function(input) {
201
+ return "Invalid input value '" + input + "' passed in";
202
+ },
203
+ 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"
204
+ };
205
+
206
+ var SliderScale = {
207
+ linear: {
208
+ toValue: function(percentage) {
209
+ var rawValue = percentage/100 * (this.options.max - this.options.min);
210
+ if (this.options.ticks_positions.length > 0) {
211
+ var minv, maxv, minp, maxp = 0;
212
+ for (var i = 0; i < this.options.ticks_positions.length; i++) {
213
+ if (percentage <= this.options.ticks_positions[i]) {
214
+ minv = (i > 0) ? this.options.ticks[i-1] : 0;
215
+ minp = (i > 0) ? this.options.ticks_positions[i-1] : 0;
216
+ maxv = this.options.ticks[i];
217
+ maxp = this.options.ticks_positions[i];
218
+
219
+ break;
220
+ }
221
+ }
222
+ if (i > 0) {
223
+ var partialPercentage = (percentage - minp) / (maxp - minp);
224
+ rawValue = minv + partialPercentage * (maxv - minv);
225
+ }
226
+ }
227
+
228
+ var value = this.options.min + Math.round(rawValue / this.options.step) * this.options.step;
229
+ if (value < this.options.min) {
230
+ return this.options.min;
231
+ } else if (value > this.options.max) {
232
+ return this.options.max;
233
+ } else {
234
+ return value;
235
+ }
236
+ },
237
+ toPercentage: function(value) {
238
+ if (this.options.max === this.options.min) {
239
+ return 0;
240
+ }
241
+
242
+ if (this.options.ticks_positions.length > 0) {
243
+ var minv, maxv, minp, maxp = 0;
244
+ for (var i = 0; i < this.options.ticks.length; i++) {
245
+ if (value <= this.options.ticks[i]) {
246
+ minv = (i > 0) ? this.options.ticks[i-1] : 0;
247
+ minp = (i > 0) ? this.options.ticks_positions[i-1] : 0;
248
+ maxv = this.options.ticks[i];
249
+ maxp = this.options.ticks_positions[i];
250
+
251
+ break;
252
+ }
253
+ }
254
+ if (i > 0) {
255
+ var partialPercentage = (value - minv) / (maxv - minv);
256
+ return minp + partialPercentage * (maxp - minp);
257
+ }
258
+ }
259
+
260
+ return 100 * (value - this.options.min) / (this.options.max - this.options.min);
261
+ }
262
+ },
263
+
264
+ logarithmic: {
265
+ /* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */
266
+ toValue: function(percentage) {
267
+ var min = (this.options.min === 0) ? 0 : Math.log(this.options.min);
268
+ var max = Math.log(this.options.max);
269
+ var value = Math.exp(min + (max - min) * percentage / 100);
270
+ value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step;
271
+ /* Rounding to the nearest step could exceed the min or
272
+ * max, so clip to those values. */
273
+ if (value < this.options.min) {
274
+ return this.options.min;
275
+ } else if (value > this.options.max) {
276
+ return this.options.max;
277
+ } else {
278
+ return value;
279
+ }
280
+ },
281
+ toPercentage: function(value) {
282
+ if (this.options.max === this.options.min) {
283
+ return 0;
284
+ } else {
285
+ var max = Math.log(this.options.max);
286
+ var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
287
+ var v = value === 0 ? 0 : Math.log(value);
288
+ return 100 * (v - min) / (max - min);
289
+ }
290
+ }
214
291
  }
215
- this.over = false;
216
- },
292
+ };
217
293
 
218
- layout: function(){
219
- var positionPercentages;
220
294
 
221
- if(this.reversed) {
222
- positionPercentages = [ 100 - this.percentage[0], this.percentage[1] ];
223
- } else {
224
- positionPercentages = [ this.percentage[0], this.percentage[1] ];
295
+ /*************************************************
296
+
297
+ CONSTRUCTOR
298
+
299
+ **************************************************/
300
+ Slider = function(element, options) {
301
+ createNewSlider.call(this, element, options);
302
+ return this;
303
+ };
304
+
305
+ function createNewSlider(element, options) {
306
+
307
+ if(typeof element === "string") {
308
+ this.element = document.querySelector(element);
309
+ } else if(element instanceof HTMLElement) {
310
+ this.element = element;
225
311
  }
226
312
 
227
- this.handle1Stype[this.stylePos] = positionPercentages[0]+'%';
228
- this.handle2Stype[this.stylePos] = positionPercentages[1]+'%';
313
+ /*************************************************
229
314
 
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]) +'%';
315
+ Process Options
316
+
317
+ **************************************************/
318
+ options = options ? options : {};
319
+ var optionTypes = Object.keys(this.defaultOptions);
320
+
321
+ for(var i = 0; i < optionTypes.length; i++) {
322
+ var optName = optionTypes[i];
323
+
324
+ // First check if an option was passed in via the constructor
325
+ var val = options[optName];
326
+ // If no data attrib, then check data atrributes
327
+ val = (typeof val !== 'undefined') ? val : getDataAttrib(this.element, optName);
328
+ // Finally, if nothing was specified, use the defaults
329
+ val = (val !== null) ? val : this.defaultOptions[optName];
330
+
331
+ // Set all options on the instance of the Slider
332
+ if(!this.options) {
333
+ this.options = {};
334
+ }
335
+ this.options[optName] = val;
236
336
  }
237
337
 
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';
338
+ function getDataAttrib(element, optName) {
339
+ var dataName = "data-slider-" + optName.replace(/_/g, '-');
340
+ var dataValString = element.getAttribute(dataName);
341
+
342
+ try {
343
+ return JSON.parse(dataValString);
344
+ }
345
+ catch(err) {
346
+ return dataValString;
347
+ }
248
348
  }
249
- },
250
349
 
251
- mousedown: function(ev) {
252
- if(!this.isEnabled()) {
253
- return false;
350
+ /*************************************************
351
+
352
+ Create Markup
353
+
354
+ **************************************************/
355
+
356
+ var origWidth = this.element.style.width;
357
+ var updateSlider = false;
358
+ var parent = this.element.parentNode;
359
+ var sliderTrackSelection;
360
+ var sliderTrackLow, sliderTrackHigh;
361
+ var sliderMinHandle;
362
+ var sliderMaxHandle;
363
+
364
+ if (this.sliderElem) {
365
+ updateSlider = true;
366
+ } else {
367
+ /* Create elements needed for slider */
368
+ this.sliderElem = document.createElement("div");
369
+ this.sliderElem.className = "slider";
370
+
371
+ /* Create slider track elements */
372
+ var sliderTrack = document.createElement("div");
373
+ sliderTrack.className = "slider-track";
374
+
375
+ sliderTrackLow = document.createElement("div");
376
+ sliderTrackLow.className = "slider-track-low";
377
+
378
+ sliderTrackSelection = document.createElement("div");
379
+ sliderTrackSelection.className = "slider-selection";
380
+
381
+ sliderTrackHigh = document.createElement("div");
382
+ sliderTrackHigh.className = "slider-track-high";
383
+
384
+ sliderMinHandle = document.createElement("div");
385
+ sliderMinHandle.className = "slider-handle min-slider-handle";
386
+
387
+ sliderMaxHandle = document.createElement("div");
388
+ sliderMaxHandle.className = "slider-handle max-slider-handle";
389
+
390
+ sliderTrack.appendChild(sliderTrackLow);
391
+ sliderTrack.appendChild(sliderTrackSelection);
392
+ sliderTrack.appendChild(sliderTrackHigh);
393
+
394
+ /* Create ticks */
395
+ this.ticks = [];
396
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
397
+ for (i = 0; i < this.options.ticks.length; i++) {
398
+ var tick = document.createElement('div');
399
+ tick.className = 'slider-tick';
400
+
401
+ this.ticks.push(tick);
402
+ sliderTrack.appendChild(tick);
403
+ }
404
+
405
+ sliderTrackSelection.className += " tick-slider-selection";
406
+ }
407
+
408
+ sliderTrack.appendChild(sliderMinHandle);
409
+ sliderTrack.appendChild(sliderMaxHandle);
410
+
411
+ this.tickLabels = [];
412
+ if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
413
+ this.tickLabelContainer = document.createElement('div');
414
+ this.tickLabelContainer.className = 'slider-tick-label-container';
415
+
416
+ for (i = 0; i < this.options.ticks_labels.length; i++) {
417
+ var label = document.createElement('div');
418
+ label.className = 'slider-tick-label';
419
+ label.innerHTML = this.options.ticks_labels[i];
420
+
421
+ this.tickLabels.push(label);
422
+ this.tickLabelContainer.appendChild(label);
423
+ }
424
+ }
425
+
426
+
427
+ var createAndAppendTooltipSubElements = function(tooltipElem) {
428
+ var arrow = document.createElement("div");
429
+ arrow.className = "tooltip-arrow";
430
+
431
+ var inner = document.createElement("div");
432
+ inner.className = "tooltip-inner";
433
+
434
+ tooltipElem.appendChild(arrow);
435
+ tooltipElem.appendChild(inner);
436
+
437
+ };
438
+
439
+ /* Create tooltip elements */
440
+ var sliderTooltip = document.createElement("div");
441
+ sliderTooltip.className = "tooltip tooltip-main";
442
+ createAndAppendTooltipSubElements(sliderTooltip);
443
+
444
+ var sliderTooltipMin = document.createElement("div");
445
+ sliderTooltipMin.className = "tooltip tooltip-min";
446
+ createAndAppendTooltipSubElements(sliderTooltipMin);
447
+
448
+ var sliderTooltipMax = document.createElement("div");
449
+ sliderTooltipMax.className = "tooltip tooltip-max";
450
+ createAndAppendTooltipSubElements(sliderTooltipMax);
451
+
452
+
453
+ /* Append components to sliderElem */
454
+ this.sliderElem.appendChild(sliderTrack);
455
+ this.sliderElem.appendChild(sliderTooltip);
456
+ this.sliderElem.appendChild(sliderTooltipMin);
457
+ this.sliderElem.appendChild(sliderTooltipMax);
458
+
459
+ if (this.tickLabelContainer) {
460
+ this.sliderElem.appendChild(this.tickLabelContainer);
461
+ }
462
+
463
+ /* Append slider element to parent container, right before the original <input> element */
464
+ parent.insertBefore(this.sliderElem, this.element);
465
+
466
+ /* Hide original <input> element */
467
+ this.element.style.display = "none";
254
468
  }
255
- // Touch: Get the original event:
256
- if (this.touchCapable && ev.type === 'touchstart') {
257
- ev = ev.originalEvent;
469
+ /* If JQuery exists, cache JQ references */
470
+ if($) {
471
+ this.$element = $(this.element);
472
+ this.$sliderElem = $(this.sliderElem);
258
473
  }
259
474
 
260
- this.offset = this.picker.offset();
261
- this.size = this.picker[0][this.sizePos];
475
+ /*************************************************
262
476
 
263
- var percentage = this.getPercentage(ev);
477
+ Setup
264
478
 
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;
269
- } else {
270
- this.dragged = 0;
479
+ **************************************************/
480
+ this.eventToCallbackMap = {};
481
+ this.sliderElem.id = this.options.id;
482
+
483
+ this.touchCapable = 'ontouchstart' in window || (window.DocumentTouch && document instanceof window.DocumentTouch);
484
+
485
+ this.tooltip = this.sliderElem.querySelector('.tooltip-main');
486
+ this.tooltipInner = this.tooltip.querySelector('.tooltip-inner');
487
+
488
+ this.tooltip_min = this.sliderElem.querySelector('.tooltip-min');
489
+ this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner');
490
+
491
+ this.tooltip_max = this.sliderElem.querySelector('.tooltip-max');
492
+ this.tooltipInner_max= this.tooltip_max.querySelector('.tooltip-inner');
493
+
494
+ if (SliderScale[this.options.scale]) {
495
+ this.options.scale = SliderScale[this.options.scale];
271
496
  }
272
497
 
273
- this.percentage[this.dragged] = this.reversed ? 100 - percentage : percentage;
274
- this.layout();
498
+ if (updateSlider === true) {
499
+ // Reset classes
500
+ this._removeClass(this.sliderElem, 'slider-horizontal');
501
+ this._removeClass(this.sliderElem, 'slider-vertical');
502
+ this._removeClass(this.tooltip, 'hide');
503
+ this._removeClass(this.tooltip_min, 'hide');
504
+ this._removeClass(this.tooltip_max, 'hide');
275
505
 
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
- });
506
+ // Undo existing inline styles for track
507
+ ["left", "top", "width", "height"].forEach(function(prop) {
508
+ this._removeProperty(this.trackLow, prop);
509
+ this._removeProperty(this.trackSelection, prop);
510
+ this._removeProperty(this.trackHigh, prop);
511
+ }, this);
512
+
513
+ // Undo inline styles on handles
514
+ [this.handle1, this.handle2].forEach(function(handle) {
515
+ this._removeProperty(handle, 'left');
516
+ this._removeProperty(handle, 'top');
517
+ }, this);
518
+
519
+ // Undo inline styles and classes on tooltips
520
+ [this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function(tooltip) {
521
+ this._removeProperty(tooltip, 'left');
522
+ this._removeProperty(tooltip, 'top');
523
+ this._removeProperty(tooltip, 'margin-left');
524
+ this._removeProperty(tooltip, 'margin-top');
525
+
526
+ this._removeClass(tooltip, 'right');
527
+ this._removeClass(tooltip, 'top');
528
+ }, this);
529
+ }
530
+
531
+ if(this.options.orientation === 'vertical') {
532
+ this._addClass(this.sliderElem,'slider-vertical');
533
+
534
+ this.stylePos = 'top';
535
+ this.mousePos = 'pageY';
536
+ this.sizePos = 'offsetHeight';
537
+
538
+ this._addClass(this.tooltip, 'right');
539
+ this.tooltip.style.left = '100%';
540
+
541
+ this._addClass(this.tooltip_min, 'right');
542
+ this.tooltip_min.style.left = '100%';
543
+
544
+ this._addClass(this.tooltip_max, 'right');
545
+ this.tooltip_max.style.left = '100%';
282
546
  } else {
283
- $(document).on({
284
- mousemove: $.proxy(this.mousemove, this),
285
- mouseup: $.proxy(this.mouseup, this)
286
- });
547
+ this._addClass(this.sliderElem, 'slider-horizontal');
548
+ this.sliderElem.style.width = origWidth;
549
+
550
+ this.options.orientation = 'horizontal';
551
+ this.stylePos = 'left';
552
+ this.mousePos = 'pageX';
553
+ this.sizePos = 'offsetWidth';
554
+
555
+ this._addClass(this.tooltip, 'top');
556
+ this.tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px';
557
+
558
+ this._addClass(this.tooltip_min, 'top');
559
+ this.tooltip_min.style.top = -this.tooltip_min.outerHeight - 14 + 'px';
560
+
561
+ this._addClass(this.tooltip_max, 'top');
562
+ this.tooltip_max.style.top = -this.tooltip_max.outerHeight - 14 + 'px';
287
563
  }
288
564
 
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
- },
565
+ /* In case ticks are specified, overwrite the min and max bounds */
566
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
567
+ this.options.max = Math.max.apply(Math, this.options.ticks);
568
+ this.options.min = Math.min.apply(Math, this.options.ticks);
569
+ }
301
570
 
302
- mousemove: function(ev) {
303
- if(!this.isEnabled()) {
304
- return false;
571
+ if (Array.isArray(this.options.value)) {
572
+ this.options.range = true;
573
+ } else if (this.options.range) {
574
+ // User wants a range, but value is not an array
575
+ this.options.value = [this.options.value, this.options.max];
305
576
  }
306
- // Touch: Get the original event:
307
- if (this.touchCapable && ev.type === 'touchmove') {
308
- ev = ev.originalEvent;
577
+
578
+ this.trackLow = sliderTrackLow || this.trackLow;
579
+ this.trackSelection = sliderTrackSelection || this.trackSelection;
580
+ this.trackHigh = sliderTrackHigh || this.trackHigh;
581
+
582
+ if (this.options.selection === 'none') {
583
+ this._addClass(this.trackLow, 'hide');
584
+ this._addClass(this.trackSelection, 'hide');
585
+ this._addClass(this.trackHigh, 'hide');
309
586
  }
310
587
 
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;
588
+ this.handle1 = sliderMinHandle || this.handle1;
589
+ this.handle2 = sliderMaxHandle || this.handle2;
590
+
591
+ if (updateSlider === true) {
592
+ // Reset classes
593
+ this._removeClass(this.handle1, 'round triangle');
594
+ this._removeClass(this.handle2, 'round triangle hide');
595
+
596
+ for (i = 0; i < this.ticks.length; i++) {
597
+ this._removeClass(this.ticks[i], 'round triangle hide');
319
598
  }
320
599
  }
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;
600
+
601
+ var availableHandleModifiers = ['round', 'triangle', 'custom'];
602
+ var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1;
603
+ if (isValidHandleType) {
604
+ this._addClass(this.handle1, this.options.handle);
605
+ this._addClass(this.handle2, this.options.handle);
606
+
607
+ for (i = 0; i < this.ticks.length; i++) {
608
+ this._addClass(this.ticks[i], this.options.handle);
609
+ }
338
610
  }
611
+
612
+ this.offset = this._offset(this.sliderElem);
613
+ this.size = this.sliderElem[this.sizePos];
614
+ this.setValue(this.options.value);
615
+
616
+ /******************************************
617
+
618
+ Bind Event Listeners
619
+
620
+ ******************************************/
621
+
622
+ // Bind keyboard handlers
623
+ this.handle1Keydown = this._keydown.bind(this, 0);
624
+ this.handle1.addEventListener("keydown", this.handle1Keydown, false);
625
+
626
+ this.handle2Keydown = this._keydown.bind(this, 1);
627
+ this.handle2.addEventListener("keydown", this.handle2Keydown, false);
628
+
629
+ this.mousedown = this._mousedown.bind(this);
339
630
  if (this.touchCapable) {
340
- // Touch: Bind touch events:
341
- $(document).off({
342
- touchmove: this.mousemove,
343
- touchend: this.mouseup
344
- });
345
- } else {
346
- $(document).off({
347
- mousemove: this.mousemove,
348
- mouseup: this.mouseup
349
- });
631
+ // Bind touch handlers
632
+ this.sliderElem.addEventListener("touchstart", this.mousedown, false);
350
633
  }
634
+ this.sliderElem.addEventListener("mousedown", this.mousedown, false);
635
+
636
+
637
+ // Bind tooltip-related handlers
638
+ if(this.options.tooltip === 'hide') {
639
+ this._addClass(this.tooltip, 'hide');
640
+ this._addClass(this.tooltip_min, 'hide');
641
+ this._addClass(this.tooltip_max, 'hide');
642
+ } else if(this.options.tooltip === 'always') {
643
+ this._showTooltip();
644
+ this._alwaysShowTooltip = true;
645
+ } else {
646
+ this.showTooltip = this._showTooltip.bind(this);
647
+ this.hideTooltip = this._hideTooltip.bind(this);
648
+
649
+ this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
650
+ this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
351
651
 
352
- this.inDrag = false;
353
- if (this.over === false) {
354
- this.hideTooltip();
652
+ this.handle1.addEventListener("focus", this.showTooltip, false);
653
+ this.handle1.addEventListener("blur", this.hideTooltip, false);
654
+
655
+ this.handle2.addEventListener("focus", this.showTooltip, false);
656
+ this.handle2.addEventListener("blur", this.hideTooltip, false);
355
657
  }
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;
658
+
659
+ if(this.options.enabled) {
660
+ this.enable();
376
661
  } 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;
662
+ this.disable();
663
+ }
664
+ }
665
+
666
+
667
+
668
+ /*************************************************
669
+
670
+ INSTANCE PROPERTIES/METHODS
671
+
672
+ - Any methods bound to the prototype are considered
673
+ part of the plugin's `public` interface
674
+
675
+ **************************************************/
676
+ Slider.prototype = {
677
+ _init: function() {}, // NOTE: Must exist to support bridget
678
+
679
+ constructor: Slider,
680
+
681
+ defaultOptions: {
682
+ id: "",
683
+ min: 0,
684
+ max: 10,
685
+ step: 1,
686
+ precision: 0,
687
+ orientation: 'horizontal',
688
+ value: 5,
689
+ range: false,
690
+ selection: 'before',
691
+ tooltip: 'show',
692
+ tooltip_split: false,
693
+ handle: 'round',
694
+ reversed: false,
695
+ enabled: true,
696
+ formatter: function(val) {
697
+ if (Array.isArray(val)) {
698
+ return val[0] + " : " + val[1];
699
+ } else {
700
+ return val;
701
+ }
702
+ },
703
+ natural_arrow_keys: false,
704
+ ticks: [],
705
+ ticks_positions: [],
706
+ ticks_labels: [],
707
+ ticks_snap_bounds: 0,
708
+ scale: 'linear',
709
+ focus: false
710
+ },
711
+
712
+ over: false,
713
+
714
+ inDrag: false,
715
+
716
+ getValue: function() {
717
+ if (this.options.range) {
718
+ return this.options.value;
380
719
  }
381
- else if (val > this.max) {
382
- val = this.max;
720
+ return this.options.value[0];
721
+ },
722
+
723
+ setValue: function(val, triggerSlideEvent, triggerChangeEvent) {
724
+ if (!val) {
725
+ val = 0;
383
726
  }
384
- val = parseFloat(val);
385
- this.value = [val, this.value[1]];
386
- }
387
- return val;
388
- },
727
+ var oldValue = this.getValue();
728
+ this.options.value = this._validateInputValue(val);
729
+ var applyPrecision = this._applyPrecision.bind(this);
389
730
 
390
- getPercentage: function(ev) {
391
- 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;
402
- }
403
- return this.value[0];
404
- },
731
+ if (this.options.range) {
732
+ this.options.value[0] = applyPrecision(this.options.value[0]);
733
+ this.options.value[1] = applyPrecision(this.options.value[1]);
405
734
 
406
- setValue: function(val) {
407
- this.value = this.validateInputValue(val);
735
+ this.options.value[0] = Math.max(this.options.min, Math.min(this.options.max, this.options.value[0]));
736
+ this.options.value[1] = Math.max(this.options.min, Math.min(this.options.max, this.options.value[1]));
737
+ } else {
738
+ this.options.value = applyPrecision(this.options.value);
739
+ this.options.value = [ Math.max(this.options.min, Math.min(this.options.max, this.options.value))];
740
+ this._addClass(this.handle2, 'hide');
741
+ if (this.options.selection === 'after') {
742
+ this.options.value[1] = this.options.max;
743
+ } else {
744
+ this.options.value[1] = this.options.min;
745
+ }
746
+ }
408
747
 
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]));
412
- } 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;
748
+ if (this.options.max > this.options.min) {
749
+ this.percentage = [
750
+ this._toPercentage(this.options.value[0]),
751
+ this._toPercentage(this.options.value[1]),
752
+ this.options.step * 100 / (this.options.max - this.options.min)
753
+ ];
417
754
  } else {
418
- this.value[1] = this.min;
755
+ this.percentage = [0, 0, 100];
419
756
  }
420
- }
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) ); }});
757
+
758
+ this._layout();
759
+ var newValue = this.options.range ? this.options.value : this.options.value[0];
760
+
761
+ if(triggerSlideEvent === true) {
762
+ this._trigger('slide', newValue);
763
+ }
764
+ if( (oldValue !== newValue) && (triggerChangeEvent === true) ) {
765
+ this._trigger('change', {
766
+ oldValue: oldValue,
767
+ newValue: newValue
768
+ });
769
+ }
770
+ this._setDataVal(newValue);
771
+
772
+ return this;
773
+ },
774
+
775
+ destroy: function(){
776
+ // Remove event handlers on slider elements
777
+ this._removeSliderEventHandlers();
778
+
779
+ // Remove the slider from the DOM
780
+ this.sliderElem.parentNode.removeChild(this.sliderElem);
781
+ /* Show original <input> element */
782
+ this.element.style.display = "";
783
+
784
+ // Clear out custom event bindings
785
+ this._cleanUpEventCallbacksMap();
786
+
787
+ // Remove data values
788
+ this.element.removeAttribute("data");
789
+
790
+ // Remove JQuery handlers/data
791
+ if($) {
792
+ this._unbindJQueryEventHandlers();
793
+ this.$element.removeData('slider');
794
+ }
795
+ },
796
+
797
+ disable: function() {
798
+ this.options.enabled = false;
799
+ this.handle1.removeAttribute("tabindex");
800
+ this.handle2.removeAttribute("tabindex");
801
+ this._addClass(this.sliderElem, 'slider-disabled');
802
+ this._trigger('slideDisabled');
803
+
804
+ return this;
805
+ },
806
+
807
+ enable: function() {
808
+ this.options.enabled = true;
809
+ this.handle1.setAttribute("tabindex", 0);
810
+ this.handle2.setAttribute("tabindex", 0);
811
+ this._removeClass(this.sliderElem, 'slider-disabled');
812
+ this._trigger('slideEnabled');
813
+
814
+ return this;
815
+ },
816
+
817
+ toggle: function() {
818
+ if(this.options.enabled) {
819
+ this.disable();
820
+ } else {
821
+ this.enable();
822
+ }
823
+ return this;
824
+ },
825
+
826
+ isEnabled: function() {
827
+ return this.options.enabled;
828
+ },
829
+
830
+ on: function(evt, callback) {
831
+ this._bindNonQueryEventHandler(evt, callback);
832
+ return this;
833
+ },
834
+
835
+ getAttribute: function(attribute) {
836
+ if(attribute) {
837
+ return this.options[attribute];
838
+ } else {
839
+ return this.options;
840
+ }
841
+ },
842
+
843
+ setAttribute: function(attribute, value) {
844
+ this.options[attribute] = value;
845
+ return this;
846
+ },
847
+
848
+ refresh: function() {
849
+ this._removeSliderEventHandlers();
850
+ createNewSlider.call(this, this.element, this.options);
851
+ if($) {
852
+ // Bind new instance of slider to the element
853
+ $.data(this.element, 'slider', this);
854
+ }
855
+ return this;
856
+ },
857
+
858
+ relayout: function() {
859
+ this._layout();
860
+ return this;
861
+ },
862
+
863
+ /******************************+
864
+
865
+ HELPERS
866
+
867
+ - Any method that is not part of the public interface.
868
+ - Place it underneath this comment block and write its signature like so:
869
+
870
+ _fnName : function() {...}
871
+
872
+ ********************************/
873
+ _removeSliderEventHandlers: function() {
874
+ // Remove event listeners from handle1
875
+ this.handle1.removeEventListener("keydown", this.handle1Keydown, false);
876
+ this.handle1.removeEventListener("focus", this.showTooltip, false);
877
+ this.handle1.removeEventListener("blur", this.hideTooltip, false);
878
+
879
+ // Remove event listeners from handle2
880
+ this.handle2.removeEventListener("keydown", this.handle2Keydown, false);
881
+ this.handle2.removeEventListener("focus", this.handle2Keydown, false);
882
+ this.handle2.removeEventListener("blur", this.handle2Keydown, false);
883
+
884
+ // Remove event listeners from sliderElem
885
+ this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false);
886
+ this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false);
887
+ this.sliderElem.removeEventListener("touchstart", this.mousedown, false);
888
+ this.sliderElem.removeEventListener("mousedown", this.mousedown, false);
889
+ },
890
+ _bindNonQueryEventHandler: function(evt, callback) {
891
+ if(this.eventToCallbackMap[evt]===undefined) {
892
+ this.eventToCallbackMap[evt] = [];
893
+ }
894
+ this.eventToCallbackMap[evt].push(callback);
895
+ },
896
+ _cleanUpEventCallbacksMap: function() {
897
+ var eventNames = Object.keys(this.eventToCallbackMap);
898
+ for(var i = 0; i < eventNames.length; i++) {
899
+ var eventName = eventNames[i];
900
+ this.eventToCallbackMap[eventName] = null;
901
+ }
902
+ },
903
+ _showTooltip: function() {
904
+ if (this.options.tooltip_split === false ){
905
+ this._addClass(this.tooltip, 'in');
906
+ } else {
907
+ this._addClass(this.tooltip_min, 'in');
908
+ this._addClass(this.tooltip_max, 'in');
909
+ }
910
+ this.over = true;
911
+ },
912
+ _hideTooltip: function() {
913
+ if (this.inDrag === false && this.alwaysShowTooltip !== true) {
914
+ this._removeClass(this.tooltip, 'in');
915
+ this._removeClass(this.tooltip_min, 'in');
916
+ this._removeClass(this.tooltip_max, 'in');
917
+ }
918
+ this.over = false;
919
+ },
920
+ _layout: function() {
921
+ var positionPercentages;
922
+
923
+ if(this.options.reversed) {
924
+ positionPercentages = [ 100 - this.percentage[0], this.percentage[1] ];
925
+ } else {
926
+ positionPercentages = [ this.percentage[0], this.percentage[1] ];
927
+ }
928
+
929
+ this.handle1.style[this.stylePos] = positionPercentages[0]+'%';
930
+ this.handle2.style[this.stylePos] = positionPercentages[1]+'%';
931
+
932
+ /* Position ticks and labels */
933
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
934
+ var maxTickValue = Math.max.apply(Math, this.options.ticks);
935
+ var minTickValue = Math.min.apply(Math, this.options.ticks);
936
+
937
+ var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width';
938
+ var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft';
939
+ var labelSize = this.size / (this.options.ticks.length - 1);
940
+
941
+ if (this.tickLabelContainer) {
942
+ var extraMargin = 0;
943
+ if (this.options.ticks_positions.length === 0) {
944
+ this.tickLabelContainer.style[styleMargin] = -labelSize/2 + 'px';
945
+ extraMargin = this.tickLabelContainer.offsetHeight;
946
+ } else {
947
+ /* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */
948
+ for (i = 0 ; i < this.tickLabelContainer.childNodes.length; i++) {
949
+ if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) {
950
+ extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight;
951
+ }
952
+ }
953
+ }
954
+ if (this.options.orientation === 'horizontal') {
955
+ this.sliderElem.style.marginBottom = extraMargin + 'px';
956
+ }
957
+ }
958
+ for (var i = 0; i < this.options.ticks.length; i++) {
959
+
960
+ var percentage = this.options.ticks_positions[i] ||
961
+ 100 * (this.options.ticks[i] - minTickValue) / (maxTickValue - minTickValue);
962
+
963
+ this.ticks[i].style[this.stylePos] = percentage + '%';
964
+
965
+ /* Set class labels to denote whether ticks are in the selection */
966
+ this._removeClass(this.ticks[i], 'in-selection');
967
+ if (!this.options.range) {
968
+ if (this.options.selection === 'after' && percentage >= positionPercentages[0]){
969
+ this._addClass(this.ticks[i], 'in-selection');
970
+ } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) {
971
+ this._addClass(this.ticks[i], 'in-selection');
972
+ }
973
+ } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) {
974
+ this._addClass(this.ticks[i], 'in-selection');
975
+ }
976
+
977
+ if (this.tickLabels[i]) {
978
+ this.tickLabels[i].style[styleSize] = labelSize + 'px';
979
+
980
+ if (this.options.ticks_positions[i] !== undefined) {
981
+ this.tickLabels[i].style.position = 'absolute';
982
+ this.tickLabels[i].style[this.stylePos] = this.options.ticks_positions[i] + '%';
983
+ this.tickLabels[i].style[styleMargin] = -labelSize/2 + 'px';
984
+ }
985
+ }
986
+ }
987
+ }
988
+
989
+ if (this.options.orientation === 'vertical') {
990
+ this.trackLow.style.top = '0';
991
+ this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
992
+
993
+ this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
994
+ this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
995
+
996
+ this.trackHigh.style.bottom = '0';
997
+ this.trackHigh.style.height = (100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1])) +'%';
998
+ } else {
999
+ this.trackLow.style.left = '0';
1000
+ this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
1001
+
1002
+ this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
1003
+ this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
1004
+
1005
+ this.trackHigh.style.right = '0';
1006
+ this.trackHigh.style.width = (100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1])) +'%';
1007
+
1008
+ var offset_min = this.tooltip_min.getBoundingClientRect();
1009
+ var offset_max = this.tooltip_max.getBoundingClientRect();
1010
+
1011
+ if (offset_min.right > offset_max.left) {
1012
+ this._removeClass(this.tooltip_max, 'top');
1013
+ this._addClass(this.tooltip_max, 'bottom');
1014
+ this.tooltip_max.style.top = 18 + 'px';
1015
+ } else {
1016
+ this._removeClass(this.tooltip_max, 'bottom');
1017
+ this._addClass(this.tooltip_max, 'top');
1018
+ this.tooltip_max.style.top = this.tooltip_min.style.top;
1019
+ }
1020
+ }
1021
+
1022
+ var formattedTooltipVal;
1023
+
1024
+ if (this.options.range) {
1025
+ formattedTooltipVal = this.options.formatter(this.options.value);
1026
+ this._setText(this.tooltipInner, formattedTooltipVal);
1027
+ this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0])/2 + '%';
1028
+
1029
+ if (this.options.orientation === 'vertical') {
1030
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1031
+ } else {
1032
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1033
+ }
1034
+
1035
+ if (this.options.orientation === 'vertical') {
1036
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1037
+ } else {
1038
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1039
+ }
1040
+
1041
+ var innerTooltipMinText = this.options.formatter(this.options.value[0]);
1042
+ this._setText(this.tooltipInner_min, innerTooltipMinText);
1043
+
1044
+ var innerTooltipMaxText = this.options.formatter(this.options.value[1]);
1045
+ this._setText(this.tooltipInner_max, innerTooltipMaxText);
1046
+
1047
+ this.tooltip_min.style[this.stylePos] = positionPercentages[0] + '%';
1048
+
1049
+ if (this.options.orientation === 'vertical') {
1050
+ this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px');
1051
+ } else {
1052
+ this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px');
1053
+ }
1054
+
1055
+ this.tooltip_max.style[this.stylePos] = positionPercentages[1] + '%';
1056
+
1057
+ if (this.options.orientation === 'vertical') {
1058
+ this._css(this.tooltip_max, 'margin-top', -this.tooltip_max.offsetHeight / 2 + 'px');
1059
+ } else {
1060
+ this._css(this.tooltip_max, 'margin-left', -this.tooltip_max.offsetWidth / 2 + 'px');
1061
+ }
1062
+ } else {
1063
+ formattedTooltipVal = this.options.formatter(this.options.value[0]);
1064
+ this._setText(this.tooltipInner, formattedTooltipVal);
1065
+
1066
+ this.tooltip.style[this.stylePos] = positionPercentages[0] + '%';
1067
+ if (this.options.orientation === 'vertical') {
1068
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1069
+ } else {
1070
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1071
+ }
1072
+ }
1073
+ },
1074
+ _removeProperty: function(element, prop) {
1075
+ if (element.style.removeProperty) {
1076
+ element.style.removeProperty(prop);
1077
+ } else {
1078
+ element.style.removeAttribute(prop);
1079
+ }
1080
+ },
1081
+ _mousedown: function(ev) {
1082
+ if(!this.options.enabled) {
1083
+ return false;
1084
+ }
1085
+
1086
+ this.offset = this._offset(this.sliderElem);
1087
+ this.size = this.sliderElem[this.sizePos];
1088
+
1089
+ var percentage = this._getPercentage(ev);
1090
+
1091
+ if (this.options.range) {
1092
+ var diff1 = Math.abs(this.percentage[0] - percentage);
1093
+ var diff2 = Math.abs(this.percentage[1] - percentage);
1094
+ this.dragged = (diff1 < diff2) ? 0 : 1;
1095
+ } else {
1096
+ this.dragged = 0;
1097
+ }
1098
+
1099
+ this.percentage[this.dragged] = this.options.reversed ? 100 - percentage : percentage;
1100
+ this._layout();
1101
+
1102
+ if (this.touchCapable) {
1103
+ document.removeEventListener("touchmove", this.mousemove, false);
1104
+ document.removeEventListener("touchend", this.mouseup, false);
1105
+ }
1106
+
1107
+ if(this.mousemove){
1108
+ document.removeEventListener("mousemove", this.mousemove, false);
1109
+ }
1110
+ if(this.mouseup){
1111
+ document.removeEventListener("mouseup", this.mouseup, false);
1112
+ }
1113
+
1114
+ this.mousemove = this._mousemove.bind(this);
1115
+ this.mouseup = this._mouseup.bind(this);
1116
+
1117
+ if (this.touchCapable) {
1118
+ // Touch: Bind touch events:
1119
+ document.addEventListener("touchmove", this.mousemove, false);
1120
+ document.addEventListener("touchend", this.mouseup, false);
1121
+ }
1122
+ // Bind mouse events:
1123
+ document.addEventListener("mousemove", this.mousemove, false);
1124
+ document.addEventListener("mouseup", this.mouseup, false);
1125
+
1126
+ this.inDrag = true;
1127
+ var newValue = this._calculateValue();
1128
+
1129
+ this._trigger('slideStart', newValue);
1130
+
1131
+ this._setDataVal(newValue);
1132
+ this.setValue(newValue, false, true);
1133
+
1134
+ this._pauseEvent(ev);
1135
+
1136
+ if (this.options.focus) {
1137
+ this._triggerFocusOnHandle(this.dragged);
1138
+ }
1139
+
1140
+ return true;
1141
+ },
1142
+ _triggerFocusOnHandle: function(handleIdx) {
1143
+ if(handleIdx === 0) {
1144
+ this.handle1.focus();
1145
+ }
1146
+ if(handleIdx === 1) {
1147
+ this.handle2.focus();
1148
+ }
1149
+ },
1150
+ _keydown: function(handleIdx, ev) {
1151
+ if(!this.options.enabled) {
1152
+ return false;
1153
+ }
1154
+
1155
+ var dir;
1156
+ switch (ev.keyCode) {
1157
+ case 37: // left
1158
+ case 40: // down
1159
+ dir = -1;
1160
+ break;
1161
+ case 39: // right
1162
+ case 38: // up
1163
+ dir = 1;
1164
+ break;
1165
+ }
1166
+ if (!dir) {
1167
+ return;
1168
+ }
1169
+
1170
+ // use natural arrow keys instead of from min to max
1171
+ if (this.options.natural_arrow_keys) {
1172
+ var ifVerticalAndNotReversed = (this.options.orientation === 'vertical' && !this.options.reversed);
1173
+ var ifHorizontalAndReversed = (this.options.orientation === 'horizontal' && this.options.reversed);
1174
+
1175
+ if (ifVerticalAndNotReversed || ifHorizontalAndReversed) {
1176
+ dir = -dir;
1177
+ }
1178
+ }
1179
+
1180
+ var val = this.options.value[handleIdx] + dir * this.options.step;
1181
+ if (this.options.range) {
1182
+ val = [ (!handleIdx) ? val : this.options.value[0],
1183
+ ( handleIdx) ? val : this.options.value[1]];
1184
+ }
1185
+
1186
+ this._trigger('slideStart', val);
1187
+ this._setDataVal(val);
1188
+ this.setValue(val, true, true);
1189
+
1190
+ this._trigger('slideStop', val);
1191
+ this._setDataVal(val);
1192
+ this._layout();
1193
+
1194
+ this._pauseEvent(ev);
1195
+
1196
+ return false;
1197
+ },
1198
+ _pauseEvent: function(ev) {
1199
+ if(ev.stopPropagation) {
1200
+ ev.stopPropagation();
1201
+ }
1202
+ if(ev.preventDefault) {
1203
+ ev.preventDefault();
1204
+ }
1205
+ ev.cancelBubble=true;
1206
+ ev.returnValue=false;
1207
+ },
1208
+ _mousemove: function(ev) {
1209
+ if(!this.options.enabled) {
1210
+ return false;
1211
+ }
1212
+
1213
+ var percentage = this._getPercentage(ev);
1214
+ this._adjustPercentageForRangeSliders(percentage);
1215
+ this.percentage[this.dragged] = this.options.reversed ? 100 - percentage : percentage;
1216
+ this._layout();
1217
+
1218
+ var val = this._calculateValue(true);
1219
+ this.setValue(val, true, true);
1220
+
1221
+ return false;
1222
+ },
1223
+ _adjustPercentageForRangeSliders: function(percentage) {
1224
+ if (this.options.range) {
1225
+ if (this.dragged === 0 && this.percentage[1] < percentage) {
1226
+ this.percentage[0] = this.percentage[1];
1227
+ this.dragged = 1;
1228
+ } else if (this.dragged === 1 && this.percentage[0] > percentage) {
1229
+ this.percentage[1] = this.percentage[0];
1230
+ this.dragged = 0;
1231
+ }
1232
+ }
1233
+ },
1234
+ _mouseup: function() {
1235
+ if(!this.options.enabled) {
1236
+ return false;
1237
+ }
1238
+ if (this.touchCapable) {
1239
+ // Touch: Unbind touch event handlers:
1240
+ document.removeEventListener("touchmove", this.mousemove, false);
1241
+ document.removeEventListener("touchend", this.mouseup, false);
1242
+ }
1243
+ // Unbind mouse event handlers:
1244
+ document.removeEventListener("mousemove", this.mousemove, false);
1245
+ document.removeEventListener("mouseup", this.mouseup, false);
1246
+
1247
+ this.inDrag = false;
1248
+ if (this.over === false) {
1249
+ this._hideTooltip();
1250
+ }
1251
+ var val = this._calculateValue(true);
1252
+
1253
+ this._layout();
1254
+ this._trigger('slideStop', val);
1255
+ this._setDataVal(val);
1256
+
1257
+ return false;
1258
+ },
1259
+ _calculateValue: function(snapToClosestTick) {
1260
+ var val;
1261
+ if (this.options.range) {
1262
+ val = [this.options.min,this.options.max];
1263
+ if (this.percentage[0] !== 0){
1264
+ val[0] = this._toValue(this.percentage[0]);
1265
+ val[0] = this._applyPrecision(val[0]);
1266
+ }
1267
+ if (this.percentage[1] !== 100){
1268
+ val[1] = this._toValue(this.percentage[1]);
1269
+ val[1] = this._applyPrecision(val[1]);
1270
+ }
1271
+ } else {
1272
+ val = this._toValue(this.percentage[0]);
1273
+ val = parseFloat(val);
1274
+ val = this._applyPrecision(val);
1275
+ }
1276
+
1277
+ if (snapToClosestTick) {
1278
+ var min = [val, Infinity];
1279
+ for (var i = 0; i < this.options.ticks.length; i++) {
1280
+ var diff = Math.abs(this.options.ticks[i] - val);
1281
+ if (diff <= min[1]) {
1282
+ min = [this.options.ticks[i], diff];
1283
+ }
1284
+ }
1285
+ if (min[1] <= this.options.ticks_snap_bounds) {
1286
+ return min[0];
1287
+ }
1288
+ }
1289
+
435
1290
  return val;
436
- } 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
- this.disable();
463
- } else {
464
- this.enable();
1291
+ },
1292
+ _applyPrecision: function(val) {
1293
+ var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step);
1294
+ return this._applyToFixedAndParseFloat(val, precision);
1295
+ },
1296
+ _getNumDigitsAfterDecimalPlace: function(num) {
1297
+ var match = (''+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
1298
+ if (!match) { return 0; }
1299
+ return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
1300
+ },
1301
+ _applyToFixedAndParseFloat: function(num, toFixedInput) {
1302
+ var truncatedNum = num.toFixed(toFixedInput);
1303
+ return parseFloat(truncatedNum);
1304
+ },
1305
+ /*
1306
+ Credits to Mike Samuel for the following method!
1307
+ Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number
1308
+ */
1309
+ _getPercentage: function(ev) {
1310
+ if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) {
1311
+ ev = ev.touches[0];
1312
+ }
1313
+
1314
+ var eventPosition = ev[this.mousePos];
1315
+ var sliderOffset = this.offset[this.stylePos];
1316
+ var distanceToSlide = eventPosition - sliderOffset;
1317
+ // Calculate what percent of the length the slider handle has slid
1318
+ var percentage = (distanceToSlide / this.size) * 100;
1319
+ percentage = Math.round(percentage / this.percentage[2]) * this.percentage[2];
1320
+
1321
+ // Make sure the percent is within the bounds of the slider.
1322
+ // 0% corresponds to the 'min' value of the slide
1323
+ // 100% corresponds to the 'max' value of the slide
1324
+ return Math.max(0, Math.min(100, percentage));
1325
+ },
1326
+ _validateInputValue: function(val) {
1327
+ if (typeof val === 'number') {
1328
+ return val;
1329
+ } else if (Array.isArray(val)) {
1330
+ this._validateArray(val);
1331
+ return val;
1332
+ } else {
1333
+ throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(val) );
1334
+ }
1335
+ },
1336
+ _validateArray: function(val) {
1337
+ for(var i = 0; i < val.length; i++) {
1338
+ var input = val[i];
1339
+ if (typeof input !== 'number') { throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(input) ); }
1340
+ }
1341
+ },
1342
+ _setDataVal: function(val) {
1343
+ var value = "value: '" + val + "'";
1344
+ this.element.setAttribute('data', value);
1345
+ this.element.setAttribute('value', val);
1346
+ this.element.value = val;
1347
+ },
1348
+ _trigger: function(evt, val) {
1349
+ val = (val || val === 0) ? val : undefined;
1350
+
1351
+ var callbackFnArray = this.eventToCallbackMap[evt];
1352
+ if(callbackFnArray && callbackFnArray.length) {
1353
+ for(var i = 0; i < callbackFnArray.length; i++) {
1354
+ var callbackFn = callbackFnArray[i];
1355
+ callbackFn(val);
1356
+ }
1357
+ }
1358
+
1359
+ /* If JQuery exists, trigger JQuery events */
1360
+ if($) {
1361
+ this._triggerJQueryEvent(evt, val);
1362
+ }
1363
+ },
1364
+ _triggerJQueryEvent: function(evt, val) {
1365
+ var eventData = {
1366
+ type: evt,
1367
+ value: val
1368
+ };
1369
+ this.$element.trigger(eventData);
1370
+ this.$sliderElem.trigger(eventData);
1371
+ },
1372
+ _unbindJQueryEventHandlers: function() {
1373
+ this.$element.off();
1374
+ this.$sliderElem.off();
1375
+ },
1376
+ _setText: function(element, text) {
1377
+ if(typeof element.innerText !== "undefined") {
1378
+ element.innerText = text;
1379
+ } else if(typeof element.textContent !== "undefined") {
1380
+ element.textContent = text;
1381
+ }
1382
+ },
1383
+ _removeClass: function(element, classString) {
1384
+ var classes = classString.split(" ");
1385
+ var newClasses = element.className;
1386
+
1387
+ for(var i = 0; i < classes.length; i++) {
1388
+ var classTag = classes[i];
1389
+ var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
1390
+ newClasses = newClasses.replace(regex, " ");
1391
+ }
1392
+
1393
+ element.className = newClasses.trim();
1394
+ },
1395
+ _addClass: function(element, classString) {
1396
+ var classes = classString.split(" ");
1397
+ var newClasses = element.className;
1398
+
1399
+ for(var i = 0; i < classes.length; i++) {
1400
+ var classTag = classes[i];
1401
+ var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
1402
+ var ifClassExists = regex.test(newClasses);
1403
+
1404
+ if(!ifClassExists) {
1405
+ newClasses += " " + classTag;
1406
+ }
1407
+ }
1408
+
1409
+ element.className = newClasses.trim();
1410
+ },
1411
+ _offsetLeft: function(obj){
1412
+ var offsetLeft = obj.offsetLeft;
1413
+ while((obj = obj.offsetParent) && !isNaN(obj.offsetLeft)){
1414
+ offsetLeft += obj.offsetLeft;
1415
+ }
1416
+ return offsetLeft;
1417
+ },
1418
+ _offsetTop: function(obj){
1419
+ var offsetTop = obj.offsetTop;
1420
+ while((obj = obj.offsetParent) && !isNaN(obj.offsetTop)){
1421
+ offsetTop += obj.offsetTop;
1422
+ }
1423
+ return offsetTop;
1424
+ },
1425
+ _offset: function (obj) {
1426
+ return {
1427
+ left: this._offsetLeft(obj),
1428
+ top: this._offsetTop(obj)
1429
+ };
1430
+ },
1431
+ _css: function(elementRef, styleName, value) {
1432
+ if ($) {
1433
+ $.style(elementRef, styleName, value);
1434
+ } else {
1435
+ var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) {
1436
+ return letter.toUpperCase();
1437
+ });
1438
+ elementRef.style[style] = value;
1439
+ }
1440
+ },
1441
+ _toValue: function(percentage) {
1442
+ return this.options.scale.toValue.apply(this, [percentage]);
1443
+ },
1444
+ _toPercentage: function(value) {
1445
+ return this.options.scale.toPercentage.apply(this, [value]);
465
1446
  }
466
- },
467
1447
 
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
- }
499
- }
1448
+ };
500
1449
 
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
- }
1450
+ /*********************************
509
1451
 
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
- }
1452
+ Attach to global namespace
519
1453
 
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;
1454
+ *********************************/
1455
+ if($) {
1456
+ var namespace = $.fn.slider ? 'bootstrapSlider' : 'slider';
1457
+ $.bridget(namespace, Slider);
533
1458
  }
534
- };
535
1459
 
536
- $.fn.slider.Constructor = Slider;
1460
+ })( $ );
537
1461
 
538
- })( window.jQuery );
1462
+ return Slider;
1463
+ }));