bootstrap-slider-rails 5.3.7 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 736a45ae2a242004265180ca63467d2403484264
4
- data.tar.gz: d62e60c840d59e6a9fbf5244673eb6cb1fc0067e
3
+ metadata.gz: ed98a0fa8b154cc9d2f323f47ec21b28822b8839
4
+ data.tar.gz: 8fa53e2f94f4895a7845b72b1ac0e65963dc75de
5
5
  SHA512:
6
- metadata.gz: 70b2663cb30cb518428d7ee60820fe89a6cc5a58a52e3ff4f00b1fc4c98d229516b8b3e0f9229c56faf5d7faa32877cb99855d1c24f228ed70edefcdc1452527
7
- data.tar.gz: 0d8f7c56d45a4ca76d693a2867fe0fc8f4d778fb3ae7206018263d903c91495d2827455e4d52d3accb746764f9b810e7a3a641fc10e8881a899d7cf6e7c510a2
6
+ metadata.gz: 903916148bfd52b68eb975c551d06cebee3ced8f9831bbed53d39cebe08e9ec99065bf4e6c133a97e0b389af91c1e7d1629224e26a4cbcaabb9b55bf76618a7a
7
+ data.tar.gz: cd632b4f644da25aedda60bcbedccee912e6d22568c1f69e9714fb75a2dffa38f7aa66d8eebedc02e9fb63015ca484a58ed500b3b493f010a755426ed575a084
@@ -1,5 +1,5 @@
1
1
  module BootstrapSlider
2
2
  module Rails
3
- VERSION = '5.3.7'
3
+ VERSION = '6.0.0'
4
4
  end
5
5
  end
@@ -1,1590 +1 @@
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
- *
12
- * =========================================================
13
- *
14
- * Licensed under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- * ========================================================= */
26
-
27
-
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");
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;
54
-
55
-
56
- (function( $ ) {
57
-
58
- 'use strict';
59
-
60
- // -------------------------- utils -------------------------- //
61
-
62
- var slice = Array.prototype.slice;
63
-
64
- function noop() {}
65
-
66
- // -------------------------- definition -------------------------- //
67
-
68
- function defineBridget( $ ) {
69
-
70
- // bail if no jQuery
71
- if ( !$ ) {
72
- return;
73
- }
74
-
75
- // -------------------------- addOptionMethod -------------------------- //
76
-
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
- };
95
- }
96
-
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
-
183
- }
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
- var shouldAdjustWithBase = true;
211
- if (this.options.ticks_positions.length > 0) {
212
- var minv, maxv, minp, maxp = 0;
213
- for (var i = 1; i < this.options.ticks_positions.length; i++) {
214
- if (percentage <= this.options.ticks_positions[i]) {
215
- minv = this.options.ticks[i-1];
216
- minp = this.options.ticks_positions[i-1];
217
- maxv = this.options.ticks[i];
218
- maxp = this.options.ticks_positions[i];
219
-
220
- break;
221
- }
222
- }
223
- var partialPercentage = (percentage - minp) / (maxp - minp);
224
- rawValue = minv + partialPercentage * (maxv - minv);
225
- shouldAdjustWithBase = false;
226
- }
227
-
228
- var adjustment = shouldAdjustWithBase ? this.options.min : 0;
229
- var value = adjustment + Math.round(rawValue / this.options.step) * this.options.step;
230
- if (value < this.options.min) {
231
- return this.options.min;
232
- } else if (value > this.options.max) {
233
- return this.options.max;
234
- } else {
235
- return value;
236
- }
237
- },
238
- toPercentage: function(value) {
239
- if (this.options.max === this.options.min) {
240
- return 0;
241
- }
242
-
243
- if (this.options.ticks_positions.length > 0) {
244
- var minv, maxv, minp, maxp = 0;
245
- for (var i = 0; i < this.options.ticks.length; i++) {
246
- if (value <= this.options.ticks[i]) {
247
- minv = (i > 0) ? this.options.ticks[i-1] : 0;
248
- minp = (i > 0) ? this.options.ticks_positions[i-1] : 0;
249
- maxv = this.options.ticks[i];
250
- maxp = this.options.ticks_positions[i];
251
-
252
- break;
253
- }
254
- }
255
- if (i > 0) {
256
- var partialPercentage = (value - minv) / (maxv - minv);
257
- return minp + partialPercentage * (maxp - minp);
258
- }
259
- }
260
-
261
- return 100 * (value - this.options.min) / (this.options.max - this.options.min);
262
- }
263
- },
264
-
265
- logarithmic: {
266
- /* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */
267
- toValue: function(percentage) {
268
- var min = (this.options.min === 0) ? 0 : Math.log(this.options.min);
269
- var max = Math.log(this.options.max);
270
- var value = Math.exp(min + (max - min) * percentage / 100);
271
- value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step;
272
- /* Rounding to the nearest step could exceed the min or
273
- * max, so clip to those values. */
274
- if (value < this.options.min) {
275
- return this.options.min;
276
- } else if (value > this.options.max) {
277
- return this.options.max;
278
- } else {
279
- return value;
280
- }
281
- },
282
- toPercentage: function(value) {
283
- if (this.options.max === this.options.min) {
284
- return 0;
285
- } else {
286
- var max = Math.log(this.options.max);
287
- var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
288
- var v = value === 0 ? 0 : Math.log(value);
289
- return 100 * (v - min) / (max - min);
290
- }
291
- }
292
- }
293
- };
294
-
295
-
296
- /*************************************************
297
-
298
- CONSTRUCTOR
299
-
300
- **************************************************/
301
- Slider = function(element, options) {
302
- createNewSlider.call(this, element, options);
303
- return this;
304
- };
305
-
306
- function createNewSlider(element, options) {
307
-
308
- /*
309
- The internal state object is used to store data about the current 'state' of slider.
310
-
311
- This includes values such as the `value`, `enabled`, etc...
312
- */
313
- this._state = {
314
- value: null,
315
- enabled: null,
316
- offset: null,
317
- size: null,
318
- percentage: null,
319
- inDrag: false,
320
- over: false
321
- };
322
-
323
-
324
- if(typeof element === "string") {
325
- this.element = document.querySelector(element);
326
- } else if(element instanceof HTMLElement) {
327
- this.element = element;
328
- }
329
-
330
- /*************************************************
331
-
332
- Process Options
333
-
334
- **************************************************/
335
- options = options ? options : {};
336
- var optionTypes = Object.keys(this.defaultOptions);
337
-
338
- for(var i = 0; i < optionTypes.length; i++) {
339
- var optName = optionTypes[i];
340
-
341
- // First check if an option was passed in via the constructor
342
- var val = options[optName];
343
- // If no data attrib, then check data atrributes
344
- val = (typeof val !== 'undefined') ? val : getDataAttrib(this.element, optName);
345
- // Finally, if nothing was specified, use the defaults
346
- val = (val !== null) ? val : this.defaultOptions[optName];
347
-
348
- // Set all options on the instance of the Slider
349
- if(!this.options) {
350
- this.options = {};
351
- }
352
- this.options[optName] = val;
353
- }
354
-
355
- /*
356
- Validate `tooltip_position` against 'orientation`
357
- - if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation`
358
- -- default for "vertical" -> "right"
359
- -- default for "horizontal" -> "left"
360
- */
361
- if(this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) {
362
-
363
- this.options.tooltip_position = "right";
364
-
365
- }
366
- else if(this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) {
367
-
368
- this.options.tooltip_position = "top";
369
-
370
- }
371
-
372
- function getDataAttrib(element, optName) {
373
- var dataName = "data-slider-" + optName.replace(/_/g, '-');
374
- var dataValString = element.getAttribute(dataName);
375
-
376
- try {
377
- return JSON.parse(dataValString);
378
- }
379
- catch(err) {
380
- return dataValString;
381
- }
382
- }
383
-
384
- /*************************************************
385
-
386
- Create Markup
387
-
388
- **************************************************/
389
-
390
- var origWidth = this.element.style.width;
391
- var updateSlider = false;
392
- var parent = this.element.parentNode;
393
- var sliderTrackSelection;
394
- var sliderTrackLow, sliderTrackHigh;
395
- var sliderMinHandle;
396
- var sliderMaxHandle;
397
-
398
- if (this.sliderElem) {
399
- updateSlider = true;
400
- } else {
401
- /* Create elements needed for slider */
402
- this.sliderElem = document.createElement("div");
403
- this.sliderElem.className = "slider";
404
-
405
- /* Create slider track elements */
406
- var sliderTrack = document.createElement("div");
407
- sliderTrack.className = "slider-track";
408
-
409
- sliderTrackLow = document.createElement("div");
410
- sliderTrackLow.className = "slider-track-low";
411
-
412
- sliderTrackSelection = document.createElement("div");
413
- sliderTrackSelection.className = "slider-selection";
414
-
415
- sliderTrackHigh = document.createElement("div");
416
- sliderTrackHigh.className = "slider-track-high";
417
-
418
- sliderMinHandle = document.createElement("div");
419
- sliderMinHandle.className = "slider-handle min-slider-handle";
420
- sliderMinHandle.setAttribute('role', 'slider');
421
- sliderMinHandle.setAttribute('aria-valuemin', this.options.min);
422
- sliderMinHandle.setAttribute('aria-valuemax', this.options.max);
423
-
424
- sliderMaxHandle = document.createElement("div");
425
- sliderMaxHandle.className = "slider-handle max-slider-handle";
426
- sliderMaxHandle.setAttribute('role', 'slider');
427
- sliderMaxHandle.setAttribute('aria-valuemin', this.options.min);
428
- sliderMaxHandle.setAttribute('aria-valuemax', this.options.max);
429
-
430
- sliderTrack.appendChild(sliderTrackLow);
431
- sliderTrack.appendChild(sliderTrackSelection);
432
- sliderTrack.appendChild(sliderTrackHigh);
433
-
434
- /* Add aria-labelledby to handle's */
435
- var isLabelledbyArray = Array.isArray(this.options.labelledby);
436
- if (isLabelledbyArray && this.options.labelledby[0]) {
437
- sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby[0]);
438
- }
439
- if (isLabelledbyArray && this.options.labelledby[1]) {
440
- sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby[1]);
441
- }
442
- if (!isLabelledbyArray && this.options.labelledby) {
443
- sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby);
444
- sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby);
445
- }
446
-
447
- /* Create ticks */
448
- this.ticks = [];
449
- if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
450
- for (i = 0; i < this.options.ticks.length; i++) {
451
- var tick = document.createElement('div');
452
- tick.className = 'slider-tick';
453
-
454
- this.ticks.push(tick);
455
- sliderTrack.appendChild(tick);
456
- }
457
-
458
- sliderTrackSelection.className += " tick-slider-selection";
459
- }
460
-
461
- sliderTrack.appendChild(sliderMinHandle);
462
- sliderTrack.appendChild(sliderMaxHandle);
463
-
464
- this.tickLabels = [];
465
- if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
466
- this.tickLabelContainer = document.createElement('div');
467
- this.tickLabelContainer.className = 'slider-tick-label-container';
468
-
469
- for (i = 0; i < this.options.ticks_labels.length; i++) {
470
- var label = document.createElement('div');
471
- var noTickPositionsSpecified = this.options.ticks_positions.length === 0;
472
- var tickLabelsIndex = (this.options.reversed && noTickPositionsSpecified) ? (this.options.ticks_labels.length - (i + 1)) : i;
473
- label.className = 'slider-tick-label';
474
- label.innerHTML = this.options.ticks_labels[tickLabelsIndex];
475
-
476
- this.tickLabels.push(label);
477
- this.tickLabelContainer.appendChild(label);
478
- }
479
- }
480
-
481
-
482
- var createAndAppendTooltipSubElements = function(tooltipElem) {
483
- var arrow = document.createElement("div");
484
- arrow.className = "tooltip-arrow";
485
-
486
- var inner = document.createElement("div");
487
- inner.className = "tooltip-inner";
488
-
489
- tooltipElem.appendChild(arrow);
490
- tooltipElem.appendChild(inner);
491
-
492
- };
493
-
494
- /* Create tooltip elements */
495
- var sliderTooltip = document.createElement("div");
496
- sliderTooltip.className = "tooltip tooltip-main";
497
- sliderTooltip.setAttribute('role', 'presentation');
498
- createAndAppendTooltipSubElements(sliderTooltip);
499
-
500
- var sliderTooltipMin = document.createElement("div");
501
- sliderTooltipMin.className = "tooltip tooltip-min";
502
- sliderTooltipMin.setAttribute('role', 'presentation');
503
- createAndAppendTooltipSubElements(sliderTooltipMin);
504
-
505
- var sliderTooltipMax = document.createElement("div");
506
- sliderTooltipMax.className = "tooltip tooltip-max";
507
- sliderTooltipMax.setAttribute('role', 'presentation');
508
- createAndAppendTooltipSubElements(sliderTooltipMax);
509
-
510
-
511
- /* Append components to sliderElem */
512
- this.sliderElem.appendChild(sliderTrack);
513
- this.sliderElem.appendChild(sliderTooltip);
514
- this.sliderElem.appendChild(sliderTooltipMin);
515
- this.sliderElem.appendChild(sliderTooltipMax);
516
-
517
- if (this.tickLabelContainer) {
518
- this.sliderElem.appendChild(this.tickLabelContainer);
519
- }
520
-
521
- /* Append slider element to parent container, right before the original <input> element */
522
- parent.insertBefore(this.sliderElem, this.element);
523
-
524
- /* Hide original <input> element */
525
- this.element.style.display = "none";
526
- }
527
- /* If JQuery exists, cache JQ references */
528
- if($) {
529
- this.$element = $(this.element);
530
- this.$sliderElem = $(this.sliderElem);
531
- }
532
-
533
- /*************************************************
534
-
535
- Setup
536
-
537
- **************************************************/
538
- this.eventToCallbackMap = {};
539
- this.sliderElem.id = this.options.id;
540
-
541
- this.touchCapable = 'ontouchstart' in window || (window.DocumentTouch && document instanceof window.DocumentTouch);
542
-
543
- this.tooltip = this.sliderElem.querySelector('.tooltip-main');
544
- this.tooltipInner = this.tooltip.querySelector('.tooltip-inner');
545
-
546
- this.tooltip_min = this.sliderElem.querySelector('.tooltip-min');
547
- this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner');
548
-
549
- this.tooltip_max = this.sliderElem.querySelector('.tooltip-max');
550
- this.tooltipInner_max= this.tooltip_max.querySelector('.tooltip-inner');
551
-
552
- if (SliderScale[this.options.scale]) {
553
- this.options.scale = SliderScale[this.options.scale];
554
- }
555
-
556
- if (updateSlider === true) {
557
- // Reset classes
558
- this._removeClass(this.sliderElem, 'slider-horizontal');
559
- this._removeClass(this.sliderElem, 'slider-vertical');
560
- this._removeClass(this.tooltip, 'hide');
561
- this._removeClass(this.tooltip_min, 'hide');
562
- this._removeClass(this.tooltip_max, 'hide');
563
-
564
- // Undo existing inline styles for track
565
- ["left", "top", "width", "height"].forEach(function(prop) {
566
- this._removeProperty(this.trackLow, prop);
567
- this._removeProperty(this.trackSelection, prop);
568
- this._removeProperty(this.trackHigh, prop);
569
- }, this);
570
-
571
- // Undo inline styles on handles
572
- [this.handle1, this.handle2].forEach(function(handle) {
573
- this._removeProperty(handle, 'left');
574
- this._removeProperty(handle, 'top');
575
- }, this);
576
-
577
- // Undo inline styles and classes on tooltips
578
- [this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function(tooltip) {
579
- this._removeProperty(tooltip, 'left');
580
- this._removeProperty(tooltip, 'top');
581
- this._removeProperty(tooltip, 'margin-left');
582
- this._removeProperty(tooltip, 'margin-top');
583
-
584
- this._removeClass(tooltip, 'right');
585
- this._removeClass(tooltip, 'top');
586
- }, this);
587
- }
588
-
589
- if(this.options.orientation === 'vertical') {
590
- this._addClass(this.sliderElem,'slider-vertical');
591
- this.stylePos = 'top';
592
- this.mousePos = 'pageY';
593
- this.sizePos = 'offsetHeight';
594
- } else {
595
- this._addClass(this.sliderElem, 'slider-horizontal');
596
- this.sliderElem.style.width = origWidth;
597
- this.options.orientation = 'horizontal';
598
- this.stylePos = 'left';
599
- this.mousePos = 'pageX';
600
- this.sizePos = 'offsetWidth';
601
-
602
- }
603
- this._setTooltipPosition();
604
- /* In case ticks are specified, overwrite the min and max bounds */
605
- if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
606
- this.options.max = Math.max.apply(Math, this.options.ticks);
607
- this.options.min = Math.min.apply(Math, this.options.ticks);
608
- }
609
-
610
- if (Array.isArray(this.options.value)) {
611
- this.options.range = true;
612
- this._state.value = this.options.value;
613
- }
614
- else if (this.options.range) {
615
- // User wants a range, but value is not an array
616
- this._state.value = [this.options.value, this.options.max];
617
- }
618
- else {
619
- this._state.value = this.options.value;
620
- }
621
-
622
- this.trackLow = sliderTrackLow || this.trackLow;
623
- this.trackSelection = sliderTrackSelection || this.trackSelection;
624
- this.trackHigh = sliderTrackHigh || this.trackHigh;
625
-
626
- if (this.options.selection === 'none') {
627
- this._addClass(this.trackLow, 'hide');
628
- this._addClass(this.trackSelection, 'hide');
629
- this._addClass(this.trackHigh, 'hide');
630
- }
631
-
632
- this.handle1 = sliderMinHandle || this.handle1;
633
- this.handle2 = sliderMaxHandle || this.handle2;
634
-
635
- if (updateSlider === true) {
636
- // Reset classes
637
- this._removeClass(this.handle1, 'round triangle');
638
- this._removeClass(this.handle2, 'round triangle hide');
639
-
640
- for (i = 0; i < this.ticks.length; i++) {
641
- this._removeClass(this.ticks[i], 'round triangle hide');
642
- }
643
- }
644
-
645
- var availableHandleModifiers = ['round', 'triangle', 'custom'];
646
- var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1;
647
- if (isValidHandleType) {
648
- this._addClass(this.handle1, this.options.handle);
649
- this._addClass(this.handle2, this.options.handle);
650
-
651
- for (i = 0; i < this.ticks.length; i++) {
652
- this._addClass(this.ticks[i], this.options.handle);
653
- }
654
- }
655
-
656
- this._state.offset = this._offset(this.sliderElem);
657
- this._state.size = this.sliderElem[this.sizePos];
658
- this.setValue(this._state.value);
659
-
660
- /******************************************
661
-
662
- Bind Event Listeners
663
-
664
- ******************************************/
665
-
666
- // Bind keyboard handlers
667
- this.handle1Keydown = this._keydown.bind(this, 0);
668
- this.handle1.addEventListener("keydown", this.handle1Keydown, false);
669
-
670
- this.handle2Keydown = this._keydown.bind(this, 1);
671
- this.handle2.addEventListener("keydown", this.handle2Keydown, false);
672
-
673
- this.mousedown = this._mousedown.bind(this);
674
- if (this.touchCapable) {
675
- // Bind touch handlers
676
- this.sliderElem.addEventListener("touchstart", this.mousedown, false);
677
- }
678
- this.sliderElem.addEventListener("mousedown", this.mousedown, false);
679
-
680
- // Bind window handlers
681
- this.resize = this._resize.bind(this);
682
- window.addEventListener("resize", this.resize, false);
683
-
684
-
685
- // Bind tooltip-related handlers
686
- if(this.options.tooltip === 'hide') {
687
- this._addClass(this.tooltip, 'hide');
688
- this._addClass(this.tooltip_min, 'hide');
689
- this._addClass(this.tooltip_max, 'hide');
690
- }
691
- else if(this.options.tooltip === 'always') {
692
- this._showTooltip();
693
- this._alwaysShowTooltip = true;
694
- }
695
- else {
696
- this.showTooltip = this._showTooltip.bind(this);
697
- this.hideTooltip = this._hideTooltip.bind(this);
698
-
699
- this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
700
- this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
701
-
702
- this.handle1.addEventListener("focus", this.showTooltip, false);
703
- this.handle1.addEventListener("blur", this.hideTooltip, false);
704
-
705
- this.handle2.addEventListener("focus", this.showTooltip, false);
706
- this.handle2.addEventListener("blur", this.hideTooltip, false);
707
- }
708
-
709
- if(this.options.enabled) {
710
- this.enable();
711
- } else {
712
- this.disable();
713
- }
714
- }
715
-
716
-
717
-
718
- /*************************************************
719
-
720
- INSTANCE PROPERTIES/METHODS
721
-
722
- - Any methods bound to the prototype are considered
723
- part of the plugin's `public` interface
724
-
725
- **************************************************/
726
- Slider.prototype = {
727
- _init: function() {}, // NOTE: Must exist to support bridget
728
-
729
- constructor: Slider,
730
-
731
- defaultOptions: {
732
- id: "",
733
- min: 0,
734
- max: 10,
735
- step: 1,
736
- precision: 0,
737
- orientation: 'horizontal',
738
- value: 5,
739
- range: false,
740
- selection: 'before',
741
- tooltip: 'show',
742
- tooltip_split: false,
743
- handle: 'round',
744
- reversed: false,
745
- enabled: true,
746
- formatter: function(val) {
747
- if (Array.isArray(val)) {
748
- return val[0] + " : " + val[1];
749
- } else {
750
- return val;
751
- }
752
- },
753
- natural_arrow_keys: false,
754
- ticks: [],
755
- ticks_positions: [],
756
- ticks_labels: [],
757
- ticks_snap_bounds: 0,
758
- scale: 'linear',
759
- focus: false,
760
- tooltip_position: null,
761
- labelledby: null
762
- },
763
-
764
- getElement: function() {
765
- return this.sliderElem;
766
- },
767
-
768
- getValue: function() {
769
- if (this.options.range) {
770
- return this._state.value;
771
- }
772
- else {
773
- return this._state.value[0];
774
- }
775
- },
776
-
777
- setValue: function(val, triggerSlideEvent, triggerChangeEvent) {
778
- if (!val) {
779
- val = 0;
780
- }
781
- var oldValue = this.getValue();
782
- this._state.value = this._validateInputValue(val);
783
- var applyPrecision = this._applyPrecision.bind(this);
784
-
785
- if (this.options.range) {
786
- this._state.value[0] = applyPrecision(this._state.value[0]);
787
- this._state.value[1] = applyPrecision(this._state.value[1]);
788
-
789
- this._state.value[0] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[0]));
790
- this._state.value[1] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[1]));
791
- }
792
- else {
793
- this._state.value = applyPrecision(this._state.value);
794
- this._state.value = [ Math.max(this.options.min, Math.min(this.options.max, this._state.value))];
795
- this._addClass(this.handle2, 'hide');
796
- if (this.options.selection === 'after') {
797
- this._state.value[1] = this.options.max;
798
- } else {
799
- this._state.value[1] = this.options.min;
800
- }
801
- }
802
-
803
- if (this.options.max > this.options.min) {
804
- this._state.percentage = [
805
- this._toPercentage(this._state.value[0]),
806
- this._toPercentage(this._state.value[1]),
807
- this.options.step * 100 / (this.options.max - this.options.min)
808
- ];
809
- } else {
810
- this._state.percentage = [0, 0, 100];
811
- }
812
-
813
- this._layout();
814
- var newValue = this.options.range ? this._state.value : this._state.value[0];
815
-
816
- if(triggerSlideEvent === true) {
817
- this._trigger('slide', newValue);
818
- }
819
- if( (oldValue !== newValue) && (triggerChangeEvent === true) ) {
820
- this._trigger('change', {
821
- oldValue: oldValue,
822
- newValue: newValue
823
- });
824
- }
825
- this._setDataVal(newValue);
826
-
827
- return this;
828
- },
829
-
830
- destroy: function(){
831
- // Remove event handlers on slider elements
832
- this._removeSliderEventHandlers();
833
-
834
- // Remove the slider from the DOM
835
- this.sliderElem.parentNode.removeChild(this.sliderElem);
836
- /* Show original <input> element */
837
- this.element.style.display = "";
838
-
839
- // Clear out custom event bindings
840
- this._cleanUpEventCallbacksMap();
841
-
842
- // Remove data values
843
- this.element.removeAttribute("data");
844
-
845
- // Remove JQuery handlers/data
846
- if($) {
847
- this._unbindJQueryEventHandlers();
848
- this.$element.removeData('slider');
849
- }
850
- },
851
-
852
- disable: function() {
853
- this._state.enabled = false;
854
- this.handle1.removeAttribute("tabindex");
855
- this.handle2.removeAttribute("tabindex");
856
- this._addClass(this.sliderElem, 'slider-disabled');
857
- this._trigger('slideDisabled');
858
-
859
- return this;
860
- },
861
-
862
- enable: function() {
863
- this._state.enabled = true;
864
- this.handle1.setAttribute("tabindex", 0);
865
- this.handle2.setAttribute("tabindex", 0);
866
- this._removeClass(this.sliderElem, 'slider-disabled');
867
- this._trigger('slideEnabled');
868
-
869
- return this;
870
- },
871
-
872
- toggle: function() {
873
- if(this._state.enabled) {
874
- this.disable();
875
- } else {
876
- this.enable();
877
- }
878
- return this;
879
- },
880
-
881
- isEnabled: function() {
882
- return this._state.enabled;
883
- },
884
-
885
- on: function(evt, callback) {
886
- this._bindNonQueryEventHandler(evt, callback);
887
- return this;
888
- },
889
-
890
- off: function(evt, callback) {
891
- if($) {
892
- this.$element.off(evt, callback);
893
- this.$sliderElem.off(evt, callback);
894
- } else {
895
- this._unbindNonQueryEventHandler(evt, callback);
896
- }
897
- },
898
-
899
- getAttribute: function(attribute) {
900
- if(attribute) {
901
- return this.options[attribute];
902
- } else {
903
- return this.options;
904
- }
905
- },
906
-
907
- setAttribute: function(attribute, value) {
908
- this.options[attribute] = value;
909
- return this;
910
- },
911
-
912
- refresh: function() {
913
- this._removeSliderEventHandlers();
914
- createNewSlider.call(this, this.element, this.options);
915
- if($) {
916
- // Bind new instance of slider to the element
917
- $.data(this.element, 'slider', this);
918
- }
919
- return this;
920
- },
921
-
922
- relayout: function() {
923
- this._layout();
924
- return this;
925
- },
926
-
927
- /******************************+
928
-
929
- HELPERS
930
-
931
- - Any method that is not part of the public interface.
932
- - Place it underneath this comment block and write its signature like so:
933
-
934
- _fnName : function() {...}
935
-
936
- ********************************/
937
- _removeSliderEventHandlers: function() {
938
- // Remove keydown event listeners
939
- this.handle1.removeEventListener("keydown", this.handle1Keydown, false);
940
- this.handle2.removeEventListener("keydown", this.handle2Keydown, false);
941
-
942
- if (this.showTooltip) {
943
- this.handle1.removeEventListener("focus", this.showTooltip, false);
944
- this.handle2.removeEventListener("focus", this.showTooltip, false);
945
- }
946
- if (this.hideTooltip) {
947
- this.handle1.removeEventListener("blur", this.hideTooltip, false);
948
- this.handle2.removeEventListener("blur", this.hideTooltip, false);
949
- }
950
-
951
- // Remove event listeners from sliderElem
952
- if (this.showTooltip) {
953
- this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false);
954
- }
955
- if (this.hideTooltip) {
956
- this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false);
957
- }
958
- this.sliderElem.removeEventListener("touchstart", this.mousedown, false);
959
- this.sliderElem.removeEventListener("mousedown", this.mousedown, false);
960
-
961
- // Remove window event listener
962
- window.removeEventListener("resize", this.resize, false);
963
- },
964
- _bindNonQueryEventHandler: function(evt, callback) {
965
- if(this.eventToCallbackMap[evt] === undefined) {
966
- this.eventToCallbackMap[evt] = [];
967
- }
968
- this.eventToCallbackMap[evt].push(callback);
969
- },
970
- _unbindNonQueryEventHandler: function(evt, callback) {
971
- var callbacks = this.eventToCallbackMap[evt];
972
- if(callbacks !== undefined) {
973
- for (var i = 0; i < callbacks.length; i++) {
974
- if (callbacks[i] === callback) {
975
- callbacks.splice(i, 1);
976
- break;
977
- }
978
- }
979
- }
980
- },
981
- _cleanUpEventCallbacksMap: function() {
982
- var eventNames = Object.keys(this.eventToCallbackMap);
983
- for(var i = 0; i < eventNames.length; i++) {
984
- var eventName = eventNames[i];
985
- this.eventToCallbackMap[eventName] = null;
986
- }
987
- },
988
- _showTooltip: function() {
989
- if (this.options.tooltip_split === false ){
990
- this._addClass(this.tooltip, 'in');
991
- this.tooltip_min.style.display = 'none';
992
- this.tooltip_max.style.display = 'none';
993
- } else {
994
- this._addClass(this.tooltip_min, 'in');
995
- this._addClass(this.tooltip_max, 'in');
996
- this.tooltip.style.display = 'none';
997
- }
998
- this._state.over = true;
999
- },
1000
- _hideTooltip: function() {
1001
- if (this._state.inDrag === false && this.alwaysShowTooltip !== true) {
1002
- this._removeClass(this.tooltip, 'in');
1003
- this._removeClass(this.tooltip_min, 'in');
1004
- this._removeClass(this.tooltip_max, 'in');
1005
- }
1006
- this._state.over = false;
1007
- },
1008
- _layout: function() {
1009
- var positionPercentages;
1010
-
1011
- if(this.options.reversed) {
1012
- positionPercentages = [ 100 - this._state.percentage[0], this.options.range ? 100 - this._state.percentage[1] : this._state.percentage[1]];
1013
- }
1014
- else {
1015
- positionPercentages = [ this._state.percentage[0], this._state.percentage[1] ];
1016
- }
1017
-
1018
- this.handle1.style[this.stylePos] = positionPercentages[0]+'%';
1019
- this.handle1.setAttribute('aria-valuenow', this._state.value[0]);
1020
-
1021
- this.handle2.style[this.stylePos] = positionPercentages[1]+'%';
1022
- this.handle2.setAttribute('aria-valuenow', this._state.value[1]);
1023
-
1024
- /* Position ticks and labels */
1025
- if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
1026
-
1027
- var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width';
1028
- var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft';
1029
- var labelSize = this._state.size / (this.options.ticks.length - 1);
1030
-
1031
- if (this.tickLabelContainer) {
1032
- var extraMargin = 0;
1033
- if (this.options.ticks_positions.length === 0) {
1034
- if (this.options.orientation !== 'vertical') {
1035
- this.tickLabelContainer.style[styleMargin] = -labelSize/2 + 'px';
1036
- }
1037
-
1038
- extraMargin = this.tickLabelContainer.offsetHeight;
1039
- } else {
1040
- /* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */
1041
- for (i = 0 ; i < this.tickLabelContainer.childNodes.length; i++) {
1042
- if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) {
1043
- extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight;
1044
- }
1045
- }
1046
- }
1047
- if (this.options.orientation === 'horizontal') {
1048
- this.sliderElem.style.marginBottom = extraMargin + 'px';
1049
- }
1050
- }
1051
- for (var i = 0; i < this.options.ticks.length; i++) {
1052
-
1053
- var percentage = this.options.ticks_positions[i] || this._toPercentage(this.options.ticks[i]);
1054
-
1055
- if (this.options.reversed) {
1056
- percentage = 100 - percentage;
1057
- }
1058
-
1059
- this.ticks[i].style[this.stylePos] = percentage + '%';
1060
-
1061
- /* Set class labels to denote whether ticks are in the selection */
1062
- this._removeClass(this.ticks[i], 'in-selection');
1063
- if (!this.options.range) {
1064
- if (this.options.selection === 'after' && percentage >= positionPercentages[0]){
1065
- this._addClass(this.ticks[i], 'in-selection');
1066
- } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) {
1067
- this._addClass(this.ticks[i], 'in-selection');
1068
- }
1069
- } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) {
1070
- this._addClass(this.ticks[i], 'in-selection');
1071
- }
1072
-
1073
- if (this.tickLabels[i]) {
1074
- this.tickLabels[i].style[styleSize] = labelSize + 'px';
1075
-
1076
- if (this.options.orientation !== 'vertical' && this.options.ticks_positions[i] !== undefined) {
1077
- this.tickLabels[i].style.position = 'absolute';
1078
- this.tickLabels[i].style[this.stylePos] = percentage + '%';
1079
- this.tickLabels[i].style[styleMargin] = -labelSize/2 + 'px';
1080
- } else if (this.options.orientation === 'vertical') {
1081
- this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px';
1082
- this.tickLabelContainer.style['marginTop'] = this.sliderElem.offsetWidth / 2 * -1 + 'px';
1083
- }
1084
- }
1085
- }
1086
- }
1087
-
1088
- var formattedTooltipVal;
1089
-
1090
- if (this.options.range) {
1091
- formattedTooltipVal = this.options.formatter(this._state.value);
1092
- this._setText(this.tooltipInner, formattedTooltipVal);
1093
- this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0])/2 + '%';
1094
-
1095
- if (this.options.orientation === 'vertical') {
1096
- this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1097
- } else {
1098
- this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1099
- }
1100
-
1101
- if (this.options.orientation === 'vertical') {
1102
- this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1103
- } else {
1104
- this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1105
- }
1106
-
1107
- var innerTooltipMinText = this.options.formatter(this._state.value[0]);
1108
- this._setText(this.tooltipInner_min, innerTooltipMinText);
1109
-
1110
- var innerTooltipMaxText = this.options.formatter(this._state.value[1]);
1111
- this._setText(this.tooltipInner_max, innerTooltipMaxText);
1112
-
1113
- this.tooltip_min.style[this.stylePos] = positionPercentages[0] + '%';
1114
-
1115
- if (this.options.orientation === 'vertical') {
1116
- this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px');
1117
- } else {
1118
- this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px');
1119
- }
1120
-
1121
- this.tooltip_max.style[this.stylePos] = positionPercentages[1] + '%';
1122
-
1123
- if (this.options.orientation === 'vertical') {
1124
- this._css(this.tooltip_max, 'margin-top', -this.tooltip_max.offsetHeight / 2 + 'px');
1125
- } else {
1126
- this._css(this.tooltip_max, 'margin-left', -this.tooltip_max.offsetWidth / 2 + 'px');
1127
- }
1128
- } else {
1129
- formattedTooltipVal = this.options.formatter(this._state.value[0]);
1130
- this._setText(this.tooltipInner, formattedTooltipVal);
1131
-
1132
- this.tooltip.style[this.stylePos] = positionPercentages[0] + '%';
1133
- if (this.options.orientation === 'vertical') {
1134
- this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1135
- } else {
1136
- this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1137
- }
1138
- }
1139
-
1140
- if (this.options.orientation === 'vertical') {
1141
- this.trackLow.style.top = '0';
1142
- this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
1143
-
1144
- this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
1145
- this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
1146
-
1147
- this.trackHigh.style.bottom = '0';
1148
- this.trackHigh.style.height = (100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1])) +'%';
1149
- }
1150
- else {
1151
- this.trackLow.style.left = '0';
1152
- this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
1153
-
1154
- this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
1155
- this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
1156
-
1157
- this.trackHigh.style.right = '0';
1158
- this.trackHigh.style.width = (100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1])) +'%';
1159
-
1160
- var offset_min = this.tooltip_min.getBoundingClientRect();
1161
- var offset_max = this.tooltip_max.getBoundingClientRect();
1162
-
1163
- if (offset_min.right > offset_max.left) {
1164
- this._removeClass(this.tooltip_max, 'top');
1165
- this._addClass(this.tooltip_max, 'bottom');
1166
- this.tooltip_max.style.top = 18 + 'px';
1167
- } else {
1168
- this._removeClass(this.tooltip_max, 'bottom');
1169
- this._addClass(this.tooltip_max, 'top');
1170
- this.tooltip_max.style.top = this.tooltip_min.style.top;
1171
- }
1172
- }
1173
- },
1174
- _resize: function (ev) {
1175
- /*jshint unused:false*/
1176
- this._state.offset = this._offset(this.sliderElem);
1177
- this._state.size = this.sliderElem[this.sizePos];
1178
- this._layout();
1179
- },
1180
- _removeProperty: function(element, prop) {
1181
- if (element.style.removeProperty) {
1182
- element.style.removeProperty(prop);
1183
- } else {
1184
- element.style.removeAttribute(prop);
1185
- }
1186
- },
1187
- _mousedown: function(ev) {
1188
- if(!this._state.enabled) {
1189
- return false;
1190
- }
1191
-
1192
- this._state.offset = this._offset(this.sliderElem);
1193
- this._state.size = this.sliderElem[this.sizePos];
1194
-
1195
- var percentage = this._getPercentage(ev);
1196
-
1197
- if (this.options.range) {
1198
- var diff1 = Math.abs(this._state.percentage[0] - percentage);
1199
- var diff2 = Math.abs(this._state.percentage[1] - percentage);
1200
- this._state.dragged = (diff1 < diff2) ? 0 : 1;
1201
- } else {
1202
- this._state.dragged = 0;
1203
- }
1204
-
1205
- this._state.percentage[this._state.dragged] = percentage;
1206
- this._layout();
1207
-
1208
- if (this.touchCapable) {
1209
- document.removeEventListener("touchmove", this.mousemove, false);
1210
- document.removeEventListener("touchend", this.mouseup, false);
1211
- }
1212
-
1213
- if(this.mousemove){
1214
- document.removeEventListener("mousemove", this.mousemove, false);
1215
- }
1216
- if(this.mouseup){
1217
- document.removeEventListener("mouseup", this.mouseup, false);
1218
- }
1219
-
1220
- this.mousemove = this._mousemove.bind(this);
1221
- this.mouseup = this._mouseup.bind(this);
1222
-
1223
- if (this.touchCapable) {
1224
- // Touch: Bind touch events:
1225
- document.addEventListener("touchmove", this.mousemove, false);
1226
- document.addEventListener("touchend", this.mouseup, false);
1227
- }
1228
- // Bind mouse events:
1229
- document.addEventListener("mousemove", this.mousemove, false);
1230
- document.addEventListener("mouseup", this.mouseup, false);
1231
-
1232
- this._state.inDrag = true;
1233
- var newValue = this._calculateValue();
1234
-
1235
- this._trigger('slideStart', newValue);
1236
-
1237
- this._setDataVal(newValue);
1238
- this.setValue(newValue, false, true);
1239
-
1240
- this._pauseEvent(ev);
1241
-
1242
- if (this.options.focus) {
1243
- this._triggerFocusOnHandle(this._state.dragged);
1244
- }
1245
-
1246
- return true;
1247
- },
1248
- _triggerFocusOnHandle: function(handleIdx) {
1249
- if(handleIdx === 0) {
1250
- this.handle1.focus();
1251
- }
1252
- if(handleIdx === 1) {
1253
- this.handle2.focus();
1254
- }
1255
- },
1256
- _keydown: function(handleIdx, ev) {
1257
- if(!this._state.enabled) {
1258
- return false;
1259
- }
1260
-
1261
- var dir;
1262
- switch (ev.keyCode) {
1263
- case 37: // left
1264
- case 40: // down
1265
- dir = -1;
1266
- break;
1267
- case 39: // right
1268
- case 38: // up
1269
- dir = 1;
1270
- break;
1271
- }
1272
- if (!dir) {
1273
- return;
1274
- }
1275
-
1276
- // use natural arrow keys instead of from min to max
1277
- if (this.options.natural_arrow_keys) {
1278
- var ifVerticalAndNotReversed = (this.options.orientation === 'vertical' && !this.options.reversed);
1279
- var ifHorizontalAndReversed = (this.options.orientation === 'horizontal' && this.options.reversed);
1280
-
1281
- if (ifVerticalAndNotReversed || ifHorizontalAndReversed) {
1282
- dir = -dir;
1283
- }
1284
- }
1285
-
1286
- var val = this._state.value[handleIdx] + dir * this.options.step;
1287
- if (this.options.range) {
1288
- val = [ (!handleIdx) ? val : this._state.value[0],
1289
- ( handleIdx) ? val : this._state.value[1]];
1290
- }
1291
-
1292
- this._trigger('slideStart', val);
1293
- this._setDataVal(val);
1294
- this.setValue(val, true, true);
1295
-
1296
- this._setDataVal(val);
1297
- this._trigger('slideStop', val);
1298
- this._layout();
1299
-
1300
- this._pauseEvent(ev);
1301
-
1302
- return false;
1303
- },
1304
- _pauseEvent: function(ev) {
1305
- if(ev.stopPropagation) {
1306
- ev.stopPropagation();
1307
- }
1308
- if(ev.preventDefault) {
1309
- ev.preventDefault();
1310
- }
1311
- ev.cancelBubble=true;
1312
- ev.returnValue=false;
1313
- },
1314
- _mousemove: function(ev) {
1315
- if(!this._state.enabled) {
1316
- return false;
1317
- }
1318
-
1319
- var percentage = this._getPercentage(ev);
1320
- this._adjustPercentageForRangeSliders(percentage);
1321
- this._state.percentage[this._state.dragged] = percentage;
1322
- this._layout();
1323
-
1324
- var val = this._calculateValue(true);
1325
- this.setValue(val, true, true);
1326
-
1327
- return false;
1328
- },
1329
- _adjustPercentageForRangeSliders: function(percentage) {
1330
- if (this.options.range) {
1331
- var precision = this._getNumDigitsAfterDecimalPlace(percentage);
1332
- precision = precision ? precision - 1 : 0;
1333
- var percentageWithAdjustedPrecision = this._applyToFixedAndParseFloat(percentage, precision);
1334
- if (this._state.dragged === 0 && this._applyToFixedAndParseFloat(this._state.percentage[1], precision) < percentageWithAdjustedPrecision) {
1335
- this._state.percentage[0] = this._state.percentage[1];
1336
- this._state.dragged = 1;
1337
- } else if (this._state.dragged === 1 && this._applyToFixedAndParseFloat(this._state.percentage[0], precision) > percentageWithAdjustedPrecision) {
1338
- this._state.percentage[1] = this._state.percentage[0];
1339
- this._state.dragged = 0;
1340
- }
1341
- }
1342
- },
1343
- _mouseup: function() {
1344
- if(!this._state.enabled) {
1345
- return false;
1346
- }
1347
- if (this.touchCapable) {
1348
- // Touch: Unbind touch event handlers:
1349
- document.removeEventListener("touchmove", this.mousemove, false);
1350
- document.removeEventListener("touchend", this.mouseup, false);
1351
- }
1352
- // Unbind mouse event handlers:
1353
- document.removeEventListener("mousemove", this.mousemove, false);
1354
- document.removeEventListener("mouseup", this.mouseup, false);
1355
-
1356
- this._state.inDrag = false;
1357
- if (this._state.over === false) {
1358
- this._hideTooltip();
1359
- }
1360
- var val = this._calculateValue(true);
1361
-
1362
- this._layout();
1363
- this._setDataVal(val);
1364
- this._trigger('slideStop', val);
1365
-
1366
- return false;
1367
- },
1368
- _calculateValue: function(snapToClosestTick) {
1369
- var val;
1370
- if (this.options.range) {
1371
- val = [this.options.min,this.options.max];
1372
- if (this._state.percentage[0] !== 0){
1373
- val[0] = this._toValue(this._state.percentage[0]);
1374
- val[0] = this._applyPrecision(val[0]);
1375
- }
1376
- if (this._state.percentage[1] !== 100){
1377
- val[1] = this._toValue(this._state.percentage[1]);
1378
- val[1] = this._applyPrecision(val[1]);
1379
- }
1380
- } else {
1381
- val = this._toValue(this._state.percentage[0]);
1382
- val = parseFloat(val);
1383
- val = this._applyPrecision(val);
1384
- }
1385
-
1386
- if (snapToClosestTick) {
1387
- var min = [val, Infinity];
1388
- for (var i = 0; i < this.options.ticks.length; i++) {
1389
- var diff = Math.abs(this.options.ticks[i] - val);
1390
- if (diff <= min[1]) {
1391
- min = [this.options.ticks[i], diff];
1392
- }
1393
- }
1394
- if (min[1] <= this.options.ticks_snap_bounds) {
1395
- return min[0];
1396
- }
1397
- }
1398
-
1399
- return val;
1400
- },
1401
- _applyPrecision: function(val) {
1402
- var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step);
1403
- return this._applyToFixedAndParseFloat(val, precision);
1404
- },
1405
- _getNumDigitsAfterDecimalPlace: function(num) {
1406
- var match = (''+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
1407
- if (!match) { return 0; }
1408
- return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
1409
- },
1410
- _applyToFixedAndParseFloat: function(num, toFixedInput) {
1411
- var truncatedNum = num.toFixed(toFixedInput);
1412
- return parseFloat(truncatedNum);
1413
- },
1414
- /*
1415
- Credits to Mike Samuel for the following method!
1416
- Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number
1417
- */
1418
- _getPercentage: function(ev) {
1419
- if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) {
1420
- ev = ev.touches[0];
1421
- }
1422
-
1423
- var eventPosition = ev[this.mousePos];
1424
- var sliderOffset = this._state.offset[this.stylePos];
1425
- var distanceToSlide = eventPosition - sliderOffset;
1426
- // Calculate what percent of the length the slider handle has slid
1427
- var percentage = (distanceToSlide / this._state.size) * 100;
1428
- percentage = Math.round(percentage / this._state.percentage[2]) * this._state.percentage[2];
1429
- if (this.options.reversed) {
1430
- percentage = 100 - percentage;
1431
- }
1432
-
1433
- // Make sure the percent is within the bounds of the slider.
1434
- // 0% corresponds to the 'min' value of the slide
1435
- // 100% corresponds to the 'max' value of the slide
1436
- return Math.max(0, Math.min(100, percentage));
1437
- },
1438
- _validateInputValue: function(val) {
1439
- if (typeof val === 'number') {
1440
- return val;
1441
- } else if (Array.isArray(val)) {
1442
- this._validateArray(val);
1443
- return val;
1444
- } else {
1445
- throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(val) );
1446
- }
1447
- },
1448
- _validateArray: function(val) {
1449
- for(var i = 0; i < val.length; i++) {
1450
- var input = val[i];
1451
- if (typeof input !== 'number') { throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(input) ); }
1452
- }
1453
- },
1454
- _setDataVal: function(val) {
1455
- this.element.setAttribute('data-value', val);
1456
- this.element.setAttribute('value', val);
1457
- this.element.value = val;
1458
- },
1459
- _trigger: function(evt, val) {
1460
- val = (val || val === 0) ? val : undefined;
1461
-
1462
- var callbackFnArray = this.eventToCallbackMap[evt];
1463
- if(callbackFnArray && callbackFnArray.length) {
1464
- for(var i = 0; i < callbackFnArray.length; i++) {
1465
- var callbackFn = callbackFnArray[i];
1466
- callbackFn(val);
1467
- }
1468
- }
1469
-
1470
- /* If JQuery exists, trigger JQuery events */
1471
- if($) {
1472
- this._triggerJQueryEvent(evt, val);
1473
- }
1474
- },
1475
- _triggerJQueryEvent: function(evt, val) {
1476
- var eventData = {
1477
- type: evt,
1478
- value: val
1479
- };
1480
- this.$element.trigger(eventData);
1481
- this.$sliderElem.trigger(eventData);
1482
- },
1483
- _unbindJQueryEventHandlers: function() {
1484
- this.$element.off();
1485
- this.$sliderElem.off();
1486
- },
1487
- _setText: function(element, text) {
1488
- if(typeof element.innerText !== "undefined") {
1489
- element.innerText = text;
1490
- } else if(typeof element.textContent !== "undefined") {
1491
- element.textContent = text;
1492
- }
1493
- },
1494
- _removeClass: function(element, classString) {
1495
- var classes = classString.split(" ");
1496
- var newClasses = element.className;
1497
-
1498
- for(var i = 0; i < classes.length; i++) {
1499
- var classTag = classes[i];
1500
- var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
1501
- newClasses = newClasses.replace(regex, " ");
1502
- }
1503
-
1504
- element.className = newClasses.trim();
1505
- },
1506
- _addClass: function(element, classString) {
1507
- var classes = classString.split(" ");
1508
- var newClasses = element.className;
1509
-
1510
- for(var i = 0; i < classes.length; i++) {
1511
- var classTag = classes[i];
1512
- var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
1513
- var ifClassExists = regex.test(newClasses);
1514
-
1515
- if(!ifClassExists) {
1516
- newClasses += " " + classTag;
1517
- }
1518
- }
1519
-
1520
- element.className = newClasses.trim();
1521
- },
1522
- _offsetLeft: function(obj){
1523
- return obj.getBoundingClientRect().left;
1524
- },
1525
- _offsetTop: function(obj){
1526
- var offsetTop = obj.offsetTop;
1527
- while((obj = obj.offsetParent) && !isNaN(obj.offsetTop)){
1528
- offsetTop += obj.offsetTop;
1529
- }
1530
- return offsetTop;
1531
- },
1532
- _offset: function (obj) {
1533
- return {
1534
- left: this._offsetLeft(obj),
1535
- top: this._offsetTop(obj)
1536
- };
1537
- },
1538
- _css: function(elementRef, styleName, value) {
1539
- if ($) {
1540
- $.style(elementRef, styleName, value);
1541
- } else {
1542
- var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) {
1543
- return letter.toUpperCase();
1544
- });
1545
- elementRef.style[style] = value;
1546
- }
1547
- },
1548
- _toValue: function(percentage) {
1549
- return this.options.scale.toValue.apply(this, [percentage]);
1550
- },
1551
- _toPercentage: function(value) {
1552
- return this.options.scale.toPercentage.apply(this, [value]);
1553
- },
1554
- _setTooltipPosition: function(){
1555
- var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max];
1556
- if (this.options.orientation === 'vertical'){
1557
- var tooltipPos = this.options.tooltip_position || 'right';
1558
- var oppositeSide = (tooltipPos === 'left') ? 'right' : 'left';
1559
- tooltips.forEach(function(tooltip){
1560
- this._addClass(tooltip, tooltipPos);
1561
- tooltip.style[oppositeSide] = '100%';
1562
- }.bind(this));
1563
- } else if(this.options.tooltip_position === 'bottom') {
1564
- tooltips.forEach(function(tooltip){
1565
- this._addClass(tooltip, 'bottom');
1566
- tooltip.style.top = 22 + 'px';
1567
- }.bind(this));
1568
- } else {
1569
- tooltips.forEach(function(tooltip){
1570
- this._addClass(tooltip, 'top');
1571
- tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px';
1572
- }.bind(this));
1573
- }
1574
- }
1575
- };
1576
-
1577
- /*********************************
1578
-
1579
- Attach to global namespace
1580
-
1581
- *********************************/
1582
- if($) {
1583
- var namespace = $.fn.slider ? 'bootstrapSlider' : 'slider';
1584
- $.bridget(namespace, Slider);
1585
- }
1586
-
1587
- })( $ );
1588
-
1589
- return Slider;
1590
- }));
1
+ Not Found