pghero 2.3.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pghero might be problematic. Click here for more details.

Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +85 -54
  3. data/README.md +20 -8
  4. data/app/assets/javascripts/pghero/Chart.bundle.js +16260 -15580
  5. data/app/assets/javascripts/pghero/application.js +8 -7
  6. data/app/assets/javascripts/pghero/chartkick.js +1973 -1325
  7. data/app/assets/javascripts/pghero/highlight.pack.js +2 -2
  8. data/app/assets/javascripts/pghero/jquery.js +3605 -4015
  9. data/app/assets/javascripts/pghero/nouislider.js +2479 -0
  10. data/app/assets/stylesheets/pghero/application.css +1 -1
  11. data/app/assets/stylesheets/pghero/nouislider.css +299 -0
  12. data/app/controllers/pg_hero/home_controller.rb +94 -35
  13. data/app/helpers/pg_hero/home_helper.rb +11 -0
  14. data/app/views/pg_hero/home/_live_queries_table.html.erb +14 -2
  15. data/app/views/pg_hero/home/connections.html.erb +9 -0
  16. data/app/views/pg_hero/home/index.html.erb +49 -10
  17. data/app/views/pg_hero/home/live_queries.html.erb +1 -1
  18. data/app/views/pg_hero/home/maintenance.html.erb +16 -2
  19. data/app/views/pg_hero/home/relation_space.html.erb +2 -2
  20. data/app/views/pg_hero/home/show_query.html.erb +3 -3
  21. data/app/views/pg_hero/home/space.html.erb +3 -3
  22. data/app/views/pg_hero/home/system.html.erb +4 -4
  23. data/app/views/pg_hero/home/tune.html.erb +2 -1
  24. data/lib/generators/pghero/templates/config.yml.tt +21 -1
  25. data/lib/pghero.rb +63 -15
  26. data/lib/pghero/database.rb +101 -17
  27. data/lib/pghero/methods/basic.rb +28 -7
  28. data/lib/pghero/methods/connections.rb +35 -0
  29. data/lib/pghero/methods/constraints.rb +30 -0
  30. data/lib/pghero/methods/indexes.rb +1 -1
  31. data/lib/pghero/methods/maintenance.rb +3 -1
  32. data/lib/pghero/methods/queries.rb +6 -2
  33. data/lib/pghero/methods/query_stats.rb +12 -3
  34. data/lib/pghero/methods/suggested_indexes.rb +1 -1
  35. data/lib/pghero/methods/system.rb +219 -23
  36. data/lib/pghero/stats.rb +1 -1
  37. data/lib/pghero/version.rb +1 -1
  38. metadata +6 -5
  39. data/app/assets/javascripts/pghero/jquery.nouislider.min.js +0 -31
  40. data/app/assets/stylesheets/pghero/jquery.nouislider.css +0 -165
@@ -0,0 +1,2479 @@
1
+ /*! nouislider - 14.0.3 - 10/10/2019 */
2
+ (function(factory) {
3
+ if (typeof define === "function" && define.amd) {
4
+ // AMD. Register as an anonymous module.
5
+ define([], factory);
6
+ } else if (typeof exports === "object") {
7
+ // Node/CommonJS
8
+ module.exports = factory();
9
+ } else {
10
+ // Browser globals
11
+ window.noUiSlider = factory();
12
+ }
13
+ })(function() {
14
+ "use strict";
15
+
16
+ var VERSION = "14.0.3";
17
+
18
+ //region Helper Methods
19
+
20
+ function isValidFormatter(entry) {
21
+ return typeof entry === "object" && typeof entry.to === "function" && typeof entry.from === "function";
22
+ }
23
+
24
+ function removeElement(el) {
25
+ el.parentElement.removeChild(el);
26
+ }
27
+
28
+ function isSet(value) {
29
+ return value !== null && value !== undefined;
30
+ }
31
+
32
+ // Bindable version
33
+ function preventDefault(e) {
34
+ e.preventDefault();
35
+ }
36
+
37
+ // Removes duplicates from an array.
38
+ function unique(array) {
39
+ return array.filter(function(a) {
40
+ return !this[a] ? (this[a] = true) : false;
41
+ }, {});
42
+ }
43
+
44
+ // Round a value to the closest 'to'.
45
+ function closest(value, to) {
46
+ return Math.round(value / to) * to;
47
+ }
48
+
49
+ // Current position of an element relative to the document.
50
+ function offset(elem, orientation) {
51
+ var rect = elem.getBoundingClientRect();
52
+ var doc = elem.ownerDocument;
53
+ var docElem = doc.documentElement;
54
+ var pageOffset = getPageOffset(doc);
55
+
56
+ // getBoundingClientRect contains left scroll in Chrome on Android.
57
+ // I haven't found a feature detection that proves this. Worst case
58
+ // scenario on mis-match: the 'tap' feature on horizontal sliders breaks.
59
+ if (/webkit.*Chrome.*Mobile/i.test(navigator.userAgent)) {
60
+ pageOffset.x = 0;
61
+ }
62
+
63
+ return orientation
64
+ ? rect.top + pageOffset.y - docElem.clientTop
65
+ : rect.left + pageOffset.x - docElem.clientLeft;
66
+ }
67
+
68
+ // Checks whether a value is numerical.
69
+ function isNumeric(a) {
70
+ return typeof a === "number" && !isNaN(a) && isFinite(a);
71
+ }
72
+
73
+ // Sets a class and removes it after [duration] ms.
74
+ function addClassFor(element, className, duration) {
75
+ if (duration > 0) {
76
+ addClass(element, className);
77
+ setTimeout(function() {
78
+ removeClass(element, className);
79
+ }, duration);
80
+ }
81
+ }
82
+
83
+ // Limits a value to 0 - 100
84
+ function limit(a) {
85
+ return Math.max(Math.min(a, 100), 0);
86
+ }
87
+
88
+ // Wraps a variable as an array, if it isn't one yet.
89
+ // Note that an input array is returned by reference!
90
+ function asArray(a) {
91
+ return Array.isArray(a) ? a : [a];
92
+ }
93
+
94
+ // Counts decimals
95
+ function countDecimals(numStr) {
96
+ numStr = String(numStr);
97
+ var pieces = numStr.split(".");
98
+ return pieces.length > 1 ? pieces[1].length : 0;
99
+ }
100
+
101
+ // http://youmightnotneedjquery.com/#add_class
102
+ function addClass(el, className) {
103
+ if (el.classList) {
104
+ el.classList.add(className);
105
+ } else {
106
+ el.className += " " + className;
107
+ }
108
+ }
109
+
110
+ // http://youmightnotneedjquery.com/#remove_class
111
+ function removeClass(el, className) {
112
+ if (el.classList) {
113
+ el.classList.remove(className);
114
+ } else {
115
+ el.className = el.className.replace(
116
+ new RegExp("(^|\\b)" + className.split(" ").join("|") + "(\\b|$)", "gi"),
117
+ " "
118
+ );
119
+ }
120
+ }
121
+
122
+ // https://plainjs.com/javascript/attributes/adding-removing-and-testing-for-classes-9/
123
+ function hasClass(el, className) {
124
+ return el.classList
125
+ ? el.classList.contains(className)
126
+ : new RegExp("\\b" + className + "\\b").test(el.className);
127
+ }
128
+
129
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY#Notes
130
+ function getPageOffset(doc) {
131
+ var supportPageOffset = window.pageXOffset !== undefined;
132
+ var isCSS1Compat = (doc.compatMode || "") === "CSS1Compat";
133
+ var x = supportPageOffset
134
+ ? window.pageXOffset
135
+ : isCSS1Compat
136
+ ? doc.documentElement.scrollLeft
137
+ : doc.body.scrollLeft;
138
+ var y = supportPageOffset
139
+ ? window.pageYOffset
140
+ : isCSS1Compat
141
+ ? doc.documentElement.scrollTop
142
+ : doc.body.scrollTop;
143
+
144
+ return {
145
+ x: x,
146
+ y: y
147
+ };
148
+ }
149
+
150
+ // we provide a function to compute constants instead
151
+ // of accessing window.* as soon as the module needs it
152
+ // so that we do not compute anything if not needed
153
+ function getActions() {
154
+ // Determine the events to bind. IE11 implements pointerEvents without
155
+ // a prefix, which breaks compatibility with the IE10 implementation.
156
+ return window.navigator.pointerEnabled
157
+ ? {
158
+ start: "pointerdown",
159
+ move: "pointermove",
160
+ end: "pointerup"
161
+ }
162
+ : window.navigator.msPointerEnabled
163
+ ? {
164
+ start: "MSPointerDown",
165
+ move: "MSPointerMove",
166
+ end: "MSPointerUp"
167
+ }
168
+ : {
169
+ start: "mousedown touchstart",
170
+ move: "mousemove touchmove",
171
+ end: "mouseup touchend"
172
+ };
173
+ }
174
+
175
+ // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
176
+ // Issue #785
177
+ function getSupportsPassive() {
178
+ var supportsPassive = false;
179
+
180
+ /* eslint-disable */
181
+ try {
182
+ var opts = Object.defineProperty({}, "passive", {
183
+ get: function() {
184
+ supportsPassive = true;
185
+ }
186
+ });
187
+
188
+ window.addEventListener("test", null, opts);
189
+ } catch (e) {}
190
+ /* eslint-enable */
191
+
192
+ return supportsPassive;
193
+ }
194
+
195
+ function getSupportsTouchActionNone() {
196
+ return window.CSS && CSS.supports && CSS.supports("touch-action", "none");
197
+ }
198
+
199
+ //endregion
200
+
201
+ //region Range Calculation
202
+
203
+ // Determine the size of a sub-range in relation to a full range.
204
+ function subRangeRatio(pa, pb) {
205
+ return 100 / (pb - pa);
206
+ }
207
+
208
+ // (percentage) How many percent is this value of this range?
209
+ function fromPercentage(range, value) {
210
+ return (value * 100) / (range[1] - range[0]);
211
+ }
212
+
213
+ // (percentage) Where is this value on this range?
214
+ function toPercentage(range, value) {
215
+ return fromPercentage(range, range[0] < 0 ? value + Math.abs(range[0]) : value - range[0]);
216
+ }
217
+
218
+ // (value) How much is this percentage on this range?
219
+ function isPercentage(range, value) {
220
+ return (value * (range[1] - range[0])) / 100 + range[0];
221
+ }
222
+
223
+ function getJ(value, arr) {
224
+ var j = 1;
225
+
226
+ while (value >= arr[j]) {
227
+ j += 1;
228
+ }
229
+
230
+ return j;
231
+ }
232
+
233
+ // (percentage) Input a value, find where, on a scale of 0-100, it applies.
234
+ function toStepping(xVal, xPct, value) {
235
+ if (value >= xVal.slice(-1)[0]) {
236
+ return 100;
237
+ }
238
+
239
+ var j = getJ(value, xVal);
240
+ var va = xVal[j - 1];
241
+ var vb = xVal[j];
242
+ var pa = xPct[j - 1];
243
+ var pb = xPct[j];
244
+
245
+ return pa + toPercentage([va, vb], value) / subRangeRatio(pa, pb);
246
+ }
247
+
248
+ // (value) Input a percentage, find where it is on the specified range.
249
+ function fromStepping(xVal, xPct, value) {
250
+ // There is no range group that fits 100
251
+ if (value >= 100) {
252
+ return xVal.slice(-1)[0];
253
+ }
254
+
255
+ var j = getJ(value, xPct);
256
+ var va = xVal[j - 1];
257
+ var vb = xVal[j];
258
+ var pa = xPct[j - 1];
259
+ var pb = xPct[j];
260
+
261
+ return isPercentage([va, vb], (value - pa) * subRangeRatio(pa, pb));
262
+ }
263
+
264
+ // (percentage) Get the step that applies at a certain value.
265
+ function getStep(xPct, xSteps, snap, value) {
266
+ if (value === 100) {
267
+ return value;
268
+ }
269
+
270
+ var j = getJ(value, xPct);
271
+ var a = xPct[j - 1];
272
+ var b = xPct[j];
273
+
274
+ // If 'snap' is set, steps are used as fixed points on the slider.
275
+ if (snap) {
276
+ // Find the closest position, a or b.
277
+ if (value - a > (b - a) / 2) {
278
+ return b;
279
+ }
280
+
281
+ return a;
282
+ }
283
+
284
+ if (!xSteps[j - 1]) {
285
+ return value;
286
+ }
287
+
288
+ return xPct[j - 1] + closest(value - xPct[j - 1], xSteps[j - 1]);
289
+ }
290
+
291
+ function handleEntryPoint(index, value, that) {
292
+ var percentage;
293
+
294
+ // Wrap numerical input in an array.
295
+ if (typeof value === "number") {
296
+ value = [value];
297
+ }
298
+
299
+ // Reject any invalid input, by testing whether value is an array.
300
+ if (!Array.isArray(value)) {
301
+ throw new Error("noUiSlider (" + VERSION + "): 'range' contains invalid value.");
302
+ }
303
+
304
+ // Covert min/max syntax to 0 and 100.
305
+ if (index === "min") {
306
+ percentage = 0;
307
+ } else if (index === "max") {
308
+ percentage = 100;
309
+ } else {
310
+ percentage = parseFloat(index);
311
+ }
312
+
313
+ // Check for correct input.
314
+ if (!isNumeric(percentage) || !isNumeric(value[0])) {
315
+ throw new Error("noUiSlider (" + VERSION + "): 'range' value isn't numeric.");
316
+ }
317
+
318
+ // Store values.
319
+ that.xPct.push(percentage);
320
+ that.xVal.push(value[0]);
321
+
322
+ // NaN will evaluate to false too, but to keep
323
+ // logging clear, set step explicitly. Make sure
324
+ // not to override the 'step' setting with false.
325
+ if (!percentage) {
326
+ if (!isNaN(value[1])) {
327
+ that.xSteps[0] = value[1];
328
+ }
329
+ } else {
330
+ that.xSteps.push(isNaN(value[1]) ? false : value[1]);
331
+ }
332
+
333
+ that.xHighestCompleteStep.push(0);
334
+ }
335
+
336
+ function handleStepPoint(i, n, that) {
337
+ // Ignore 'false' stepping.
338
+ if (!n) {
339
+ return;
340
+ }
341
+
342
+ // Step over zero-length ranges (#948);
343
+ if (that.xVal[i] === that.xVal[i + 1]) {
344
+ that.xSteps[i] = that.xHighestCompleteStep[i] = that.xVal[i];
345
+
346
+ return;
347
+ }
348
+
349
+ // Factor to range ratio
350
+ that.xSteps[i] =
351
+ fromPercentage([that.xVal[i], that.xVal[i + 1]], n) / subRangeRatio(that.xPct[i], that.xPct[i + 1]);
352
+
353
+ var totalSteps = (that.xVal[i + 1] - that.xVal[i]) / that.xNumSteps[i];
354
+ var highestStep = Math.ceil(Number(totalSteps.toFixed(3)) - 1);
355
+ var step = that.xVal[i] + that.xNumSteps[i] * highestStep;
356
+
357
+ that.xHighestCompleteStep[i] = step;
358
+ }
359
+
360
+ //endregion
361
+
362
+ //region Spectrum
363
+
364
+ function Spectrum(entry, snap, singleStep) {
365
+ this.xPct = [];
366
+ this.xVal = [];
367
+ this.xSteps = [singleStep || false];
368
+ this.xNumSteps = [false];
369
+ this.xHighestCompleteStep = [];
370
+
371
+ this.snap = snap;
372
+
373
+ var index;
374
+ var ordered = []; // [0, 'min'], [1, '50%'], [2, 'max']
375
+
376
+ // Map the object keys to an array.
377
+ for (index in entry) {
378
+ if (entry.hasOwnProperty(index)) {
379
+ ordered.push([entry[index], index]);
380
+ }
381
+ }
382
+
383
+ // Sort all entries by value (numeric sort).
384
+ if (ordered.length && typeof ordered[0][0] === "object") {
385
+ ordered.sort(function(a, b) {
386
+ return a[0][0] - b[0][0];
387
+ });
388
+ } else {
389
+ ordered.sort(function(a, b) {
390
+ return a[0] - b[0];
391
+ });
392
+ }
393
+
394
+ // Convert all entries to subranges.
395
+ for (index = 0; index < ordered.length; index++) {
396
+ handleEntryPoint(ordered[index][1], ordered[index][0], this);
397
+ }
398
+
399
+ // Store the actual step values.
400
+ // xSteps is sorted in the same order as xPct and xVal.
401
+ this.xNumSteps = this.xSteps.slice(0);
402
+
403
+ // Convert all numeric steps to the percentage of the subrange they represent.
404
+ for (index = 0; index < this.xNumSteps.length; index++) {
405
+ handleStepPoint(index, this.xNumSteps[index], this);
406
+ }
407
+ }
408
+
409
+ Spectrum.prototype.getMargin = function(value) {
410
+ var step = this.xNumSteps[0];
411
+
412
+ if (step && (value / step) % 1 !== 0) {
413
+ throw new Error("noUiSlider (" + VERSION + "): 'limit', 'margin' and 'padding' must be divisible by step.");
414
+ }
415
+
416
+ return this.xPct.length === 2 ? fromPercentage(this.xVal, value) : false;
417
+ };
418
+
419
+ Spectrum.prototype.toStepping = function(value) {
420
+ value = toStepping(this.xVal, this.xPct, value);
421
+
422
+ return value;
423
+ };
424
+
425
+ Spectrum.prototype.fromStepping = function(value) {
426
+ return fromStepping(this.xVal, this.xPct, value);
427
+ };
428
+
429
+ Spectrum.prototype.getStep = function(value) {
430
+ value = getStep(this.xPct, this.xSteps, this.snap, value);
431
+
432
+ return value;
433
+ };
434
+
435
+ Spectrum.prototype.getDefaultStep = function(value, isDown, size) {
436
+ var j = getJ(value, this.xPct);
437
+
438
+ // When at the top or stepping down, look at the previous sub-range
439
+ if (value === 100 || (isDown && value === this.xPct[j - 1])) {
440
+ j = Math.max(j - 1, 1);
441
+ }
442
+
443
+ return (this.xVal[j] - this.xVal[j - 1]) / size;
444
+ };
445
+
446
+ Spectrum.prototype.getNearbySteps = function(value) {
447
+ var j = getJ(value, this.xPct);
448
+
449
+ return {
450
+ stepBefore: {
451
+ startValue: this.xVal[j - 2],
452
+ step: this.xNumSteps[j - 2],
453
+ highestStep: this.xHighestCompleteStep[j - 2]
454
+ },
455
+ thisStep: {
456
+ startValue: this.xVal[j - 1],
457
+ step: this.xNumSteps[j - 1],
458
+ highestStep: this.xHighestCompleteStep[j - 1]
459
+ },
460
+ stepAfter: {
461
+ startValue: this.xVal[j],
462
+ step: this.xNumSteps[j],
463
+ highestStep: this.xHighestCompleteStep[j]
464
+ }
465
+ };
466
+ };
467
+
468
+ Spectrum.prototype.countStepDecimals = function() {
469
+ var stepDecimals = this.xNumSteps.map(countDecimals);
470
+ return Math.max.apply(null, stepDecimals);
471
+ };
472
+
473
+ // Outside testing
474
+ Spectrum.prototype.convert = function(value) {
475
+ return this.getStep(this.toStepping(value));
476
+ };
477
+
478
+ //endregion
479
+
480
+ //region Options
481
+
482
+ /* Every input option is tested and parsed. This'll prevent
483
+ endless validation in internal methods. These tests are
484
+ structured with an item for every option available. An
485
+ option can be marked as required by setting the 'r' flag.
486
+ The testing function is provided with three arguments:
487
+ - The provided value for the option;
488
+ - A reference to the options object;
489
+ - The name for the option;
490
+
491
+ The testing function returns false when an error is detected,
492
+ or true when everything is OK. It can also modify the option
493
+ object, to make sure all values can be correctly looped elsewhere. */
494
+
495
+ var defaultFormatter = {
496
+ to: function(value) {
497
+ return value !== undefined && value.toFixed(2);
498
+ },
499
+ from: Number
500
+ };
501
+
502
+ function validateFormat(entry) {
503
+ // Any object with a to and from method is supported.
504
+ if (isValidFormatter(entry)) {
505
+ return true;
506
+ }
507
+
508
+ throw new Error("noUiSlider (" + VERSION + "): 'format' requires 'to' and 'from' methods.");
509
+ }
510
+
511
+ function testStep(parsed, entry) {
512
+ if (!isNumeric(entry)) {
513
+ throw new Error("noUiSlider (" + VERSION + "): 'step' is not numeric.");
514
+ }
515
+
516
+ // The step option can still be used to set stepping
517
+ // for linear sliders. Overwritten if set in 'range'.
518
+ parsed.singleStep = entry;
519
+ }
520
+
521
+ function testRange(parsed, entry) {
522
+ // Filter incorrect input.
523
+ if (typeof entry !== "object" || Array.isArray(entry)) {
524
+ throw new Error("noUiSlider (" + VERSION + "): 'range' is not an object.");
525
+ }
526
+
527
+ // Catch missing start or end.
528
+ if (entry.min === undefined || entry.max === undefined) {
529
+ throw new Error("noUiSlider (" + VERSION + "): Missing 'min' or 'max' in 'range'.");
530
+ }
531
+
532
+ // Catch equal start or end.
533
+ if (entry.min === entry.max) {
534
+ throw new Error("noUiSlider (" + VERSION + "): 'range' 'min' and 'max' cannot be equal.");
535
+ }
536
+
537
+ parsed.spectrum = new Spectrum(entry, parsed.snap, parsed.singleStep);
538
+ }
539
+
540
+ function testStart(parsed, entry) {
541
+ entry = asArray(entry);
542
+
543
+ // Validate input. Values aren't tested, as the public .val method
544
+ // will always provide a valid location.
545
+ if (!Array.isArray(entry) || !entry.length) {
546
+ throw new Error("noUiSlider (" + VERSION + "): 'start' option is incorrect.");
547
+ }
548
+
549
+ // Store the number of handles.
550
+ parsed.handles = entry.length;
551
+
552
+ // When the slider is initialized, the .val method will
553
+ // be called with the start options.
554
+ parsed.start = entry;
555
+ }
556
+
557
+ function testSnap(parsed, entry) {
558
+ // Enforce 100% stepping within subranges.
559
+ parsed.snap = entry;
560
+
561
+ if (typeof entry !== "boolean") {
562
+ throw new Error("noUiSlider (" + VERSION + "): 'snap' option must be a boolean.");
563
+ }
564
+ }
565
+
566
+ function testAnimate(parsed, entry) {
567
+ // Enforce 100% stepping within subranges.
568
+ parsed.animate = entry;
569
+
570
+ if (typeof entry !== "boolean") {
571
+ throw new Error("noUiSlider (" + VERSION + "): 'animate' option must be a boolean.");
572
+ }
573
+ }
574
+
575
+ function testAnimationDuration(parsed, entry) {
576
+ parsed.animationDuration = entry;
577
+
578
+ if (typeof entry !== "number") {
579
+ throw new Error("noUiSlider (" + VERSION + "): 'animationDuration' option must be a number.");
580
+ }
581
+ }
582
+
583
+ function testConnect(parsed, entry) {
584
+ var connect = [false];
585
+ var i;
586
+
587
+ // Map legacy options
588
+ if (entry === "lower") {
589
+ entry = [true, false];
590
+ } else if (entry === "upper") {
591
+ entry = [false, true];
592
+ }
593
+
594
+ // Handle boolean options
595
+ if (entry === true || entry === false) {
596
+ for (i = 1; i < parsed.handles; i++) {
597
+ connect.push(entry);
598
+ }
599
+
600
+ connect.push(false);
601
+ }
602
+
603
+ // Reject invalid input
604
+ else if (!Array.isArray(entry) || !entry.length || entry.length !== parsed.handles + 1) {
605
+ throw new Error("noUiSlider (" + VERSION + "): 'connect' option doesn't match handle count.");
606
+ } else {
607
+ connect = entry;
608
+ }
609
+
610
+ parsed.connect = connect;
611
+ }
612
+
613
+ function testOrientation(parsed, entry) {
614
+ // Set orientation to an a numerical value for easy
615
+ // array selection.
616
+ switch (entry) {
617
+ case "horizontal":
618
+ parsed.ort = 0;
619
+ break;
620
+ case "vertical":
621
+ parsed.ort = 1;
622
+ break;
623
+ default:
624
+ throw new Error("noUiSlider (" + VERSION + "): 'orientation' option is invalid.");
625
+ }
626
+ }
627
+
628
+ function testMargin(parsed, entry) {
629
+ if (!isNumeric(entry)) {
630
+ throw new Error("noUiSlider (" + VERSION + "): 'margin' option must be numeric.");
631
+ }
632
+
633
+ // Issue #582
634
+ if (entry === 0) {
635
+ return;
636
+ }
637
+
638
+ parsed.margin = parsed.spectrum.getMargin(entry);
639
+
640
+ if (!parsed.margin) {
641
+ throw new Error("noUiSlider (" + VERSION + "): 'margin' option is only supported on linear sliders.");
642
+ }
643
+ }
644
+
645
+ function testLimit(parsed, entry) {
646
+ if (!isNumeric(entry)) {
647
+ throw new Error("noUiSlider (" + VERSION + "): 'limit' option must be numeric.");
648
+ }
649
+
650
+ parsed.limit = parsed.spectrum.getMargin(entry);
651
+
652
+ if (!parsed.limit || parsed.handles < 2) {
653
+ throw new Error(
654
+ "noUiSlider (" +
655
+ VERSION +
656
+ "): 'limit' option is only supported on linear sliders with 2 or more handles."
657
+ );
658
+ }
659
+ }
660
+
661
+ function testPadding(parsed, entry) {
662
+ if (!isNumeric(entry) && !Array.isArray(entry)) {
663
+ throw new Error(
664
+ "noUiSlider (" + VERSION + "): 'padding' option must be numeric or array of exactly 2 numbers."
665
+ );
666
+ }
667
+
668
+ if (Array.isArray(entry) && !(entry.length === 2 || isNumeric(entry[0]) || isNumeric(entry[1]))) {
669
+ throw new Error(
670
+ "noUiSlider (" + VERSION + "): 'padding' option must be numeric or array of exactly 2 numbers."
671
+ );
672
+ }
673
+
674
+ if (entry === 0) {
675
+ return;
676
+ }
677
+
678
+ if (!Array.isArray(entry)) {
679
+ entry = [entry, entry];
680
+ }
681
+
682
+ // 'getMargin' returns false for invalid values.
683
+ parsed.padding = [parsed.spectrum.getMargin(entry[0]), parsed.spectrum.getMargin(entry[1])];
684
+
685
+ if (parsed.padding[0] === false || parsed.padding[1] === false) {
686
+ throw new Error("noUiSlider (" + VERSION + "): 'padding' option is only supported on linear sliders.");
687
+ }
688
+
689
+ if (parsed.padding[0] < 0 || parsed.padding[1] < 0) {
690
+ throw new Error("noUiSlider (" + VERSION + "): 'padding' option must be a positive number(s).");
691
+ }
692
+
693
+ if (parsed.padding[0] + parsed.padding[1] > 100) {
694
+ throw new Error("noUiSlider (" + VERSION + "): 'padding' option must not exceed 100% of the range.");
695
+ }
696
+ }
697
+
698
+ function testDirection(parsed, entry) {
699
+ // Set direction as a numerical value for easy parsing.
700
+ // Invert connection for RTL sliders, so that the proper
701
+ // handles get the connect/background classes.
702
+ switch (entry) {
703
+ case "ltr":
704
+ parsed.dir = 0;
705
+ break;
706
+ case "rtl":
707
+ parsed.dir = 1;
708
+ break;
709
+ default:
710
+ throw new Error("noUiSlider (" + VERSION + "): 'direction' option was not recognized.");
711
+ }
712
+ }
713
+
714
+ function testBehaviour(parsed, entry) {
715
+ // Make sure the input is a string.
716
+ if (typeof entry !== "string") {
717
+ throw new Error("noUiSlider (" + VERSION + "): 'behaviour' must be a string containing options.");
718
+ }
719
+
720
+ // Check if the string contains any keywords.
721
+ // None are required.
722
+ var tap = entry.indexOf("tap") >= 0;
723
+ var drag = entry.indexOf("drag") >= 0;
724
+ var fixed = entry.indexOf("fixed") >= 0;
725
+ var snap = entry.indexOf("snap") >= 0;
726
+ var hover = entry.indexOf("hover") >= 0;
727
+ var unconstrained = entry.indexOf("unconstrained") >= 0;
728
+
729
+ if (fixed) {
730
+ if (parsed.handles !== 2) {
731
+ throw new Error("noUiSlider (" + VERSION + "): 'fixed' behaviour must be used with 2 handles");
732
+ }
733
+
734
+ // Use margin to enforce fixed state
735
+ testMargin(parsed, parsed.start[1] - parsed.start[0]);
736
+ }
737
+
738
+ if (unconstrained && (parsed.margin || parsed.limit)) {
739
+ throw new Error(
740
+ "noUiSlider (" + VERSION + "): 'unconstrained' behaviour cannot be used with margin or limit"
741
+ );
742
+ }
743
+
744
+ parsed.events = {
745
+ tap: tap || snap,
746
+ drag: drag,
747
+ fixed: fixed,
748
+ snap: snap,
749
+ hover: hover,
750
+ unconstrained: unconstrained
751
+ };
752
+ }
753
+
754
+ function testTooltips(parsed, entry) {
755
+ if (entry === false) {
756
+ return;
757
+ }
758
+
759
+ if (entry === true) {
760
+ parsed.tooltips = [];
761
+
762
+ for (var i = 0; i < parsed.handles; i++) {
763
+ parsed.tooltips.push(true);
764
+ }
765
+ } else {
766
+ parsed.tooltips = asArray(entry);
767
+
768
+ if (parsed.tooltips.length !== parsed.handles) {
769
+ throw new Error("noUiSlider (" + VERSION + "): must pass a formatter for all handles.");
770
+ }
771
+
772
+ parsed.tooltips.forEach(function(formatter) {
773
+ if (
774
+ typeof formatter !== "boolean" &&
775
+ (typeof formatter !== "object" || typeof formatter.to !== "function")
776
+ ) {
777
+ throw new Error("noUiSlider (" + VERSION + "): 'tooltips' must be passed a formatter or 'false'.");
778
+ }
779
+ });
780
+ }
781
+ }
782
+
783
+ function testAriaFormat(parsed, entry) {
784
+ parsed.ariaFormat = entry;
785
+ validateFormat(entry);
786
+ }
787
+
788
+ function testFormat(parsed, entry) {
789
+ parsed.format = entry;
790
+ validateFormat(entry);
791
+ }
792
+
793
+ function testKeyboardSupport(parsed, entry) {
794
+ parsed.keyboardSupport = entry;
795
+
796
+ if (typeof entry !== "boolean") {
797
+ throw new Error("noUiSlider (" + VERSION + "): 'keyboardSupport' option must be a boolean.");
798
+ }
799
+ }
800
+
801
+ function testDocumentElement(parsed, entry) {
802
+ // This is an advanced option. Passed values are used without validation.
803
+ parsed.documentElement = entry;
804
+ }
805
+
806
+ function testCssPrefix(parsed, entry) {
807
+ if (typeof entry !== "string" && entry !== false) {
808
+ throw new Error("noUiSlider (" + VERSION + "): 'cssPrefix' must be a string or `false`.");
809
+ }
810
+
811
+ parsed.cssPrefix = entry;
812
+ }
813
+
814
+ function testCssClasses(parsed, entry) {
815
+ if (typeof entry !== "object") {
816
+ throw new Error("noUiSlider (" + VERSION + "): 'cssClasses' must be an object.");
817
+ }
818
+
819
+ if (typeof parsed.cssPrefix === "string") {
820
+ parsed.cssClasses = {};
821
+
822
+ for (var key in entry) {
823
+ if (!entry.hasOwnProperty(key)) {
824
+ continue;
825
+ }
826
+
827
+ parsed.cssClasses[key] = parsed.cssPrefix + entry[key];
828
+ }
829
+ } else {
830
+ parsed.cssClasses = entry;
831
+ }
832
+ }
833
+
834
+ // Test all developer settings and parse to assumption-safe values.
835
+ function testOptions(options) {
836
+ // To prove a fix for #537, freeze options here.
837
+ // If the object is modified, an error will be thrown.
838
+ // Object.freeze(options);
839
+
840
+ var parsed = {
841
+ margin: 0,
842
+ limit: 0,
843
+ padding: 0,
844
+ animate: true,
845
+ animationDuration: 300,
846
+ ariaFormat: defaultFormatter,
847
+ format: defaultFormatter
848
+ };
849
+
850
+ // Tests are executed in the order they are presented here.
851
+ var tests = {
852
+ step: { r: false, t: testStep },
853
+ start: { r: true, t: testStart },
854
+ connect: { r: true, t: testConnect },
855
+ direction: { r: true, t: testDirection },
856
+ snap: { r: false, t: testSnap },
857
+ animate: { r: false, t: testAnimate },
858
+ animationDuration: { r: false, t: testAnimationDuration },
859
+ range: { r: true, t: testRange },
860
+ orientation: { r: false, t: testOrientation },
861
+ margin: { r: false, t: testMargin },
862
+ limit: { r: false, t: testLimit },
863
+ padding: { r: false, t: testPadding },
864
+ behaviour: { r: true, t: testBehaviour },
865
+ ariaFormat: { r: false, t: testAriaFormat },
866
+ format: { r: false, t: testFormat },
867
+ tooltips: { r: false, t: testTooltips },
868
+ keyboardSupport: { r: true, t: testKeyboardSupport },
869
+ documentElement: { r: false, t: testDocumentElement },
870
+ cssPrefix: { r: true, t: testCssPrefix },
871
+ cssClasses: { r: true, t: testCssClasses }
872
+ };
873
+
874
+ var defaults = {
875
+ connect: false,
876
+ direction: "ltr",
877
+ behaviour: "tap",
878
+ orientation: "horizontal",
879
+ keyboardSupport: true,
880
+ cssPrefix: "noUi-",
881
+ cssClasses: {
882
+ target: "target",
883
+ base: "base",
884
+ origin: "origin",
885
+ handle: "handle",
886
+ handleLower: "handle-lower",
887
+ handleUpper: "handle-upper",
888
+ touchArea: "touch-area",
889
+ horizontal: "horizontal",
890
+ vertical: "vertical",
891
+ background: "background",
892
+ connect: "connect",
893
+ connects: "connects",
894
+ ltr: "ltr",
895
+ rtl: "rtl",
896
+ draggable: "draggable",
897
+ drag: "state-drag",
898
+ tap: "state-tap",
899
+ active: "active",
900
+ tooltip: "tooltip",
901
+ pips: "pips",
902
+ pipsHorizontal: "pips-horizontal",
903
+ pipsVertical: "pips-vertical",
904
+ marker: "marker",
905
+ markerHorizontal: "marker-horizontal",
906
+ markerVertical: "marker-vertical",
907
+ markerNormal: "marker-normal",
908
+ markerLarge: "marker-large",
909
+ markerSub: "marker-sub",
910
+ value: "value",
911
+ valueHorizontal: "value-horizontal",
912
+ valueVertical: "value-vertical",
913
+ valueNormal: "value-normal",
914
+ valueLarge: "value-large",
915
+ valueSub: "value-sub"
916
+ }
917
+ };
918
+
919
+ // AriaFormat defaults to regular format, if any.
920
+ if (options.format && !options.ariaFormat) {
921
+ options.ariaFormat = options.format;
922
+ }
923
+
924
+ // Run all options through a testing mechanism to ensure correct
925
+ // input. It should be noted that options might get modified to
926
+ // be handled properly. E.g. wrapping integers in arrays.
927
+ Object.keys(tests).forEach(function(name) {
928
+ // If the option isn't set, but it is required, throw an error.
929
+ if (!isSet(options[name]) && defaults[name] === undefined) {
930
+ if (tests[name].r) {
931
+ throw new Error("noUiSlider (" + VERSION + "): '" + name + "' is required.");
932
+ }
933
+
934
+ return true;
935
+ }
936
+
937
+ tests[name].t(parsed, !isSet(options[name]) ? defaults[name] : options[name]);
938
+ });
939
+
940
+ // Forward pips options
941
+ parsed.pips = options.pips;
942
+
943
+ // All recent browsers accept unprefixed transform.
944
+ // We need -ms- for IE9 and -webkit- for older Android;
945
+ // Assume use of -webkit- if unprefixed and -ms- are not supported.
946
+ // https://caniuse.com/#feat=transforms2d
947
+ var d = document.createElement("div");
948
+ var msPrefix = d.style.msTransform !== undefined;
949
+ var noPrefix = d.style.transform !== undefined;
950
+
951
+ parsed.transformRule = noPrefix ? "transform" : msPrefix ? "msTransform" : "webkitTransform";
952
+
953
+ // Pips don't move, so we can place them using left/top.
954
+ var styles = [["left", "top"], ["right", "bottom"]];
955
+
956
+ parsed.style = styles[parsed.dir][parsed.ort];
957
+
958
+ return parsed;
959
+ }
960
+
961
+ //endregion
962
+
963
+ function scope(target, options, originalOptions) {
964
+ var actions = getActions();
965
+ var supportsTouchActionNone = getSupportsTouchActionNone();
966
+ var supportsPassive = supportsTouchActionNone && getSupportsPassive();
967
+
968
+ // All variables local to 'scope' are prefixed with 'scope_'
969
+
970
+ // Slider DOM Nodes
971
+ var scope_Target = target;
972
+ var scope_Base;
973
+ var scope_Handles;
974
+ var scope_Connects;
975
+ var scope_Pips;
976
+ var scope_Tooltips;
977
+
978
+ // Slider state values
979
+ var scope_Spectrum = options.spectrum;
980
+ var scope_Values = [];
981
+ var scope_Locations = [];
982
+ var scope_HandleNumbers = [];
983
+ var scope_ActiveHandlesCount = 0;
984
+ var scope_Events = {};
985
+
986
+ // Exposed API
987
+ var scope_Self;
988
+
989
+ // Document Nodes
990
+ var scope_Document = target.ownerDocument;
991
+ var scope_DocumentElement = options.documentElement || scope_Document.documentElement;
992
+ var scope_Body = scope_Document.body;
993
+
994
+ // Pips constants
995
+ var PIPS_NONE = -1;
996
+ var PIPS_NO_VALUE = 0;
997
+ var PIPS_LARGE_VALUE = 1;
998
+ var PIPS_SMALL_VALUE = 2;
999
+
1000
+ // For horizontal sliders in standard ltr documents,
1001
+ // make .noUi-origin overflow to the left so the document doesn't scroll.
1002
+ var scope_DirOffset = scope_Document.dir === "rtl" || options.ort === 1 ? 0 : 100;
1003
+
1004
+ // Creates a node, adds it to target, returns the new node.
1005
+ function addNodeTo(addTarget, className) {
1006
+ var div = scope_Document.createElement("div");
1007
+
1008
+ if (className) {
1009
+ addClass(div, className);
1010
+ }
1011
+
1012
+ addTarget.appendChild(div);
1013
+
1014
+ return div;
1015
+ }
1016
+
1017
+ // Append a origin to the base
1018
+ function addOrigin(base, handleNumber) {
1019
+ var origin = addNodeTo(base, options.cssClasses.origin);
1020
+ var handle = addNodeTo(origin, options.cssClasses.handle);
1021
+
1022
+ addNodeTo(handle, options.cssClasses.touchArea);
1023
+
1024
+ handle.setAttribute("data-handle", handleNumber);
1025
+
1026
+ if (options.keyboardSupport) {
1027
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
1028
+ // 0 = focusable and reachable
1029
+ handle.setAttribute("tabindex", "0");
1030
+ handle.addEventListener("keydown", function(event) {
1031
+ return eventKeydown(event, handleNumber);
1032
+ });
1033
+ }
1034
+
1035
+ handle.setAttribute("role", "slider");
1036
+ handle.setAttribute("aria-orientation", options.ort ? "vertical" : "horizontal");
1037
+
1038
+ if (handleNumber === 0) {
1039
+ addClass(handle, options.cssClasses.handleLower);
1040
+ } else if (handleNumber === options.handles - 1) {
1041
+ addClass(handle, options.cssClasses.handleUpper);
1042
+ }
1043
+
1044
+ return origin;
1045
+ }
1046
+
1047
+ // Insert nodes for connect elements
1048
+ function addConnect(base, add) {
1049
+ if (!add) {
1050
+ return false;
1051
+ }
1052
+
1053
+ return addNodeTo(base, options.cssClasses.connect);
1054
+ }
1055
+
1056
+ // Add handles to the slider base.
1057
+ function addElements(connectOptions, base) {
1058
+ var connectBase = addNodeTo(base, options.cssClasses.connects);
1059
+
1060
+ scope_Handles = [];
1061
+ scope_Connects = [];
1062
+
1063
+ scope_Connects.push(addConnect(connectBase, connectOptions[0]));
1064
+
1065
+ // [::::O====O====O====]
1066
+ // connectOptions = [0, 1, 1, 1]
1067
+
1068
+ for (var i = 0; i < options.handles; i++) {
1069
+ // Keep a list of all added handles.
1070
+ scope_Handles.push(addOrigin(base, i));
1071
+ scope_HandleNumbers[i] = i;
1072
+ scope_Connects.push(addConnect(connectBase, connectOptions[i + 1]));
1073
+ }
1074
+ }
1075
+
1076
+ // Initialize a single slider.
1077
+ function addSlider(addTarget) {
1078
+ // Apply classes and data to the target.
1079
+ addClass(addTarget, options.cssClasses.target);
1080
+
1081
+ if (options.dir === 0) {
1082
+ addClass(addTarget, options.cssClasses.ltr);
1083
+ } else {
1084
+ addClass(addTarget, options.cssClasses.rtl);
1085
+ }
1086
+
1087
+ if (options.ort === 0) {
1088
+ addClass(addTarget, options.cssClasses.horizontal);
1089
+ } else {
1090
+ addClass(addTarget, options.cssClasses.vertical);
1091
+ }
1092
+
1093
+ return addNodeTo(addTarget, options.cssClasses.base);
1094
+ }
1095
+
1096
+ function addTooltip(handle, handleNumber) {
1097
+ if (!options.tooltips[handleNumber]) {
1098
+ return false;
1099
+ }
1100
+
1101
+ return addNodeTo(handle.firstChild, options.cssClasses.tooltip);
1102
+ }
1103
+
1104
+ function isSliderDisabled() {
1105
+ return scope_Target.hasAttribute("disabled");
1106
+ }
1107
+
1108
+ // Disable the slider dragging if any handle is disabled
1109
+ function isHandleDisabled(handleNumber) {
1110
+ var handleOrigin = scope_Handles[handleNumber];
1111
+ return handleOrigin.hasAttribute("disabled");
1112
+ }
1113
+
1114
+ function removeTooltips() {
1115
+ if (scope_Tooltips) {
1116
+ removeEvent("update.tooltips");
1117
+ scope_Tooltips.forEach(function(tooltip) {
1118
+ if (tooltip) {
1119
+ removeElement(tooltip);
1120
+ }
1121
+ });
1122
+ scope_Tooltips = null;
1123
+ }
1124
+ }
1125
+
1126
+ // The tooltips option is a shorthand for using the 'update' event.
1127
+ function tooltips() {
1128
+ removeTooltips();
1129
+
1130
+ // Tooltips are added with options.tooltips in original order.
1131
+ scope_Tooltips = scope_Handles.map(addTooltip);
1132
+
1133
+ bindEvent("update.tooltips", function(values, handleNumber, unencoded) {
1134
+ if (!scope_Tooltips[handleNumber]) {
1135
+ return;
1136
+ }
1137
+
1138
+ var formattedValue = values[handleNumber];
1139
+
1140
+ if (options.tooltips[handleNumber] !== true) {
1141
+ formattedValue = options.tooltips[handleNumber].to(unencoded[handleNumber]);
1142
+ }
1143
+
1144
+ scope_Tooltips[handleNumber].innerHTML = formattedValue;
1145
+ });
1146
+ }
1147
+
1148
+ function aria() {
1149
+ bindEvent("update", function(values, handleNumber, unencoded, tap, positions) {
1150
+ // Update Aria Values for all handles, as a change in one changes min and max values for the next.
1151
+ scope_HandleNumbers.forEach(function(index) {
1152
+ var handle = scope_Handles[index];
1153
+
1154
+ var min = checkHandlePosition(scope_Locations, index, 0, true, true, true);
1155
+ var max = checkHandlePosition(scope_Locations, index, 100, true, true, true);
1156
+
1157
+ var now = positions[index];
1158
+
1159
+ // Formatted value for display
1160
+ var text = options.ariaFormat.to(unencoded[index]);
1161
+
1162
+ // Map to slider range values
1163
+ min = scope_Spectrum.fromStepping(min).toFixed(1);
1164
+ max = scope_Spectrum.fromStepping(max).toFixed(1);
1165
+ now = scope_Spectrum.fromStepping(now).toFixed(1);
1166
+
1167
+ handle.children[0].setAttribute("aria-valuemin", min);
1168
+ handle.children[0].setAttribute("aria-valuemax", max);
1169
+ handle.children[0].setAttribute("aria-valuenow", now);
1170
+ handle.children[0].setAttribute("aria-valuetext", text);
1171
+ });
1172
+ });
1173
+ }
1174
+
1175
+ function getGroup(mode, values, stepped) {
1176
+ // Use the range.
1177
+ if (mode === "range" || mode === "steps") {
1178
+ return scope_Spectrum.xVal;
1179
+ }
1180
+
1181
+ if (mode === "count") {
1182
+ if (values < 2) {
1183
+ throw new Error("noUiSlider (" + VERSION + "): 'values' (>= 2) required for mode 'count'.");
1184
+ }
1185
+
1186
+ // Divide 0 - 100 in 'count' parts.
1187
+ var interval = values - 1;
1188
+ var spread = 100 / interval;
1189
+
1190
+ values = [];
1191
+
1192
+ // List these parts and have them handled as 'positions'.
1193
+ while (interval--) {
1194
+ values[interval] = interval * spread;
1195
+ }
1196
+
1197
+ values.push(100);
1198
+
1199
+ mode = "positions";
1200
+ }
1201
+
1202
+ if (mode === "positions") {
1203
+ // Map all percentages to on-range values.
1204
+ return values.map(function(value) {
1205
+ return scope_Spectrum.fromStepping(stepped ? scope_Spectrum.getStep(value) : value);
1206
+ });
1207
+ }
1208
+
1209
+ if (mode === "values") {
1210
+ // If the value must be stepped, it needs to be converted to a percentage first.
1211
+ if (stepped) {
1212
+ return values.map(function(value) {
1213
+ // Convert to percentage, apply step, return to value.
1214
+ return scope_Spectrum.fromStepping(scope_Spectrum.getStep(scope_Spectrum.toStepping(value)));
1215
+ });
1216
+ }
1217
+
1218
+ // Otherwise, we can simply use the values.
1219
+ return values;
1220
+ }
1221
+ }
1222
+
1223
+ function generateSpread(density, mode, group) {
1224
+ function safeIncrement(value, increment) {
1225
+ // Avoid floating point variance by dropping the smallest decimal places.
1226
+ return (value + increment).toFixed(7) / 1;
1227
+ }
1228
+
1229
+ var indexes = {};
1230
+ var firstInRange = scope_Spectrum.xVal[0];
1231
+ var lastInRange = scope_Spectrum.xVal[scope_Spectrum.xVal.length - 1];
1232
+ var ignoreFirst = false;
1233
+ var ignoreLast = false;
1234
+ var prevPct = 0;
1235
+
1236
+ // Create a copy of the group, sort it and filter away all duplicates.
1237
+ group = unique(
1238
+ group.slice().sort(function(a, b) {
1239
+ return a - b;
1240
+ })
1241
+ );
1242
+
1243
+ // Make sure the range starts with the first element.
1244
+ if (group[0] !== firstInRange) {
1245
+ group.unshift(firstInRange);
1246
+ ignoreFirst = true;
1247
+ }
1248
+
1249
+ // Likewise for the last one.
1250
+ if (group[group.length - 1] !== lastInRange) {
1251
+ group.push(lastInRange);
1252
+ ignoreLast = true;
1253
+ }
1254
+
1255
+ group.forEach(function(current, index) {
1256
+ // Get the current step and the lower + upper positions.
1257
+ var step;
1258
+ var i;
1259
+ var q;
1260
+ var low = current;
1261
+ var high = group[index + 1];
1262
+ var newPct;
1263
+ var pctDifference;
1264
+ var pctPos;
1265
+ var type;
1266
+ var steps;
1267
+ var realSteps;
1268
+ var stepSize;
1269
+ var isSteps = mode === "steps";
1270
+
1271
+ // When using 'steps' mode, use the provided steps.
1272
+ // Otherwise, we'll step on to the next subrange.
1273
+ if (isSteps) {
1274
+ step = scope_Spectrum.xNumSteps[index];
1275
+ }
1276
+
1277
+ // Default to a 'full' step.
1278
+ if (!step) {
1279
+ step = high - low;
1280
+ }
1281
+
1282
+ // Low can be 0, so test for false. If high is undefined,
1283
+ // we are at the last subrange. Index 0 is already handled.
1284
+ if (low === false || high === undefined) {
1285
+ return;
1286
+ }
1287
+
1288
+ // Make sure step isn't 0, which would cause an infinite loop (#654)
1289
+ step = Math.max(step, 0.0000001);
1290
+
1291
+ // Find all steps in the subrange.
1292
+ for (i = low; i <= high; i = safeIncrement(i, step)) {
1293
+ // Get the percentage value for the current step,
1294
+ // calculate the size for the subrange.
1295
+ newPct = scope_Spectrum.toStepping(i);
1296
+ pctDifference = newPct - prevPct;
1297
+
1298
+ steps = pctDifference / density;
1299
+ realSteps = Math.round(steps);
1300
+
1301
+ // This ratio represents the amount of percentage-space a point indicates.
1302
+ // For a density 1 the points/percentage = 1. For density 2, that percentage needs to be re-divided.
1303
+ // Round the percentage offset to an even number, then divide by two
1304
+ // to spread the offset on both sides of the range.
1305
+ stepSize = pctDifference / realSteps;
1306
+
1307
+ // Divide all points evenly, adding the correct number to this subrange.
1308
+ // Run up to <= so that 100% gets a point, event if ignoreLast is set.
1309
+ for (q = 1; q <= realSteps; q += 1) {
1310
+ // The ratio between the rounded value and the actual size might be ~1% off.
1311
+ // Correct the percentage offset by the number of points
1312
+ // per subrange. density = 1 will result in 100 points on the
1313
+ // full range, 2 for 50, 4 for 25, etc.
1314
+ pctPos = prevPct + q * stepSize;
1315
+ indexes[pctPos.toFixed(5)] = [scope_Spectrum.fromStepping(pctPos), 0];
1316
+ }
1317
+
1318
+ // Determine the point type.
1319
+ type = group.indexOf(i) > -1 ? PIPS_LARGE_VALUE : isSteps ? PIPS_SMALL_VALUE : PIPS_NO_VALUE;
1320
+
1321
+ // Enforce the 'ignoreFirst' option by overwriting the type for 0.
1322
+ if (!index && ignoreFirst) {
1323
+ type = 0;
1324
+ }
1325
+
1326
+ if (!(i === high && ignoreLast)) {
1327
+ // Mark the 'type' of this point. 0 = plain, 1 = real value, 2 = step value.
1328
+ indexes[newPct.toFixed(5)] = [i, type];
1329
+ }
1330
+
1331
+ // Update the percentage count.
1332
+ prevPct = newPct;
1333
+ }
1334
+ });
1335
+
1336
+ return indexes;
1337
+ }
1338
+
1339
+ function addMarking(spread, filterFunc, formatter) {
1340
+ var element = scope_Document.createElement("div");
1341
+
1342
+ var valueSizeClasses = [];
1343
+ valueSizeClasses[PIPS_NO_VALUE] = options.cssClasses.valueNormal;
1344
+ valueSizeClasses[PIPS_LARGE_VALUE] = options.cssClasses.valueLarge;
1345
+ valueSizeClasses[PIPS_SMALL_VALUE] = options.cssClasses.valueSub;
1346
+
1347
+ var markerSizeClasses = [];
1348
+ markerSizeClasses[PIPS_NO_VALUE] = options.cssClasses.markerNormal;
1349
+ markerSizeClasses[PIPS_LARGE_VALUE] = options.cssClasses.markerLarge;
1350
+ markerSizeClasses[PIPS_SMALL_VALUE] = options.cssClasses.markerSub;
1351
+
1352
+ var valueOrientationClasses = [options.cssClasses.valueHorizontal, options.cssClasses.valueVertical];
1353
+ var markerOrientationClasses = [options.cssClasses.markerHorizontal, options.cssClasses.markerVertical];
1354
+
1355
+ addClass(element, options.cssClasses.pips);
1356
+ addClass(element, options.ort === 0 ? options.cssClasses.pipsHorizontal : options.cssClasses.pipsVertical);
1357
+
1358
+ function getClasses(type, source) {
1359
+ var a = source === options.cssClasses.value;
1360
+ var orientationClasses = a ? valueOrientationClasses : markerOrientationClasses;
1361
+ var sizeClasses = a ? valueSizeClasses : markerSizeClasses;
1362
+
1363
+ return source + " " + orientationClasses[options.ort] + " " + sizeClasses[type];
1364
+ }
1365
+
1366
+ function addSpread(offset, value, type) {
1367
+ // Apply the filter function, if it is set.
1368
+ type = filterFunc ? filterFunc(value, type) : type;
1369
+
1370
+ if (type === PIPS_NONE) {
1371
+ return;
1372
+ }
1373
+
1374
+ // Add a marker for every point
1375
+ var node = addNodeTo(element, false);
1376
+ node.className = getClasses(type, options.cssClasses.marker);
1377
+ node.style[options.style] = offset + "%";
1378
+
1379
+ // Values are only appended for points marked '1' or '2'.
1380
+ if (type > PIPS_NO_VALUE) {
1381
+ node = addNodeTo(element, false);
1382
+ node.className = getClasses(type, options.cssClasses.value);
1383
+ node.setAttribute("data-value", value);
1384
+ node.style[options.style] = offset + "%";
1385
+ node.innerHTML = formatter.to(value);
1386
+ }
1387
+ }
1388
+
1389
+ // Append all points.
1390
+ Object.keys(spread).forEach(function(offset) {
1391
+ addSpread(offset, spread[offset][0], spread[offset][1]);
1392
+ });
1393
+
1394
+ return element;
1395
+ }
1396
+
1397
+ function removePips() {
1398
+ if (scope_Pips) {
1399
+ removeElement(scope_Pips);
1400
+ scope_Pips = null;
1401
+ }
1402
+ }
1403
+
1404
+ function pips(grid) {
1405
+ // Fix #669
1406
+ removePips();
1407
+
1408
+ var mode = grid.mode;
1409
+ var density = grid.density || 1;
1410
+ var filter = grid.filter || false;
1411
+ var values = grid.values || false;
1412
+ var stepped = grid.stepped || false;
1413
+ var group = getGroup(mode, values, stepped);
1414
+ var spread = generateSpread(density, mode, group);
1415
+ var format = grid.format || {
1416
+ to: Math.round
1417
+ };
1418
+
1419
+ scope_Pips = scope_Target.appendChild(addMarking(spread, filter, format));
1420
+
1421
+ return scope_Pips;
1422
+ }
1423
+
1424
+ // Shorthand for base dimensions.
1425
+ function baseSize() {
1426
+ var rect = scope_Base.getBoundingClientRect();
1427
+ var alt = "offset" + ["Width", "Height"][options.ort];
1428
+ return options.ort === 0 ? rect.width || scope_Base[alt] : rect.height || scope_Base[alt];
1429
+ }
1430
+
1431
+ // Handler for attaching events trough a proxy.
1432
+ function attachEvent(events, element, callback, data) {
1433
+ // This function can be used to 'filter' events to the slider.
1434
+ // element is a node, not a nodeList
1435
+
1436
+ var method = function(e) {
1437
+ e = fixEvent(e, data.pageOffset, data.target || element);
1438
+
1439
+ // fixEvent returns false if this event has a different target
1440
+ // when handling (multi-) touch events;
1441
+ if (!e) {
1442
+ return false;
1443
+ }
1444
+
1445
+ // doNotReject is passed by all end events to make sure released touches
1446
+ // are not rejected, leaving the slider "stuck" to the cursor;
1447
+ if (isSliderDisabled() && !data.doNotReject) {
1448
+ return false;
1449
+ }
1450
+
1451
+ // Stop if an active 'tap' transition is taking place.
1452
+ if (hasClass(scope_Target, options.cssClasses.tap) && !data.doNotReject) {
1453
+ return false;
1454
+ }
1455
+
1456
+ // Ignore right or middle clicks on start #454
1457
+ if (events === actions.start && e.buttons !== undefined && e.buttons > 1) {
1458
+ return false;
1459
+ }
1460
+
1461
+ // Ignore right or middle clicks on start #454
1462
+ if (data.hover && e.buttons) {
1463
+ return false;
1464
+ }
1465
+
1466
+ // 'supportsPassive' is only true if a browser also supports touch-action: none in CSS.
1467
+ // iOS safari does not, so it doesn't get to benefit from passive scrolling. iOS does support
1468
+ // touch-action: manipulation, but that allows panning, which breaks
1469
+ // sliders after zooming/on non-responsive pages.
1470
+ // See: https://bugs.webkit.org/show_bug.cgi?id=133112
1471
+ if (!supportsPassive) {
1472
+ e.preventDefault();
1473
+ }
1474
+
1475
+ e.calcPoint = e.points[options.ort];
1476
+
1477
+ // Call the event handler with the event [ and additional data ].
1478
+ callback(e, data);
1479
+ };
1480
+
1481
+ var methods = [];
1482
+
1483
+ // Bind a closure on the target for every event type.
1484
+ events.split(" ").forEach(function(eventName) {
1485
+ element.addEventListener(eventName, method, supportsPassive ? { passive: true } : false);
1486
+ methods.push([eventName, method]);
1487
+ });
1488
+
1489
+ return methods;
1490
+ }
1491
+
1492
+ // Provide a clean event with standardized offset values.
1493
+ function fixEvent(e, pageOffset, eventTarget) {
1494
+ // Filter the event to register the type, which can be
1495
+ // touch, mouse or pointer. Offset changes need to be
1496
+ // made on an event specific basis.
1497
+ var touch = e.type.indexOf("touch") === 0;
1498
+ var mouse = e.type.indexOf("mouse") === 0;
1499
+ var pointer = e.type.indexOf("pointer") === 0;
1500
+
1501
+ var x;
1502
+ var y;
1503
+
1504
+ // IE10 implemented pointer events with a prefix;
1505
+ if (e.type.indexOf("MSPointer") === 0) {
1506
+ pointer = true;
1507
+ }
1508
+
1509
+ // The only thing one handle should be concerned about is the touches that originated on top of it.
1510
+ if (touch) {
1511
+ // Returns true if a touch originated on the target.
1512
+ var isTouchOnTarget = function(checkTouch) {
1513
+ return checkTouch.target === eventTarget || eventTarget.contains(checkTouch.target);
1514
+ };
1515
+
1516
+ // In the case of touchstart events, we need to make sure there is still no more than one
1517
+ // touch on the target so we look amongst all touches.
1518
+ if (e.type === "touchstart") {
1519
+ var targetTouches = Array.prototype.filter.call(e.touches, isTouchOnTarget);
1520
+
1521
+ // Do not support more than one touch per handle.
1522
+ if (targetTouches.length > 1) {
1523
+ return false;
1524
+ }
1525
+
1526
+ x = targetTouches[0].pageX;
1527
+ y = targetTouches[0].pageY;
1528
+ } else {
1529
+ // In the other cases, find on changedTouches is enough.
1530
+ var targetTouch = Array.prototype.find.call(e.changedTouches, isTouchOnTarget);
1531
+
1532
+ // Cancel if the target touch has not moved.
1533
+ if (!targetTouch) {
1534
+ return false;
1535
+ }
1536
+
1537
+ x = targetTouch.pageX;
1538
+ y = targetTouch.pageY;
1539
+ }
1540
+ }
1541
+
1542
+ pageOffset = pageOffset || getPageOffset(scope_Document);
1543
+
1544
+ if (mouse || pointer) {
1545
+ x = e.clientX + pageOffset.x;
1546
+ y = e.clientY + pageOffset.y;
1547
+ }
1548
+
1549
+ e.pageOffset = pageOffset;
1550
+ e.points = [x, y];
1551
+ e.cursor = mouse || pointer; // Fix #435
1552
+
1553
+ return e;
1554
+ }
1555
+
1556
+ // Translate a coordinate in the document to a percentage on the slider
1557
+ function calcPointToPercentage(calcPoint) {
1558
+ var location = calcPoint - offset(scope_Base, options.ort);
1559
+ var proposal = (location * 100) / baseSize();
1560
+
1561
+ // Clamp proposal between 0% and 100%
1562
+ // Out-of-bound coordinates may occur when .noUi-base pseudo-elements
1563
+ // are used (e.g. contained handles feature)
1564
+ proposal = limit(proposal);
1565
+
1566
+ return options.dir ? 100 - proposal : proposal;
1567
+ }
1568
+
1569
+ // Find handle closest to a certain percentage on the slider
1570
+ function getClosestHandle(clickedPosition) {
1571
+ var smallestDifference = 100;
1572
+ var handleNumber = false;
1573
+
1574
+ scope_Handles.forEach(function(handle, index) {
1575
+ // Disabled handles are ignored
1576
+ if (isHandleDisabled(index)) {
1577
+ return;
1578
+ }
1579
+
1580
+ var handlePosition = scope_Locations[index];
1581
+ var differenceWithThisHandle = Math.abs(handlePosition - clickedPosition);
1582
+
1583
+ // Initial state
1584
+ var clickAtEdge = differenceWithThisHandle === 100 && smallestDifference === 100;
1585
+
1586
+ // Difference with this handle is smaller than the previously checked handle
1587
+ var isCloser = differenceWithThisHandle < smallestDifference;
1588
+ var isCloserAfter = differenceWithThisHandle <= smallestDifference && clickedPosition > handlePosition;
1589
+
1590
+ if (isCloser || isCloserAfter || clickAtEdge) {
1591
+ handleNumber = index;
1592
+ smallestDifference = differenceWithThisHandle;
1593
+ }
1594
+ });
1595
+
1596
+ return handleNumber;
1597
+ }
1598
+
1599
+ // Fire 'end' when a mouse or pen leaves the document.
1600
+ function documentLeave(event, data) {
1601
+ if (event.type === "mouseout" && event.target.nodeName === "HTML" && event.relatedTarget === null) {
1602
+ eventEnd(event, data);
1603
+ }
1604
+ }
1605
+
1606
+ // Handle movement on document for handle and range drag.
1607
+ function eventMove(event, data) {
1608
+ // Fix #498
1609
+ // Check value of .buttons in 'start' to work around a bug in IE10 mobile (data.buttonsProperty).
1610
+ // https://connect.microsoft.com/IE/feedback/details/927005/mobile-ie10-windows-phone-buttons-property-of-pointermove-event-always-zero
1611
+ // IE9 has .buttons and .which zero on mousemove.
1612
+ // Firefox breaks the spec MDN defines.
1613
+ if (navigator.appVersion.indexOf("MSIE 9") === -1 && event.buttons === 0 && data.buttonsProperty !== 0) {
1614
+ return eventEnd(event, data);
1615
+ }
1616
+
1617
+ // Check if we are moving up or down
1618
+ var movement = (options.dir ? -1 : 1) * (event.calcPoint - data.startCalcPoint);
1619
+
1620
+ // Convert the movement into a percentage of the slider width/height
1621
+ var proposal = (movement * 100) / data.baseSize;
1622
+
1623
+ moveHandles(movement > 0, proposal, data.locations, data.handleNumbers);
1624
+ }
1625
+
1626
+ // Unbind move events on document, call callbacks.
1627
+ function eventEnd(event, data) {
1628
+ // The handle is no longer active, so remove the class.
1629
+ if (data.handle) {
1630
+ removeClass(data.handle, options.cssClasses.active);
1631
+ scope_ActiveHandlesCount -= 1;
1632
+ }
1633
+
1634
+ // Unbind the move and end events, which are added on 'start'.
1635
+ data.listeners.forEach(function(c) {
1636
+ scope_DocumentElement.removeEventListener(c[0], c[1]);
1637
+ });
1638
+
1639
+ if (scope_ActiveHandlesCount === 0) {
1640
+ // Remove dragging class.
1641
+ removeClass(scope_Target, options.cssClasses.drag);
1642
+ setZindex();
1643
+
1644
+ // Remove cursor styles and text-selection events bound to the body.
1645
+ if (event.cursor) {
1646
+ scope_Body.style.cursor = "";
1647
+ scope_Body.removeEventListener("selectstart", preventDefault);
1648
+ }
1649
+ }
1650
+
1651
+ data.handleNumbers.forEach(function(handleNumber) {
1652
+ fireEvent("change", handleNumber);
1653
+ fireEvent("set", handleNumber);
1654
+ fireEvent("end", handleNumber);
1655
+ });
1656
+ }
1657
+
1658
+ // Bind move events on document.
1659
+ function eventStart(event, data) {
1660
+ // Ignore event if any handle is disabled
1661
+ if (data.handleNumbers.some(isHandleDisabled)) {
1662
+ return false;
1663
+ }
1664
+
1665
+ var handle;
1666
+
1667
+ if (data.handleNumbers.length === 1) {
1668
+ var handleOrigin = scope_Handles[data.handleNumbers[0]];
1669
+
1670
+ handle = handleOrigin.children[0];
1671
+ scope_ActiveHandlesCount += 1;
1672
+
1673
+ // Mark the handle as 'active' so it can be styled.
1674
+ addClass(handle, options.cssClasses.active);
1675
+ }
1676
+
1677
+ // A drag should never propagate up to the 'tap' event.
1678
+ event.stopPropagation();
1679
+
1680
+ // Record the event listeners.
1681
+ var listeners = [];
1682
+
1683
+ // Attach the move and end events.
1684
+ var moveEvent = attachEvent(actions.move, scope_DocumentElement, eventMove, {
1685
+ // The event target has changed so we need to propagate the original one so that we keep
1686
+ // relying on it to extract target touches.
1687
+ target: event.target,
1688
+ handle: handle,
1689
+ listeners: listeners,
1690
+ startCalcPoint: event.calcPoint,
1691
+ baseSize: baseSize(),
1692
+ pageOffset: event.pageOffset,
1693
+ handleNumbers: data.handleNumbers,
1694
+ buttonsProperty: event.buttons,
1695
+ locations: scope_Locations.slice()
1696
+ });
1697
+
1698
+ var endEvent = attachEvent(actions.end, scope_DocumentElement, eventEnd, {
1699
+ target: event.target,
1700
+ handle: handle,
1701
+ listeners: listeners,
1702
+ doNotReject: true,
1703
+ handleNumbers: data.handleNumbers
1704
+ });
1705
+
1706
+ var outEvent = attachEvent("mouseout", scope_DocumentElement, documentLeave, {
1707
+ target: event.target,
1708
+ handle: handle,
1709
+ listeners: listeners,
1710
+ doNotReject: true,
1711
+ handleNumbers: data.handleNumbers
1712
+ });
1713
+
1714
+ // We want to make sure we pushed the listeners in the listener list rather than creating
1715
+ // a new one as it has already been passed to the event handlers.
1716
+ listeners.push.apply(listeners, moveEvent.concat(endEvent, outEvent));
1717
+
1718
+ // Text selection isn't an issue on touch devices,
1719
+ // so adding cursor styles can be skipped.
1720
+ if (event.cursor) {
1721
+ // Prevent the 'I' cursor and extend the range-drag cursor.
1722
+ scope_Body.style.cursor = getComputedStyle(event.target).cursor;
1723
+
1724
+ // Mark the target with a dragging state.
1725
+ if (scope_Handles.length > 1) {
1726
+ addClass(scope_Target, options.cssClasses.drag);
1727
+ }
1728
+
1729
+ // Prevent text selection when dragging the handles.
1730
+ // In noUiSlider <= 9.2.0, this was handled by calling preventDefault on mouse/touch start/move,
1731
+ // which is scroll blocking. The selectstart event is supported by FireFox starting from version 52,
1732
+ // meaning the only holdout is iOS Safari. This doesn't matter: text selection isn't triggered there.
1733
+ // The 'cursor' flag is false.
1734
+ // See: http://caniuse.com/#search=selectstart
1735
+ scope_Body.addEventListener("selectstart", preventDefault, false);
1736
+ }
1737
+
1738
+ data.handleNumbers.forEach(function(handleNumber) {
1739
+ fireEvent("start", handleNumber);
1740
+ });
1741
+ }
1742
+
1743
+ // Move closest handle to tapped location.
1744
+ function eventTap(event) {
1745
+ // The tap event shouldn't propagate up
1746
+ event.stopPropagation();
1747
+
1748
+ var proposal = calcPointToPercentage(event.calcPoint);
1749
+ var handleNumber = getClosestHandle(proposal);
1750
+
1751
+ // Tackle the case that all handles are 'disabled'.
1752
+ if (handleNumber === false) {
1753
+ return false;
1754
+ }
1755
+
1756
+ // Flag the slider as it is now in a transitional state.
1757
+ // Transition takes a configurable amount of ms (default 300). Re-enable the slider after that.
1758
+ if (!options.events.snap) {
1759
+ addClassFor(scope_Target, options.cssClasses.tap, options.animationDuration);
1760
+ }
1761
+
1762
+ setHandle(handleNumber, proposal, true, true);
1763
+
1764
+ setZindex();
1765
+
1766
+ fireEvent("slide", handleNumber, true);
1767
+ fireEvent("update", handleNumber, true);
1768
+ fireEvent("change", handleNumber, true);
1769
+ fireEvent("set", handleNumber, true);
1770
+
1771
+ if (options.events.snap) {
1772
+ eventStart(event, { handleNumbers: [handleNumber] });
1773
+ }
1774
+ }
1775
+
1776
+ // Fires a 'hover' event for a hovered mouse/pen position.
1777
+ function eventHover(event) {
1778
+ var proposal = calcPointToPercentage(event.calcPoint);
1779
+
1780
+ var to = scope_Spectrum.getStep(proposal);
1781
+ var value = scope_Spectrum.fromStepping(to);
1782
+
1783
+ Object.keys(scope_Events).forEach(function(targetEvent) {
1784
+ if ("hover" === targetEvent.split(".")[0]) {
1785
+ scope_Events[targetEvent].forEach(function(callback) {
1786
+ callback.call(scope_Self, value);
1787
+ });
1788
+ }
1789
+ });
1790
+ }
1791
+
1792
+ // Handles keydown on focused handles
1793
+ // Don't move the document when pressing arrow keys on focused handles
1794
+ function eventKeydown(event, handleNumber) {
1795
+ if (isSliderDisabled() || isHandleDisabled(handleNumber)) {
1796
+ return false;
1797
+ }
1798
+
1799
+ var horizontalKeys = ["Left", "Right"];
1800
+ var verticalKeys = ["Down", "Up"];
1801
+
1802
+ if (options.dir && !options.ort) {
1803
+ // On an right-to-left slider, the left and right keys act inverted
1804
+ horizontalKeys.reverse();
1805
+ } else if (options.ort && !options.dir) {
1806
+ // On a top-to-bottom slider, the up and down keys act inverted
1807
+ verticalKeys.reverse();
1808
+ }
1809
+
1810
+ // Strip "Arrow" for IE compatibility. https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
1811
+ var key = event.key.replace("Arrow", "");
1812
+ var isDown = key === verticalKeys[0] || key === horizontalKeys[0];
1813
+ var isUp = key === verticalKeys[1] || key === horizontalKeys[1];
1814
+
1815
+ if (!isDown && !isUp) {
1816
+ return true;
1817
+ }
1818
+
1819
+ event.preventDefault();
1820
+
1821
+ var direction = isDown ? 0 : 1;
1822
+ var steps = getNextStepsForHandle(handleNumber);
1823
+ var step = steps[direction];
1824
+
1825
+ // At the edge of a slider, do nothing
1826
+ if (step === null) {
1827
+ return false;
1828
+ }
1829
+
1830
+ // No step set, use the default of 10% of the sub-range
1831
+ if (step === false) {
1832
+ step = scope_Spectrum.getDefaultStep(scope_Locations[handleNumber], isDown, 10);
1833
+ }
1834
+
1835
+ // Step over zero-length ranges (#948);
1836
+ step = Math.max(step, 0.0000001);
1837
+
1838
+ // Decrement for down steps
1839
+ step = (isDown ? -1 : 1) * step;
1840
+
1841
+ setHandle(handleNumber, scope_Spectrum.toStepping(scope_Values[handleNumber] + step), true, true);
1842
+
1843
+ fireEvent("slide", handleNumber);
1844
+ fireEvent("update", handleNumber);
1845
+ fireEvent("change", handleNumber);
1846
+ fireEvent("set", handleNumber);
1847
+
1848
+ return false;
1849
+ }
1850
+
1851
+ // Attach events to several slider parts.
1852
+ function bindSliderEvents(behaviour) {
1853
+ // Attach the standard drag event to the handles.
1854
+ if (!behaviour.fixed) {
1855
+ scope_Handles.forEach(function(handle, index) {
1856
+ // These events are only bound to the visual handle
1857
+ // element, not the 'real' origin element.
1858
+ attachEvent(actions.start, handle.children[0], eventStart, {
1859
+ handleNumbers: [index]
1860
+ });
1861
+ });
1862
+ }
1863
+
1864
+ // Attach the tap event to the slider base.
1865
+ if (behaviour.tap) {
1866
+ attachEvent(actions.start, scope_Base, eventTap, {});
1867
+ }
1868
+
1869
+ // Fire hover events
1870
+ if (behaviour.hover) {
1871
+ attachEvent(actions.move, scope_Base, eventHover, {
1872
+ hover: true
1873
+ });
1874
+ }
1875
+
1876
+ // Make the range draggable.
1877
+ if (behaviour.drag) {
1878
+ scope_Connects.forEach(function(connect, index) {
1879
+ if (connect === false || index === 0 || index === scope_Connects.length - 1) {
1880
+ return;
1881
+ }
1882
+
1883
+ var handleBefore = scope_Handles[index - 1];
1884
+ var handleAfter = scope_Handles[index];
1885
+ var eventHolders = [connect];
1886
+
1887
+ addClass(connect, options.cssClasses.draggable);
1888
+
1889
+ // When the range is fixed, the entire range can
1890
+ // be dragged by the handles. The handle in the first
1891
+ // origin will propagate the start event upward,
1892
+ // but it needs to be bound manually on the other.
1893
+ if (behaviour.fixed) {
1894
+ eventHolders.push(handleBefore.children[0]);
1895
+ eventHolders.push(handleAfter.children[0]);
1896
+ }
1897
+
1898
+ eventHolders.forEach(function(eventHolder) {
1899
+ attachEvent(actions.start, eventHolder, eventStart, {
1900
+ handles: [handleBefore, handleAfter],
1901
+ handleNumbers: [index - 1, index]
1902
+ });
1903
+ });
1904
+ });
1905
+ }
1906
+ }
1907
+
1908
+ // Attach an event to this slider, possibly including a namespace
1909
+ function bindEvent(namespacedEvent, callback) {
1910
+ scope_Events[namespacedEvent] = scope_Events[namespacedEvent] || [];
1911
+ scope_Events[namespacedEvent].push(callback);
1912
+
1913
+ // If the event bound is 'update,' fire it immediately for all handles.
1914
+ if (namespacedEvent.split(".")[0] === "update") {
1915
+ scope_Handles.forEach(function(a, index) {
1916
+ fireEvent("update", index);
1917
+ });
1918
+ }
1919
+ }
1920
+
1921
+ // Undo attachment of event
1922
+ function removeEvent(namespacedEvent) {
1923
+ var event = namespacedEvent && namespacedEvent.split(".")[0];
1924
+ var namespace = event && namespacedEvent.substring(event.length);
1925
+
1926
+ Object.keys(scope_Events).forEach(function(bind) {
1927
+ var tEvent = bind.split(".")[0];
1928
+ var tNamespace = bind.substring(tEvent.length);
1929
+
1930
+ if ((!event || event === tEvent) && (!namespace || namespace === tNamespace)) {
1931
+ delete scope_Events[bind];
1932
+ }
1933
+ });
1934
+ }
1935
+
1936
+ // External event handling
1937
+ function fireEvent(eventName, handleNumber, tap) {
1938
+ Object.keys(scope_Events).forEach(function(targetEvent) {
1939
+ var eventType = targetEvent.split(".")[0];
1940
+
1941
+ if (eventName === eventType) {
1942
+ scope_Events[targetEvent].forEach(function(callback) {
1943
+ callback.call(
1944
+ // Use the slider public API as the scope ('this')
1945
+ scope_Self,
1946
+ // Return values as array, so arg_1[arg_2] is always valid.
1947
+ scope_Values.map(options.format.to),
1948
+ // Handle index, 0 or 1
1949
+ handleNumber,
1950
+ // Un-formatted slider values
1951
+ scope_Values.slice(),
1952
+ // Event is fired by tap, true or false
1953
+ tap || false,
1954
+ // Left offset of the handle, in relation to the slider
1955
+ scope_Locations.slice()
1956
+ );
1957
+ });
1958
+ }
1959
+ });
1960
+ }
1961
+
1962
+ // Split out the handle positioning logic so the Move event can use it, too
1963
+ function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue) {
1964
+ // For sliders with multiple handles, limit movement to the other handle.
1965
+ // Apply the margin option by adding it to the handle positions.
1966
+ if (scope_Handles.length > 1 && !options.events.unconstrained) {
1967
+ if (lookBackward && handleNumber > 0) {
1968
+ to = Math.max(to, reference[handleNumber - 1] + options.margin);
1969
+ }
1970
+
1971
+ if (lookForward && handleNumber < scope_Handles.length - 1) {
1972
+ to = Math.min(to, reference[handleNumber + 1] - options.margin);
1973
+ }
1974
+ }
1975
+
1976
+ // The limit option has the opposite effect, limiting handles to a
1977
+ // maximum distance from another. Limit must be > 0, as otherwise
1978
+ // handles would be unmovable.
1979
+ if (scope_Handles.length > 1 && options.limit) {
1980
+ if (lookBackward && handleNumber > 0) {
1981
+ to = Math.min(to, reference[handleNumber - 1] + options.limit);
1982
+ }
1983
+
1984
+ if (lookForward && handleNumber < scope_Handles.length - 1) {
1985
+ to = Math.max(to, reference[handleNumber + 1] - options.limit);
1986
+ }
1987
+ }
1988
+
1989
+ // The padding option keeps the handles a certain distance from the
1990
+ // edges of the slider. Padding must be > 0.
1991
+ if (options.padding) {
1992
+ if (handleNumber === 0) {
1993
+ to = Math.max(to, options.padding[0]);
1994
+ }
1995
+
1996
+ if (handleNumber === scope_Handles.length - 1) {
1997
+ to = Math.min(to, 100 - options.padding[1]);
1998
+ }
1999
+ }
2000
+
2001
+ to = scope_Spectrum.getStep(to);
2002
+
2003
+ // Limit percentage to the 0 - 100 range
2004
+ to = limit(to);
2005
+
2006
+ // Return false if handle can't move
2007
+ if (to === reference[handleNumber] && !getValue) {
2008
+ return false;
2009
+ }
2010
+
2011
+ return to;
2012
+ }
2013
+
2014
+ // Uses slider orientation to create CSS rules. a = base value;
2015
+ function inRuleOrder(v, a) {
2016
+ var o = options.ort;
2017
+ return (o ? a : v) + ", " + (o ? v : a);
2018
+ }
2019
+
2020
+ // Moves handle(s) by a percentage
2021
+ // (bool, % to move, [% where handle started, ...], [index in scope_Handles, ...])
2022
+ function moveHandles(upward, proposal, locations, handleNumbers) {
2023
+ var proposals = locations.slice();
2024
+
2025
+ var b = [!upward, upward];
2026
+ var f = [upward, !upward];
2027
+
2028
+ // Copy handleNumbers so we don't change the dataset
2029
+ handleNumbers = handleNumbers.slice();
2030
+
2031
+ // Check to see which handle is 'leading'.
2032
+ // If that one can't move the second can't either.
2033
+ if (upward) {
2034
+ handleNumbers.reverse();
2035
+ }
2036
+
2037
+ // Step 1: get the maximum percentage that any of the handles can move
2038
+ if (handleNumbers.length > 1) {
2039
+ handleNumbers.forEach(function(handleNumber, o) {
2040
+ var to = checkHandlePosition(
2041
+ proposals,
2042
+ handleNumber,
2043
+ proposals[handleNumber] + proposal,
2044
+ b[o],
2045
+ f[o],
2046
+ false
2047
+ );
2048
+
2049
+ // Stop if one of the handles can't move.
2050
+ if (to === false) {
2051
+ proposal = 0;
2052
+ } else {
2053
+ proposal = to - proposals[handleNumber];
2054
+ proposals[handleNumber] = to;
2055
+ }
2056
+ });
2057
+ }
2058
+
2059
+ // If using one handle, check backward AND forward
2060
+ else {
2061
+ b = f = [true];
2062
+ }
2063
+
2064
+ var state = false;
2065
+
2066
+ // Step 2: Try to set the handles with the found percentage
2067
+ handleNumbers.forEach(function(handleNumber, o) {
2068
+ state = setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o]) || state;
2069
+ });
2070
+
2071
+ // Step 3: If a handle moved, fire events
2072
+ if (state) {
2073
+ handleNumbers.forEach(function(handleNumber) {
2074
+ fireEvent("update", handleNumber);
2075
+ fireEvent("slide", handleNumber);
2076
+ });
2077
+ }
2078
+ }
2079
+
2080
+ // Takes a base value and an offset. This offset is used for the connect bar size.
2081
+ // In the initial design for this feature, the origin element was 1% wide.
2082
+ // Unfortunately, a rounding bug in Chrome makes it impossible to implement this feature
2083
+ // in this manner: https://bugs.chromium.org/p/chromium/issues/detail?id=798223
2084
+ function transformDirection(a, b) {
2085
+ return options.dir ? 100 - a - b : a;
2086
+ }
2087
+
2088
+ // Updates scope_Locations and scope_Values, updates visual state
2089
+ function updateHandlePosition(handleNumber, to) {
2090
+ // Update locations.
2091
+ scope_Locations[handleNumber] = to;
2092
+
2093
+ // Convert the value to the slider stepping/range.
2094
+ scope_Values[handleNumber] = scope_Spectrum.fromStepping(to);
2095
+
2096
+ var translation = 10 * (transformDirection(to, 0) - scope_DirOffset);
2097
+ var translateRule = "translate(" + inRuleOrder(translation + "%", "0") + ")";
2098
+
2099
+ scope_Handles[handleNumber].style[options.transformRule] = translateRule;
2100
+
2101
+ updateConnect(handleNumber);
2102
+ updateConnect(handleNumber + 1);
2103
+ }
2104
+
2105
+ // Handles before the slider middle are stacked later = higher,
2106
+ // Handles after the middle later is lower
2107
+ // [[7] [8] .......... | .......... [5] [4]
2108
+ function setZindex() {
2109
+ scope_HandleNumbers.forEach(function(handleNumber) {
2110
+ var dir = scope_Locations[handleNumber] > 50 ? -1 : 1;
2111
+ var zIndex = 3 + (scope_Handles.length + dir * handleNumber);
2112
+ scope_Handles[handleNumber].style.zIndex = zIndex;
2113
+ });
2114
+ }
2115
+
2116
+ // Test suggested values and apply margin, step.
2117
+ function setHandle(handleNumber, to, lookBackward, lookForward) {
2118
+ to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false);
2119
+
2120
+ if (to === false) {
2121
+ return false;
2122
+ }
2123
+
2124
+ updateHandlePosition(handleNumber, to);
2125
+
2126
+ return true;
2127
+ }
2128
+
2129
+ // Updates style attribute for connect nodes
2130
+ function updateConnect(index) {
2131
+ // Skip connects set to false
2132
+ if (!scope_Connects[index]) {
2133
+ return;
2134
+ }
2135
+
2136
+ var l = 0;
2137
+ var h = 100;
2138
+
2139
+ if (index !== 0) {
2140
+ l = scope_Locations[index - 1];
2141
+ }
2142
+
2143
+ if (index !== scope_Connects.length - 1) {
2144
+ h = scope_Locations[index];
2145
+ }
2146
+
2147
+ // We use two rules:
2148
+ // 'translate' to change the left/top offset;
2149
+ // 'scale' to change the width of the element;
2150
+ // As the element has a width of 100%, a translation of 100% is equal to 100% of the parent (.noUi-base)
2151
+ var connectWidth = h - l;
2152
+ var translateRule = "translate(" + inRuleOrder(transformDirection(l, connectWidth) + "%", "0") + ")";
2153
+ var scaleRule = "scale(" + inRuleOrder(connectWidth / 100, "1") + ")";
2154
+
2155
+ scope_Connects[index].style[options.transformRule] = translateRule + " " + scaleRule;
2156
+ }
2157
+
2158
+ // Parses value passed to .set method. Returns current value if not parse-able.
2159
+ function resolveToValue(to, handleNumber) {
2160
+ // Setting with null indicates an 'ignore'.
2161
+ // Inputting 'false' is invalid.
2162
+ if (to === null || to === false || to === undefined) {
2163
+ return scope_Locations[handleNumber];
2164
+ }
2165
+
2166
+ // If a formatted number was passed, attempt to decode it.
2167
+ if (typeof to === "number") {
2168
+ to = String(to);
2169
+ }
2170
+
2171
+ to = options.format.from(to);
2172
+ to = scope_Spectrum.toStepping(to);
2173
+
2174
+ // If parsing the number failed, use the current value.
2175
+ if (to === false || isNaN(to)) {
2176
+ return scope_Locations[handleNumber];
2177
+ }
2178
+
2179
+ return to;
2180
+ }
2181
+
2182
+ // Set the slider value.
2183
+ function valueSet(input, fireSetEvent) {
2184
+ var values = asArray(input);
2185
+ var isInit = scope_Locations[0] === undefined;
2186
+
2187
+ // Event fires by default
2188
+ fireSetEvent = fireSetEvent === undefined ? true : !!fireSetEvent;
2189
+
2190
+ // Animation is optional.
2191
+ // Make sure the initial values were set before using animated placement.
2192
+ if (options.animate && !isInit) {
2193
+ addClassFor(scope_Target, options.cssClasses.tap, options.animationDuration);
2194
+ }
2195
+
2196
+ // First pass, without lookAhead but with lookBackward. Values are set from left to right.
2197
+ scope_HandleNumbers.forEach(function(handleNumber) {
2198
+ setHandle(handleNumber, resolveToValue(values[handleNumber], handleNumber), true, false);
2199
+ });
2200
+
2201
+ var i = scope_HandleNumbers.length === 1 ? 0 : 1;
2202
+
2203
+ // Secondary passes. Now that all base values are set, apply constraints.
2204
+ // Iterate all handles to ensure constraints are applied for the entire slider (Issue #1009)
2205
+ for (; i < scope_HandleNumbers.length; ++i) {
2206
+ scope_HandleNumbers.forEach(function(handleNumber) {
2207
+ setHandle(handleNumber, scope_Locations[handleNumber], true, true);
2208
+ });
2209
+ }
2210
+
2211
+ setZindex();
2212
+
2213
+ scope_HandleNumbers.forEach(function(handleNumber) {
2214
+ fireEvent("update", handleNumber);
2215
+
2216
+ // Fire the event only for handles that received a new value, as per #579
2217
+ if (values[handleNumber] !== null && fireSetEvent) {
2218
+ fireEvent("set", handleNumber);
2219
+ }
2220
+ });
2221
+ }
2222
+
2223
+ // Reset slider to initial values
2224
+ function valueReset(fireSetEvent) {
2225
+ valueSet(options.start, fireSetEvent);
2226
+ }
2227
+
2228
+ // Set value for a single handle
2229
+ function valueSetHandle(handleNumber, value, fireSetEvent) {
2230
+ // Ensure numeric input
2231
+ handleNumber = Number(handleNumber);
2232
+
2233
+ if (!(handleNumber >= 0 && handleNumber < scope_HandleNumbers.length)) {
2234
+ throw new Error("noUiSlider (" + VERSION + "): invalid handle number, got: " + handleNumber);
2235
+ }
2236
+
2237
+ // Look both backward and forward, since we don't want this handle to "push" other handles (#960);
2238
+ setHandle(handleNumber, resolveToValue(value, handleNumber), true, true);
2239
+
2240
+ fireEvent("update", handleNumber);
2241
+
2242
+ if (fireSetEvent) {
2243
+ fireEvent("set", handleNumber);
2244
+ }
2245
+ }
2246
+
2247
+ // Get the slider value.
2248
+ function valueGet() {
2249
+ var values = scope_Values.map(options.format.to);
2250
+
2251
+ // If only one handle is used, return a single value.
2252
+ if (values.length === 1) {
2253
+ return values[0];
2254
+ }
2255
+
2256
+ return values;
2257
+ }
2258
+
2259
+ // Removes classes from the root and empties it.
2260
+ function destroy() {
2261
+ for (var key in options.cssClasses) {
2262
+ if (!options.cssClasses.hasOwnProperty(key)) {
2263
+ continue;
2264
+ }
2265
+ removeClass(scope_Target, options.cssClasses[key]);
2266
+ }
2267
+
2268
+ while (scope_Target.firstChild) {
2269
+ scope_Target.removeChild(scope_Target.firstChild);
2270
+ }
2271
+
2272
+ delete scope_Target.noUiSlider;
2273
+ }
2274
+
2275
+ function getNextStepsForHandle(handleNumber) {
2276
+ var location = scope_Locations[handleNumber];
2277
+ var nearbySteps = scope_Spectrum.getNearbySteps(location);
2278
+ var value = scope_Values[handleNumber];
2279
+ var increment = nearbySteps.thisStep.step;
2280
+ var decrement = null;
2281
+
2282
+ // If snapped, directly use defined step value
2283
+ if (options.snap) {
2284
+ return [
2285
+ value - nearbySteps.stepBefore.startValue || null,
2286
+ nearbySteps.stepAfter.startValue - value || null
2287
+ ];
2288
+ }
2289
+
2290
+ // If the next value in this step moves into the next step,
2291
+ // the increment is the start of the next step - the current value
2292
+ if (increment !== false) {
2293
+ if (value + increment > nearbySteps.stepAfter.startValue) {
2294
+ increment = nearbySteps.stepAfter.startValue - value;
2295
+ }
2296
+ }
2297
+
2298
+ // If the value is beyond the starting point
2299
+ if (value > nearbySteps.thisStep.startValue) {
2300
+ decrement = nearbySteps.thisStep.step;
2301
+ } else if (nearbySteps.stepBefore.step === false) {
2302
+ decrement = false;
2303
+ }
2304
+
2305
+ // If a handle is at the start of a step, it always steps back into the previous step first
2306
+ else {
2307
+ decrement = value - nearbySteps.stepBefore.highestStep;
2308
+ }
2309
+
2310
+ // Now, if at the slider edges, there is no in/decrement
2311
+ if (location === 100) {
2312
+ increment = null;
2313
+ } else if (location === 0) {
2314
+ decrement = null;
2315
+ }
2316
+
2317
+ // As per #391, the comparison for the decrement step can have some rounding issues.
2318
+ var stepDecimals = scope_Spectrum.countStepDecimals();
2319
+
2320
+ // Round per #391
2321
+ if (increment !== null && increment !== false) {
2322
+ increment = Number(increment.toFixed(stepDecimals));
2323
+ }
2324
+
2325
+ if (decrement !== null && decrement !== false) {
2326
+ decrement = Number(decrement.toFixed(stepDecimals));
2327
+ }
2328
+
2329
+ return [decrement, increment];
2330
+ }
2331
+
2332
+ // Get the current step size for the slider.
2333
+ function getNextSteps() {
2334
+ return scope_HandleNumbers.map(getNextStepsForHandle);
2335
+ }
2336
+
2337
+ // Updateable: margin, limit, padding, step, range, animate, snap
2338
+ function updateOptions(optionsToUpdate, fireSetEvent) {
2339
+ // Spectrum is created using the range, snap, direction and step options.
2340
+ // 'snap' and 'step' can be updated.
2341
+ // If 'snap' and 'step' are not passed, they should remain unchanged.
2342
+ var v = valueGet();
2343
+
2344
+ var updateAble = [
2345
+ "margin",
2346
+ "limit",
2347
+ "padding",
2348
+ "range",
2349
+ "animate",
2350
+ "snap",
2351
+ "step",
2352
+ "format",
2353
+ "pips",
2354
+ "tooltips"
2355
+ ];
2356
+
2357
+ // Only change options that we're actually passed to update.
2358
+ updateAble.forEach(function(name) {
2359
+ // Check for undefined. null removes the value.
2360
+ if (optionsToUpdate[name] !== undefined) {
2361
+ originalOptions[name] = optionsToUpdate[name];
2362
+ }
2363
+ });
2364
+
2365
+ var newOptions = testOptions(originalOptions);
2366
+
2367
+ // Load new options into the slider state
2368
+ updateAble.forEach(function(name) {
2369
+ if (optionsToUpdate[name] !== undefined) {
2370
+ options[name] = newOptions[name];
2371
+ }
2372
+ });
2373
+
2374
+ scope_Spectrum = newOptions.spectrum;
2375
+
2376
+ // Limit, margin and padding depend on the spectrum but are stored outside of it. (#677)
2377
+ options.margin = newOptions.margin;
2378
+ options.limit = newOptions.limit;
2379
+ options.padding = newOptions.padding;
2380
+
2381
+ // Update pips, removes existing.
2382
+ if (options.pips) {
2383
+ pips(options.pips);
2384
+ } else {
2385
+ removePips();
2386
+ }
2387
+
2388
+ // Update tooltips, removes existing.
2389
+ if (options.tooltips) {
2390
+ tooltips();
2391
+ } else {
2392
+ removeTooltips();
2393
+ }
2394
+
2395
+ // Invalidate the current positioning so valueSet forces an update.
2396
+ scope_Locations = [];
2397
+ valueSet(optionsToUpdate.start || v, fireSetEvent);
2398
+ }
2399
+
2400
+ // Initialization steps
2401
+ function setupSlider() {
2402
+ // Create the base element, initialize HTML and set classes.
2403
+ // Add handles and connect elements.
2404
+ scope_Base = addSlider(scope_Target);
2405
+
2406
+ addElements(options.connect, scope_Base);
2407
+
2408
+ // Attach user events.
2409
+ bindSliderEvents(options.events);
2410
+
2411
+ // Use the public value method to set the start values.
2412
+ valueSet(options.start);
2413
+
2414
+ if (options.pips) {
2415
+ pips(options.pips);
2416
+ }
2417
+
2418
+ if (options.tooltips) {
2419
+ tooltips();
2420
+ }
2421
+
2422
+ aria();
2423
+ }
2424
+
2425
+ setupSlider();
2426
+
2427
+ // noinspection JSUnusedGlobalSymbols
2428
+ scope_Self = {
2429
+ destroy: destroy,
2430
+ steps: getNextSteps,
2431
+ on: bindEvent,
2432
+ off: removeEvent,
2433
+ get: valueGet,
2434
+ set: valueSet,
2435
+ setHandle: valueSetHandle,
2436
+ reset: valueReset,
2437
+ // Exposed for unit testing, don't use this in your application.
2438
+ __moveHandles: function(a, b, c) {
2439
+ moveHandles(a, b, scope_Locations, c);
2440
+ },
2441
+ options: originalOptions, // Issue #600, #678
2442
+ updateOptions: updateOptions,
2443
+ target: scope_Target, // Issue #597
2444
+ removePips: removePips,
2445
+ removeTooltips: removeTooltips,
2446
+ pips: pips // Issue #594
2447
+ };
2448
+
2449
+ return scope_Self;
2450
+ }
2451
+
2452
+ // Run the standard initializer
2453
+ function initialize(target, originalOptions) {
2454
+ if (!target || !target.nodeName) {
2455
+ throw new Error("noUiSlider (" + VERSION + "): create requires a single element, got: " + target);
2456
+ }
2457
+
2458
+ // Throw an error if the slider was already initialized.
2459
+ if (target.noUiSlider) {
2460
+ throw new Error("noUiSlider (" + VERSION + "): Slider was already initialized.");
2461
+ }
2462
+
2463
+ // Test the options and create the slider environment;
2464
+ var options = testOptions(originalOptions, target);
2465
+ var api = scope(target, options, originalOptions);
2466
+
2467
+ target.noUiSlider = api;
2468
+
2469
+ return api;
2470
+ }
2471
+
2472
+ // Use an object instead of a function for future expandability;
2473
+ return {
2474
+ // Exposed for unit testing, don't use this in your application.
2475
+ __spectrum: Spectrum,
2476
+ version: VERSION,
2477
+ create: initialize
2478
+ };
2479
+ });