codelation_ui 1.0.1 → 1.0.57
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/codelation_ui/_base_resources/app.js +54 -5
- data/app/assets/javascripts/codelation_ui/base.js +1 -0
- data/app/assets/javascripts/codelation_ui/extended/checkmark.js +31 -0
- data/app/assets/javascripts/codelation_ui/extended/code.js +64 -0
- data/app/assets/javascripts/codelation_ui/extended/fail.js +31 -0
- data/app/assets/javascripts/codelation_ui/extended/radial_progress_bar.js +267 -0
- data/app/assets/javascripts/codelation_ui/extended/slider.js +636 -639
- data/app/assets/javascripts/codelation_ui/extended/spinner.js +103 -0
- data/app/assets/javascripts/codelation_ui/forms/components/input.js +417 -388
- data/app/assets/javascripts/codelation_ui/forms/interfaces/form.js +35 -30
- data/app/assets/javascripts/codelation_ui/std.js +3 -1
- data/app/assets/javascripts/codelation_ui/std/components/info.js +22 -0
- data/app/assets/javascripts/codelation_ui/std/components/transition.js +26 -0
- data/app/assets/javascripts/codelation_ui/std/computed_interfaces/mockAPI.js +17 -0
- data/app/assets/javascripts/codelation_ui/std/interfaces/array.js +28 -0
- data/app/assets/javascripts/codelation_ui/std/interfaces/content_formatters.js +37 -10
- data/app/assets/javascripts/codelation_ui/std/interfaces/date.js +8 -0
- data/app/assets/javascripts/codelation_ui/std/interfaces/number.js +20 -0
- data/app/assets/javascripts/codelation_ui/std/interfaces/rest_api.js +104 -0
- data/app/assets/javascripts/codelation_ui/std/interfaces/string.js +29 -0
- data/app/assets/javascripts/codelation_ui/vue.js +25 -8
- data/app/assets/javascripts/codelation_ui/vue_pages.js +35 -10
- data/app/assets/stylesheets/codelation_ui.scss +1 -3
- data/app/assets/stylesheets/codelation_ui/_base_resources/_turbolinks.scss +11 -0
- data/app/assets/stylesheets/codelation_ui/_base_resources/mixins/button.scss +185 -33
- data/app/assets/stylesheets/codelation_ui/base.scss +3 -0
- data/app/assets/stylesheets/codelation_ui/colors.scss +2 -0
- data/app/assets/stylesheets/codelation_ui/extended/checkmark.scss +53 -0
- data/app/assets/stylesheets/codelation_ui/extended/code.scss +153 -0
- data/app/assets/stylesheets/codelation_ui/extended/fail.scss +50 -0
- data/app/assets/stylesheets/codelation_ui/extended/radial_progress_bar.scss +70 -0
- data/app/assets/stylesheets/codelation_ui/extended/slider.scss +2 -2
- data/app/assets/stylesheets/codelation_ui/extended/spinner.scss +100 -0
- data/app/assets/stylesheets/codelation_ui/std.scss +1 -1
- data/app/assets/stylesheets/codelation_ui/std/info.scss +51 -0
- data/app/assets/stylesheets/codelation_ui/vue_transitions.scss +94 -0
- data/app/helpers/action_view/helpers/url_helper.rb +22 -0
- data/lib/generators/ui/component/USAGE +22 -0
- data/lib/generators/ui/component/component_generator.rb +41 -0
- data/lib/generators/ui/component/templates/javascript.js.erb +20 -0
- data/lib/generators/ui/component/templates/page_javascript.js.erb +20 -0
- data/lib/generators/ui/component/templates/page_stylesheet.scss.erb +3 -0
- data/lib/generators/ui/component/templates/stylesheet.scss.erb +3 -0
- data/lib/generators/ui/component/templates/template.html.erb +5 -0
- data/lib/generators/ui/mixin/USAGE +8 -0
- data/lib/generators/ui/mixin/mixin_generator.rb +11 -0
- data/lib/generators/ui/mixin/templates/javascript.js.erb +8 -0
- data/lib/generators/ui/pages/USAGE +23 -0
- data/lib/generators/ui/pages/pages_generator.rb +48 -0
- data/lib/generators/ui/pages/templates/controller.rb +2 -0
- data/lib/generators/ui/pages/templates/javascript.js.erb +22 -0
- data/lib/generators/ui/pages/templates/stylesheet.scss.erb +3 -0
- data/lib/generators/ui/pages/templates/template.html.erb +3 -0
- data/vendor/assets/javascripts/highlight.pack.js +2 -0
- data/vendor/assets/javascripts/pluralize.js +1 -0
- data/vendor/assets/javascripts/vue.js +4 -10232
- metadata +107 -11
- data/app/assets/javascripts/codelation_ui/std/index.js +0 -2
@@ -4,651 +4,648 @@
|
|
4
4
|
(function() {
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
|
7
|
+
var template = '<div v-el:wrap :class="[\'vue-slider-wrap\', flowDirection, disabledClass, { \'vue-slider-has-label\': piecewiseLabel }]" v-show="show" :style="wrapStyles" @click="wrapClick">\
|
8
|
+
<div v-el:elem class="vue-slider" :style="styleMerge(elemStyles, bgStyle)">\
|
9
|
+
<template v-if="isMoblie">\
|
10
|
+
<template v-if="isRange">\
|
11
|
+
<div v-el:dot0 :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles[0], dotStyles)" @touchstart="moveStart(0)">\
|
12
|
+
<span :class="[\'vue-slider-tooltip-\' + tooltipDirection[0], \'vue-slider-tooltip\']" :style="tooltipStyles[0]">{{ formatter ? formatting(val[0]) : val[0] }}</span>\
|
13
|
+
</div>\
|
14
|
+
<div v-el:dot1 :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles[1], dotStyles)" @touchstart="moveStart(1)">\
|
15
|
+
<span :class="[\'vue-slider-tooltip-\' + tooltipDirection[1], \'vue-slider-tooltip\']" :style="tooltipStyles[1]">{{ formatter ? formatting(val[1]) : val[1] }}</span>\
|
16
|
+
</div>\
|
17
|
+
</template>\
|
18
|
+
<template v-else>\
|
19
|
+
<div v-el:dot :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles, dotStyles)" @touchstart="moveStart">\
|
20
|
+
<span :class="[\'vue-slider-tooltip-\' + tooltipDirection, \'vue-slider-tooltip\']" :style="tooltipStyles">{{ formatter ? formatting(val) : val}}</span>\
|
21
|
+
</div>\
|
22
|
+
</template>\
|
23
|
+
</template>\
|
24
|
+
<template v-else>\
|
25
|
+
<template v-if="isRange">\
|
26
|
+
<div v-el:dot0 :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles[0], dotStyles)" @mousedown="moveStart(0)">\
|
27
|
+
<span :class="[\'vue-slider-tooltip-\' + tooltipDirection[0], \'vue-slider-tooltip\']" :style="tooltipStyles[0]">{{ formatter ? formatting(val[0]) : val[0] }}</span>\
|
28
|
+
</div>\
|
29
|
+
<div v-el:dot1 :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles[1], dotStyles)" @mousedown="moveStart(1)">\
|
30
|
+
<span :class="[\'vue-slider-tooltip-\' + tooltipDirection[1], \'vue-slider-tooltip\']" :style="tooltipStyles[1]">{{ formatter ? formatting(val[1]) : val[1] }}</span>\
|
31
|
+
</div>\
|
32
|
+
</template>\
|
33
|
+
<template v-else>\
|
34
|
+
<div v-el:dot :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles, dotStyles)" @mousedown="moveStart">\
|
35
|
+
<span :class="[\'vue-slider-tooltip-\' + tooltipDirection, \'vue-slider-tooltip\']" :style="tooltipStyles">{{ formatter ? formatting(val) : val }}</span>\
|
36
|
+
</div>\
|
37
|
+
</template>\
|
38
|
+
</template>\
|
39
|
+
<template v-if="piecewise">\
|
40
|
+
<ul class="vue-slider-piecewise">\
|
41
|
+
<li v-for="piecewiseObj in piecewiseDotWrap" :style="styleMerge(piecewiseDotStyle, piecewiseObj.style)">\
|
42
|
+
<span class="vue-slider-piecewise-dot" :style="styleMerge(piecewiseStyle, piecewiseObj.inRange ? piecewiseActiveStyle : null)"></span>\
|
43
|
+
<span v-if="piecewiseLabel" class="vue-slider-piecewise-label" :style="styleMerge(labelStyle, piecewiseObj.inRange ? labelActiveStyle : null)">{{ piecewiseObj.label }}</span>\
|
44
|
+
</li>\
|
45
|
+
</ul>\
|
46
|
+
</template>\
|
47
|
+
<div v-el:process class="vue-slider-process" :style="processStyle"></div>\
|
48
|
+
</div>\
|
49
|
+
</div>';
|
8
50
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
},
|
168
|
-
tooltipStatus() {
|
169
|
-
return this.tooltip === 'hover' && this.flag ? 'vue-slider-always' : this.tooltip ? `vue-slider-${this.tooltip}` : ''
|
170
|
-
},
|
171
|
-
tooltipClass() {
|
172
|
-
return [`vue-slider-tooltip-${this.tooltipDirection}`, 'vue-slider-tooltip']
|
173
|
-
},
|
174
|
-
isMoblie() {
|
175
|
-
return this.eventType === 'touch' || this.eventType !== 'mouse' && /(iPhone|iPad|iPod|iOS|Android|SymbianOS|Windows Phone|Mobile)/i.test(navigator.userAgent)
|
176
|
-
},
|
177
|
-
isDisabled() {
|
178
|
-
return this.eventType === 'none' ? true : this.disabled
|
179
|
-
},
|
180
|
-
disabledClass() {
|
181
|
-
return this.disabled ? 'vue-slider-disabled' : ''
|
182
|
-
},
|
183
|
-
isRange() {
|
184
|
-
return Array.isArray(this.value)
|
185
|
-
},
|
186
|
-
slider() {
|
187
|
-
return this.isRange ? [this.$els.dot0, this.$els.dot1] : this.$els.dot
|
188
|
-
},
|
189
|
-
minimum() {
|
190
|
-
return this.data ? 0 : this.min
|
191
|
-
},
|
192
|
-
val: {
|
193
|
-
get() {
|
194
|
-
return this.data ? (this.isRange ? [this.data[this.currentValue[0]], this.data[this.currentValue[1]]] : this.data[this.currentValue]) : this.currentValue
|
195
|
-
},
|
196
|
-
set(val) {
|
197
|
-
if (this.data) {
|
198
|
-
if (this.isRange) {
|
199
|
-
let index0 = this.data.indexOf(val[0])
|
200
|
-
let index1 = this.data.indexOf(val[1])
|
201
|
-
if (index0 > -1 && index1 > -1) {
|
202
|
-
this.currentValue = [index0, index1]
|
203
|
-
}
|
204
|
-
}
|
205
|
-
else {
|
206
|
-
let index = this.data.indexOf(val)
|
207
|
-
if (index > -1) {
|
208
|
-
this.currentValue = index
|
209
|
-
}
|
210
|
-
}
|
211
|
-
}
|
212
|
-
else {
|
213
|
-
this.currentValue = val
|
214
|
-
}
|
215
|
-
}
|
216
|
-
},
|
217
|
-
currentIndex() {
|
218
|
-
if (this.isRange) {
|
219
|
-
return this.data ? this.currentValue : [(this.currentValue[0] - this.minimum) / this.spacing, (this.currentValue[1] - this.minimum) / this.spacing]
|
220
|
-
}
|
221
|
-
else {
|
222
|
-
return (this.currentValue - this.minimum) / this.spacing
|
223
|
-
}
|
224
|
-
},
|
225
|
-
indexRange() {
|
226
|
-
if (this.isRange) {
|
227
|
-
return this.currentIndex
|
228
|
-
}
|
229
|
-
else {
|
230
|
-
return [0, this.currentIndex]
|
231
|
-
}
|
232
|
-
},
|
233
|
-
maximum() {
|
234
|
-
return this.data ? (this.data.length - 1) : this.max
|
235
|
-
},
|
236
|
-
multiple() {
|
237
|
-
let decimals = `${this.interval}`.split('.')[1]
|
238
|
-
return decimals ? Math.pow(10, decimals.length) : 1
|
239
|
-
},
|
240
|
-
spacing() {
|
241
|
-
return this.data ? 1 : this.interval
|
242
|
-
},
|
243
|
-
total() {
|
244
|
-
if (this.data) {
|
245
|
-
return this.data.length - 1
|
246
|
-
}
|
247
|
-
else if (~~((this.maximum - this.minimum) * this.multiple) % (this.interval * this.multiple) !== 0) {
|
248
|
-
console.error('[Vue-slider warn]: Prop[interval] is illegal, Please make sure that the interval can be divisible')
|
249
|
-
}
|
250
|
-
return (this.maximum - this.minimum) / this.interval
|
251
|
-
},
|
252
|
-
gap() {
|
253
|
-
return this.size / this.total
|
254
|
-
},
|
255
|
-
position() {
|
256
|
-
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)
|
257
|
-
},
|
258
|
-
limit() {
|
259
|
-
return this.isRange ? [[0, this.position[1]], [this.position[0], this.size]] : [0, this.size]
|
260
|
-
},
|
261
|
-
valueLimit() {
|
262
|
-
return this.isRange ? [[this.minimum, this.currentValue[1]], [this.currentValue[0], this.maximum]] : [this.minimum, this.maximum]
|
263
|
-
},
|
264
|
-
wrapStyles() {
|
265
|
-
return this.direction === 'vertical' ? {
|
266
|
-
height: typeof this.height === 'number' ? `${this.height}px` : this.height,
|
267
|
-
padding: `${this.dotSize / 2}px`
|
268
|
-
} : {
|
269
|
-
width: typeof this.width === 'number' ? `${this.width}px` : this.width,
|
270
|
-
padding: `${this.dotSize / 2}px`
|
271
|
-
}
|
272
|
-
},
|
273
|
-
sliderStyles() {
|
274
|
-
if (Array.isArray(this.sliderStyle)) {
|
275
|
-
return this.isRange ? this.sliderStyle : this.sliderStyle[1]
|
276
|
-
}
|
277
|
-
else {
|
278
|
-
return this.isRange ? [this.sliderStyle, this.sliderStyle] : this.sliderStyle
|
279
|
-
}
|
280
|
-
},
|
281
|
-
tooltipStyles() {
|
282
|
-
if (Array.isArray(this.tooltipStyle)) {
|
283
|
-
return this.isRange ? this.tooltipStyle : this.tooltipStyle[1]
|
284
|
-
}
|
285
|
-
else {
|
286
|
-
return this.isRange ? [this.tooltipStyle, this.tooltipStyle] : this.tooltipStyle
|
287
|
-
}
|
288
|
-
},
|
289
|
-
elemStyles() {
|
290
|
-
return this.direction === 'vertical' ? {
|
291
|
-
width: `${this.width}px`,
|
292
|
-
height: '100%'
|
293
|
-
} : {
|
294
|
-
height: `${this.height}px`
|
295
|
-
}
|
296
|
-
},
|
297
|
-
dotStyles() {
|
298
|
-
return this.direction === 'vertical' ? {
|
299
|
-
width: `${this.dotSize}px`,
|
300
|
-
height: `${this.dotSize}px`,
|
301
|
-
left: `${(-(this.dotSize - this.width) / 2)}px`
|
302
|
-
} : {
|
303
|
-
width: `${this.dotSize}px`,
|
304
|
-
height: `${this.dotSize}px`,
|
305
|
-
top: `${(-(this.dotSize - this.height) / 2)}px`
|
306
|
-
}
|
307
|
-
},
|
308
|
-
piecewiseDotStyle() {
|
309
|
-
return this.direction === 'vertical' ? {
|
310
|
-
width: `${this.width}px`,
|
311
|
-
height: `${this.width}px`
|
312
|
-
} : {
|
313
|
-
width: `${this.height}px`,
|
314
|
-
height: `${this.height}px`
|
315
|
-
}
|
316
|
-
},
|
317
|
-
piecewiseDotWrap() {
|
318
|
-
if (!this.piecewise) {
|
319
|
-
return false
|
320
|
-
}
|
321
|
-
|
322
|
-
let arr = []
|
323
|
-
let gap = (this.size - (this.direction === 'vertical' ? this.width : this.height)) / this.total
|
324
|
-
for (let i = 0; i <= this.total; i++) {
|
325
|
-
let style = this.direction === 'vertical' ? {
|
326
|
-
bottom: `${this.gap * i - this.width / 2}px`,
|
327
|
-
left: '200px'
|
328
|
-
} : {
|
329
|
-
left: `${this.gap * i - this.height / 2}px`,
|
330
|
-
top: '0'
|
331
|
-
}
|
332
|
-
let index = this.reverse ? (this.total - i) : i
|
333
|
-
let label = this.data ? this.data[index] : (this.spacing * index) + this.min
|
334
|
-
arr.push({
|
335
|
-
style,
|
336
|
-
label: this.formatter ? this.formatting(label) : label,
|
337
|
-
inRange: index >= this.indexRange[0] && index <= this.indexRange[1]
|
338
|
-
})
|
339
|
-
}
|
340
|
-
return arr
|
341
|
-
}
|
342
|
-
},
|
343
|
-
watch: {
|
344
|
-
value(val) {
|
345
|
-
this.flag || this.setValue(val)
|
346
|
-
},
|
347
|
-
currentValue: function(val) {
|
348
|
-
this.value = this.val
|
349
|
-
},
|
350
|
-
max(val) {
|
351
|
-
if (this.flag || this.data) {
|
352
|
-
this.refresh()
|
353
|
-
}
|
354
|
-
else if (this.isRange) {
|
355
|
-
let bool
|
356
|
-
val = this.val.map((v) => {
|
357
|
-
if (v > val) {
|
358
|
-
bool = true
|
359
|
-
return val
|
360
|
-
}
|
361
|
-
return v
|
362
|
-
})
|
363
|
-
bool && this.setValue(val)
|
364
|
-
this.refresh()
|
365
|
-
}
|
366
|
-
else {
|
367
|
-
this.val > val && this.setValue(val)
|
368
|
-
this.refresh()
|
369
|
-
}
|
370
|
-
},
|
371
|
-
min(val) {
|
372
|
-
if (this.flag || this.data) {
|
373
|
-
this.refresh()
|
374
|
-
}
|
375
|
-
else if (this.isRange) {
|
376
|
-
let bool
|
377
|
-
val = this.val.map((v) => {
|
378
|
-
if (v < val) {
|
379
|
-
bool = true
|
380
|
-
return val
|
381
|
-
}
|
382
|
-
return v
|
383
|
-
})
|
384
|
-
bool && this.setValue(val)
|
385
|
-
this.refresh()
|
386
|
-
}
|
387
|
-
else {
|
388
|
-
this.val < val && this.setValue(val)
|
389
|
-
this.refresh()
|
390
|
-
}
|
391
|
-
},
|
392
|
-
show(bool) {
|
393
|
-
if (bool && !this.size) {
|
394
|
-
this.$nextTick(() => {
|
395
|
-
this.refresh()
|
396
|
-
})
|
397
|
-
}
|
398
|
-
}
|
399
|
-
},
|
400
|
-
methods: {
|
401
|
-
styleMerge(one, two) {
|
402
|
-
if (one === undefined) {
|
403
|
-
return two;
|
51
|
+
App.vue.components.vueSlider = Vue.extend({
|
52
|
+
template: template,
|
53
|
+
data: function() {
|
54
|
+
return {
|
55
|
+
flag: false,
|
56
|
+
size: 0,
|
57
|
+
currentValue: 0,
|
58
|
+
currentSlider: 0
|
59
|
+
}
|
60
|
+
},
|
61
|
+
props: {
|
62
|
+
width: {
|
63
|
+
type: [Number, String],
|
64
|
+
default: 'auto'
|
65
|
+
},
|
66
|
+
height: {
|
67
|
+
type: [Number, String],
|
68
|
+
default: 6
|
69
|
+
},
|
70
|
+
data: {
|
71
|
+
type: Array,
|
72
|
+
default: null
|
73
|
+
},
|
74
|
+
dotSize: {
|
75
|
+
type: Number,
|
76
|
+
default: 16
|
77
|
+
},
|
78
|
+
min: {
|
79
|
+
type: Number,
|
80
|
+
default: 0
|
81
|
+
},
|
82
|
+
max: {
|
83
|
+
type: Number,
|
84
|
+
default: 100
|
85
|
+
},
|
86
|
+
interval: {
|
87
|
+
type: Number,
|
88
|
+
default: 1
|
89
|
+
},
|
90
|
+
show: {
|
91
|
+
type: Boolean,
|
92
|
+
default: true
|
93
|
+
},
|
94
|
+
disabled: {
|
95
|
+
type: Boolean,
|
96
|
+
default: false
|
97
|
+
},
|
98
|
+
piecewise: {
|
99
|
+
type: Boolean,
|
100
|
+
default: false
|
101
|
+
},
|
102
|
+
tooltip: {
|
103
|
+
type: [String, Boolean],
|
104
|
+
default: 'always'
|
105
|
+
},
|
106
|
+
eventType: {
|
107
|
+
type: String,
|
108
|
+
default: 'auto'
|
109
|
+
},
|
110
|
+
direction: {
|
111
|
+
type: String,
|
112
|
+
default: 'horizontal'
|
113
|
+
},
|
114
|
+
reverse: {
|
115
|
+
type: Boolean,
|
116
|
+
default: false
|
117
|
+
},
|
118
|
+
lazy: {
|
119
|
+
type: Boolean,
|
120
|
+
default: false
|
121
|
+
},
|
122
|
+
clickable: {
|
123
|
+
type: Boolean,
|
124
|
+
default: true
|
125
|
+
},
|
126
|
+
speed: {
|
127
|
+
type: Number,
|
128
|
+
default: 0.5
|
129
|
+
},
|
130
|
+
realTime: {
|
131
|
+
type: Boolean,
|
132
|
+
default: false
|
133
|
+
},
|
134
|
+
value: {
|
135
|
+
type: [String, Number, Array],
|
136
|
+
default: 0
|
137
|
+
},
|
138
|
+
piecewiseLabel: {
|
139
|
+
type: Boolean,
|
140
|
+
default: false
|
141
|
+
},
|
142
|
+
sliderStyle: [Array, Object],
|
143
|
+
tooltipDir: [Array, String],
|
144
|
+
formatter: [String, Function],
|
145
|
+
piecewiseStyle: Object,
|
146
|
+
piecewiseActiveStyle: Object,
|
147
|
+
processStyle: Object,
|
148
|
+
bgStyle: Object,
|
149
|
+
tooltipStyle: [Array, Object],
|
150
|
+
labelStyle: Object,
|
151
|
+
labelActiveStyle: Object
|
152
|
+
},
|
153
|
+
computed: {
|
154
|
+
flowDirection: function() {
|
155
|
+
return 'vue-slider-' + this.direction + (this.reverse ? '-reverse' : '');
|
156
|
+
},
|
157
|
+
tooltipDirection: function() {
|
158
|
+
var dir = this.tooltipDir || (this.direction === 'vertical' ? 'left' : 'top')
|
159
|
+
if (Array.isArray(dir)) {
|
160
|
+
return this.isRange ? dir : dir[1]
|
161
|
+
}
|
162
|
+
else {
|
163
|
+
return this.isRange ? [dir, dir] : dir
|
164
|
+
}
|
165
|
+
},
|
166
|
+
tooltipStatus: function() {
|
167
|
+
return this.tooltip === 'hover' && this.flag ? 'vue-slider-always' : this.tooltip ? 'vue-slider-' + this.tooltip : ''
|
168
|
+
},
|
169
|
+
tooltipClass: function() {
|
170
|
+
return ['vue-slider-tooltip-' + this.tooltipDirection, 'vue-slider-tooltip']
|
171
|
+
},
|
172
|
+
isMoblie: function() {
|
173
|
+
return this.eventType === 'touch' || this.eventType !== 'mouse' && /(iPhone|iPad|iPod|iOS|Android|SymbianOS|Windows Phone|Mobile)/i.test(navigator.userAgent)
|
174
|
+
},
|
175
|
+
isDisabled: function() {
|
176
|
+
return this.eventType === 'none' ? true : this.disabled
|
177
|
+
},
|
178
|
+
disabledClass: function() {
|
179
|
+
return this.disabled ? 'vue-slider-disabled' : ''
|
180
|
+
},
|
181
|
+
isRange: function() {
|
182
|
+
return Array.isArray(this.value)
|
183
|
+
},
|
184
|
+
slider: function() {
|
185
|
+
return this.isRange ? [this.$els.dot0, this.$els.dot1] : this.$els.dot
|
186
|
+
},
|
187
|
+
minimum: function() {
|
188
|
+
return this.data ? 0 : this.min
|
189
|
+
},
|
190
|
+
val: {
|
191
|
+
get: function() {
|
192
|
+
return this.data ? (this.isRange ? [this.data[this.currentValue[0]], this.data[this.currentValue[1]]] : this.data[this.currentValue]) : this.currentValue
|
193
|
+
},
|
194
|
+
set: function(val) {
|
195
|
+
if (this.data) {
|
196
|
+
if (this.isRange) {
|
197
|
+
var index0 = this.data.indexOf(val[0])
|
198
|
+
var index1 = this.data.indexOf(val[1])
|
199
|
+
if (index0 > -1 && index1 > -1) {
|
200
|
+
this.currentValue = [index0, index1]
|
201
|
+
}
|
202
|
+
}
|
203
|
+
else {
|
204
|
+
var index = this.data.indexOf(val)
|
205
|
+
if (index > -1) {
|
206
|
+
this.currentValue = index
|
207
|
+
}
|
208
|
+
}
|
404
209
|
}
|
405
|
-
|
406
|
-
|
210
|
+
else {
|
211
|
+
this.currentValue = val
|
212
|
+
}
|
213
|
+
}
|
214
|
+
},
|
215
|
+
currentIndex: function() {
|
216
|
+
if (this.isRange) {
|
217
|
+
return this.data ? this.currentValue : [(this.currentValue[0] - this.minimum) / this.spacing, (this.currentValue[1] - this.minimum) / this.spacing]
|
218
|
+
}
|
219
|
+
else {
|
220
|
+
return (this.currentValue - this.minimum) / this.spacing
|
221
|
+
}
|
222
|
+
},
|
223
|
+
indexRange: function() {
|
224
|
+
if (this.isRange) {
|
225
|
+
return this.currentIndex
|
226
|
+
}
|
227
|
+
else {
|
228
|
+
return [0, this.currentIndex]
|
229
|
+
}
|
230
|
+
},
|
231
|
+
maximum: function() {
|
232
|
+
return this.data ? (this.data.length - 1) : this.max
|
233
|
+
},
|
234
|
+
multiple: function() {
|
235
|
+
var decimals = this.interval.toString().split('.')[1]
|
236
|
+
return decimals ? Math.pow(10, decimals.length) : 1
|
237
|
+
},
|
238
|
+
spacing: function() {
|
239
|
+
return this.data ? 1 : this.interval
|
240
|
+
},
|
241
|
+
total: function() {
|
242
|
+
if (this.data) {
|
243
|
+
return this.data.length - 1
|
244
|
+
}
|
245
|
+
else if (~~((this.maximum - this.minimum) * this.multiple) % (this.interval * this.multiple) !== 0) {
|
246
|
+
console.error('[Vue-slider warn]: Prop[interval] is illegal, Please make sure that the interval can be divisible')
|
247
|
+
}
|
248
|
+
return (this.maximum - this.minimum) / this.interval
|
249
|
+
},
|
250
|
+
gap: function() {
|
251
|
+
return this.size / this.total
|
252
|
+
},
|
253
|
+
position: function() {
|
254
|
+
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)
|
255
|
+
},
|
256
|
+
limit: function() {
|
257
|
+
return this.isRange ? [[0, this.position[1]], [this.position[0], this.size]] : [0, this.size]
|
258
|
+
},
|
259
|
+
valueLimit: function() {
|
260
|
+
return this.isRange ? [[this.minimum, this.currentValue[1]], [this.currentValue[0], this.maximum]] : [this.minimum, this.maximum]
|
261
|
+
},
|
262
|
+
wrapStyles: function() {
|
263
|
+
return this.direction === 'vertical' ? {
|
264
|
+
height: typeof this.height === 'number' ? this.height + 'px' : this.height,
|
265
|
+
padding: (this.dotSize / 2) + 'px'
|
266
|
+
} : {
|
267
|
+
width: typeof this.width === 'number' ? this.width + 'px' : this.width,
|
268
|
+
padding: (this.dotSize / 2) + 'px'
|
269
|
+
}
|
270
|
+
},
|
271
|
+
sliderStyles: function() {
|
272
|
+
if (Array.isArray(this.sliderStyle)) {
|
273
|
+
return this.isRange ? this.sliderStyle : this.sliderStyle[1]
|
274
|
+
}
|
275
|
+
else {
|
276
|
+
return this.isRange ? [this.sliderStyle, this.sliderStyle] : this.sliderStyle
|
277
|
+
}
|
278
|
+
},
|
279
|
+
tooltipStyles: function() {
|
280
|
+
if (Array.isArray(this.tooltipStyle)) {
|
281
|
+
return this.isRange ? this.tooltipStyle : this.tooltipStyle[1]
|
282
|
+
}
|
283
|
+
else {
|
284
|
+
return this.isRange ? [this.tooltipStyle, this.tooltipStyle] : this.tooltipStyle
|
285
|
+
}
|
286
|
+
},
|
287
|
+
elemStyles: function() {
|
288
|
+
return this.direction === 'vertical' ? {
|
289
|
+
width: this.width + 'px',
|
290
|
+
height: '100%'
|
291
|
+
} : {
|
292
|
+
height: this.height + 'px'
|
293
|
+
}
|
294
|
+
},
|
295
|
+
dotStyles: function() {
|
296
|
+
return this.direction === 'vertical' ? {
|
297
|
+
width: this.dotSize + 'px',
|
298
|
+
height: this.dotSize + 'px',
|
299
|
+
left: (-(this.dotSize - this.width) / 2) + 'px'
|
300
|
+
} : {
|
301
|
+
width: this.dotSize + 'px',
|
302
|
+
height: this.dotSize + 'px',
|
303
|
+
top: (-(this.dotSize - this.height) / 2) + 'px'
|
304
|
+
}
|
305
|
+
},
|
306
|
+
piecewiseDotStyle: function() {
|
307
|
+
return this.direction === 'vertical' ? {
|
308
|
+
width: this.width + 'px',
|
309
|
+
height: this.width + 'px'
|
310
|
+
} : {
|
311
|
+
width: this.height + 'px',
|
312
|
+
height: this.height + 'px'
|
313
|
+
}
|
314
|
+
},
|
315
|
+
piecewiseDotWrap: function() {
|
316
|
+
if (!this.piecewise) {
|
317
|
+
return false
|
318
|
+
}
|
319
|
+
|
320
|
+
var arr = []
|
321
|
+
var gap = (this.size - (this.direction === 'vertical' ? this.width : this.height)) / this.total
|
322
|
+
for (var i = 0; i <= this.total; i++) {
|
323
|
+
var style = this.direction === 'vertical' ? {
|
324
|
+
bottom: (this.gap * i - this.width / 2) + 'px',
|
325
|
+
left: '200px'
|
326
|
+
} : {
|
327
|
+
left: (this.gap * i - this.height / 2) + 'px',
|
328
|
+
top: '0'
|
407
329
|
}
|
408
|
-
|
330
|
+
var index = this.reverse ? (this.total - i) : i
|
331
|
+
var label = this.data ? this.data[index] : (this.spacing * index) + this.min
|
332
|
+
arr.push({
|
333
|
+
style: style,
|
334
|
+
label: this.formatter ? this.formatting(label) : label,
|
335
|
+
inRange: index >= this.indexRange[0] && index <= this.indexRange[1]
|
336
|
+
})
|
337
|
+
}
|
338
|
+
return arr
|
339
|
+
}
|
340
|
+
},
|
341
|
+
watch: {
|
342
|
+
value: function(val) {
|
343
|
+
this.flag || this.setValue(val)
|
344
|
+
},
|
345
|
+
currentValue: function(val) {
|
346
|
+
this.value = this.val
|
347
|
+
},
|
348
|
+
max: function(val) {
|
349
|
+
if (this.flag || this.data) {
|
350
|
+
this.refresh()
|
351
|
+
}
|
352
|
+
else if (this.isRange) {
|
353
|
+
var bool
|
354
|
+
val = this.val.map(function(v) {
|
355
|
+
if (v > val) {
|
356
|
+
bool = true
|
357
|
+
return val
|
358
|
+
}
|
359
|
+
return v
|
360
|
+
})
|
361
|
+
bool && this.setValue(val)
|
362
|
+
this.refresh()
|
363
|
+
}
|
364
|
+
else {
|
365
|
+
this.val > val && this.setValue(val)
|
366
|
+
this.refresh()
|
367
|
+
}
|
368
|
+
},
|
369
|
+
min: function(val) {
|
370
|
+
if (this.flag || this.data) {
|
371
|
+
this.refresh()
|
372
|
+
}
|
373
|
+
else if (this.isRange) {
|
374
|
+
var bool
|
375
|
+
val = this.val.map(function(v) {
|
376
|
+
if (v < val) {
|
377
|
+
bool = true
|
378
|
+
return val
|
379
|
+
}
|
380
|
+
return v
|
381
|
+
})
|
382
|
+
bool && this.setValue(val)
|
383
|
+
this.refresh()
|
384
|
+
}
|
385
|
+
else {
|
386
|
+
this.val < val && this.setValue(val)
|
387
|
+
this.refresh()
|
388
|
+
}
|
389
|
+
},
|
390
|
+
show: function(bool) {
|
391
|
+
if (bool && !this.size) {
|
392
|
+
this.$nextTick(function() {
|
393
|
+
this.refresh()
|
394
|
+
})
|
395
|
+
}
|
396
|
+
}
|
397
|
+
},
|
398
|
+
methods: {
|
399
|
+
styleMerge: function(one, two) {
|
400
|
+
if (one === undefined) {
|
401
|
+
return two;
|
402
|
+
}
|
403
|
+
if (two === undefined) {
|
409
404
|
return one;
|
410
|
-
}
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
405
|
+
}
|
406
|
+
for (var attrname in two) { one[attrname] = two[attrname]; }
|
407
|
+
return one;
|
408
|
+
},
|
409
|
+
bindEvents: function() {
|
410
|
+
if (this.isMoblie) {
|
411
|
+
this.$els.wrap.addEventListener('touchmove', this.moving)
|
412
|
+
this.$els.wrap.addEventListener('touchend', this.moveEnd)
|
413
|
+
}
|
414
|
+
else {
|
415
|
+
document.addEventListener('mousemove', this.moving)
|
416
|
+
document.addEventListener('mouseup', this.moveEnd)
|
417
|
+
document.addEventListener('mouseleave', this.moveEnd)
|
418
|
+
}
|
419
|
+
},
|
420
|
+
unbindEvents: function() {
|
421
|
+
window.removeEventListener('resize', this.refresh)
|
424
422
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
423
|
+
if (this.isMoblie) {
|
424
|
+
this.$els.wrap.removeEventListener('touchmove', this.moving)
|
425
|
+
this.$els.wrap.removeEventListener('touchend', this.moveEnd)
|
426
|
+
}
|
427
|
+
else {
|
428
|
+
document.removeEventListener('mousemove', this.moving)
|
429
|
+
document.removeEventListener('mouseup', this.moveEnd)
|
430
|
+
document.removeEventListener('mouseleave', this.moveEnd)
|
431
|
+
}
|
432
|
+
},
|
433
|
+
formatting: function(value) {
|
434
|
+
return typeof this.formatter === 'string' ? this.formatter.replace(/\{value\}/, value) : this.formatter(value)
|
435
|
+
},
|
436
|
+
getPos: function(e) {
|
437
|
+
this.realTime && this.getStaticData()
|
438
|
+
return this.direction === 'vertical' ? (this.reverse ? (e.pageY - this.offset) : (this.size - (e.pageY - this.offset))) : (this.reverse ? (this.size - (e.clientX - this.offset)) : (e.clientX - this.offset))
|
439
|
+
},
|
440
|
+
wrapClick: function(e) {
|
441
|
+
if (this.isDisabled || !this.clickable) return false
|
442
|
+
var pos = this.getPos(e)
|
443
|
+
if (this.isRange) {
|
444
|
+
this.currentSlider = pos > ((this.position[1] - this.position[0]) / 2 + this.position[0]) ? 1 : 0
|
445
|
+
}
|
446
|
+
this.setValueOnPos(pos)
|
447
|
+
},
|
448
|
+
moveStart: function(index) {
|
449
|
+
if (this.isDisabled) return false
|
450
|
+
else if (this.isRange) {
|
451
|
+
this.currentSlider = index
|
452
|
+
}
|
453
|
+
this.flag = true
|
454
|
+
this.$emit('drag-start', this)
|
455
|
+
},
|
456
|
+
moving: function(e) {
|
457
|
+
if (!this.flag) return false
|
458
|
+
e.preventDefault()
|
461
459
|
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
460
|
+
if (this.isMoblie) e = e.targetTouches[0]
|
461
|
+
this.setValueOnPos(this.getPos(e), true)
|
462
|
+
},
|
463
|
+
moveEnd: function(e) {
|
464
|
+
if (this.flag) {
|
465
|
+
this.$emit('drag-end', this)
|
466
|
+
if (this.lazy && this.isDiff(this.val, this.value)) {
|
467
|
+
this.syncValue()
|
468
|
+
}
|
469
|
+
}
|
470
|
+
else {
|
471
|
+
return false
|
472
|
+
}
|
473
|
+
this.flag = false
|
474
|
+
this.setPosition()
|
475
|
+
},
|
476
|
+
setValueOnPos: function(pos, isDrag) {
|
477
|
+
var range = this.isRange ? this.limit[this.currentSlider] : this.limit
|
478
|
+
var valueRange = this.isRange ? this.valueLimit[this.currentSlider] : this.valueLimit
|
479
|
+
if (pos >= range[0] && pos <= range[1]) {
|
480
|
+
this.setTransform(pos)
|
481
|
+
var v = (Math.round(pos / this.gap) * (this.spacing * this.multiple) + (this.minimum * this.multiple)) / this.multiple
|
482
|
+
this.setCurrentValue(v, isDrag)
|
483
|
+
}
|
484
|
+
else if (pos < range[0]) {
|
485
|
+
this.setTransform(range[0])
|
486
|
+
this.setCurrentValue(valueRange[0])
|
487
|
+
if (this.currentSlider === 1) this.currentSlider = 0
|
488
|
+
}
|
489
|
+
else {
|
490
|
+
this.setTransform(range[1])
|
491
|
+
this.setCurrentValue(valueRange[1])
|
492
|
+
if (this.currentSlider === 0) this.currentSlider = 1
|
493
|
+
}
|
494
|
+
},
|
495
|
+
isDiff: function(a, b) {
|
496
|
+
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
|
497
|
+
return true
|
498
|
+
}
|
499
|
+
else if (Array.isArray(a) && a.length === b.length) {
|
500
|
+
return a.some(function(v, i) {return v !== b[i]})
|
501
|
+
}
|
502
|
+
return a !== b
|
503
|
+
},
|
504
|
+
setCurrentValue: function(val, bool) {
|
505
|
+
if (val < this.minimum || val > this.maximum) return false
|
506
|
+
if (this.isRange) {
|
507
|
+
if (this.isDiff(this.currentValue[this.currentSlider], val)) {
|
508
|
+
this.currentValue.splice(this.currentSlider, 1, val)
|
509
|
+
if (!this.lazy || !this.flag) {
|
510
|
+
this.syncValue()
|
511
|
+
}
|
512
|
+
}
|
513
|
+
}
|
514
|
+
else if (this.isDiff(this.currentValue, val)) {
|
515
|
+
this.currentValue = val
|
516
|
+
if (!this.lazy || !this.flag) {
|
517
|
+
this.syncValue()
|
518
|
+
}
|
519
|
+
}
|
520
|
+
bool || this.setPosition()
|
521
|
+
},
|
522
|
+
setIndex: function(val) {
|
523
|
+
if (Array.isArray(val) && this.isRange) {
|
524
|
+
var value
|
525
|
+
if (this.data) {
|
526
|
+
value = [this.data[val[0]], this.data[val[1]]]
|
527
|
+
}
|
528
|
+
else {
|
529
|
+
value = [this.spacing * val[0] + this.minimum, this.spacing * val[1] + this.minimum]
|
530
|
+
}
|
531
|
+
this.setValue(value)
|
532
|
+
}
|
533
|
+
else {
|
534
|
+
val = this.spacing * val + this.minimum
|
535
|
+
if (this.isRange) {
|
536
|
+
this.currentSlider = val > ((this.currentValue[1] - this.currentValue[0]) / 2 + this.currentValue[0]) ? 1 : 0
|
537
|
+
}
|
538
|
+
this.setCurrentValue(val)
|
539
|
+
}
|
540
|
+
},
|
541
|
+
setValue: function(val, speed, isInit) {
|
542
|
+
if (this.isDiff(this.val, val)) {
|
543
|
+
this.val = val
|
544
|
+
!isInit && this.syncValue()
|
545
|
+
}
|
548
546
|
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
});
|
547
|
+
this.$nextTick(function() {
|
548
|
+
this.setPosition(speed)
|
549
|
+
})
|
550
|
+
},
|
551
|
+
setPosition: function(speed) {
|
552
|
+
this.flag || this.setTransitionTime(speed === undefined ? this.speed : speed)
|
553
|
+
if (this.isRange) {
|
554
|
+
this.currentSlider = 0
|
555
|
+
this.setTransform(this.position[this.currentSlider])
|
556
|
+
this.currentSlider = 1
|
557
|
+
this.setTransform(this.position[this.currentSlider])
|
558
|
+
}
|
559
|
+
else {
|
560
|
+
this.setTransform(this.position)
|
561
|
+
}
|
562
|
+
this.flag || this.setTransitionTime(0)
|
563
|
+
},
|
564
|
+
setTransform: function(val) {
|
565
|
+
var value = (this.direction === 'vertical' ? ((this.dotSize / 2) - val) : (val - (this.dotSize / 2))) * (this.reverse ? -1 : 1)
|
566
|
+
var translateValue = this.direction === 'vertical' ? 'translateY(' + value + 'px)' : 'translateX(' + value + 'px)'
|
567
|
+
var processSize = (this.currentSlider === 0 ? this.position[1] - val : val - this.position[0]) + 'px'
|
568
|
+
var processPos = (this.currentSlider === 0 ? val : this.position[0]) + 'px'
|
569
|
+
if (this.isRange) {
|
570
|
+
this.slider[this.currentSlider].style.transform = translateValue
|
571
|
+
this.slider[this.currentSlider].style.WebkitTransform = translateValue
|
572
|
+
this.slider[this.currentSlider].style.msTransform = translateValue
|
573
|
+
if (this.direction === 'vertical') {
|
574
|
+
this.$els.process.style.height = processSize
|
575
|
+
this.$els.process.style[this.reverse ? 'top' : 'bottom'] = processPos
|
576
|
+
}
|
577
|
+
else {
|
578
|
+
this.$els.process.style.width = processSize
|
579
|
+
this.$els.process.style[this.reverse ? 'right' : 'left'] = processPos
|
580
|
+
}
|
581
|
+
}
|
582
|
+
else {
|
583
|
+
this.slider.style.transform = translateValue
|
584
|
+
this.slider.style.WebkitTransform = translateValue
|
585
|
+
this.slider.style.msTransform = translateValue
|
586
|
+
if (this.direction === 'vertical') {
|
587
|
+
this.$els.process.style.height = val + 'px'
|
588
|
+
this.$els.process.style[this.reverse ? 'top' : 'bottom'] = 0
|
589
|
+
}
|
590
|
+
else {
|
591
|
+
this.$els.process.style.width = val + 'px'
|
592
|
+
this.$els.process.style[this.reverse ? 'right' : 'left'] = 0
|
593
|
+
}
|
594
|
+
}
|
595
|
+
},
|
596
|
+
setTransitionTime: function(time) {
|
597
|
+
time || this.$els.process.offsetWidth
|
598
|
+
if (this.isRange) {
|
599
|
+
for (var i = 0; i < this.slider.length; i++) {
|
600
|
+
this.slider[i].style.transitionDuration = time + 's'
|
601
|
+
this.slider[i].style.WebkitTransitionDuration = time + 's'
|
602
|
+
}
|
603
|
+
this.$els.process.style.transitionDuration = time + 's'
|
604
|
+
this.$els.process.style.WebkitTransitionDuration = time + 's'
|
605
|
+
}
|
606
|
+
else {
|
607
|
+
this.slider.style.transitionDuration = time + 's'
|
608
|
+
this.slider.style.WebkitTransitionDuration = time + 's'
|
609
|
+
this.$els.process.style.transitionDuration = time + 's'
|
610
|
+
this.$els.process.style.WebkitTransitionDuration = time + 's'
|
611
|
+
}
|
612
|
+
},
|
613
|
+
syncValue: function() {
|
614
|
+
this.$emit('callback', this.val)
|
615
|
+
this.$emit('input', this.isRange ? this.val.slice() : this.val)
|
616
|
+
},
|
617
|
+
getValue: function() {
|
618
|
+
return this.val
|
619
|
+
},
|
620
|
+
getIndex: function() {
|
621
|
+
return this.currentIndex
|
622
|
+
},
|
623
|
+
getStaticData: function() {
|
624
|
+
if (this.$els.elem) {
|
625
|
+
this.size = this.direction === 'vertical' ? this.$els.elem.offsetHeight : this.$els.elem.offsetWidth
|
626
|
+
this.offset = this.direction === 'vertical' ? (this.$els.elem.getBoundingClientRect().top + window.pageYOffset || document.documentElement.scrollTop) : this.$els.elem.getBoundingClientRect().left
|
627
|
+
}
|
628
|
+
},
|
629
|
+
refresh: function() {
|
630
|
+
if (this.$els.elem) {
|
631
|
+
this.getStaticData()
|
632
|
+
this.setPosition()
|
633
|
+
}
|
634
|
+
}
|
635
|
+
},
|
636
|
+
created: function() {
|
637
|
+
window.addEventListener('resize', this.refresh)
|
638
|
+
},
|
639
|
+
ready: function() {
|
640
|
+
var self = this;
|
641
|
+
this.$nextTick(function(){
|
642
|
+
self.getStaticData()
|
643
|
+
self.setValue(self.value, 0, true)
|
644
|
+
self.bindEvents()
|
645
|
+
})
|
646
|
+
},
|
647
|
+
destroyed: function() {
|
648
|
+
this.unbindEvents()
|
649
|
+
}
|
653
650
|
});
|
654
651
|
})();
|