1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.noUiSlider = {}));
|
5 | })(this, (function (exports) { 'use strict';
|
6 |
|
7 | exports.PipsMode = void 0;
|
8 | (function (PipsMode) {
|
9 | PipsMode["Range"] = "range";
|
10 | PipsMode["Steps"] = "steps";
|
11 | PipsMode["Positions"] = "positions";
|
12 | PipsMode["Count"] = "count";
|
13 | PipsMode["Values"] = "values";
|
14 | })(exports.PipsMode || (exports.PipsMode = {}));
|
15 | exports.PipsType = void 0;
|
16 | (function (PipsType) {
|
17 | PipsType[PipsType["None"] = -1] = "None";
|
18 | PipsType[PipsType["NoValue"] = 0] = "NoValue";
|
19 | PipsType[PipsType["LargeValue"] = 1] = "LargeValue";
|
20 | PipsType[PipsType["SmallValue"] = 2] = "SmallValue";
|
21 | })(exports.PipsType || (exports.PipsType = {}));
|
22 |
|
23 | function isValidFormatter(entry) {
|
24 | return isValidPartialFormatter(entry) && typeof entry.from === "function";
|
25 | }
|
26 | function isValidPartialFormatter(entry) {
|
27 |
|
28 | return typeof entry === "object" && typeof entry.to === "function";
|
29 | }
|
30 | function removeElement(el) {
|
31 | el.parentElement.removeChild(el);
|
32 | }
|
33 | function isSet(value) {
|
34 | return value !== null && value !== undefined;
|
35 | }
|
36 |
|
37 | function preventDefault(e) {
|
38 | e.preventDefault();
|
39 | }
|
40 |
|
41 | function unique(array) {
|
42 | return array.filter(function (a) {
|
43 | return !this[a] ? (this[a] = true) : false;
|
44 | }, {});
|
45 | }
|
46 |
|
47 | function closest(value, to) {
|
48 | return Math.round(value / to) * to;
|
49 | }
|
50 |
|
51 | function offset(elem, orientation) {
|
52 | var rect = elem.getBoundingClientRect();
|
53 | var doc = elem.ownerDocument;
|
54 | var docElem = doc.documentElement;
|
55 | var pageOffset = getPageOffset(doc);
|
56 |
|
57 |
|
58 |
|
59 | if (/webkit.*Chrome.*Mobile/i.test(navigator.userAgent)) {
|
60 | pageOffset.x = 0;
|
61 | }
|
62 | return orientation ? rect.top + pageOffset.y - docElem.clientTop : rect.left + pageOffset.x - docElem.clientLeft;
|
63 | }
|
64 |
|
65 | function isNumeric(a) {
|
66 | return typeof a === "number" && !isNaN(a) && isFinite(a);
|
67 | }
|
68 |
|
69 | function addClassFor(element, className, duration) {
|
70 | if (duration > 0) {
|
71 | addClass(element, className);
|
72 | setTimeout(function () {
|
73 | removeClass(element, className);
|
74 | }, duration);
|
75 | }
|
76 | }
|
77 |
|
78 | function limit(a) {
|
79 | return Math.max(Math.min(a, 100), 0);
|
80 | }
|
81 |
|
82 |
|
83 | function asArray(a) {
|
84 | return Array.isArray(a) ? a : [a];
|
85 | }
|
86 |
|
87 | function countDecimals(numStr) {
|
88 | numStr = String(numStr);
|
89 | var pieces = numStr.split(".");
|
90 | return pieces.length > 1 ? pieces[1].length : 0;
|
91 | }
|
92 |
|
93 | function addClass(el, className) {
|
94 | if (el.classList && !/\s/.test(className)) {
|
95 | el.classList.add(className);
|
96 | }
|
97 | else {
|
98 | el.className += " " + className;
|
99 | }
|
100 | }
|
101 |
|
102 | function removeClass(el, className) {
|
103 | if (el.classList && !/\s/.test(className)) {
|
104 | el.classList.remove(className);
|
105 | }
|
106 | else {
|
107 | el.className = el.className.replace(new RegExp("(^|\\b)" + className.split(" ").join("|") + "(\\b|$)", "gi"), " ");
|
108 | }
|
109 | }
|
110 |
|
111 | function hasClass(el, className) {
|
112 | return el.classList ? el.classList.contains(className) : new RegExp("\\b" + className + "\\b").test(el.className);
|
113 | }
|
114 |
|
115 | function getPageOffset(doc) {
|
116 | var supportPageOffset = window.pageXOffset !== undefined;
|
117 | var isCSS1Compat = (doc.compatMode || "") === "CSS1Compat";
|
118 | var x = supportPageOffset
|
119 | ? window.pageXOffset
|
120 | : isCSS1Compat
|
121 | ? doc.documentElement.scrollLeft
|
122 | : doc.body.scrollLeft;
|
123 | var y = supportPageOffset
|
124 | ? window.pageYOffset
|
125 | : isCSS1Compat
|
126 | ? doc.documentElement.scrollTop
|
127 | : doc.body.scrollTop;
|
128 | return {
|
129 | x: x,
|
130 | y: y,
|
131 | };
|
132 | }
|
133 |
|
134 |
|
135 |
|
136 | function getActions() {
|
137 |
|
138 |
|
139 | return window.navigator.pointerEnabled
|
140 | ? {
|
141 | start: "pointerdown",
|
142 | move: "pointermove",
|
143 | end: "pointerup",
|
144 | }
|
145 | : window.navigator.msPointerEnabled
|
146 | ? {
|
147 | start: "MSPointerDown",
|
148 | move: "MSPointerMove",
|
149 | end: "MSPointerUp",
|
150 | }
|
151 | : {
|
152 | start: "mousedown touchstart",
|
153 | move: "mousemove touchmove",
|
154 | end: "mouseup touchend",
|
155 | };
|
156 | }
|
157 |
|
158 |
|
159 | function getSupportsPassive() {
|
160 | var supportsPassive = false;
|
161 |
|
162 | try {
|
163 | var opts = Object.defineProperty({}, "passive", {
|
164 | get: function () {
|
165 | supportsPassive = true;
|
166 | },
|
167 | });
|
168 |
|
169 | window.addEventListener("test", null, opts);
|
170 | }
|
171 | catch (e) { }
|
172 |
|
173 | return supportsPassive;
|
174 | }
|
175 | function getSupportsTouchActionNone() {
|
176 | return window.CSS && CSS.supports && CSS.supports("touch-action", "none");
|
177 | }
|
178 |
|
179 |
|
180 |
|
181 | function subRangeRatio(pa, pb) {
|
182 | return 100 / (pb - pa);
|
183 | }
|
184 |
|
185 | function fromPercentage(range, value, startRange) {
|
186 | return (value * 100) / (range[startRange + 1] - range[startRange]);
|
187 | }
|
188 |
|
189 | function toPercentage(range, value) {
|
190 | return fromPercentage(range, range[0] < 0 ? value + Math.abs(range[0]) : value - range[0], 0);
|
191 | }
|
192 |
|
193 | function isPercentage(range, value) {
|
194 | return (value * (range[1] - range[0])) / 100 + range[0];
|
195 | }
|
196 | function getJ(value, arr) {
|
197 | var j = 1;
|
198 | while (value >= arr[j]) {
|
199 | j += 1;
|
200 | }
|
201 | return j;
|
202 | }
|
203 |
|
204 | function toStepping(xVal, xPct, value) {
|
205 | if (value >= xVal.slice(-1)[0]) {
|
206 | return 100;
|
207 | }
|
208 | var j = getJ(value, xVal);
|
209 | var va = xVal[j - 1];
|
210 | var vb = xVal[j];
|
211 | var pa = xPct[j - 1];
|
212 | var pb = xPct[j];
|
213 | return pa + toPercentage([va, vb], value) / subRangeRatio(pa, pb);
|
214 | }
|
215 |
|
216 | function fromStepping(xVal, xPct, value) {
|
217 |
|
218 | if (value >= 100) {
|
219 | return xVal.slice(-1)[0];
|
220 | }
|
221 | var j = getJ(value, xPct);
|
222 | var va = xVal[j - 1];
|
223 | var vb = xVal[j];
|
224 | var pa = xPct[j - 1];
|
225 | var pb = xPct[j];
|
226 | return isPercentage([va, vb], (value - pa) * subRangeRatio(pa, pb));
|
227 | }
|
228 |
|
229 | function getStep(xPct, xSteps, snap, value) {
|
230 | if (value === 100) {
|
231 | return value;
|
232 | }
|
233 | var j = getJ(value, xPct);
|
234 | var a = xPct[j - 1];
|
235 | var b = xPct[j];
|
236 |
|
237 | if (snap) {
|
238 |
|
239 | if (value - a > (b - a) / 2) {
|
240 | return b;
|
241 | }
|
242 | return a;
|
243 | }
|
244 | if (!xSteps[j - 1]) {
|
245 | return value;
|
246 | }
|
247 | return xPct[j - 1] + closest(value - xPct[j - 1], xSteps[j - 1]);
|
248 | }
|
249 |
|
250 |
|
251 | var Spectrum = (function () {
|
252 | function Spectrum(entry, snap, singleStep) {
|
253 | this.xPct = [];
|
254 | this.xVal = [];
|
255 | this.xSteps = [];
|
256 | this.xNumSteps = [];
|
257 | this.xHighestCompleteStep = [];
|
258 | this.xSteps = [singleStep || false];
|
259 | this.xNumSteps = [false];
|
260 | this.snap = snap;
|
261 | var index;
|
262 | var ordered = [];
|
263 |
|
264 | Object.keys(entry).forEach(function (index) {
|
265 | ordered.push([asArray(entry[index]), index]);
|
266 | });
|
267 |
|
268 | ordered.sort(function (a, b) {
|
269 | return a[0][0] - b[0][0];
|
270 | });
|
271 |
|
272 | for (index = 0; index < ordered.length; index++) {
|
273 | this.handleEntryPoint(ordered[index][1], ordered[index][0]);
|
274 | }
|
275 |
|
276 |
|
277 | this.xNumSteps = this.xSteps.slice(0);
|
278 |
|
279 | for (index = 0; index < this.xNumSteps.length; index++) {
|
280 | this.handleStepPoint(index, this.xNumSteps[index]);
|
281 | }
|
282 | }
|
283 | Spectrum.prototype.getDistance = function (value) {
|
284 | var distances = [];
|
285 | for (var index = 0; index < this.xNumSteps.length - 1; index++) {
|
286 | distances[index] = fromPercentage(this.xVal, value, index);
|
287 | }
|
288 | return distances;
|
289 | };
|
290 |
|
291 |
|
292 | Spectrum.prototype.getAbsoluteDistance = function (value, distances, direction) {
|
293 | var xPct_index = 0;
|
294 |
|
295 | if (value < this.xPct[this.xPct.length - 1]) {
|
296 | while (value > this.xPct[xPct_index + 1]) {
|
297 | xPct_index++;
|
298 | }
|
299 | }
|
300 | else if (value === this.xPct[this.xPct.length - 1]) {
|
301 | xPct_index = this.xPct.length - 2;
|
302 | }
|
303 |
|
304 | if (!direction && value === this.xPct[xPct_index + 1]) {
|
305 | xPct_index++;
|
306 | }
|
307 | if (distances === null) {
|
308 | distances = [];
|
309 | }
|
310 | var start_factor;
|
311 | var rest_factor = 1;
|
312 | var rest_rel_distance = distances[xPct_index];
|
313 | var range_pct = 0;
|
314 | var rel_range_distance = 0;
|
315 | var abs_distance_counter = 0;
|
316 | var range_counter = 0;
|
317 |
|
318 | if (direction) {
|
319 | start_factor = (value - this.xPct[xPct_index]) / (this.xPct[xPct_index + 1] - this.xPct[xPct_index]);
|
320 | }
|
321 | else {
|
322 | start_factor = (this.xPct[xPct_index + 1] - value) / (this.xPct[xPct_index + 1] - this.xPct[xPct_index]);
|
323 | }
|
324 |
|
325 | while (rest_rel_distance > 0) {
|
326 |
|
327 | range_pct = this.xPct[xPct_index + 1 + range_counter] - this.xPct[xPct_index + range_counter];
|
328 |
|
329 | if (distances[xPct_index + range_counter] * rest_factor + 100 - start_factor * 100 > 100) {
|
330 |
|
331 | rel_range_distance = range_pct * start_factor;
|
332 |
|
333 | rest_factor = (rest_rel_distance - 100 * start_factor) / distances[xPct_index + range_counter];
|
334 |
|
335 | start_factor = 1;
|
336 | }
|
337 | else {
|
338 |
|
339 | rel_range_distance = ((distances[xPct_index + range_counter] * range_pct) / 100) * rest_factor;
|
340 |
|
341 | rest_factor = 0;
|
342 | }
|
343 | if (direction) {
|
344 | abs_distance_counter = abs_distance_counter - rel_range_distance;
|
345 |
|
346 | if (this.xPct.length + range_counter >= 1) {
|
347 | range_counter--;
|
348 | }
|
349 | }
|
350 | else {
|
351 | abs_distance_counter = abs_distance_counter + rel_range_distance;
|
352 |
|
353 | if (this.xPct.length - range_counter >= 1) {
|
354 | range_counter++;
|
355 | }
|
356 | }
|
357 |
|
358 | rest_rel_distance = distances[xPct_index + range_counter] * rest_factor;
|
359 | }
|
360 | return value + abs_distance_counter;
|
361 | };
|
362 | Spectrum.prototype.toStepping = function (value) {
|
363 | value = toStepping(this.xVal, this.xPct, value);
|
364 | return value;
|
365 | };
|
366 | Spectrum.prototype.fromStepping = function (value) {
|
367 | return fromStepping(this.xVal, this.xPct, value);
|
368 | };
|
369 | Spectrum.prototype.getStep = function (value) {
|
370 | value = getStep(this.xPct, this.xSteps, this.snap, value);
|
371 | return value;
|
372 | };
|
373 | Spectrum.prototype.getDefaultStep = function (value, isDown, size) {
|
374 | var j = getJ(value, this.xPct);
|
375 |
|
376 | if (value === 100 || (isDown && value === this.xPct[j - 1])) {
|
377 | j = Math.max(j - 1, 1);
|
378 | }
|
379 | return (this.xVal[j] - this.xVal[j - 1]) / size;
|
380 | };
|
381 | Spectrum.prototype.getNearbySteps = function (value) {
|
382 | var j = getJ(value, this.xPct);
|
383 | return {
|
384 | stepBefore: {
|
385 | startValue: this.xVal[j - 2],
|
386 | step: this.xNumSteps[j - 2],
|
387 | highestStep: this.xHighestCompleteStep[j - 2],
|
388 | },
|
389 | thisStep: {
|
390 | startValue: this.xVal[j - 1],
|
391 | step: this.xNumSteps[j - 1],
|
392 | highestStep: this.xHighestCompleteStep[j - 1],
|
393 | },
|
394 | stepAfter: {
|
395 | startValue: this.xVal[j],
|
396 | step: this.xNumSteps[j],
|
397 | highestStep: this.xHighestCompleteStep[j],
|
398 | },
|
399 | };
|
400 | };
|
401 | Spectrum.prototype.countStepDecimals = function () {
|
402 | var stepDecimals = this.xNumSteps.map(countDecimals);
|
403 | return Math.max.apply(null, stepDecimals);
|
404 | };
|
405 | Spectrum.prototype.hasNoSize = function () {
|
406 | return this.xVal[0] === this.xVal[this.xVal.length - 1];
|
407 | };
|
408 |
|
409 | Spectrum.prototype.convert = function (value) {
|
410 | return this.getStep(this.toStepping(value));
|
411 | };
|
412 | Spectrum.prototype.handleEntryPoint = function (index, value) {
|
413 | var percentage;
|
414 |
|
415 | if (index === "min") {
|
416 | percentage = 0;
|
417 | }
|
418 | else if (index === "max") {
|
419 | percentage = 100;
|
420 | }
|
421 | else {
|
422 | percentage = parseFloat(index);
|
423 | }
|
424 |
|
425 | if (!isNumeric(percentage) || !isNumeric(value[0])) {
|
426 | throw new Error("noUiSlider: 'range' value isn't numeric.");
|
427 | }
|
428 |
|
429 | this.xPct.push(percentage);
|
430 | this.xVal.push(value[0]);
|
431 | var value1 = Number(value[1]);
|
432 |
|
433 |
|
434 |
|
435 | if (!percentage) {
|
436 | if (!isNaN(value1)) {
|
437 | this.xSteps[0] = value1;
|
438 | }
|
439 | }
|
440 | else {
|
441 | this.xSteps.push(isNaN(value1) ? false : value1);
|
442 | }
|
443 | this.xHighestCompleteStep.push(0);
|
444 | };
|
445 | Spectrum.prototype.handleStepPoint = function (i, n) {
|
446 |
|
447 | if (!n) {
|
448 | return;
|
449 | }
|
450 |
|
451 | if (this.xVal[i] === this.xVal[i + 1]) {
|
452 | this.xSteps[i] = this.xHighestCompleteStep[i] = this.xVal[i];
|
453 | return;
|
454 | }
|
455 |
|
456 | this.xSteps[i] =
|
457 | fromPercentage([this.xVal[i], this.xVal[i + 1]], n, 0) / subRangeRatio(this.xPct[i], this.xPct[i + 1]);
|
458 | var totalSteps = (this.xVal[i + 1] - this.xVal[i]) / this.xNumSteps[i];
|
459 | var highestStep = Math.ceil(Number(totalSteps.toFixed(3)) - 1);
|
460 | var step = this.xVal[i] + this.xNumSteps[i] * highestStep;
|
461 | this.xHighestCompleteStep[i] = step;
|
462 | };
|
463 | return Spectrum;
|
464 | }());
|
465 |
|
466 |
|
467 | |
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 | var defaultFormatter = {
|
481 | to: function (value) {
|
482 | return value === undefined ? "" : value.toFixed(2);
|
483 | },
|
484 | from: Number,
|
485 | };
|
486 | var cssClasses = {
|
487 | target: "target",
|
488 | base: "base",
|
489 | origin: "origin",
|
490 | handle: "handle",
|
491 | handleLower: "handle-lower",
|
492 | handleUpper: "handle-upper",
|
493 | touchArea: "touch-area",
|
494 | horizontal: "horizontal",
|
495 | vertical: "vertical",
|
496 | background: "background",
|
497 | connect: "connect",
|
498 | connects: "connects",
|
499 | ltr: "ltr",
|
500 | rtl: "rtl",
|
501 | textDirectionLtr: "txt-dir-ltr",
|
502 | textDirectionRtl: "txt-dir-rtl",
|
503 | draggable: "draggable",
|
504 | drag: "state-drag",
|
505 | tap: "state-tap",
|
506 | active: "active",
|
507 | tooltip: "tooltip",
|
508 | pips: "pips",
|
509 | pipsHorizontal: "pips-horizontal",
|
510 | pipsVertical: "pips-vertical",
|
511 | marker: "marker",
|
512 | markerHorizontal: "marker-horizontal",
|
513 | markerVertical: "marker-vertical",
|
514 | markerNormal: "marker-normal",
|
515 | markerLarge: "marker-large",
|
516 | markerSub: "marker-sub",
|
517 | value: "value",
|
518 | valueHorizontal: "value-horizontal",
|
519 | valueVertical: "value-vertical",
|
520 | valueNormal: "value-normal",
|
521 | valueLarge: "value-large",
|
522 | valueSub: "value-sub",
|
523 | };
|
524 |
|
525 | var INTERNAL_EVENT_NS = {
|
526 | tooltips: ".__tooltips",
|
527 | aria: ".__aria",
|
528 | };
|
529 |
|
530 | function testStep(parsed, entry) {
|
531 | if (!isNumeric(entry)) {
|
532 | throw new Error("noUiSlider: 'step' is not numeric.");
|
533 | }
|
534 |
|
535 |
|
536 | parsed.singleStep = entry;
|
537 | }
|
538 | function testKeyboardPageMultiplier(parsed, entry) {
|
539 | if (!isNumeric(entry)) {
|
540 | throw new Error("noUiSlider: 'keyboardPageMultiplier' is not numeric.");
|
541 | }
|
542 | parsed.keyboardPageMultiplier = entry;
|
543 | }
|
544 | function testKeyboardMultiplier(parsed, entry) {
|
545 | if (!isNumeric(entry)) {
|
546 | throw new Error("noUiSlider: 'keyboardMultiplier' is not numeric.");
|
547 | }
|
548 | parsed.keyboardMultiplier = entry;
|
549 | }
|
550 | function testKeyboardDefaultStep(parsed, entry) {
|
551 | if (!isNumeric(entry)) {
|
552 | throw new Error("noUiSlider: 'keyboardDefaultStep' is not numeric.");
|
553 | }
|
554 | parsed.keyboardDefaultStep = entry;
|
555 | }
|
556 | function testRange(parsed, entry) {
|
557 |
|
558 | if (typeof entry !== "object" || Array.isArray(entry)) {
|
559 | throw new Error("noUiSlider: 'range' is not an object.");
|
560 | }
|
561 |
|
562 | if (entry.min === undefined || entry.max === undefined) {
|
563 | throw new Error("noUiSlider: Missing 'min' or 'max' in 'range'.");
|
564 | }
|
565 | parsed.spectrum = new Spectrum(entry, parsed.snap || false, parsed.singleStep);
|
566 | }
|
567 | function testStart(parsed, entry) {
|
568 | entry = asArray(entry);
|
569 |
|
570 |
|
571 | if (!Array.isArray(entry) || !entry.length) {
|
572 | throw new Error("noUiSlider: 'start' option is incorrect.");
|
573 | }
|
574 |
|
575 | parsed.handles = entry.length;
|
576 |
|
577 |
|
578 | parsed.start = entry;
|
579 | }
|
580 | function testSnap(parsed, entry) {
|
581 | if (typeof entry !== "boolean") {
|
582 | throw new Error("noUiSlider: 'snap' option must be a boolean.");
|
583 | }
|
584 |
|
585 | parsed.snap = entry;
|
586 | }
|
587 | function testAnimate(parsed, entry) {
|
588 | if (typeof entry !== "boolean") {
|
589 | throw new Error("noUiSlider: 'animate' option must be a boolean.");
|
590 | }
|
591 |
|
592 | parsed.animate = entry;
|
593 | }
|
594 | function testAnimationDuration(parsed, entry) {
|
595 | if (typeof entry !== "number") {
|
596 | throw new Error("noUiSlider: 'animationDuration' option must be a number.");
|
597 | }
|
598 | parsed.animationDuration = entry;
|
599 | }
|
600 | function testConnect(parsed, entry) {
|
601 | var connect = [false];
|
602 | var i;
|
603 |
|
604 | if (entry === "lower") {
|
605 | entry = [true, false];
|
606 | }
|
607 | else if (entry === "upper") {
|
608 | entry = [false, true];
|
609 | }
|
610 |
|
611 | if (entry === true || entry === false) {
|
612 | for (i = 1; i < parsed.handles; i++) {
|
613 | connect.push(entry);
|
614 | }
|
615 | connect.push(false);
|
616 | }
|
617 |
|
618 | else if (!Array.isArray(entry) || !entry.length || entry.length !== parsed.handles + 1) {
|
619 | throw new Error("noUiSlider: 'connect' option doesn't match handle count.");
|
620 | }
|
621 | else {
|
622 | connect = entry;
|
623 | }
|
624 | parsed.connect = connect;
|
625 | }
|
626 | function testOrientation(parsed, entry) {
|
627 |
|
628 |
|
629 | switch (entry) {
|
630 | case "horizontal":
|
631 | parsed.ort = 0;
|
632 | break;
|
633 | case "vertical":
|
634 | parsed.ort = 1;
|
635 | break;
|
636 | default:
|
637 | throw new Error("noUiSlider: 'orientation' option is invalid.");
|
638 | }
|
639 | }
|
640 | function testMargin(parsed, entry) {
|
641 | if (!isNumeric(entry)) {
|
642 | throw new Error("noUiSlider: 'margin' option must be numeric.");
|
643 | }
|
644 |
|
645 | if (entry === 0) {
|
646 | return;
|
647 | }
|
648 | parsed.margin = parsed.spectrum.getDistance(entry);
|
649 | }
|
650 | function testLimit(parsed, entry) {
|
651 | if (!isNumeric(entry)) {
|
652 | throw new Error("noUiSlider: 'limit' option must be numeric.");
|
653 | }
|
654 | parsed.limit = parsed.spectrum.getDistance(entry);
|
655 | if (!parsed.limit || parsed.handles < 2) {
|
656 | throw new Error("noUiSlider: 'limit' option is only supported on linear sliders with 2 or more handles.");
|
657 | }
|
658 | }
|
659 | function testPadding(parsed, entry) {
|
660 | var index;
|
661 | if (!isNumeric(entry) && !Array.isArray(entry)) {
|
662 | throw new Error("noUiSlider: 'padding' option must be numeric or array of exactly 2 numbers.");
|
663 | }
|
664 | if (Array.isArray(entry) && !(entry.length === 2 || isNumeric(entry[0]) || isNumeric(entry[1]))) {
|
665 | throw new Error("noUiSlider: 'padding' option must be numeric or array of exactly 2 numbers.");
|
666 | }
|
667 | if (entry === 0) {
|
668 | return;
|
669 | }
|
670 | if (!Array.isArray(entry)) {
|
671 | entry = [entry, entry];
|
672 | }
|
673 |
|
674 | parsed.padding = [parsed.spectrum.getDistance(entry[0]), parsed.spectrum.getDistance(entry[1])];
|
675 | for (index = 0; index < parsed.spectrum.xNumSteps.length - 1; index++) {
|
676 |
|
677 | if (parsed.padding[0][index] < 0 || parsed.padding[1][index] < 0) {
|
678 | throw new Error("noUiSlider: 'padding' option must be a positive number(s).");
|
679 | }
|
680 | }
|
681 | var totalPadding = entry[0] + entry[1];
|
682 | var firstValue = parsed.spectrum.xVal[0];
|
683 | var lastValue = parsed.spectrum.xVal[parsed.spectrum.xVal.length - 1];
|
684 | if (totalPadding / (lastValue - firstValue) > 1) {
|
685 | throw new Error("noUiSlider: 'padding' option must not exceed 100% of the range.");
|
686 | }
|
687 | }
|
688 | function testDirection(parsed, entry) {
|
689 |
|
690 |
|
691 |
|
692 | switch (entry) {
|
693 | case "ltr":
|
694 | parsed.dir = 0;
|
695 | break;
|
696 | case "rtl":
|
697 | parsed.dir = 1;
|
698 | break;
|
699 | default:
|
700 | throw new Error("noUiSlider: 'direction' option was not recognized.");
|
701 | }
|
702 | }
|
703 | function testBehaviour(parsed, entry) {
|
704 |
|
705 | if (typeof entry !== "string") {
|
706 | throw new Error("noUiSlider: 'behaviour' must be a string containing options.");
|
707 | }
|
708 |
|
709 |
|
710 | var tap = entry.indexOf("tap") >= 0;
|
711 | var drag = entry.indexOf("drag") >= 0;
|
712 | var fixed = entry.indexOf("fixed") >= 0;
|
713 | var snap = entry.indexOf("snap") >= 0;
|
714 | var hover = entry.indexOf("hover") >= 0;
|
715 | var unconstrained = entry.indexOf("unconstrained") >= 0;
|
716 | var invertConnects = entry.indexOf("invert-connects") >= 0;
|
717 | var dragAll = entry.indexOf("drag-all") >= 0;
|
718 | var smoothSteps = entry.indexOf("smooth-steps") >= 0;
|
719 | if (fixed) {
|
720 | if (parsed.handles !== 2) {
|
721 | throw new Error("noUiSlider: 'fixed' behaviour must be used with 2 handles");
|
722 | }
|
723 |
|
724 | testMargin(parsed, parsed.start[1] - parsed.start[0]);
|
725 | }
|
726 | if (invertConnects && parsed.handles !== 2) {
|
727 | throw new Error("noUiSlider: 'invert-connects' behaviour must be used with 2 handles");
|
728 | }
|
729 | if (unconstrained && (parsed.margin || parsed.limit)) {
|
730 | throw new Error("noUiSlider: 'unconstrained' behaviour cannot be used with margin or limit");
|
731 | }
|
732 | parsed.events = {
|
733 | tap: tap || snap,
|
734 | drag: drag,
|
735 | dragAll: dragAll,
|
736 | smoothSteps: smoothSteps,
|
737 | fixed: fixed,
|
738 | snap: snap,
|
739 | hover: hover,
|
740 | unconstrained: unconstrained,
|
741 | invertConnects: invertConnects,
|
742 | };
|
743 | }
|
744 | function testTooltips(parsed, entry) {
|
745 | if (entry === false) {
|
746 | return;
|
747 | }
|
748 | if (entry === true || isValidPartialFormatter(entry)) {
|
749 | parsed.tooltips = [];
|
750 | for (var i = 0; i < parsed.handles; i++) {
|
751 | parsed.tooltips.push(entry);
|
752 | }
|
753 | }
|
754 | else {
|
755 | entry = asArray(entry);
|
756 | if (entry.length !== parsed.handles) {
|
757 | throw new Error("noUiSlider: must pass a formatter for all handles.");
|
758 | }
|
759 | entry.forEach(function (formatter) {
|
760 | if (typeof formatter !== "boolean" && !isValidPartialFormatter(formatter)) {
|
761 | throw new Error("noUiSlider: 'tooltips' must be passed a formatter or 'false'.");
|
762 | }
|
763 | });
|
764 | parsed.tooltips = entry;
|
765 | }
|
766 | }
|
767 | function testHandleAttributes(parsed, entry) {
|
768 | if (entry.length !== parsed.handles) {
|
769 | throw new Error("noUiSlider: must pass a attributes for all handles.");
|
770 | }
|
771 | parsed.handleAttributes = entry;
|
772 | }
|
773 | function testAriaFormat(parsed, entry) {
|
774 | if (!isValidPartialFormatter(entry)) {
|
775 | throw new Error("noUiSlider: 'ariaFormat' requires 'to' method.");
|
776 | }
|
777 | parsed.ariaFormat = entry;
|
778 | }
|
779 | function testFormat(parsed, entry) {
|
780 | if (!isValidFormatter(entry)) {
|
781 | throw new Error("noUiSlider: 'format' requires 'to' and 'from' methods.");
|
782 | }
|
783 | parsed.format = entry;
|
784 | }
|
785 | function testKeyboardSupport(parsed, entry) {
|
786 | if (typeof entry !== "boolean") {
|
787 | throw new Error("noUiSlider: 'keyboardSupport' option must be a boolean.");
|
788 | }
|
789 | parsed.keyboardSupport = entry;
|
790 | }
|
791 | function testDocumentElement(parsed, entry) {
|
792 |
|
793 | parsed.documentElement = entry;
|
794 | }
|
795 | function testCssPrefix(parsed, entry) {
|
796 | if (typeof entry !== "string" && entry !== false) {
|
797 | throw new Error("noUiSlider: 'cssPrefix' must be a string or `false`.");
|
798 | }
|
799 | parsed.cssPrefix = entry;
|
800 | }
|
801 | function testCssClasses(parsed, entry) {
|
802 | if (typeof entry !== "object") {
|
803 | throw new Error("noUiSlider: 'cssClasses' must be an object.");
|
804 | }
|
805 | if (typeof parsed.cssPrefix === "string") {
|
806 | parsed.cssClasses = {};
|
807 | Object.keys(entry).forEach(function (key) {
|
808 | parsed.cssClasses[key] = parsed.cssPrefix + entry[key];
|
809 | });
|
810 | }
|
811 | else {
|
812 | parsed.cssClasses = entry;
|
813 | }
|
814 | }
|
815 |
|
816 | function testOptions(options) {
|
817 |
|
818 |
|
819 |
|
820 | var parsed = {
|
821 | margin: null,
|
822 | limit: null,
|
823 | padding: null,
|
824 | animate: true,
|
825 | animationDuration: 300,
|
826 | ariaFormat: defaultFormatter,
|
827 | format: defaultFormatter,
|
828 | };
|
829 |
|
830 | var tests = {
|
831 | step: { r: false, t: testStep },
|
832 | keyboardPageMultiplier: { r: false, t: testKeyboardPageMultiplier },
|
833 | keyboardMultiplier: { r: false, t: testKeyboardMultiplier },
|
834 | keyboardDefaultStep: { r: false, t: testKeyboardDefaultStep },
|
835 | start: { r: true, t: testStart },
|
836 | connect: { r: true, t: testConnect },
|
837 | direction: { r: true, t: testDirection },
|
838 | snap: { r: false, t: testSnap },
|
839 | animate: { r: false, t: testAnimate },
|
840 | animationDuration: { r: false, t: testAnimationDuration },
|
841 | range: { r: true, t: testRange },
|
842 | orientation: { r: false, t: testOrientation },
|
843 | margin: { r: false, t: testMargin },
|
844 | limit: { r: false, t: testLimit },
|
845 | padding: { r: false, t: testPadding },
|
846 | behaviour: { r: true, t: testBehaviour },
|
847 | ariaFormat: { r: false, t: testAriaFormat },
|
848 | format: { r: false, t: testFormat },
|
849 | tooltips: { r: false, t: testTooltips },
|
850 | keyboardSupport: { r: true, t: testKeyboardSupport },
|
851 | documentElement: { r: false, t: testDocumentElement },
|
852 | cssPrefix: { r: true, t: testCssPrefix },
|
853 | cssClasses: { r: true, t: testCssClasses },
|
854 | handleAttributes: { r: false, t: testHandleAttributes },
|
855 | };
|
856 | var defaults = {
|
857 | connect: false,
|
858 | direction: "ltr",
|
859 | behaviour: "tap",
|
860 | orientation: "horizontal",
|
861 | keyboardSupport: true,
|
862 | cssPrefix: "noUi-",
|
863 | cssClasses: cssClasses,
|
864 | keyboardPageMultiplier: 5,
|
865 | keyboardMultiplier: 1,
|
866 | keyboardDefaultStep: 10,
|
867 | };
|
868 |
|
869 | if (options.format && !options.ariaFormat) {
|
870 | options.ariaFormat = options.format;
|
871 | }
|
872 |
|
873 |
|
874 |
|
875 | Object.keys(tests).forEach(function (name) {
|
876 |
|
877 | if (!isSet(options[name]) && defaults[name] === undefined) {
|
878 | if (tests[name].r) {
|
879 | throw new Error("noUiSlider: '" + name + "' is required.");
|
880 | }
|
881 | return;
|
882 | }
|
883 | tests[name].t(parsed, !isSet(options[name]) ? defaults[name] : options[name]);
|
884 | });
|
885 |
|
886 | parsed.pips = options.pips;
|
887 |
|
888 |
|
889 |
|
890 |
|
891 | var d = document.createElement("div");
|
892 | var msPrefix = d.style.msTransform !== undefined;
|
893 | var noPrefix = d.style.transform !== undefined;
|
894 | parsed.transformRule = noPrefix ? "transform" : msPrefix ? "msTransform" : "webkitTransform";
|
895 |
|
896 | var styles = [
|
897 | ["left", "top"],
|
898 | ["right", "bottom"],
|
899 | ];
|
900 | parsed.style = styles[parsed.dir][parsed.ort];
|
901 | return parsed;
|
902 | }
|
903 |
|
904 | function scope(target, options, originalOptions) {
|
905 | var actions = getActions();
|
906 | var supportsTouchActionNone = getSupportsTouchActionNone();
|
907 | var supportsPassive = supportsTouchActionNone && getSupportsPassive();
|
908 |
|
909 |
|
910 | var scope_Target = target;
|
911 | var scope_Base;
|
912 | var scope_ConnectBase;
|
913 | var scope_Handles;
|
914 | var scope_Connects;
|
915 | var scope_Pips;
|
916 | var scope_Tooltips;
|
917 |
|
918 | var scope_Spectrum = options.spectrum;
|
919 | var scope_Values = [];
|
920 | var scope_Locations = [];
|
921 | var scope_HandleNumbers = [];
|
922 | var scope_ActiveHandlesCount = 0;
|
923 | var scope_Events = {};
|
924 | var scope_ConnectsInverted = false;
|
925 |
|
926 | var scope_Document = target.ownerDocument;
|
927 | var scope_DocumentElement = options.documentElement || scope_Document.documentElement;
|
928 | var scope_Body = scope_Document.body;
|
929 |
|
930 |
|
931 | var scope_DirOffset = scope_Document.dir === "rtl" || options.ort === 1 ? 0 : 100;
|
932 |
|
933 | function addNodeTo(addTarget, className) {
|
934 | var div = scope_Document.createElement("div");
|
935 | if (className) {
|
936 | addClass(div, className);
|
937 | }
|
938 | addTarget.appendChild(div);
|
939 | return div;
|
940 | }
|
941 |
|
942 | function addOrigin(base, handleNumber) {
|
943 | var origin = addNodeTo(base, options.cssClasses.origin);
|
944 | var handle = addNodeTo(origin, options.cssClasses.handle);
|
945 | addNodeTo(handle, options.cssClasses.touchArea);
|
946 | handle.setAttribute("data-handle", String(handleNumber));
|
947 | if (options.keyboardSupport) {
|
948 |
|
949 |
|
950 | handle.setAttribute("tabindex", "0");
|
951 | handle.addEventListener("keydown", function (event) {
|
952 | return eventKeydown(event, handleNumber);
|
953 | });
|
954 | }
|
955 | if (options.handleAttributes !== undefined) {
|
956 | var attributes_1 = options.handleAttributes[handleNumber];
|
957 | Object.keys(attributes_1).forEach(function (attribute) {
|
958 | handle.setAttribute(attribute, attributes_1[attribute]);
|
959 | });
|
960 | }
|
961 | handle.setAttribute("role", "slider");
|
962 | handle.setAttribute("aria-orientation", options.ort ? "vertical" : "horizontal");
|
963 | if (handleNumber === 0) {
|
964 | addClass(handle, options.cssClasses.handleLower);
|
965 | }
|
966 | else if (handleNumber === options.handles - 1) {
|
967 | addClass(handle, options.cssClasses.handleUpper);
|
968 | }
|
969 | origin.handle = handle;
|
970 | return origin;
|
971 | }
|
972 |
|
973 | function addConnect(base, add) {
|
974 | if (!add) {
|
975 | return false;
|
976 | }
|
977 | return addNodeTo(base, options.cssClasses.connect);
|
978 | }
|
979 |
|
980 | function addElements(connectOptions, base) {
|
981 | scope_ConnectBase = addNodeTo(base, options.cssClasses.connects);
|
982 | scope_Handles = [];
|
983 | scope_Connects = [];
|
984 | scope_Connects.push(addConnect(scope_ConnectBase, connectOptions[0]));
|
985 |
|
986 |
|
987 | for (var i = 0; i < options.handles; i++) {
|
988 |
|
989 | scope_Handles.push(addOrigin(base, i));
|
990 | scope_HandleNumbers[i] = i;
|
991 | scope_Connects.push(addConnect(scope_ConnectBase, connectOptions[i + 1]));
|
992 | }
|
993 | }
|
994 |
|
995 | function addSlider(addTarget) {
|
996 |
|
997 | addClass(addTarget, options.cssClasses.target);
|
998 | if (options.dir === 0) {
|
999 | addClass(addTarget, options.cssClasses.ltr);
|
1000 | }
|
1001 | else {
|
1002 | addClass(addTarget, options.cssClasses.rtl);
|
1003 | }
|
1004 | if (options.ort === 0) {
|
1005 | addClass(addTarget, options.cssClasses.horizontal);
|
1006 | }
|
1007 | else {
|
1008 | addClass(addTarget, options.cssClasses.vertical);
|
1009 | }
|
1010 | var textDirection = getComputedStyle(addTarget).direction;
|
1011 | if (textDirection === "rtl") {
|
1012 | addClass(addTarget, options.cssClasses.textDirectionRtl);
|
1013 | }
|
1014 | else {
|
1015 | addClass(addTarget, options.cssClasses.textDirectionLtr);
|
1016 | }
|
1017 | return addNodeTo(addTarget, options.cssClasses.base);
|
1018 | }
|
1019 | function addTooltip(handle, handleNumber) {
|
1020 | if (!options.tooltips || !options.tooltips[handleNumber]) {
|
1021 | return false;
|
1022 | }
|
1023 | return addNodeTo(handle.firstChild, options.cssClasses.tooltip);
|
1024 | }
|
1025 | function isSliderDisabled() {
|
1026 | return scope_Target.hasAttribute("disabled");
|
1027 | }
|
1028 |
|
1029 | function isHandleDisabled(handleNumber) {
|
1030 | var handleOrigin = scope_Handles[handleNumber];
|
1031 | return handleOrigin.hasAttribute("disabled");
|
1032 | }
|
1033 | function disable(handleNumber) {
|
1034 | if (handleNumber !== null && handleNumber !== undefined) {
|
1035 | scope_Handles[handleNumber].setAttribute("disabled", "");
|
1036 | scope_Handles[handleNumber].handle.removeAttribute("tabindex");
|
1037 | }
|
1038 | else {
|
1039 | scope_Target.setAttribute("disabled", "");
|
1040 | scope_Handles.forEach(function (handle) {
|
1041 | handle.handle.removeAttribute("tabindex");
|
1042 | });
|
1043 | }
|
1044 | }
|
1045 | function enable(handleNumber) {
|
1046 | if (handleNumber !== null && handleNumber !== undefined) {
|
1047 | scope_Handles[handleNumber].removeAttribute("disabled");
|
1048 | scope_Handles[handleNumber].handle.setAttribute("tabindex", "0");
|
1049 | }
|
1050 | else {
|
1051 | scope_Target.removeAttribute("disabled");
|
1052 | scope_Handles.forEach(function (handle) {
|
1053 | handle.removeAttribute("disabled");
|
1054 | handle.handle.setAttribute("tabindex", "0");
|
1055 | });
|
1056 | }
|
1057 | }
|
1058 | function removeTooltips() {
|
1059 | if (scope_Tooltips) {
|
1060 | removeEvent("update" + INTERNAL_EVENT_NS.tooltips);
|
1061 | scope_Tooltips.forEach(function (tooltip) {
|
1062 | if (tooltip) {
|
1063 | removeElement(tooltip);
|
1064 | }
|
1065 | });
|
1066 | scope_Tooltips = null;
|
1067 | }
|
1068 | }
|
1069 |
|
1070 | function tooltips() {
|
1071 | removeTooltips();
|
1072 |
|
1073 | scope_Tooltips = scope_Handles.map(addTooltip);
|
1074 | bindEvent("update" + INTERNAL_EVENT_NS.tooltips, function (values, handleNumber, unencoded) {
|
1075 | if (!scope_Tooltips || !options.tooltips) {
|
1076 | return;
|
1077 | }
|
1078 | if (scope_Tooltips[handleNumber] === false) {
|
1079 | return;
|
1080 | }
|
1081 | var formattedValue = values[handleNumber];
|
1082 | if (options.tooltips[handleNumber] !== true) {
|
1083 | formattedValue = options.tooltips[handleNumber].to(unencoded[handleNumber]);
|
1084 | }
|
1085 | scope_Tooltips[handleNumber].innerHTML = formattedValue;
|
1086 | });
|
1087 | }
|
1088 | function aria() {
|
1089 | removeEvent("update" + INTERNAL_EVENT_NS.aria);
|
1090 | bindEvent("update" + INTERNAL_EVENT_NS.aria, function (values, handleNumber, unencoded, tap, positions) {
|
1091 |
|
1092 | scope_HandleNumbers.forEach(function (index) {
|
1093 | var handle = scope_Handles[index];
|
1094 | var min = checkHandlePosition(scope_Locations, index, 0, true, true, true);
|
1095 | var max = checkHandlePosition(scope_Locations, index, 100, true, true, true);
|
1096 | var now = positions[index];
|
1097 |
|
1098 | var text = String(options.ariaFormat.to(unencoded[index]));
|
1099 |
|
1100 | min = scope_Spectrum.fromStepping(min).toFixed(1);
|
1101 | max = scope_Spectrum.fromStepping(max).toFixed(1);
|
1102 | now = scope_Spectrum.fromStepping(now).toFixed(1);
|
1103 | handle.children[0].setAttribute("aria-valuemin", min);
|
1104 | handle.children[0].setAttribute("aria-valuemax", max);
|
1105 | handle.children[0].setAttribute("aria-valuenow", now);
|
1106 | handle.children[0].setAttribute("aria-valuetext", text);
|
1107 | });
|
1108 | });
|
1109 | }
|
1110 | function getGroup(pips) {
|
1111 |
|
1112 | if (pips.mode === exports.PipsMode.Range || pips.mode === exports.PipsMode.Steps) {
|
1113 | return scope_Spectrum.xVal;
|
1114 | }
|
1115 | if (pips.mode === exports.PipsMode.Count) {
|
1116 | if (pips.values < 2) {
|
1117 | throw new Error("noUiSlider: 'values' (>= 2) required for mode 'count'.");
|
1118 | }
|
1119 |
|
1120 | var interval = pips.values - 1;
|
1121 | var spread = 100 / interval;
|
1122 | var values = [];
|
1123 |
|
1124 | while (interval--) {
|
1125 | values[interval] = interval * spread;
|
1126 | }
|
1127 | values.push(100);
|
1128 | return mapToRange(values, pips.stepped);
|
1129 | }
|
1130 | if (pips.mode === exports.PipsMode.Positions) {
|
1131 |
|
1132 | return mapToRange(pips.values, pips.stepped);
|
1133 | }
|
1134 | if (pips.mode === exports.PipsMode.Values) {
|
1135 |
|
1136 | if (pips.stepped) {
|
1137 | return pips.values.map(function (value) {
|
1138 |
|
1139 | return scope_Spectrum.fromStepping(scope_Spectrum.getStep(scope_Spectrum.toStepping(value)));
|
1140 | });
|
1141 | }
|
1142 |
|
1143 | return pips.values;
|
1144 | }
|
1145 | return [];
|
1146 | }
|
1147 | function mapToRange(values, stepped) {
|
1148 | return values.map(function (value) {
|
1149 | return scope_Spectrum.fromStepping(stepped ? scope_Spectrum.getStep(value) : value);
|
1150 | });
|
1151 | }
|
1152 | function generateSpread(pips) {
|
1153 | function safeIncrement(value, increment) {
|
1154 |
|
1155 | return Number((value + increment).toFixed(7));
|
1156 | }
|
1157 | var group = getGroup(pips);
|
1158 | var indexes = {};
|
1159 | var firstInRange = scope_Spectrum.xVal[0];
|
1160 | var lastInRange = scope_Spectrum.xVal[scope_Spectrum.xVal.length - 1];
|
1161 | var ignoreFirst = false;
|
1162 | var ignoreLast = false;
|
1163 | var prevPct = 0;
|
1164 |
|
1165 | group = unique(group.slice().sort(function (a, b) {
|
1166 | return a - b;
|
1167 | }));
|
1168 |
|
1169 | if (group[0] !== firstInRange) {
|
1170 | group.unshift(firstInRange);
|
1171 | ignoreFirst = true;
|
1172 | }
|
1173 |
|
1174 | if (group[group.length - 1] !== lastInRange) {
|
1175 | group.push(lastInRange);
|
1176 | ignoreLast = true;
|
1177 | }
|
1178 | group.forEach(function (current, index) {
|
1179 |
|
1180 | var step;
|
1181 | var i;
|
1182 | var q;
|
1183 | var low = current;
|
1184 | var high = group[index + 1];
|
1185 | var newPct;
|
1186 | var pctDifference;
|
1187 | var pctPos;
|
1188 | var type;
|
1189 | var steps;
|
1190 | var realSteps;
|
1191 | var stepSize;
|
1192 | var isSteps = pips.mode === exports.PipsMode.Steps;
|
1193 |
|
1194 |
|
1195 | if (isSteps) {
|
1196 | step = scope_Spectrum.xNumSteps[index];
|
1197 | }
|
1198 |
|
1199 | if (!step) {
|
1200 | step = high - low;
|
1201 | }
|
1202 |
|
1203 | if (high === undefined) {
|
1204 | high = low;
|
1205 | }
|
1206 |
|
1207 | step = Math.max(step, 0.0000001);
|
1208 |
|
1209 | for (i = low; i <= high; i = safeIncrement(i, step)) {
|
1210 |
|
1211 |
|
1212 | newPct = scope_Spectrum.toStepping(i);
|
1213 | pctDifference = newPct - prevPct;
|
1214 | steps = pctDifference / (pips.density || 1);
|
1215 | realSteps = Math.round(steps);
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 | stepSize = pctDifference / realSteps;
|
1221 |
|
1222 |
|
1223 | for (q = 1; q <= realSteps; q += 1) {
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 | pctPos = prevPct + q * stepSize;
|
1229 | indexes[pctPos.toFixed(5)] = [scope_Spectrum.fromStepping(pctPos), 0];
|
1230 | }
|
1231 |
|
1232 | type = group.indexOf(i) > -1 ? exports.PipsType.LargeValue : isSteps ? exports.PipsType.SmallValue : exports.PipsType.NoValue;
|
1233 |
|
1234 | if (!index && ignoreFirst && i !== high) {
|
1235 | type = 0;
|
1236 | }
|
1237 | if (!(i === high && ignoreLast)) {
|
1238 |
|
1239 | indexes[newPct.toFixed(5)] = [i, type];
|
1240 | }
|
1241 |
|
1242 | prevPct = newPct;
|
1243 | }
|
1244 | });
|
1245 | return indexes;
|
1246 | }
|
1247 | function addMarking(spread, filterFunc, formatter) {
|
1248 | var _a, _b;
|
1249 | var element = scope_Document.createElement("div");
|
1250 | var valueSizeClasses = (_a = {},
|
1251 | _a[exports.PipsType.None] = "",
|
1252 | _a[exports.PipsType.NoValue] = options.cssClasses.valueNormal,
|
1253 | _a[exports.PipsType.LargeValue] = options.cssClasses.valueLarge,
|
1254 | _a[exports.PipsType.SmallValue] = options.cssClasses.valueSub,
|
1255 | _a);
|
1256 | var markerSizeClasses = (_b = {},
|
1257 | _b[exports.PipsType.None] = "",
|
1258 | _b[exports.PipsType.NoValue] = options.cssClasses.markerNormal,
|
1259 | _b[exports.PipsType.LargeValue] = options.cssClasses.markerLarge,
|
1260 | _b[exports.PipsType.SmallValue] = options.cssClasses.markerSub,
|
1261 | _b);
|
1262 | var valueOrientationClasses = [options.cssClasses.valueHorizontal, options.cssClasses.valueVertical];
|
1263 | var markerOrientationClasses = [options.cssClasses.markerHorizontal, options.cssClasses.markerVertical];
|
1264 | addClass(element, options.cssClasses.pips);
|
1265 | addClass(element, options.ort === 0 ? options.cssClasses.pipsHorizontal : options.cssClasses.pipsVertical);
|
1266 | function getClasses(type, source) {
|
1267 | var a = source === options.cssClasses.value;
|
1268 | var orientationClasses = a ? valueOrientationClasses : markerOrientationClasses;
|
1269 | var sizeClasses = a ? valueSizeClasses : markerSizeClasses;
|
1270 | return source + " " + orientationClasses[options.ort] + " " + sizeClasses[type];
|
1271 | }
|
1272 | function addSpread(offset, value, type) {
|
1273 |
|
1274 | type = filterFunc ? filterFunc(value, type) : type;
|
1275 | if (type === exports.PipsType.None) {
|
1276 | return;
|
1277 | }
|
1278 |
|
1279 | var node = addNodeTo(element, false);
|
1280 | node.className = getClasses(type, options.cssClasses.marker);
|
1281 | node.style[options.style] = offset + "%";
|
1282 |
|
1283 | if (type > exports.PipsType.NoValue) {
|
1284 | node = addNodeTo(element, false);
|
1285 | node.className = getClasses(type, options.cssClasses.value);
|
1286 | node.setAttribute("data-value", String(value));
|
1287 | node.style[options.style] = offset + "%";
|
1288 | node.innerHTML = String(formatter.to(value));
|
1289 | }
|
1290 | }
|
1291 |
|
1292 | Object.keys(spread).forEach(function (offset) {
|
1293 | addSpread(offset, spread[offset][0], spread[offset][1]);
|
1294 | });
|
1295 | return element;
|
1296 | }
|
1297 | function removePips() {
|
1298 | if (scope_Pips) {
|
1299 | removeElement(scope_Pips);
|
1300 | scope_Pips = null;
|
1301 | }
|
1302 | }
|
1303 | function pips(pips) {
|
1304 |
|
1305 | removePips();
|
1306 | var spread = generateSpread(pips);
|
1307 | var filter = pips.filter;
|
1308 | var format = pips.format || {
|
1309 | to: function (value) {
|
1310 | return String(Math.round(value));
|
1311 | },
|
1312 | };
|
1313 | scope_Pips = scope_Target.appendChild(addMarking(spread, filter, format));
|
1314 | return scope_Pips;
|
1315 | }
|
1316 |
|
1317 | function baseSize() {
|
1318 | var rect = scope_Base.getBoundingClientRect();
|
1319 | var alt = ("offset" + ["Width", "Height"][options.ort]);
|
1320 | return options.ort === 0 ? rect.width || scope_Base[alt] : rect.height || scope_Base[alt];
|
1321 | }
|
1322 |
|
1323 | function attachEvent(events, element, callback, data) {
|
1324 |
|
1325 |
|
1326 | var method = function (event) {
|
1327 | var e = fixEvent(event, data.pageOffset, data.target || element);
|
1328 |
|
1329 |
|
1330 | if (!e) {
|
1331 | return false;
|
1332 | }
|
1333 |
|
1334 |
|
1335 | if (isSliderDisabled() && !data.doNotReject) {
|
1336 | return false;
|
1337 | }
|
1338 |
|
1339 | if (hasClass(scope_Target, options.cssClasses.tap) && !data.doNotReject) {
|
1340 | return false;
|
1341 | }
|
1342 |
|
1343 | if (events === actions.start && e.buttons !== undefined && e.buttons > 1) {
|
1344 | return false;
|
1345 | }
|
1346 |
|
1347 | if (data.hover && e.buttons) {
|
1348 | return false;
|
1349 | }
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 | if (!supportsPassive) {
|
1356 | e.preventDefault();
|
1357 | }
|
1358 | e.calcPoint = e.points[options.ort];
|
1359 |
|
1360 | callback(e, data);
|
1361 | return;
|
1362 | };
|
1363 | var methods = [];
|
1364 |
|
1365 | events.split(" ").forEach(function (eventName) {
|
1366 | element.addEventListener(eventName, method, supportsPassive ? { passive: true } : false);
|
1367 | methods.push([eventName, method]);
|
1368 | });
|
1369 | return methods;
|
1370 | }
|
1371 |
|
1372 | function fixEvent(e, pageOffset, eventTarget) {
|
1373 |
|
1374 |
|
1375 |
|
1376 | var touch = e.type.indexOf("touch") === 0;
|
1377 | var mouse = e.type.indexOf("mouse") === 0;
|
1378 | var pointer = e.type.indexOf("pointer") === 0;
|
1379 | var x = 0;
|
1380 | var y = 0;
|
1381 |
|
1382 | if (e.type.indexOf("MSPointer") === 0) {
|
1383 | pointer = true;
|
1384 | }
|
1385 |
|
1386 |
|
1387 |
|
1388 | if (e.type === "mousedown" && !e.buttons && !e.touches) {
|
1389 | return false;
|
1390 | }
|
1391 |
|
1392 | if (touch) {
|
1393 |
|
1394 | var isTouchOnTarget = function (checkTouch) {
|
1395 | var target = checkTouch.target;
|
1396 | return (target === eventTarget ||
|
1397 | eventTarget.contains(target) ||
|
1398 | (e.composed && e.composedPath().shift() === eventTarget));
|
1399 | };
|
1400 |
|
1401 |
|
1402 | if (e.type === "touchstart") {
|
1403 | var targetTouches = Array.prototype.filter.call(e.touches, isTouchOnTarget);
|
1404 |
|
1405 | if (targetTouches.length > 1) {
|
1406 | return false;
|
1407 | }
|
1408 | x = targetTouches[0].pageX;
|
1409 | y = targetTouches[0].pageY;
|
1410 | }
|
1411 | else {
|
1412 |
|
1413 | var targetTouch = Array.prototype.find.call(e.changedTouches, isTouchOnTarget);
|
1414 |
|
1415 | if (!targetTouch) {
|
1416 | return false;
|
1417 | }
|
1418 | x = targetTouch.pageX;
|
1419 | y = targetTouch.pageY;
|
1420 | }
|
1421 | }
|
1422 | pageOffset = pageOffset || getPageOffset(scope_Document);
|
1423 | if (mouse || pointer) {
|
1424 | x = e.clientX + pageOffset.x;
|
1425 | y = e.clientY + pageOffset.y;
|
1426 | }
|
1427 | e.pageOffset = pageOffset;
|
1428 | e.points = [x, y];
|
1429 | e.cursor = mouse || pointer;
|
1430 | return e;
|
1431 | }
|
1432 |
|
1433 | function calcPointToPercentage(calcPoint) {
|
1434 | var location = calcPoint - offset(scope_Base, options.ort);
|
1435 | var proposal = (location * 100) / baseSize();
|
1436 |
|
1437 |
|
1438 |
|
1439 | proposal = limit(proposal);
|
1440 | return options.dir ? 100 - proposal : proposal;
|
1441 | }
|
1442 |
|
1443 | function getClosestHandle(clickedPosition) {
|
1444 | var smallestDifference = 100;
|
1445 | var handleNumber = false;
|
1446 | scope_Handles.forEach(function (handle, index) {
|
1447 |
|
1448 | if (isHandleDisabled(index)) {
|
1449 | return;
|
1450 | }
|
1451 | var handlePosition = scope_Locations[index];
|
1452 | var differenceWithThisHandle = Math.abs(handlePosition - clickedPosition);
|
1453 |
|
1454 | var clickAtEdge = differenceWithThisHandle === 100 && smallestDifference === 100;
|
1455 |
|
1456 | var isCloser = differenceWithThisHandle < smallestDifference;
|
1457 | var isCloserAfter = differenceWithThisHandle <= smallestDifference && clickedPosition > handlePosition;
|
1458 | if (isCloser || isCloserAfter || clickAtEdge) {
|
1459 | handleNumber = index;
|
1460 | smallestDifference = differenceWithThisHandle;
|
1461 | }
|
1462 | });
|
1463 | return handleNumber;
|
1464 | }
|
1465 |
|
1466 | function documentLeave(event, data) {
|
1467 | if (event.type === "mouseout" &&
|
1468 | event.target.nodeName === "HTML" &&
|
1469 | event.relatedTarget === null) {
|
1470 | eventEnd(event, data);
|
1471 | }
|
1472 | }
|
1473 |
|
1474 | function eventMove(event, data) {
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 | if (navigator.appVersion.indexOf("MSIE 9") === -1 && event.buttons === 0 && data.buttonsProperty !== 0) {
|
1481 | return eventEnd(event, data);
|
1482 | }
|
1483 |
|
1484 | var movement = (options.dir ? -1 : 1) * (event.calcPoint - data.startCalcPoint);
|
1485 |
|
1486 | var proposal = (movement * 100) / data.baseSize;
|
1487 | moveHandles(movement > 0, proposal, data.locations, data.handleNumbers, data.connect);
|
1488 | }
|
1489 |
|
1490 | function eventEnd(event, data) {
|
1491 |
|
1492 | if (data.handle) {
|
1493 | removeClass(data.handle, options.cssClasses.active);
|
1494 | scope_ActiveHandlesCount -= 1;
|
1495 | }
|
1496 |
|
1497 | data.listeners.forEach(function (c) {
|
1498 | scope_DocumentElement.removeEventListener(c[0], c[1]);
|
1499 | });
|
1500 | if (scope_ActiveHandlesCount === 0) {
|
1501 |
|
1502 | removeClass(scope_Target, options.cssClasses.drag);
|
1503 | setZindex();
|
1504 |
|
1505 | if (event.cursor) {
|
1506 | scope_Body.style.cursor = "";
|
1507 | scope_Body.removeEventListener("selectstart", preventDefault);
|
1508 | }
|
1509 | }
|
1510 | if (options.events.smoothSteps) {
|
1511 | data.handleNumbers.forEach(function (handleNumber) {
|
1512 | setHandle(handleNumber, scope_Locations[handleNumber], true, true, false, false);
|
1513 | });
|
1514 | data.handleNumbers.forEach(function (handleNumber) {
|
1515 | fireEvent("update", handleNumber);
|
1516 | });
|
1517 | }
|
1518 | data.handleNumbers.forEach(function (handleNumber) {
|
1519 | fireEvent("change", handleNumber);
|
1520 | fireEvent("set", handleNumber);
|
1521 | fireEvent("end", handleNumber);
|
1522 | });
|
1523 | }
|
1524 |
|
1525 | function eventStart(event, data) {
|
1526 |
|
1527 | if (data.handleNumbers.some(isHandleDisabled)) {
|
1528 | return;
|
1529 | }
|
1530 | var handle;
|
1531 | if (data.handleNumbers.length === 1) {
|
1532 | var handleOrigin = scope_Handles[data.handleNumbers[0]];
|
1533 | handle = handleOrigin.children[0];
|
1534 | scope_ActiveHandlesCount += 1;
|
1535 |
|
1536 | addClass(handle, options.cssClasses.active);
|
1537 | }
|
1538 |
|
1539 | event.stopPropagation();
|
1540 |
|
1541 | var listeners = [];
|
1542 |
|
1543 | var moveEvent = attachEvent(actions.move, scope_DocumentElement, eventMove, {
|
1544 |
|
1545 |
|
1546 | target: event.target,
|
1547 | handle: handle,
|
1548 | connect: data.connect,
|
1549 | listeners: listeners,
|
1550 | startCalcPoint: event.calcPoint,
|
1551 | baseSize: baseSize(),
|
1552 | pageOffset: event.pageOffset,
|
1553 | handleNumbers: data.handleNumbers,
|
1554 | buttonsProperty: event.buttons,
|
1555 | locations: scope_Locations.slice(),
|
1556 | });
|
1557 | var endEvent = attachEvent(actions.end, scope_DocumentElement, eventEnd, {
|
1558 | target: event.target,
|
1559 | handle: handle,
|
1560 | listeners: listeners,
|
1561 | doNotReject: true,
|
1562 | handleNumbers: data.handleNumbers,
|
1563 | });
|
1564 | var outEvent = attachEvent("mouseout", scope_DocumentElement, documentLeave, {
|
1565 | target: event.target,
|
1566 | handle: handle,
|
1567 | listeners: listeners,
|
1568 | doNotReject: true,
|
1569 | handleNumbers: data.handleNumbers,
|
1570 | });
|
1571 |
|
1572 |
|
1573 | listeners.push.apply(listeners, moveEvent.concat(endEvent, outEvent));
|
1574 |
|
1575 |
|
1576 | if (event.cursor) {
|
1577 |
|
1578 | scope_Body.style.cursor = getComputedStyle(event.target).cursor;
|
1579 |
|
1580 | if (scope_Handles.length > 1) {
|
1581 | addClass(scope_Target, options.cssClasses.drag);
|
1582 | }
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 | scope_Body.addEventListener("selectstart", preventDefault, false);
|
1590 | }
|
1591 | data.handleNumbers.forEach(function (handleNumber) {
|
1592 | fireEvent("start", handleNumber);
|
1593 | });
|
1594 | }
|
1595 |
|
1596 | function eventTap(event) {
|
1597 |
|
1598 | event.stopPropagation();
|
1599 | var proposal = calcPointToPercentage(event.calcPoint);
|
1600 | var handleNumber = getClosestHandle(proposal);
|
1601 |
|
1602 | if (handleNumber === false) {
|
1603 | return;
|
1604 | }
|
1605 |
|
1606 |
|
1607 | if (!options.events.snap) {
|
1608 | addClassFor(scope_Target, options.cssClasses.tap, options.animationDuration);
|
1609 | }
|
1610 | setHandle(handleNumber, proposal, true, true);
|
1611 | setZindex();
|
1612 | fireEvent("slide", handleNumber, true);
|
1613 | fireEvent("update", handleNumber, true);
|
1614 | if (!options.events.snap) {
|
1615 | fireEvent("change", handleNumber, true);
|
1616 | fireEvent("set", handleNumber, true);
|
1617 | }
|
1618 | else {
|
1619 | eventStart(event, { handleNumbers: [handleNumber] });
|
1620 | }
|
1621 | }
|
1622 |
|
1623 | function eventHover(event) {
|
1624 | var proposal = calcPointToPercentage(event.calcPoint);
|
1625 | var to = scope_Spectrum.getStep(proposal);
|
1626 | var value = scope_Spectrum.fromStepping(to);
|
1627 | Object.keys(scope_Events).forEach(function (targetEvent) {
|
1628 | if ("hover" === targetEvent.split(".")[0]) {
|
1629 | scope_Events[targetEvent].forEach(function (callback) {
|
1630 | callback.call(scope_Self, value);
|
1631 | });
|
1632 | }
|
1633 | });
|
1634 | }
|
1635 |
|
1636 |
|
1637 | function eventKeydown(event, handleNumber) {
|
1638 | if (isSliderDisabled() || isHandleDisabled(handleNumber)) {
|
1639 | return false;
|
1640 | }
|
1641 | var horizontalKeys = ["Left", "Right"];
|
1642 | var verticalKeys = ["Down", "Up"];
|
1643 | var largeStepKeys = ["PageDown", "PageUp"];
|
1644 | var edgeKeys = ["Home", "End"];
|
1645 | if (options.dir && !options.ort) {
|
1646 |
|
1647 | horizontalKeys.reverse();
|
1648 | }
|
1649 | else if (options.ort && !options.dir) {
|
1650 |
|
1651 | verticalKeys.reverse();
|
1652 | largeStepKeys.reverse();
|
1653 | }
|
1654 |
|
1655 | var key = event.key.replace("Arrow", "");
|
1656 | var isLargeDown = key === largeStepKeys[0];
|
1657 | var isLargeUp = key === largeStepKeys[1];
|
1658 | var isDown = key === verticalKeys[0] || key === horizontalKeys[0] || isLargeDown;
|
1659 | var isUp = key === verticalKeys[1] || key === horizontalKeys[1] || isLargeUp;
|
1660 | var isMin = key === edgeKeys[0];
|
1661 | var isMax = key === edgeKeys[1];
|
1662 | if (!isDown && !isUp && !isMin && !isMax) {
|
1663 | return true;
|
1664 | }
|
1665 | event.preventDefault();
|
1666 | var to;
|
1667 | if (isUp || isDown) {
|
1668 | var direction = isDown ? 0 : 1;
|
1669 | var steps = getNextStepsForHandle(handleNumber);
|
1670 | var step = steps[direction];
|
1671 |
|
1672 | if (step === null) {
|
1673 | return false;
|
1674 | }
|
1675 |
|
1676 | if (step === false) {
|
1677 | step = scope_Spectrum.getDefaultStep(scope_Locations[handleNumber], isDown, options.keyboardDefaultStep);
|
1678 | }
|
1679 | if (isLargeUp || isLargeDown) {
|
1680 | step *= options.keyboardPageMultiplier;
|
1681 | }
|
1682 | else {
|
1683 | step *= options.keyboardMultiplier;
|
1684 | }
|
1685 |
|
1686 | step = Math.max(step, 0.0000001);
|
1687 |
|
1688 | step = (isDown ? -1 : 1) * step;
|
1689 | to = scope_Values[handleNumber] + step;
|
1690 | }
|
1691 | else if (isMax) {
|
1692 |
|
1693 | to = options.spectrum.xVal[options.spectrum.xVal.length - 1];
|
1694 | }
|
1695 | else {
|
1696 |
|
1697 | to = options.spectrum.xVal[0];
|
1698 | }
|
1699 | setHandle(handleNumber, scope_Spectrum.toStepping(to), true, true);
|
1700 | fireEvent("slide", handleNumber);
|
1701 | fireEvent("update", handleNumber);
|
1702 | fireEvent("change", handleNumber);
|
1703 | fireEvent("set", handleNumber);
|
1704 | return false;
|
1705 | }
|
1706 |
|
1707 | function bindSliderEvents(behaviour) {
|
1708 |
|
1709 | if (!behaviour.fixed) {
|
1710 | scope_Handles.forEach(function (handle, index) {
|
1711 |
|
1712 |
|
1713 | attachEvent(actions.start, handle.children[0], eventStart, {
|
1714 | handleNumbers: [index],
|
1715 | });
|
1716 | });
|
1717 | }
|
1718 |
|
1719 | if (behaviour.tap) {
|
1720 | attachEvent(actions.start, scope_Base, eventTap, {});
|
1721 | }
|
1722 |
|
1723 | if (behaviour.hover) {
|
1724 | attachEvent(actions.move, scope_Base, eventHover, {
|
1725 | hover: true,
|
1726 | });
|
1727 | }
|
1728 |
|
1729 | if (behaviour.drag) {
|
1730 | scope_Connects.forEach(function (connect, index) {
|
1731 | if (connect === false || index === 0 || index === scope_Connects.length - 1) {
|
1732 | return;
|
1733 | }
|
1734 | var handleBefore = scope_Handles[index - 1];
|
1735 | var handleAfter = scope_Handles[index];
|
1736 | var eventHolders = [connect];
|
1737 | var handlesToDrag = [handleBefore, handleAfter];
|
1738 | var handleNumbersToDrag = [index - 1, index];
|
1739 | addClass(connect, options.cssClasses.draggable);
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 | if (behaviour.fixed) {
|
1745 | eventHolders.push(handleBefore.children[0]);
|
1746 | eventHolders.push(handleAfter.children[0]);
|
1747 | }
|
1748 | if (behaviour.dragAll) {
|
1749 | handlesToDrag = scope_Handles;
|
1750 | handleNumbersToDrag = scope_HandleNumbers;
|
1751 | }
|
1752 | eventHolders.forEach(function (eventHolder) {
|
1753 | attachEvent(actions.start, eventHolder, eventStart, {
|
1754 | handles: handlesToDrag,
|
1755 | handleNumbers: handleNumbersToDrag,
|
1756 | connect: connect,
|
1757 | });
|
1758 | });
|
1759 | });
|
1760 | }
|
1761 | }
|
1762 |
|
1763 | function bindEvent(namespacedEvent, callback) {
|
1764 | scope_Events[namespacedEvent] = scope_Events[namespacedEvent] || [];
|
1765 | scope_Events[namespacedEvent].push(callback);
|
1766 |
|
1767 | if (namespacedEvent.split(".")[0] === "update") {
|
1768 | scope_Handles.forEach(function (a, index) {
|
1769 | fireEvent("update", index);
|
1770 | });
|
1771 | }
|
1772 | }
|
1773 | function isInternalNamespace(namespace) {
|
1774 | return namespace === INTERNAL_EVENT_NS.aria || namespace === INTERNAL_EVENT_NS.tooltips;
|
1775 | }
|
1776 |
|
1777 | function removeEvent(namespacedEvent) {
|
1778 | var event = namespacedEvent && namespacedEvent.split(".")[0];
|
1779 | var namespace = event ? namespacedEvent.substring(event.length) : namespacedEvent;
|
1780 | Object.keys(scope_Events).forEach(function (bind) {
|
1781 | var tEvent = bind.split(".")[0];
|
1782 | var tNamespace = bind.substring(tEvent.length);
|
1783 | if ((!event || event === tEvent) && (!namespace || namespace === tNamespace)) {
|
1784 |
|
1785 | if (!isInternalNamespace(tNamespace) || namespace === tNamespace) {
|
1786 | delete scope_Events[bind];
|
1787 | }
|
1788 | }
|
1789 | });
|
1790 | }
|
1791 |
|
1792 | function fireEvent(eventName, handleNumber, tap) {
|
1793 | Object.keys(scope_Events).forEach(function (targetEvent) {
|
1794 | var eventType = targetEvent.split(".")[0];
|
1795 | if (eventName === eventType) {
|
1796 | scope_Events[targetEvent].forEach(function (callback) {
|
1797 | callback.call(
|
1798 |
|
1799 | scope_Self,
|
1800 |
|
1801 | scope_Values.map(options.format.to),
|
1802 |
|
1803 | handleNumber,
|
1804 |
|
1805 | scope_Values.slice(),
|
1806 |
|
1807 | tap || false,
|
1808 |
|
1809 | scope_Locations.slice(),
|
1810 |
|
1811 | scope_Self);
|
1812 | });
|
1813 | }
|
1814 | });
|
1815 | }
|
1816 |
|
1817 | function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue, smoothSteps) {
|
1818 | var distance;
|
1819 |
|
1820 |
|
1821 | if (scope_Handles.length > 1 && !options.events.unconstrained) {
|
1822 | if (lookBackward && handleNumber > 0) {
|
1823 | distance = scope_Spectrum.getAbsoluteDistance(reference[handleNumber - 1], options.margin, false);
|
1824 | to = Math.max(to, distance);
|
1825 | }
|
1826 | if (lookForward && handleNumber < scope_Handles.length - 1) {
|
1827 | distance = scope_Spectrum.getAbsoluteDistance(reference[handleNumber + 1], options.margin, true);
|
1828 | to = Math.min(to, distance);
|
1829 | }
|
1830 | }
|
1831 |
|
1832 |
|
1833 |
|
1834 | if (scope_Handles.length > 1 && options.limit) {
|
1835 | if (lookBackward && handleNumber > 0) {
|
1836 | distance = scope_Spectrum.getAbsoluteDistance(reference[handleNumber - 1], options.limit, false);
|
1837 | to = Math.min(to, distance);
|
1838 | }
|
1839 | if (lookForward && handleNumber < scope_Handles.length - 1) {
|
1840 | distance = scope_Spectrum.getAbsoluteDistance(reference[handleNumber + 1], options.limit, true);
|
1841 | to = Math.max(to, distance);
|
1842 | }
|
1843 | }
|
1844 |
|
1845 |
|
1846 | if (options.padding) {
|
1847 | if (handleNumber === 0) {
|
1848 | distance = scope_Spectrum.getAbsoluteDistance(0, options.padding[0], false);
|
1849 | to = Math.max(to, distance);
|
1850 | }
|
1851 | if (handleNumber === scope_Handles.length - 1) {
|
1852 | distance = scope_Spectrum.getAbsoluteDistance(100, options.padding[1], true);
|
1853 | to = Math.min(to, distance);
|
1854 | }
|
1855 | }
|
1856 | if (!smoothSteps) {
|
1857 | to = scope_Spectrum.getStep(to);
|
1858 | }
|
1859 |
|
1860 | to = limit(to);
|
1861 |
|
1862 | if (to === reference[handleNumber] && !getValue) {
|
1863 | return false;
|
1864 | }
|
1865 | return to;
|
1866 | }
|
1867 |
|
1868 | function inRuleOrder(v, a) {
|
1869 | var o = options.ort;
|
1870 | return (o ? a : v) + ", " + (o ? v : a);
|
1871 | }
|
1872 |
|
1873 |
|
1874 | function moveHandles(upward, proposal, locations, handleNumbers, connect) {
|
1875 | var proposals = locations.slice();
|
1876 |
|
1877 | var firstHandle = handleNumbers[0];
|
1878 | var smoothSteps = options.events.smoothSteps;
|
1879 | var b = [!upward, upward];
|
1880 | var f = [upward, !upward];
|
1881 |
|
1882 | handleNumbers = handleNumbers.slice();
|
1883 |
|
1884 |
|
1885 | if (upward) {
|
1886 | handleNumbers.reverse();
|
1887 | }
|
1888 |
|
1889 | if (handleNumbers.length > 1) {
|
1890 | handleNumbers.forEach(function (handleNumber, o) {
|
1891 | var to = checkHandlePosition(proposals, handleNumber, proposals[handleNumber] + proposal, b[o], f[o], false, smoothSteps);
|
1892 |
|
1893 | if (to === false) {
|
1894 | proposal = 0;
|
1895 | }
|
1896 | else {
|
1897 | proposal = to - proposals[handleNumber];
|
1898 | proposals[handleNumber] = to;
|
1899 | }
|
1900 | });
|
1901 | }
|
1902 |
|
1903 | else {
|
1904 | b = f = [true];
|
1905 | }
|
1906 | var state = false;
|
1907 |
|
1908 | handleNumbers.forEach(function (handleNumber, o) {
|
1909 | state =
|
1910 | setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o], false, smoothSteps) || state;
|
1911 | });
|
1912 |
|
1913 | if (state) {
|
1914 | handleNumbers.forEach(function (handleNumber) {
|
1915 | fireEvent("update", handleNumber);
|
1916 | fireEvent("slide", handleNumber);
|
1917 | });
|
1918 |
|
1919 | if (connect != undefined) {
|
1920 | fireEvent("drag", firstHandle);
|
1921 | }
|
1922 | }
|
1923 | }
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 | function transformDirection(a, b) {
|
1929 | return options.dir ? 100 - a - b : a;
|
1930 | }
|
1931 |
|
1932 | function updateHandlePosition(handleNumber, to) {
|
1933 |
|
1934 | scope_Locations[handleNumber] = to;
|
1935 |
|
1936 | scope_Values[handleNumber] = scope_Spectrum.fromStepping(to);
|
1937 | var translation = transformDirection(to, 0) - scope_DirOffset;
|
1938 | var translateRule = "translate(" + inRuleOrder(translation + "%", "0") + ")";
|
1939 | scope_Handles[handleNumber].style[options.transformRule] = translateRule;
|
1940 |
|
1941 | if (options.events.invertConnects && scope_Locations.length > 1) {
|
1942 |
|
1943 | var handlesAreInOrder = scope_Locations.every(function (position, index, locations) {
|
1944 | return index === 0 || position >= locations[index - 1];
|
1945 | });
|
1946 | if (scope_ConnectsInverted !== !handlesAreInOrder) {
|
1947 |
|
1948 | invertConnects();
|
1949 |
|
1950 | return;
|
1951 | }
|
1952 | }
|
1953 | updateConnect(handleNumber);
|
1954 | updateConnect(handleNumber + 1);
|
1955 | if (scope_ConnectsInverted) {
|
1956 |
|
1957 | updateConnect(handleNumber - 1);
|
1958 | updateConnect(handleNumber + 2);
|
1959 | }
|
1960 | }
|
1961 |
|
1962 |
|
1963 |
|
1964 | function setZindex() {
|
1965 | scope_HandleNumbers.forEach(function (handleNumber) {
|
1966 | var dir = scope_Locations[handleNumber] > 50 ? -1 : 1;
|
1967 | var zIndex = 3 + (scope_Handles.length + dir * handleNumber);
|
1968 | scope_Handles[handleNumber].style.zIndex = String(zIndex);
|
1969 | });
|
1970 | }
|
1971 |
|
1972 |
|
1973 | function setHandle(handleNumber, to, lookBackward, lookForward, exactInput, smoothSteps) {
|
1974 | if (!exactInput) {
|
1975 | to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false, smoothSteps);
|
1976 | }
|
1977 | if (to === false) {
|
1978 | return false;
|
1979 | }
|
1980 | updateHandlePosition(handleNumber, to);
|
1981 | return true;
|
1982 | }
|
1983 |
|
1984 | function updateConnect(index) {
|
1985 |
|
1986 | if (!scope_Connects[index]) {
|
1987 | return;
|
1988 | }
|
1989 |
|
1990 | var locations = scope_Locations.slice();
|
1991 | if (scope_ConnectsInverted) {
|
1992 | locations.sort(function (a, b) {
|
1993 | return a - b;
|
1994 | });
|
1995 | }
|
1996 | var l = 0;
|
1997 | var h = 100;
|
1998 | if (index !== 0) {
|
1999 | l = locations[index - 1];
|
2000 | }
|
2001 | if (index !== scope_Connects.length - 1) {
|
2002 | h = locations[index];
|
2003 | }
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 | var connectWidth = h - l;
|
2009 | var translateRule = "translate(" + inRuleOrder(transformDirection(l, connectWidth) + "%", "0") + ")";
|
2010 | var scaleRule = "scale(" + inRuleOrder(connectWidth / 100, "1") + ")";
|
2011 | scope_Connects[index].style[options.transformRule] =
|
2012 | translateRule + " " + scaleRule;
|
2013 | }
|
2014 |
|
2015 | function resolveToValue(to, handleNumber) {
|
2016 |
|
2017 |
|
2018 | if (to === null || to === false || to === undefined) {
|
2019 | return scope_Locations[handleNumber];
|
2020 | }
|
2021 |
|
2022 | if (typeof to === "number") {
|
2023 | to = String(to);
|
2024 | }
|
2025 | to = options.format.from(to);
|
2026 | if (to !== false) {
|
2027 | to = scope_Spectrum.toStepping(to);
|
2028 | }
|
2029 |
|
2030 | if (to === false || isNaN(to)) {
|
2031 | return scope_Locations[handleNumber];
|
2032 | }
|
2033 | return to;
|
2034 | }
|
2035 |
|
2036 | function valueSet(input, fireSetEvent, exactInput) {
|
2037 | var values = asArray(input);
|
2038 | var isInit = scope_Locations[0] === undefined;
|
2039 |
|
2040 | fireSetEvent = fireSetEvent === undefined ? true : fireSetEvent;
|
2041 |
|
2042 |
|
2043 | if (options.animate && !isInit) {
|
2044 | addClassFor(scope_Target, options.cssClasses.tap, options.animationDuration);
|
2045 | }
|
2046 |
|
2047 | scope_HandleNumbers.forEach(function (handleNumber) {
|
2048 | setHandle(handleNumber, resolveToValue(values[handleNumber], handleNumber), true, false, exactInput);
|
2049 | });
|
2050 | var i = scope_HandleNumbers.length === 1 ? 0 : 1;
|
2051 |
|
2052 | if (isInit && scope_Spectrum.hasNoSize()) {
|
2053 | exactInput = true;
|
2054 | scope_Locations[0] = 0;
|
2055 | if (scope_HandleNumbers.length > 1) {
|
2056 | var space_1 = 100 / (scope_HandleNumbers.length - 1);
|
2057 | scope_HandleNumbers.forEach(function (handleNumber) {
|
2058 | scope_Locations[handleNumber] = handleNumber * space_1;
|
2059 | });
|
2060 | }
|
2061 | }
|
2062 |
|
2063 |
|
2064 | for (; i < scope_HandleNumbers.length; ++i) {
|
2065 | scope_HandleNumbers.forEach(function (handleNumber) {
|
2066 | setHandle(handleNumber, scope_Locations[handleNumber], true, true, exactInput);
|
2067 | });
|
2068 | }
|
2069 | setZindex();
|
2070 | scope_HandleNumbers.forEach(function (handleNumber) {
|
2071 | fireEvent("update", handleNumber);
|
2072 |
|
2073 | if (values[handleNumber] !== null && fireSetEvent) {
|
2074 | fireEvent("set", handleNumber);
|
2075 | }
|
2076 | });
|
2077 | }
|
2078 |
|
2079 | function valueReset(fireSetEvent) {
|
2080 | valueSet(options.start, fireSetEvent);
|
2081 | }
|
2082 |
|
2083 | function valueSetHandle(handleNumber, value, fireSetEvent, exactInput) {
|
2084 |
|
2085 | handleNumber = Number(handleNumber);
|
2086 | if (!(handleNumber >= 0 && handleNumber < scope_HandleNumbers.length)) {
|
2087 | throw new Error("noUiSlider: invalid handle number, got: " + handleNumber);
|
2088 | }
|
2089 |
|
2090 |
|
2091 | setHandle(handleNumber, resolveToValue(value, handleNumber), true, true, exactInput);
|
2092 | fireEvent("update", handleNumber);
|
2093 | if (fireSetEvent) {
|
2094 | fireEvent("set", handleNumber);
|
2095 | }
|
2096 | }
|
2097 |
|
2098 | function valueGet(unencoded) {
|
2099 | if (unencoded === void 0) { unencoded = false; }
|
2100 | if (unencoded) {
|
2101 |
|
2102 | return scope_Values.length === 1 ? scope_Values[0] : scope_Values.slice(0);
|
2103 | }
|
2104 | var values = scope_Values.map(options.format.to);
|
2105 |
|
2106 | if (values.length === 1) {
|
2107 | return values[0];
|
2108 | }
|
2109 | return values;
|
2110 | }
|
2111 |
|
2112 | function destroy() {
|
2113 |
|
2114 | removeEvent(INTERNAL_EVENT_NS.aria);
|
2115 | removeEvent(INTERNAL_EVENT_NS.tooltips);
|
2116 | Object.keys(options.cssClasses).forEach(function (key) {
|
2117 | removeClass(scope_Target, options.cssClasses[key]);
|
2118 | });
|
2119 | while (scope_Target.firstChild) {
|
2120 | scope_Target.removeChild(scope_Target.firstChild);
|
2121 | }
|
2122 | delete scope_Target.noUiSlider;
|
2123 | }
|
2124 | function getNextStepsForHandle(handleNumber) {
|
2125 | var location = scope_Locations[handleNumber];
|
2126 | var nearbySteps = scope_Spectrum.getNearbySteps(location);
|
2127 | var value = scope_Values[handleNumber];
|
2128 | var increment = nearbySteps.thisStep.step;
|
2129 | var decrement = null;
|
2130 |
|
2131 | if (options.snap) {
|
2132 | return [
|
2133 | value - nearbySteps.stepBefore.startValue || null,
|
2134 | nearbySteps.stepAfter.startValue - value || null,
|
2135 | ];
|
2136 | }
|
2137 |
|
2138 |
|
2139 | if (increment !== false) {
|
2140 | if (value + increment > nearbySteps.stepAfter.startValue) {
|
2141 | increment = nearbySteps.stepAfter.startValue - value;
|
2142 | }
|
2143 | }
|
2144 |
|
2145 | if (value > nearbySteps.thisStep.startValue) {
|
2146 | decrement = nearbySteps.thisStep.step;
|
2147 | }
|
2148 | else if (nearbySteps.stepBefore.step === false) {
|
2149 | decrement = false;
|
2150 | }
|
2151 |
|
2152 | else {
|
2153 | decrement = value - nearbySteps.stepBefore.highestStep;
|
2154 | }
|
2155 |
|
2156 | if (location === 100) {
|
2157 | increment = null;
|
2158 | }
|
2159 | else if (location === 0) {
|
2160 | decrement = null;
|
2161 | }
|
2162 |
|
2163 | var stepDecimals = scope_Spectrum.countStepDecimals();
|
2164 |
|
2165 | if (increment !== null && increment !== false) {
|
2166 | increment = Number(increment.toFixed(stepDecimals));
|
2167 | }
|
2168 | if (decrement !== null && decrement !== false) {
|
2169 | decrement = Number(decrement.toFixed(stepDecimals));
|
2170 | }
|
2171 | return [decrement, increment];
|
2172 | }
|
2173 |
|
2174 | function getNextSteps() {
|
2175 | return scope_HandleNumbers.map(getNextStepsForHandle);
|
2176 | }
|
2177 |
|
2178 | function updateOptions(optionsToUpdate, fireSetEvent) {
|
2179 |
|
2180 |
|
2181 |
|
2182 | var v = valueGet();
|
2183 | var updateAble = [
|
2184 | "margin",
|
2185 | "limit",
|
2186 | "padding",
|
2187 | "range",
|
2188 | "animate",
|
2189 | "snap",
|
2190 | "step",
|
2191 | "format",
|
2192 | "pips",
|
2193 | "tooltips",
|
2194 | "connect",
|
2195 | ];
|
2196 |
|
2197 | updateAble.forEach(function (name) {
|
2198 |
|
2199 | if (optionsToUpdate[name] !== undefined) {
|
2200 | originalOptions[name] = optionsToUpdate[name];
|
2201 | }
|
2202 | });
|
2203 | var newOptions = testOptions(originalOptions);
|
2204 |
|
2205 | updateAble.forEach(function (name) {
|
2206 | if (optionsToUpdate[name] !== undefined) {
|
2207 | options[name] = newOptions[name];
|
2208 | }
|
2209 | });
|
2210 | scope_Spectrum = newOptions.spectrum;
|
2211 |
|
2212 | options.margin = newOptions.margin;
|
2213 | options.limit = newOptions.limit;
|
2214 | options.padding = newOptions.padding;
|
2215 |
|
2216 | if (options.pips) {
|
2217 | pips(options.pips);
|
2218 | }
|
2219 | else {
|
2220 | removePips();
|
2221 | }
|
2222 |
|
2223 | if (options.tooltips) {
|
2224 | tooltips();
|
2225 | }
|
2226 | else {
|
2227 | removeTooltips();
|
2228 | }
|
2229 |
|
2230 | scope_Locations = [];
|
2231 | valueSet(isSet(optionsToUpdate.start) ? optionsToUpdate.start : v, fireSetEvent);
|
2232 |
|
2233 | if (optionsToUpdate.connect) {
|
2234 | updateConnectOption();
|
2235 | }
|
2236 | }
|
2237 | function updateConnectOption() {
|
2238 |
|
2239 | while (scope_ConnectBase.firstChild) {
|
2240 | scope_ConnectBase.removeChild(scope_ConnectBase.firstChild);
|
2241 | }
|
2242 |
|
2243 | for (var i = 0; i <= options.handles; i++) {
|
2244 | scope_Connects[i] = addConnect(scope_ConnectBase, options.connect[i]);
|
2245 | updateConnect(i);
|
2246 | }
|
2247 |
|
2248 |
|
2249 | bindSliderEvents({ drag: options.events.drag, fixed: true });
|
2250 | }
|
2251 |
|
2252 | function invertConnects() {
|
2253 | scope_ConnectsInverted = !scope_ConnectsInverted;
|
2254 | testConnect(options,
|
2255 |
|
2256 | options.connect.map(function (b) { return !b; }));
|
2257 | updateConnectOption();
|
2258 | }
|
2259 |
|
2260 | function setupSlider() {
|
2261 |
|
2262 |
|
2263 | scope_Base = addSlider(scope_Target);
|
2264 | addElements(options.connect, scope_Base);
|
2265 |
|
2266 | bindSliderEvents(options.events);
|
2267 |
|
2268 | valueSet(options.start);
|
2269 | if (options.pips) {
|
2270 | pips(options.pips);
|
2271 | }
|
2272 | if (options.tooltips) {
|
2273 | tooltips();
|
2274 | }
|
2275 | aria();
|
2276 | }
|
2277 | setupSlider();
|
2278 | var scope_Self = {
|
2279 | destroy: destroy,
|
2280 | steps: getNextSteps,
|
2281 | on: bindEvent,
|
2282 | off: removeEvent,
|
2283 | get: valueGet,
|
2284 | set: valueSet,
|
2285 | setHandle: valueSetHandle,
|
2286 | reset: valueReset,
|
2287 | disable: disable,
|
2288 | enable: enable,
|
2289 | // Exposed for unit testing, don't use this in your application.
|
2290 | __moveHandles: function (upward, proposal, handleNumbers) {
|
2291 | moveHandles(upward, proposal, scope_Locations, handleNumbers);
|
2292 | },
|
2293 | options: originalOptions,
|
2294 | updateOptions: updateOptions,
|
2295 | target: scope_Target,
|
2296 | removePips: removePips,
|
2297 | removeTooltips: removeTooltips,
|
2298 | getPositions: function () {
|
2299 | return scope_Locations.slice();
|
2300 | },
|
2301 | getTooltips: function () {
|
2302 | return scope_Tooltips;
|
2303 | },
|
2304 | getOrigins: function () {
|
2305 | return scope_Handles;
|
2306 | },
|
2307 | pips: pips,
|
2308 | };
|
2309 | return scope_Self;
|
2310 | }
|
2311 |
|
2312 | function initialize(target, originalOptions) {
|
2313 | if (!target || !target.nodeName) {
|
2314 | throw new Error("noUiSlider: create requires a single element, got: " + target);
|
2315 | }
|
2316 |
|
2317 | if (target.noUiSlider) {
|
2318 | throw new Error("noUiSlider: Slider was already initialized.");
|
2319 | }
|
2320 |
|
2321 | var options = testOptions(originalOptions);
|
2322 | var api = scope(target, options, originalOptions);
|
2323 | target.noUiSlider = api;
|
2324 | return api;
|
2325 | }
|
2326 | var nouislider = {
|
2327 |
|
2328 | __spectrum: Spectrum,
|
2329 |
|
2330 |
|
2331 | cssClasses: cssClasses,
|
2332 | create: initialize,
|
2333 | };
|
2334 |
|
2335 | exports.create = initialize;
|
2336 | exports.cssClasses = cssClasses;
|
2337 | exports["default"] = nouislider;
|
2338 |
|
2339 | Object.defineProperty(exports, '__esModule', { value: true });
|
2340 |
|
2341 | }));
|