@itfin/components 1.3.86 → 1.3.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1261 @@
1
+ <script>
2
+ import {roundToDPR, isMobile, isArray, isDiff, prefixStyle, addEvent, removeEvent} from './utils'
3
+
4
+ const transform = prefixStyle('transform')
5
+ const transitionDuration = prefixStyle('transitionDuration')
6
+ const transitionEnd = prefixStyle('transitionEnd')
7
+
8
+ const EVENT_TOUCH_START = 'touchstart'
9
+ const EVENT_TOUCH_MOVE = 'touchmove'
10
+ const EVENT_TOUCH_END = 'touchend'
11
+ const EVENT_TOUCH_CANCEL = 'touchcancel'
12
+
13
+ const EVENT_MOUSE_DOWN = 'mousedown'
14
+ const EVENT_MOUSE_MOVE = 'mousemove'
15
+ const EVENT_MOUSE_UP = 'mouseup'
16
+ const EVENT_MOUSE_LEAVE = 'mouseleave'
17
+
18
+ const EVENT_KEY_DOWN = 'keydown'
19
+ const EVENT_KEY_UP = 'keyup'
20
+ const EVENT_RESIZE = 'resize'
21
+
22
+ export default {
23
+ name: 'vue-range-slider',
24
+ props: {
25
+ // 是否显示组件
26
+ show: {
27
+ type: Boolean,
28
+ default: true
29
+ },
30
+ // 值
31
+ value: {
32
+ type: [String, Number, Array, Object],
33
+ default: 0
34
+ },
35
+ // 最小值
36
+ min: {
37
+ type: Number,
38
+ default: 0
39
+ },
40
+ // 最大值
41
+ max: {
42
+ type: Number,
43
+ default: 100
44
+ },
45
+ // 分段间隔
46
+ step: {
47
+ type: Number,
48
+ default: 1
49
+ },
50
+ // 组件宽度
51
+ width: {
52
+ type: [Number, String],
53
+ default: 'auto'
54
+ },
55
+ // 组件高度
56
+ height: {
57
+ type: [Number, String],
58
+ default: 6
59
+ },
60
+ // 滑块大小
61
+ dotSize: {
62
+ type: Number,
63
+ default: 16
64
+ },
65
+ dotWidth: {
66
+ type: Number,
67
+ required: false
68
+ },
69
+ dotHeight: {
70
+ type: Number,
71
+ required: false
72
+ },
73
+ stopPropagation: {
74
+ type: Boolean,
75
+ default: false
76
+ },
77
+ // 事件类型
78
+ eventType: {
79
+ type: String,
80
+ default: 'auto'
81
+ },
82
+ // 是否实时计算组件布局
83
+ realTime: {
84
+ type: Boolean,
85
+ default: false
86
+ },
87
+ // 是否显示工具提示
88
+ tooltip: {
89
+ type: [String, Boolean],
90
+ default: 'always',
91
+ validator(val) {
92
+ return ['hover', 'always', false].indexOf(val) > -1
93
+ }
94
+ },
95
+ // 组件方向
96
+ direction: {
97
+ type: String,
98
+ default: 'horizontal',
99
+ validator(val) {
100
+ return ['horizontal', 'vertical'].indexOf(val) > -1
101
+ }
102
+ },
103
+ // 是否反向组件
104
+ reverse: {
105
+ type: Boolean,
106
+ default: false
107
+ },
108
+ // 是否不可用
109
+ disabled: {
110
+ type: [Boolean, Array],
111
+ default: false
112
+ },
113
+ piecewiseLabel: {
114
+ type: Boolean,
115
+ default: false
116
+ },
117
+ piecewise: {
118
+ type: Boolean,
119
+ default: false
120
+ },
121
+ // 进度条是否可拖拽(只限范围模式)
122
+ processDraggable: {
123
+ type: Boolean,
124
+ default: false
125
+ },
126
+ // 是否可点击的
127
+ clickable: {
128
+ type: Boolean,
129
+ default: true
130
+ },
131
+ // 是否固定距离
132
+ fixed: {
133
+ type: Boolean,
134
+ default: false
135
+ },
136
+ // 是否为开发环境(打印错误)
137
+ debug: {
138
+ type: Boolean,
139
+ default: true
140
+ },
141
+ // 最小范围
142
+ minRange: {
143
+ type: Number
144
+ },
145
+ // 最大范围
146
+ maxRange: {
147
+ type: Number
148
+ },
149
+ tooltipMerge: {
150
+ type: Boolean,
151
+ default: true
152
+ },
153
+ // 是否开启初始动画
154
+ startAnimation: {
155
+ type: Boolean,
156
+ default: false
157
+ },
158
+ // 是否在拖拽结束后同步值
159
+ lazy: {
160
+ type: Boolean,
161
+ default: false
162
+ },
163
+ // 在范围模式中,是否允许交叉
164
+ enableCross: {
165
+ type: Boolean,
166
+ default: true
167
+ },
168
+ // 动画速度比
169
+ speed: {
170
+ type: Number,
171
+ default: 0.5
172
+ },
173
+ useKeyboard: {
174
+ type: Boolean,
175
+ default: false
176
+ },
177
+ actionsKeyboard: {
178
+ type: Array,
179
+ default() {
180
+ return [(i) => i - 1, (i) => i + 1]
181
+ }
182
+ },
183
+ data: Array,
184
+ formatter: [String, Function],
185
+ mergeFormatter: [String, Function],
186
+ // 工具提示方向
187
+ tooltipDir: [Array, String],
188
+ // 工具提示样式
189
+ tooltipStyle: [Array, Object, Function],
190
+ // 滑块样式
191
+ sliderStyle: [Array, Object, Function],
192
+ // 键盘控制时,算滑块获得焦点时样式
193
+ focusStyle: [Array, Object, Function],
194
+ // 组件禁用状态下样式
195
+ disabledStyle: Object,
196
+ // 进度条样式
197
+ processStyle: Object,
198
+ // 组件背景样式
199
+ bgStyle: Object,
200
+ piecewiseStyle: Object,
201
+ piecewiseActiveStyle: Object,
202
+ disabledDotStyle: [Array, Object, Function],
203
+ labelStyle: Object,
204
+ labelActiveStyle: Object
205
+ },
206
+ data() {
207
+ return {
208
+ currentValue: 0,
209
+ size: 0,
210
+ fixedValue: 0,
211
+ focusSlider: 0,
212
+ currentSlider: 0,
213
+ flag: false,
214
+ processFlag: false,
215
+ processSign: false,
216
+ keydownFlag: false,
217
+ focusFlag: false,
218
+ dragFlag: false,
219
+ crossFlag: false,
220
+ isComponentExists: true,
221
+ isMounted: false
222
+ }
223
+ },
224
+ render(h) {
225
+ const sliderConBlocks = []
226
+
227
+ // dot
228
+ if (this.isRange) {
229
+ const dot0 = h('div', {
230
+ ref: 'dot0',
231
+ staticClass: 'slider-dot',
232
+ class: [this.tooltipStatus, {
233
+ 'slider-dot-focus': this.focusFlag && this.focusSlider === 0,
234
+ 'slider-dot-dragging': this.flag && this.currentSlider === 0,
235
+ 'slider-dot-disabled': !this.boolDisabled && this.disabledArray[0]
236
+ }],
237
+ style: this.dotStyles
238
+ }, [
239
+ this._t('dot', [
240
+ h('div', {
241
+ staticClass: 'slider-dot-handle',
242
+ style: [
243
+ (!this.boolDisabled && this.disabledArray[0]) ? this.disabledDotStyles[0] : null,
244
+ this.sliderStyles[0],
245
+ this.focusFlag && this.focusSlider === 0 ? this.focusStyles[0]: null
246
+ ]
247
+ })
248
+ ], {
249
+ index: 0,
250
+ value: this.val[0],
251
+ disabled: this.disabledArray[0]
252
+ }),
253
+ h('div', {
254
+ ref: 'tooltip0',
255
+ staticClass: 'slider-tooltip-wrap',
256
+ class: `slider-tooltip-${this.tooltipDirection[0]}`
257
+ }, [
258
+ this._t('tooltip', [
259
+ h('span', {
260
+ staticClass: 'slider-tooltip',
261
+ style: this.tooltipStyles[0]
262
+ }, this.formatter ? this.formatting(this.val[0]) : this.val[0])
263
+ ], {
264
+ value: this.val[0],
265
+ index: 0,
266
+ disabled: !this.boolDisabled && this.disabledArray[0]
267
+ })
268
+ ])
269
+ ])
270
+ sliderConBlocks.push(dot0)
271
+
272
+ const dot1 = h('div', {
273
+ ref: 'dot1',
274
+ staticClass: 'slider-dot',
275
+ class: [this.tooltipStatus, {
276
+ 'slider-dot-focus': this.focusFlag && this.focusSlider === 1,
277
+ 'slider-dot-dragging': this.flag && this.currentSlider === 1,
278
+ 'slider-dot-disabled': !this.boolDisabled && this.disabledArray[1]
279
+ }],
280
+ style: this.dotStyles
281
+ }, [
282
+ this._t('dot', [
283
+ h('div', {
284
+ staticClass: 'slider-dot-handle',
285
+ style: [
286
+ (!this.boolDisabled && this.disabledArray[1]) ? this.disabledDotStyles[1] : null,
287
+ this.sliderStyles[1],
288
+ this.focusFlag && this.focusSlider === 1 ? this.focusStyles[1]: null
289
+ ]
290
+ })
291
+ ], {
292
+ index: 1,
293
+ value: this.val[1],
294
+ disabled: this.disabledArray[1]
295
+ }),
296
+ h('div', {
297
+ ref: 'tooltip1',
298
+ staticClass: 'slider-tooltip-wrap',
299
+ class: `slider-tooltip-${this.tooltipDirection[1]}`
300
+ }, [
301
+ this._t('tooltip', [
302
+ h('span', {
303
+ staticClass: 'slider-tooltip',
304
+ style: this.tooltipStyles[1]
305
+ }, this.formatter ? this.formatting(this.val[1]) : this.val[1])
306
+ ], {
307
+ value: this.val[1],
308
+ index: 1,
309
+ disabled: !this.boolDisabled && this.disabledArray[1]
310
+ })
311
+ ])
312
+ ])
313
+ sliderConBlocks.push(dot1)
314
+ } else {
315
+ const dot = h('div', {
316
+ ref: 'dot',
317
+ staticClass: 'slider-dot',
318
+ class: [
319
+ this.tooltipStatus,
320
+ {
321
+ 'slider-dot-focus': this.focusFlag && this.focusSlider === 0,
322
+ 'slider-dot-dragging': this.flag && this.currentSlider === 0
323
+ }
324
+ ],
325
+ style: this.dotStyles
326
+ }, [
327
+ this._t('dot', [
328
+ h('div', {
329
+ staticClass: 'slider-dot-handle',
330
+ style: [
331
+ this.sliderStyles,
332
+ this.focusFlag && this.focusSlider === 0 ? this.focusStyles : null
333
+ ]
334
+ })
335
+ ], {
336
+ value: this.val,
337
+ disabled: this.boolDisabled
338
+ }),
339
+ h('div', {
340
+ staticClass: 'slider-tooltip-wrap',
341
+ class: `slider-tooltip-${this.tooltipDirection}`
342
+ }, [
343
+ this._t('tooltip', [
344
+ h('span', {
345
+ staticClass: 'slider-tooltip',
346
+ style: this.tooltipStyles
347
+ },
348
+ this.formatter ? this.formatting(this.val) : this.val
349
+ )
350
+ ], {
351
+ value: this.val
352
+ })
353
+ ])
354
+ ])
355
+ sliderConBlocks.push(dot)
356
+ }
357
+
358
+ // piecewise
359
+ const dotWrapLen = this.piecewiseDotWrap.length
360
+ const ulBlock = h('ul', {
361
+ staticClass: 'slider-piecewise'
362
+ }, this._l(this.piecewiseDotWrap, (item, i) => {
363
+ const piecewiseDot = []
364
+ if (this.piecewise) {
365
+ piecewiseDot.push(h('span', {
366
+ staticClass: 'piecewise-dot',
367
+ style: [this.piecewiseStyle, item.inRange ? this.piecewiseActiveStyle : null]
368
+ }))
369
+ }
370
+
371
+ const piecewiseLabel = []
372
+ if (this.piecewiseLabel) {
373
+ piecewiseLabel.push(h('span', {
374
+ staticClass: 'piecewise-label',
375
+ style: [this.labelStyle, item.inRange ? this.labelActiveStyle : null]
376
+ }, item.label))
377
+ }
378
+
379
+ return h('li', {
380
+ key: i,
381
+ staticClass: 'piecewise-item',
382
+ style: [this.piecewiseDotStyle, item.style]
383
+ }, [
384
+ this._t('piecewise', piecewiseDot , {
385
+ label: item.label,
386
+ index: i,
387
+ first: i === 0,
388
+ last: i === dotWrapLen - 1,
389
+ active: item.inRange
390
+ }),
391
+ this._t('label', piecewiseLabel, {
392
+ label: item.label,
393
+ index: i,
394
+ first: i === 0,
395
+ last: i === dotWrapLen - 1,
396
+ active: item.inRange
397
+ })
398
+ ])
399
+ }))
400
+ sliderConBlocks.push(ulBlock)
401
+
402
+ // process
403
+ const processBlock = h('div', {
404
+ ref: 'process',
405
+ staticClass: 'slider-process',
406
+ class: {
407
+ 'slider-process-draggable': this.isRange && this.processDraggable
408
+ },
409
+ style: this.processStyle,
410
+ on: {
411
+ click: e => this.processClick(e)
412
+ }
413
+ }, [
414
+ h('div', {
415
+ ref: 'mergedTooltip',
416
+ staticClass: 'merged-tooltip slider-tooltip-wrap',
417
+ class: `slider-tooltip-${this.isRange ? this.tooltipDirection[0] : this.tooltipDirection}`,
418
+ style: this.tooltipMergedPosition
419
+ }, [
420
+ this._t('tooltip', [
421
+ h('span', {
422
+ staticClass: 'slider-tooltip',
423
+ style: this.tooltipStyles
424
+ }, this.mergeFormatter ? this.mergeFormatting(this.val[0], this.val[1]) : (this.formatter ? (this.val[0] === this.val[1] ? this.formatting(this.val[0]) : `${this.formatting(this.val[0])} - ${this.formatting(this.val[1])}`) : (this.val[0] === this.val[1] ? this.val[0] : `${this.val[0]} - ${this.val[1]}`))
425
+ )
426
+ ], {
427
+ value: this.val,
428
+ merge: true
429
+ })
430
+ ])
431
+ ])
432
+ sliderConBlocks.push(processBlock)
433
+
434
+ // <input type="range">
435
+ if (!this.isRange && !this.data) {
436
+ sliderConBlocks.push(h('input', {
437
+ staticClass: 'slider-input',
438
+ attrs: {
439
+ type: 'range',
440
+ min: this.min,
441
+ max: this.max
442
+ },
443
+ domProps: {
444
+ value: this.val
445
+ },
446
+ on: {
447
+ input: e => this.val = e.target.value
448
+ }
449
+ }))
450
+ }
451
+
452
+ return h('div', {
453
+ ref: 'wrap',
454
+ staticClass: 'vue-range-slider slider-component',
455
+ class: [this.flowDirection, this.disabledClass, this.stateClass, {'slider-has-label': this.piecewiseLabel}],
456
+ style: [this.wrapStyles, this.boolDisabled ? this.disabledStyle : null],
457
+ directives: [
458
+ {
459
+ name: 'show',
460
+ value: this.show
461
+ }
462
+ ],
463
+ on: {
464
+ click: e => this.wrapClick(e)
465
+ }
466
+ }, [
467
+ h('div', {
468
+ ref: 'elem',
469
+ staticClass: 'slider',
470
+ style: [this.elemStyles, this.bgStyle],
471
+ attrs: {
472
+ 'aria-hidden': true
473
+ }
474
+ }, sliderConBlocks)
475
+ ])
476
+ },
477
+ computed: {
478
+ val: {
479
+ get() {
480
+ return this.data ? (this.isRange ? [this.data[this.currentValue[0]], this.data[this.currentValue[1]]] : this.data[this.currentValue]) : this.currentValue
481
+ },
482
+ set(val) {
483
+ if (this.data) {
484
+ if (this.isRange) {
485
+ const index0 = this.data.indexOf(val[0])
486
+ const index1 = this.data.indexOf(val[1])
487
+ if (index0 > -1 && index1 > -1) {
488
+ this.currentValue = [index0, index1]
489
+ }
490
+ } else {
491
+ const index = this.data.indexOf(val)
492
+ if (index > -1) {
493
+ this.currentValue = index
494
+ }
495
+ }
496
+ } else {
497
+ this.currentValue = val
498
+ }
499
+ }
500
+ },
501
+ currentIndex() {
502
+ if (this.isRange) {
503
+ return this.data ? this.currentValue : [this.getIndexByValue(this.currentValue[0]), this.getIndexByValue(this.currentValue[1])]
504
+ } else {
505
+ return this.getIndexByValue(this.currentValue)
506
+ }
507
+ },
508
+ tooltipMergedPosition() {
509
+ if (!this.isMounted) return {}
510
+ const tooltipDirection = this.tooltipDirection[0]
511
+ const dot0 = this.$refs.dot0
512
+ if (dot0) {
513
+ let style = {}
514
+ if (this.direction === 'vertical') {
515
+ style[tooltipDirection] = `-${(this.dotHeightVal / 2) - (this.width / 2) + 9}px`
516
+ } else {
517
+ style[tooltipDirection] = `-${(this.dotWidthVal / 2) - (this.height / 2) + 9}px`
518
+ style['left'] = `50%`
519
+ }
520
+ return style
521
+ }
522
+ },
523
+ tooltipDirection() {
524
+ const dir = this.tooltipDir || (this.direction === 'vertical' ? 'left' : 'top')
525
+ if (isArray(dir)) {
526
+ return this.isRange ? dir : dir[1]
527
+ } else {
528
+ return this.isRange ? [dir, dir] : dir
529
+ }
530
+ },
531
+ piecewiseDotWrap() {
532
+ if (!this.piecewise && !this.piecewiseLabel) {
533
+ return false
534
+ }
535
+ let arr = []
536
+ for (let i = 0; i <= this.total; i++) {
537
+ let style = this.direction === 'vertical' ? {
538
+ bottom: `${this.gap * i - this.width / 2}px`,
539
+ left: 0
540
+ } : {
541
+ left: `${this.gap * i - this.height / 2}px`,
542
+ top: 0
543
+ }
544
+ let index = this.reverse ? (this.total - i) : i
545
+ let label = this.data ? this.data[index] : (this.spacing * index) + this.min
546
+ arr.push({
547
+ style,
548
+ label: this.formatter ? this.formatting(label) : label,
549
+ inRange: index >= this.indexRange[0] && index <= this.indexRange[1]
550
+ })
551
+ }
552
+ return arr
553
+ },
554
+ total() {
555
+ if (this.data) {
556
+ return this.data.length - 1
557
+ } else if (Math.floor((this.maximum - this.minimum) * this.multiple) % (this.step * this.multiple) !== 0) {
558
+ this.printError('Prop[step] is illegal, Please make sure that the step can be divisible')
559
+ }
560
+ return (this.maximum - this.minimum) / this.step
561
+ },
562
+ piecewiseDotStyle() {
563
+ return this.direction === 'vertical' ? {
564
+ width: `${this.width}px`,
565
+ height: `${this.width}px`
566
+ } : {
567
+ width: `${this.height}px`,
568
+ height: `${this.height}px`
569
+ }
570
+ },
571
+ dotStyles() {
572
+ return this.direction === 'vertical' ? {
573
+ width: `${this.dotWidthVal}px`,
574
+ height: `${this.dotHeightVal}px`,
575
+ left: `${(-(this.dotWidthVal - this.width) / 2)}px`
576
+ } : {
577
+ width: `${this.dotWidthVal}px`,
578
+ height: `${this.dotHeightVal}px`,
579
+ top: `${(-(this.dotHeightVal - this.height) / 2)}px`
580
+ }
581
+ },
582
+ sliderStyles() {
583
+ if (isArray(this.sliderStyle)) {
584
+ return this.isRange ? this.sliderStyle : this.sliderStyle[1]
585
+ } else if (typeof this.sliderStyle === 'function') {
586
+ return this.sliderStyle(this.val, this.currentIndex)
587
+ } else {
588
+ return this.isRange ? [this.sliderStyle, this.sliderStyle] : this.sliderStyle
589
+ }
590
+ },
591
+ tooltipStyles() {
592
+ if (isArray(this.tooltipStyle)) {
593
+ return this.isRange ? this.tooltipStyle : this.tooltipStyle[1]
594
+ } else if (typeof this.tooltipStyle === 'function') {
595
+ return this.tooltipStyle(this.val, this.currentIndex)
596
+ } else {
597
+ return this.isRange ? [this.tooltipStyle, this.tooltipStyle] : this.tooltipStyle
598
+ }
599
+ },
600
+ focusStyles() {
601
+ if (isArray(this.focusStyle)) {
602
+ return this.isRange ? this.focusStyle : this.focusStyle[1]
603
+ } else if (typeof this.focusStyle === 'function') {
604
+ return this.focusStyle(this.val, this.currentIndex)
605
+ } else {
606
+ return this.isRange ? [this.focusStyle, this.focusStyle] : this.focusStyle
607
+ }
608
+ },
609
+ disabledDotStyles() {
610
+ const disabledStyle = this.disabledDotStyle
611
+ if (isArray(disabledStyle)) {
612
+ return disabledStyle
613
+ } else if (typeof disabledStyle === 'function') {
614
+ const style = disabledStyle(this.val, this.currentIndex)
615
+ return isArray(style) ? style : [style, style]
616
+ } else if (disabledStyle) {
617
+ return [disabledStyle, disabledStyle]
618
+ } else {
619
+ return [{
620
+ backgroundColor: '#ccc'
621
+ }, {
622
+ backgroundColor: '#ccc'
623
+ }]
624
+ }
625
+ },
626
+ elemStyles() {
627
+ return this.direction === 'vertical' ? {
628
+ width: `${this.width}px`,
629
+ height: '100%'
630
+ } : {
631
+ height: `${this.height}px`
632
+ }
633
+ },
634
+ wrapStyles() {
635
+ return this.direction === 'vertical' ? {
636
+ height: typeof this.height === 'number' ? `${this.height}px` : this.height,
637
+ padding: `${this.dotHeightVal / 2}px ${this.dotWidthVal / 2}px`
638
+ } : {
639
+ width: typeof this.width === 'number' ? `${this.width}px` : this.width,
640
+ padding: `${this.dotHeightVal / 2}px ${this.dotWidthVal / 2}px`
641
+ }
642
+ },
643
+ stateClass() {
644
+ return {
645
+ 'slider-state-process-drag': this.processFlag,
646
+ 'slider-state-drag': this.flag && !this.processFlag && !this.keydownFlag,
647
+ 'slider-state-focus': this.focusFlag
648
+ }
649
+ },
650
+ tooltipStatus() {
651
+ return this.tooltip === 'hover' && this.flag ? 'slider-always' : this.tooltip ? `slider-${this.tooltip}` : ''
652
+ },
653
+ tooltipClass() {
654
+ return [`slider-tooltip-${this.tooltipDirection}`, 'slider-tooltip']
655
+ },
656
+ minimum() {
657
+ return this.data ? 0 : this.min
658
+ },
659
+ maximum() {
660
+ return this.data ? (this.data.length - 1) : this.max
661
+ },
662
+ multiple() {
663
+ const decimals = `${this.step}`.split('.')[1]
664
+ return decimals ? Math.pow(10, decimals.length) : 1
665
+ },
666
+ indexRange() {
667
+ return this.isRange ? this.currentIndex : [0, this.currentIndex]
668
+ },
669
+ spacing() {
670
+ return this.data ? 1 : this.step
671
+ },
672
+ gap() {
673
+ return this.size / this.total
674
+ },
675
+ dotWidthVal() {
676
+ return typeof this.dotWidth === 'number' ? this.dotWidth : this.dotSize
677
+ },
678
+ dotHeightVal() {
679
+ return typeof this.dotHeight === 'number' ? this.dotHeight : this.dotSize
680
+ },
681
+ disabledArray() {
682
+ return isArray(this.disabled) ? this.disabled : [this.disabled, this.disabled]
683
+ },
684
+ boolDisabled() {
685
+ return this.disabledArray.every(b => b === true)
686
+ },
687
+ disabledClass() {
688
+ return this.boolDisabled ? 'slider-disabled' : ''
689
+ },
690
+ flowDirection() {
691
+ return `slider-${this.direction + (this.reverse ? '-reverse' : '')}`
692
+ },
693
+ isRange() {
694
+ return isArray(this.value)
695
+ },
696
+ isDisabled() {
697
+ return this.eventType === 'none' ? true : this.boolDisabled
698
+ },
699
+ isFixed() {
700
+ return this.fixed || this.minRange
701
+ },
702
+ position() {
703
+ return this.isRange ? [(this.currentValue[0] - this.minimum) / this.spacing * this.gap, (this.currentValue[1] - this.minimum) / this.spacing * this.gap] : ((this.currentValue - this.minimum) / this.spacing * this.gap)
704
+ },
705
+ limit() {
706
+ return this.isRange ? this.isFixed ? [[0, (this.total - this.fixedValue) * this.gap], [this.fixedValue * this.gap, this.size]] : [[0, this.position[1]], [this.position[0], this.size]] : [0, this.size]
707
+ },
708
+ valueLimit() {
709
+ return this.isRange ? this.isFixed ? [[this.minimum, this.maximum - (this.fixedValue * (this.spacing * this.multiple)) / this.multiple], [this.minimum + (this.fixedValue * (this.spacing * this.multiple)) / this.multiple, this.maximum]] : [[this.minimum, this.currentValue[1]], [this.currentValue[0], this.maximum]] : [this.minimum, this.maximum]
710
+ },
711
+ idleSlider() {
712
+ return this.currentSlider === 0 ? 1 : 0
713
+ },
714
+ slider() {
715
+ return this.isRange ? [this.$refs.dot0, this.$refs.dot1] : this.$refs.dot
716
+ }
717
+ },
718
+ methods: {
719
+ setValue(val, noCb, speed) {
720
+ if (isDiff(this.val, val)) {
721
+ const resetVal = this.limitValue(val)
722
+ this.val = this.isRange ? resetVal.concat() : resetVal
723
+ this.computedFixedValue()
724
+ this.syncValue(noCb)
725
+ }
726
+ this.$nextTick(() => this.setPosition(speed))
727
+ },
728
+ setIndex(val) {
729
+ if (isArray(val) && this.isRange) {
730
+ let value
731
+ if (this.data) {
732
+ value = [this.data[val[0]], this.data[val[1]]]
733
+ } else {
734
+ value = [this.getValueByIndex(val[0]), this.getValueByIndex(val[1])]
735
+ }
736
+ this.setValue(value)
737
+ } else {
738
+ val = this.getValueByIndex(val)
739
+ if (this.isRange) {
740
+ this.currentSlider = val > ((this.currentValue[1] - this.currentValue[0]) / 2 + this.currentValue[0]) ? 1 : 0
741
+ }
742
+ this.setCurrentValue(val)
743
+ }
744
+ },
745
+ wrapClick(e) {
746
+ if (this.isDisabled || !this.clickable || this.processFlag || this.dragFlag) return false
747
+ const pos = this.getPos(e)
748
+ if (this.isRange) {
749
+ if (this.disabledArray.every(b => b === false)) {
750
+ this.currentSlider = pos > ((this.position[1] - this.position[0]) / 2 + this.position[0]) ? 1 : 0
751
+ } else if (this.disabledArray[0]) {
752
+ if (pos < this.position[0]) return false
753
+ this.currentSlider = 1
754
+ } else if (this.disabledArray[1]) {
755
+ if (pos > this.position[1]) return false
756
+ this.currentSlider = 0
757
+ }
758
+ }
759
+ if (this.disabledArray[this.currentSlider]) {
760
+ return false
761
+ }
762
+ this.setValueOnPos(pos)
763
+ if (this.isRange && this.tooltipMerge) {
764
+ const timer = setInterval(this.handleOverlapTooltip, 16.7)
765
+ setTimeout(() => window.clearInterval(timer), this.speed * 1000)
766
+ }
767
+ },
768
+ processClick(e) {
769
+ if (this.fixed) e.stopPropagation()
770
+ },
771
+ syncValue(noCb) {
772
+ let val = this.isRange ? this.val.concat() : this.val
773
+ this.$emit('input', val)
774
+ this.keydownFlag && this.$emit('on-keypress', val)
775
+ noCb || this.$emit('slide-end', val)
776
+ },
777
+ getPos(e) {
778
+ this.realTime && this.getStaticData()
779
+ return this.direction === 'vertical' ? (this.reverse ? (e.pageY - this.offset) : (this.size - (e.pageY - this.offset))) : (this.reverse ? (this.size - (e.pageX - this.offset)) : (e.pageX - this.offset))
780
+ },
781
+ setValueOnPos(pos, isDrag) {
782
+ const range = this.isRange ? this.limit[this.currentSlider] : this.limit
783
+ const valueRange = this.isRange ? this.valueLimit[this.currentSlider] : this.valueLimit
784
+ const index = Math.round(pos / this.gap)
785
+ if (pos >= range[0] && pos <= range[1]) {
786
+ const v = this.getValueByIndex(index)
787
+ this.setTransform(pos)
788
+ this.setCurrentValue(v, isDrag)
789
+ if (this.isRange && (this.fixed || this.isLessRange(pos, index))) {
790
+ this.setTransform(pos + ((this.fixedValue * this.gap) * (this.currentSlider === 0 ? 1 : -1)), true)
791
+ this.setCurrentValue((v * this.multiple + (this.fixedValue * this.spacing * this.multiple * (this.currentSlider === 0 ? 1 : -1))) / this.multiple, isDrag, true)
792
+ }
793
+ } else {
794
+ const anotherSlider = pos < range[0] ? 0 : 1
795
+ const currentSlider = anotherSlider === 0 ? 1 : 0
796
+ this.setTransform(range[anotherSlider])
797
+ this.setCurrentValue(valueRange[anotherSlider])
798
+ if (this.isRange && (this.fixed || this.isLessRange(pos, index))) {
799
+ this.setTransform(this.limit[this.idleSlider][anotherSlider], true)
800
+ this.setCurrentValue(this.valueLimit[this.idleSlider][anotherSlider], isDrag, true)
801
+ } else if (this.isRange && (this.enableCross || this.crossFlag) && !this.isFixed && !this.disabledArray[anotherSlider] && this.currentSlider === currentSlider) {
802
+ this.focusSlider = anotherSlider
803
+ this.currentSlider = anotherSlider
804
+ }
805
+ }
806
+ this.crossFlag = false
807
+ },
808
+ setCurrentValue(val, isDrag, isIdleSlider) {
809
+ const slider = isIdleSlider ? this.idleSlider : this.currentSlider
810
+ if (val < this.minimum || val > this.maximum) return false
811
+ if (this.isRange) {
812
+ if (isDiff(this.currentValue[slider], val)) {
813
+ this.currentValue.splice(slider, 1, val)
814
+ if (!this.lazy || !this.flag) {
815
+ this.syncValue()
816
+ }
817
+ }
818
+ } else if (isDiff(this.currentValue, val)) {
819
+ this.currentValue = val
820
+ if (!this.lazy || !this.flag) {
821
+ this.syncValue()
822
+ }
823
+ }
824
+ isDrag || this.setPosition()
825
+ },
826
+ setPosition(speed) {
827
+ this.flag || this.setTransitionTime(speed === undefined ? this.speed : speed)
828
+ if (this.isRange) {
829
+ this.setTransform(this.position[0], this.currentSlider === 1)
830
+ this.setTransform(this.position[1], this.currentSlider === 0)
831
+ } else {
832
+ this.setTransform(this.position)
833
+ }
834
+ this.flag || this.setTransitionTime(0)
835
+ },
836
+ setTransform(val, isIdleSlider) {
837
+ const slider = isIdleSlider ? this.idleSlider : this.currentSlider
838
+ const value = roundToDPR((this.direction === 'vertical' ? ((this.dotHeightVal / 2) - val) : (val - (this.dotWidthVal / 2))) * (this.reverse ? -1 : 1))
839
+ const translateValue = this.direction === 'vertical' ? `translateY(${value}px)` : `translateX(${value}px)`
840
+ const processSize = this.fixed ? `${this.fixedValue * this.gap}px` : `${slider === 0 ? this.position[1] - val : val - this.position[0]}px`
841
+ const processPos = this.fixed ? `${slider === 0 ? val : (val - this.fixedValue * this.gap)}px` : `${slider === 0 ? val : this.position[0]}px`
842
+ if (this.isRange) {
843
+ this.slider[slider].style[transform] = translateValue
844
+ if (this.direction === 'vertical') {
845
+ this.$refs.process.style.height = processSize
846
+ this.$refs.process.style[this.reverse ? 'top' : 'bottom'] = processPos
847
+ } else {
848
+ this.$refs.process.style.width = processSize
849
+ this.$refs.process.style[this.reverse ? 'right' : 'left'] = processPos
850
+ }
851
+ } else {
852
+ this.slider.style[transform] = translateValue
853
+ if (this.direction === 'vertical') {
854
+ this.$refs.process.style.height = `${val}px`
855
+ this.$refs.process.style[this.reverse ? 'top' : 'bottom'] = 0
856
+ } else {
857
+ this.$refs.process.style.width = `${val}px`
858
+ this.$refs.process.style[this.reverse ? 'right' : 'left'] = 0
859
+ }
860
+ }
861
+ },
862
+ setTransitionTime(time) {
863
+ // In order to avoid browser merge style and modify together
864
+ time || this.$refs.process.offsetWidth
865
+ if (this.isRange) {
866
+ const sliderLen = this.slider.length
867
+ for (let i = 0; i < sliderLen; i++) {
868
+ this.slider[i].style[transitionDuration] = `${time}s`
869
+ }
870
+ this.$refs.process.style[transitionDuration] = `${time}s`
871
+ } else {
872
+ this.slider.style[transitionDuration] = `${time}s`
873
+ this.$refs.process.style[transitionDuration] = `${time}s`
874
+ }
875
+ },
876
+ computedFixedValue() {
877
+ if (!this.isFixed) {
878
+ this.fixedValue = 0
879
+ return false
880
+ }
881
+ this.fixedValue = this.currentIndex[1] - this.currentIndex[0]
882
+ this.fixedValue = Math.max(this.fixed ? this.currentIndex[1] - this.currentIndex[0] : 0, this.minRange || 0)
883
+ },
884
+ limitValue(val) {
885
+ if (this.data) {
886
+ return val
887
+ }
888
+ const inRange = v => {
889
+ if (v < this.min) {
890
+ this.printError(`The value of the slider is ${val}, the minimum value is ${this.min}, the value of this slider can not be less than the minimum value`)
891
+ return this.min
892
+ } else if (v > this.max) {
893
+ this.printError(`The value of the slider is ${val}, the maximum value is ${this.max}, the value of this slider can not be greater than the maximum value`)
894
+ return this.max
895
+ }
896
+ return v
897
+ }
898
+ if (this.isRange) {
899
+ return val.map(v => inRange(v))
900
+ } else {
901
+ return inRange(val)
902
+ }
903
+ },
904
+ getStaticData() {
905
+ if (this.$refs.elem) {
906
+ this.size = this.direction === 'vertical' ? this.$refs.elem.offsetHeight : (this.width || this.$refs.elem.offsetWidth)
907
+ this.offset = this.direction === 'vertical' ? (this.$refs.elem.getBoundingClientRect().top + window.pageYOffset || document.documentElement.scrollTop) : this.$refs.elem.getBoundingClientRect().left
908
+ }
909
+ },
910
+ handleOverlapTooltip () {
911
+ const isDirectionSame = this.tooltipDirection[0] === this.tooltipDirection[1]
912
+ if (this.isRange && isDirectionSame) {
913
+ const tooltip0 = this.reverse ? this.$refs.tooltip1 : this.$refs.tooltip0
914
+ const tooltip1 = this.reverse ? this.$refs.tooltip0 : this.$refs.tooltip1
915
+ const tooltip0Rect = tooltip0.getBoundingClientRect()
916
+ const tooltip1Rect = tooltip1.getBoundingClientRect()
917
+
918
+ const tooltip0Right = tooltip0Rect.right
919
+ const tooltip1Left = tooltip1Rect.left
920
+
921
+ const tooltip0Y = tooltip0Rect.top
922
+ const tooltip1Y = tooltip1Rect.top + tooltip1Rect.height
923
+
924
+ const horizontalOverlap = this.direction === 'horizontal' && tooltip0Right > tooltip1Left
925
+ const verticalOverlap = this.direction === 'vertical' && tooltip1Y > tooltip0Y
926
+
927
+ if (horizontalOverlap || verticalOverlap) {
928
+ this.handleDisplayMergedTooltip(true)
929
+ } else {
930
+ this.handleDisplayMergedTooltip(false)
931
+ }
932
+ }
933
+ },
934
+ handleDisplayMergedTooltip (show) {
935
+ const tooltip0 = this.$refs.tooltip0
936
+ const tooltip1 = this.$refs.tooltip1
937
+ const mergedTooltip = this.$refs.process.getElementsByClassName('merged-tooltip')[0]
938
+ if (show) {
939
+ tooltip0.style.visibility = 'hidden'
940
+ tooltip1.style.visibility = 'hidden'
941
+ mergedTooltip.style.visibility = 'visible'
942
+ } else {
943
+ tooltip0.style.visibility = 'visible'
944
+ tooltip1.style.visibility = 'visible'
945
+ mergedTooltip.style.visibility = 'hidden'
946
+ }
947
+ },
948
+ isLessRange(pos, index) {
949
+ if (!this.isRange || (!this.minRange && !this.maxRange)) {
950
+ return false
951
+ }
952
+ const diff = this.currentSlider === 0 ? this.currentIndex[1] - index : index - this.currentIndex[0]
953
+ if (this.minRange && diff <= this.minRange) {
954
+ this.fixedValue = this.minRange
955
+ return true
956
+ }
957
+ if (this.maxRange && diff >= this.maxRange) {
958
+ this.fixedValue = this.maxRange
959
+ return true
960
+ }
961
+ this.computedFixedValue()
962
+ return false
963
+ },
964
+ getValueByIndex(index) {
965
+ return ((this.spacing * this.multiple) * index + (this.minimum * this.multiple)) / this.multiple
966
+ },
967
+ getIndexByValue(value) {
968
+ return Math.round((value - this.minimum) * this.multiple) / (this.spacing * this.multiple)
969
+ },
970
+ formatting(value) {
971
+ return typeof this.formatter === 'string' ? this.formatter.replace(/{value}/, value) : this.formatter(value)
972
+ },
973
+ mergeFormatting(value1, value2) {
974
+ return typeof this.mergeFormatter === 'string' ? this.mergeFormatter.replace(/{(value1|value2)}/g, (_, key) => key === 'value1' ? value1 : value2) : this.mergeFormatter(value1, value2)
975
+ },
976
+ _start(e, index = 0, isProcess) {
977
+ if (this.disabledArray[index]) {
978
+ return false
979
+ }
980
+ if (this.stopPropagation) {
981
+ e.stopPropagation()
982
+ }
983
+ if (this.isRange) {
984
+ this.currentSlider = index
985
+ if (isProcess) {
986
+ if (!this.processDraggable) {
987
+ return false
988
+ }
989
+ this.processFlag = true
990
+ this.processSign = {
991
+ pos: this.position,
992
+ start: this.getPos((e.targetTouches && e.targetTouches[0]) ? e.targetTouches[0] : e)
993
+ }
994
+ }
995
+ if (!this.enableCross && this.val[0] === this.val[1]) {
996
+ this.crossFlag = true
997
+ }
998
+ }
999
+ if (!isProcess && this.useKeyboard) {
1000
+ this.focusFlag = true
1001
+ this.focusSlider = index
1002
+ }
1003
+ this.flag = true
1004
+ this.$emit('drag-start', this)
1005
+ },
1006
+ _move(e) {
1007
+ // e.preventDefault() // NOTE: COMMENTED, BREAKS SELECTING THINGS ON PAGE
1008
+ if (this.stopPropagation) {
1009
+ e.stopPropagation()
1010
+ }
1011
+ if (!this.flag) return false
1012
+ if (e.targetTouches && e.targetTouches[0]) e = e.targetTouches[0]
1013
+ if (this.processFlag) {
1014
+ this.currentSlider = 0
1015
+ this.setValueOnPos(this.processSign.pos[0] + this.getPos(e) - this.processSign.start, true)
1016
+ this.currentSlider = 1
1017
+ this.setValueOnPos(this.processSign.pos[1] + this.getPos(e) - this.processSign.start, true)
1018
+ } else {
1019
+ this.dragFlag = true
1020
+ this.setValueOnPos(this.getPos(e), true)
1021
+ }
1022
+ if (this.isRange && this.tooltipMerge) {
1023
+ this.handleOverlapTooltip()
1024
+ }
1025
+ },
1026
+ _end(e) {
1027
+ if (this.stopPropagation) {
1028
+ e.stopPropagation()
1029
+ }
1030
+ if (this.flag) {
1031
+ this.$emit('drag-end', this)
1032
+ if (this.lazy && isDiff(this.val, this.value)) {
1033
+ this.syncValue()
1034
+ }
1035
+ } else {
1036
+ return false
1037
+ }
1038
+ this.flag = false
1039
+ this.$nextTick(() => {
1040
+ this.crossFlag = false
1041
+ this.dragFlag = false
1042
+ this.processFlag = false
1043
+ })
1044
+ this.setPosition()
1045
+ },
1046
+ blurSlider(e) {
1047
+ const dot = this.isRange ? this.$refs[`dot${this.focusSlider}`] : this.$refs.dot
1048
+ if (!dot || dot === e.target || dot.contains(e.target)) {
1049
+ return false
1050
+ }
1051
+ this.focusFlag = false
1052
+ },
1053
+ handleKeydown(e) {
1054
+ if (!this.useKeyboard) {
1055
+ return false
1056
+ }
1057
+ const keyCode = e.which || e.keyCode
1058
+ switch (keyCode) {
1059
+ case 37:
1060
+ case 40:
1061
+ e.preventDefault()
1062
+ // e.stopPropagation()
1063
+ this.keydownFlag = true
1064
+ this.flag = true
1065
+ this.changeFocusSlider(this.actionsKeyboard[0])
1066
+ break
1067
+ case 38:
1068
+ case 39:
1069
+ e.preventDefault()
1070
+ // e.stopPropagation()
1071
+ this.keydownFlag = true
1072
+ this.flag = true
1073
+ this.changeFocusSlider(this.actionsKeyboard[1])
1074
+ break
1075
+ default:
1076
+ break
1077
+ }
1078
+ },
1079
+ handleKeyup() {
1080
+ if (this.keydownFlag) {
1081
+ this.keydownFlag = false
1082
+ this.flag = false
1083
+ }
1084
+ },
1085
+ changeFocusSlider(fn) {
1086
+ if (this.isRange) {
1087
+ let arr = this.currentIndex.map((index, i) => {
1088
+ if (i === this.focusSlider || this.fixed) {
1089
+ const val = fn(index)
1090
+ const range = this.fixed ? this.valueLimit[i] : [0, this.total]
1091
+ if (val <= range[1] && val >= range[0]) {
1092
+ return val
1093
+ }
1094
+ }
1095
+ return index
1096
+ })
1097
+ if (arr[0] > arr[1]) {
1098
+ this.focusSlider = this.focusSlider === 0 ? 1 : 0
1099
+ arr = arr.reverse()
1100
+ }
1101
+ this.setIndex(arr)
1102
+ } else {
1103
+ this.setIndex(fn(this.currentIndex))
1104
+ }
1105
+ },
1106
+ bindEvents() {
1107
+ const me = this
1108
+ this.processStartFn = function(e) {
1109
+ me._start(e, 0, true)
1110
+ }
1111
+ this.dot0StartFn = function(e) {
1112
+ me._start(e, 0)
1113
+ }
1114
+ this.dot1StartFn = function(e) {
1115
+ me._start(e, 1)
1116
+ }
1117
+ if (isMobile) {
1118
+ addEvent(this.$refs.process, EVENT_TOUCH_START, this.processStartFn)
1119
+
1120
+ addEvent(document, EVENT_TOUCH_MOVE, this._move)
1121
+ addEvent(document, EVENT_TOUCH_END, this._end)
1122
+ addEvent(document, EVENT_TOUCH_CANCEL, this._end)
1123
+
1124
+ if (this.isRange) {
1125
+ addEvent(this.$refs.dot0, EVENT_TOUCH_START, this.dot0StartFn)
1126
+ addEvent(this.$refs.dot1, EVENT_TOUCH_START, this.dot1StartFn)
1127
+ } else {
1128
+ addEvent(this.$refs.dot, EVENT_TOUCH_START, this._start)
1129
+ }
1130
+ } else {
1131
+ addEvent(this.$refs.process, EVENT_MOUSE_DOWN, this.processStartFn)
1132
+
1133
+ addEvent(document, EVENT_MOUSE_DOWN, this.blurSlider)
1134
+ addEvent(document, EVENT_MOUSE_MOVE, this._move)
1135
+ addEvent(document, EVENT_MOUSE_UP, this._end)
1136
+ addEvent(document, EVENT_MOUSE_LEAVE, this._end)
1137
+
1138
+ if (this.isRange) {
1139
+ addEvent(this.$refs.dot0, EVENT_MOUSE_DOWN, this.dot0StartFn)
1140
+ addEvent(this.$refs.dot1, EVENT_MOUSE_DOWN, this.dot1StartFn)
1141
+ } else {
1142
+ addEvent(this.$refs.dot, EVENT_MOUSE_DOWN, this._start)
1143
+ }
1144
+ }
1145
+ addEvent(document, EVENT_KEY_DOWN, this.handleKeydown)
1146
+ addEvent(document, EVENT_KEY_UP, this.handleKeyup)
1147
+ addEvent(window, EVENT_RESIZE, this.refresh)
1148
+ if (this.isRange && this.tooltipMerge) {
1149
+ addEvent(this.$refs.dot0, transitionEnd, this.handleOverlapTooltip)
1150
+ addEvent(this.$refs.dot1, transitionEnd, this.handleOverlapTooltip)
1151
+ }
1152
+ },
1153
+ unbindEvents() {
1154
+ if (isMobile) {
1155
+ removeEvent(this.$refs.process, EVENT_TOUCH_START, this.processStartFn)
1156
+ removeEvent(document, EVENT_TOUCH_MOVE, this._move)
1157
+ removeEvent(document, EVENT_TOUCH_END, this._end)
1158
+ removeEvent(document, EVENT_TOUCH_CANCEL, this._end)
1159
+
1160
+ if (this.isRange) {
1161
+ removeEvent(this.$refs.dot0, EVENT_TOUCH_START, this.dot0StartFn)
1162
+ removeEvent(this.$refs.dot1, EVENT_TOUCH_START, this.dot1StartFn)
1163
+ } else {
1164
+ removeEvent(this.$refs.dot, EVENT_TOUCH_START, this._start)
1165
+ }
1166
+ } else {
1167
+ removeEvent(this.$refs.process, EVENT_MOUSE_DOWN, this.processStartFn)
1168
+ removeEvent(document, EVENT_MOUSE_DOWN, this.blurSlider)
1169
+ removeEvent(document, EVENT_MOUSE_MOVE, this._move)
1170
+ removeEvent(document, EVENT_MOUSE_UP, this._end)
1171
+ removeEvent(document, EVENT_MOUSE_LEAVE, this._end)
1172
+
1173
+ if (this.isRange) {
1174
+ removeEvent(this.$refs.dot0, EVENT_MOUSE_DOWN, this.dot0StartFn)
1175
+ removeEvent(this.$refs.dot1, EVENT_MOUSE_DOWN, this.dot1StartFn)
1176
+ } else {
1177
+ removeEvent(this.$refs.dot, EVENT_MOUSE_DOWN, this._start)
1178
+ }
1179
+ }
1180
+ removeEvent(document, EVENT_KEY_DOWN, this.handleKeydown)
1181
+ removeEvent(document, EVENT_KEY_UP, this.handleKeyup)
1182
+ removeEvent(window, EVENT_RESIZE, this.refresh)
1183
+ if (this.isRange && this.tooltipMerge) {
1184
+ removeEvent(this.$refs.dot0, transitionEnd, this.handleOverlapTooltip)
1185
+ removeEvent(this.$refs.dot1, transitionEnd, this.handleOverlapTooltip)
1186
+ }
1187
+ },
1188
+ refresh() {
1189
+ if (this.$refs.elem) {
1190
+ this.getStaticData()
1191
+ this.computedFixedValue()
1192
+ this.setPosition()
1193
+ this.unbindEvents()
1194
+ this.bindEvents()
1195
+ }
1196
+ },
1197
+ printError(msg) {
1198
+ if (this.debug) {
1199
+ console.error(`[VueSlider error]: ${msg}`)
1200
+ }
1201
+ }
1202
+ },
1203
+ mounted() {
1204
+ this.isComponentExists = true
1205
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
1206
+ return this.printError('window or document is undefined, can not be initialization.')
1207
+ }
1208
+ this.$nextTick(() => {
1209
+ this.getStaticData()
1210
+ this.setValue(this.limitValue(this.value), true, this.startAnimation ? this.speed : 0)
1211
+ this.bindEvents()
1212
+ if (this.isRange && this.tooltipMerge && !this.startAnimation) {
1213
+ this.handleOverlapTooltip()
1214
+ }
1215
+ })
1216
+ this.isMounted = true
1217
+ },
1218
+ watch: {
1219
+ value(val) {
1220
+ this.flag || this.setValue(val, true)
1221
+ },
1222
+ show(bool) {
1223
+ if (bool && !this.size) {
1224
+ this.$nextTick(this.refresh)
1225
+ }
1226
+ },
1227
+ max(val) {
1228
+ if (val < this.min) {
1229
+ return this.printError('The maximum value can not be less than the minimum value.')
1230
+ }
1231
+ const resetVal = this.limitValue(this.val)
1232
+ this.setValue(resetVal)
1233
+ this.refresh()
1234
+ },
1235
+ min(val) {
1236
+ if (val > this.max) {
1237
+ return this.printError('The minimum value can not be greater than the maximum value.')
1238
+ }
1239
+ const resetVal = this.limitValue(this.val)
1240
+ this.setValue(resetVal)
1241
+ this.refresh()
1242
+ },
1243
+ fixed() {
1244
+ this.computedFixedValue()
1245
+ },
1246
+ minRange() {
1247
+ this.computedFixedValue()
1248
+ }
1249
+ },
1250
+ beforeDestroy() {
1251
+ this.isComponentExists = false
1252
+ this.unbindEvents()
1253
+ this.refresh()
1254
+ },
1255
+ deactivated() {
1256
+ this.isComponentExists = false
1257
+ this.unbindEvents()
1258
+ this.refresh()
1259
+ }
1260
+ }
1261
+ </script>