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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/codelation_ui/_base_resources/app.js +54 -5
  3. data/app/assets/javascripts/codelation_ui/base.js +1 -0
  4. data/app/assets/javascripts/codelation_ui/extended/checkmark.js +31 -0
  5. data/app/assets/javascripts/codelation_ui/extended/code.js +64 -0
  6. data/app/assets/javascripts/codelation_ui/extended/fail.js +31 -0
  7. data/app/assets/javascripts/codelation_ui/extended/radial_progress_bar.js +267 -0
  8. data/app/assets/javascripts/codelation_ui/extended/slider.js +636 -639
  9. data/app/assets/javascripts/codelation_ui/extended/spinner.js +103 -0
  10. data/app/assets/javascripts/codelation_ui/forms/components/input.js +417 -388
  11. data/app/assets/javascripts/codelation_ui/forms/interfaces/form.js +35 -30
  12. data/app/assets/javascripts/codelation_ui/std.js +3 -1
  13. data/app/assets/javascripts/codelation_ui/std/components/info.js +22 -0
  14. data/app/assets/javascripts/codelation_ui/std/components/transition.js +26 -0
  15. data/app/assets/javascripts/codelation_ui/std/computed_interfaces/mockAPI.js +17 -0
  16. data/app/assets/javascripts/codelation_ui/std/interfaces/array.js +28 -0
  17. data/app/assets/javascripts/codelation_ui/std/interfaces/content_formatters.js +37 -10
  18. data/app/assets/javascripts/codelation_ui/std/interfaces/date.js +8 -0
  19. data/app/assets/javascripts/codelation_ui/std/interfaces/number.js +20 -0
  20. data/app/assets/javascripts/codelation_ui/std/interfaces/rest_api.js +104 -0
  21. data/app/assets/javascripts/codelation_ui/std/interfaces/string.js +29 -0
  22. data/app/assets/javascripts/codelation_ui/vue.js +25 -8
  23. data/app/assets/javascripts/codelation_ui/vue_pages.js +35 -10
  24. data/app/assets/stylesheets/codelation_ui.scss +1 -3
  25. data/app/assets/stylesheets/codelation_ui/_base_resources/_turbolinks.scss +11 -0
  26. data/app/assets/stylesheets/codelation_ui/_base_resources/mixins/button.scss +185 -33
  27. data/app/assets/stylesheets/codelation_ui/base.scss +3 -0
  28. data/app/assets/stylesheets/codelation_ui/colors.scss +2 -0
  29. data/app/assets/stylesheets/codelation_ui/extended/checkmark.scss +53 -0
  30. data/app/assets/stylesheets/codelation_ui/extended/code.scss +153 -0
  31. data/app/assets/stylesheets/codelation_ui/extended/fail.scss +50 -0
  32. data/app/assets/stylesheets/codelation_ui/extended/radial_progress_bar.scss +70 -0
  33. data/app/assets/stylesheets/codelation_ui/extended/slider.scss +2 -2
  34. data/app/assets/stylesheets/codelation_ui/extended/spinner.scss +100 -0
  35. data/app/assets/stylesheets/codelation_ui/std.scss +1 -1
  36. data/app/assets/stylesheets/codelation_ui/std/info.scss +51 -0
  37. data/app/assets/stylesheets/codelation_ui/vue_transitions.scss +94 -0
  38. data/app/helpers/action_view/helpers/url_helper.rb +22 -0
  39. data/lib/generators/ui/component/USAGE +22 -0
  40. data/lib/generators/ui/component/component_generator.rb +41 -0
  41. data/lib/generators/ui/component/templates/javascript.js.erb +20 -0
  42. data/lib/generators/ui/component/templates/page_javascript.js.erb +20 -0
  43. data/lib/generators/ui/component/templates/page_stylesheet.scss.erb +3 -0
  44. data/lib/generators/ui/component/templates/stylesheet.scss.erb +3 -0
  45. data/lib/generators/ui/component/templates/template.html.erb +5 -0
  46. data/lib/generators/ui/mixin/USAGE +8 -0
  47. data/lib/generators/ui/mixin/mixin_generator.rb +11 -0
  48. data/lib/generators/ui/mixin/templates/javascript.js.erb +8 -0
  49. data/lib/generators/ui/pages/USAGE +23 -0
  50. data/lib/generators/ui/pages/pages_generator.rb +48 -0
  51. data/lib/generators/ui/pages/templates/controller.rb +2 -0
  52. data/lib/generators/ui/pages/templates/javascript.js.erb +22 -0
  53. data/lib/generators/ui/pages/templates/stylesheet.scss.erb +3 -0
  54. data/lib/generators/ui/pages/templates/template.html.erb +3 -0
  55. data/vendor/assets/javascripts/highlight.pack.js +2 -0
  56. data/vendor/assets/javascripts/pluralize.js +1 -0
  57. data/vendor/assets/javascripts/vue.js +4 -10232
  58. metadata +107 -11
  59. 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
- App.register('component').enter(function() {
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
- var template = '<div v-el:wrap :class="[\'vue-slider-wrap\', flowDirection, disabledClass, { \'vue-slider-has-label\': piecewiseLabel }]" v-show="show" :style="wrapStyles" @click="wrapClick">\
10
- <div v-el:elem class="vue-slider" :style="styleMerge(elemStyles, bgStyle)">\
11
- <template v-if="isMoblie">\
12
- <template v-if="isRange">\
13
- <div v-el:dot0 :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles[0], dotStyles)" @touchstart="moveStart(0)">\
14
- <span :class="[\'vue-slider-tooltip-\' + tooltipDirection[0], \'vue-slider-tooltip\']" :style="tooltipStyles[0]">{{ formatter ? formatting(val[0]) : val[0] }}</span>\
15
- </div>\
16
- <div v-el:dot1 :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles[1], dotStyles)" @touchstart="moveStart(1)">\
17
- <span :class="[\'vue-slider-tooltip-\' + tooltipDirection[1], \'vue-slider-tooltip\']" :style="tooltipStyles[1]">{{ formatter ? formatting(val[1]) : val[1] }}</span>\
18
- </div>\
19
- </template>\
20
- <template v-else>\
21
- <div v-el:dot :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles, dotStyles)" @touchstart="moveStart">\
22
- <span :class="[\'vue-slider-tooltip-\' + tooltipDirection, \'vue-slider-tooltip\']" :style="tooltipStyles">{{ formatter ? formatting(val) : val}}</span>\
23
- </div>\
24
- </template>\
25
- </template>\
26
- <template v-else>\
27
- <template v-if="isRange">\
28
- <div v-el:dot0 :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles[0], dotStyles)" @mousedown="moveStart(0)">\
29
- <span :class="[\'vue-slider-tooltip-\' + tooltipDirection[0], \'vue-slider-tooltip\']" :style="tooltipStyles[0]">{{ formatter ? formatting(val[0]) : val[0] }}</span>\
30
- </div>\
31
- <div v-el:dot1 :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles[1], dotStyles)" @mousedown="moveStart(1)">\
32
- <span :class="[\'vue-slider-tooltip-\' + tooltipDirection[1], \'vue-slider-tooltip\']" :style="tooltipStyles[1]">{{ formatter ? formatting(val[1]) : val[1] }}</span>\
33
- </div>\
34
- </template>\
35
- <template v-else>\
36
- <div v-el:dot :class="[tooltipStatus, \'vue-slider-dot\']" :style="styleMerge(sliderStyles, dotStyles)" @mousedown="moveStart">\
37
- <span :class="[\'vue-slider-tooltip-\' + tooltipDirection, \'vue-slider-tooltip\']" :style="tooltipStyles">{{ formatter ? formatting(val) : val }}</span>\
38
- </div>\
39
- </template>\
40
- </template>\
41
- <template v-if="piecewise">\
42
- <ul class="vue-slider-piecewise">\
43
- <li v-for="piecewiseObj in piecewiseDotWrap" :style="styleMerge(piecewiseDotStyle, piecewiseObj.style)">\
44
- <span class="vue-slider-piecewise-dot" :style="styleMerge(piecewiseStyle, piecewiseObj.inRange ? piecewiseActiveStyle : null)"></span>\
45
- <span v-if="piecewiseLabel" class="vue-slider-piecewise-label" :style="styleMerge(labelStyle, piecewiseObj.inRange ? labelActiveStyle : null)">{{ piecewiseObj.label }}</span>\
46
- </li>\
47
- </ul>\
48
- </template>\
49
- <div v-el:process class="vue-slider-process" :style="processStyle"></div>\
50
- </div>\
51
- </div>';
52
-
53
- Vue.component('vue-slider', {
54
- template: template,
55
- data: function() {
56
- return {
57
- flag: false,
58
- size: 0,
59
- currentValue: 0,
60
- currentSlider: 0
61
- }
62
- },
63
- props: {
64
- width: {
65
- type: [Number, String],
66
- default: 'auto'
67
- },
68
- height: {
69
- type: [Number, String],
70
- default: 6
71
- },
72
- data: {
73
- type: Array,
74
- default: null
75
- },
76
- dotSize: {
77
- type: Number,
78
- default: 16
79
- },
80
- min: {
81
- type: Number,
82
- default: 0
83
- },
84
- max: {
85
- type: Number,
86
- default: 100
87
- },
88
- interval: {
89
- type: Number,
90
- default: 1
91
- },
92
- show: {
93
- type: Boolean,
94
- default: true
95
- },
96
- disabled: {
97
- type: Boolean,
98
- default: false
99
- },
100
- piecewise: {
101
- type: Boolean,
102
- default: false
103
- },
104
- tooltip: {
105
- type: [String, Boolean],
106
- default: 'always'
107
- },
108
- eventType: {
109
- type: String,
110
- default: 'auto'
111
- },
112
- direction: {
113
- type: String,
114
- default: 'horizontal'
115
- },
116
- reverse: {
117
- type: Boolean,
118
- default: false
119
- },
120
- lazy: {
121
- type: Boolean,
122
- default: false
123
- },
124
- clickable: {
125
- type: Boolean,
126
- default: true
127
- },
128
- speed: {
129
- type: Number,
130
- default: 0.5
131
- },
132
- realTime: {
133
- type: Boolean,
134
- default: false
135
- },
136
- value: {
137
- type: [String, Number, Array],
138
- default: 0
139
- },
140
- piecewiseLabel: {
141
- type: Boolean,
142
- default: false
143
- },
144
- sliderStyle: [Array, Object],
145
- tooltipDir: [Array, String],
146
- formatter: [String, Function],
147
- piecewiseStyle: Object,
148
- piecewiseActiveStyle: Object,
149
- processStyle: Object,
150
- bgStyle: Object,
151
- tooltipStyle: [Array, Object],
152
- labelStyle: Object,
153
- labelActiveStyle: Object
154
- },
155
- computed: {
156
- flowDirection() {
157
- return `vue-slider-${this.direction + (this.reverse ? '-reverse' : '')}`
158
- },
159
- tooltipDirection() {
160
- let dir = this.tooltipDir || (this.direction === 'vertical' ? 'left' : 'top')
161
- if (Array.isArray(dir)) {
162
- return this.isRange ? dir : dir[1]
163
- }
164
- else {
165
- return this.isRange ? [dir, dir] : dir
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
- if (two === undefined) {
406
- return one;
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
- for (var attrname in two) { one[attrname] = two[attrname]; }
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
- bindEvents() {
412
- if (this.isMoblie) {
413
- this.$els.wrap.addEventListener('touchmove', this.moving)
414
- this.$els.wrap.addEventListener('touchend', this.moveEnd)
415
- }
416
- else {
417
- document.addEventListener('mousemove', this.moving)
418
- document.addEventListener('mouseup', this.moveEnd)
419
- document.addEventListener('mouseleave', this.moveEnd)
420
- }
421
- },
422
- unbindEvents() {
423
- window.removeEventListener('resize', this.refresh)
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
- if (this.isMoblie) {
426
- this.$els.wrap.removeEventListener('touchmove', this.moving)
427
- this.$els.wrap.removeEventListener('touchend', this.moveEnd)
428
- }
429
- else {
430
- document.removeEventListener('mousemove', this.moving)
431
- document.removeEventListener('mouseup', this.moveEnd)
432
- document.removeEventListener('mouseleave', this.moveEnd)
433
- }
434
- },
435
- formatting(value) {
436
- return typeof this.formatter === 'string' ? this.formatter.replace(/\{value\}/, value) : this.formatter(value)
437
- },
438
- getPos(e) {
439
- this.realTime && this.getStaticData()
440
- 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))
441
- },
442
- wrapClick(e) {
443
- if (this.isDisabled || !this.clickable) return false
444
- let pos = this.getPos(e)
445
- if (this.isRange) {
446
- this.currentSlider = pos > ((this.position[1] - this.position[0]) / 2 + this.position[0]) ? 1 : 0
447
- }
448
- this.setValueOnPos(pos)
449
- },
450
- moveStart(index) {
451
- if (this.isDisabled) return false
452
- else if (this.isRange) {
453
- this.currentSlider = index
454
- }
455
- this.flag = true
456
- this.$emit('drag-start', this)
457
- },
458
- moving(e) {
459
- if (!this.flag) return false
460
- e.preventDefault()
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
- if (this.isMoblie) e = e.targetTouches[0]
463
- this.setValueOnPos(this.getPos(e), true)
464
- },
465
- moveEnd(e) {
466
- if (this.flag) {
467
- this.$emit('drag-end', this)
468
- if (this.lazy && this.isDiff(this.val, this.value)) {
469
- this.syncValue()
470
- }
471
- }
472
- else {
473
- return false
474
- }
475
- this.flag = false
476
- this.setPosition()
477
- },
478
- setValueOnPos(pos, isDrag) {
479
- let range = this.isRange ? this.limit[this.currentSlider] : this.limit
480
- let valueRange = this.isRange ? this.valueLimit[this.currentSlider] : this.valueLimit
481
- if (pos >= range[0] && pos <= range[1]) {
482
- this.setTransform(pos)
483
- let v = (Math.round(pos / this.gap) * (this.spacing * this.multiple) + (this.minimum * this.multiple)) / this.multiple
484
- this.setCurrentValue(v, isDrag)
485
- }
486
- else if (pos < range[0]) {
487
- this.setTransform(range[0])
488
- this.setCurrentValue(valueRange[0])
489
- if (this.currentSlider === 1) this.currentSlider = 0
490
- }
491
- else {
492
- this.setTransform(range[1])
493
- this.setCurrentValue(valueRange[1])
494
- if (this.currentSlider === 0) this.currentSlider = 1
495
- }
496
- },
497
- isDiff(a, b) {
498
- if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
499
- return true
500
- }
501
- else if (Array.isArray(a) && a.length === b.length) {
502
- return a.some((v, i) => v !== b[i])
503
- }
504
- return a !== b
505
- },
506
- setCurrentValue(val, bool) {
507
- if (val < this.minimum || val > this.maximum) return false
508
- if (this.isRange) {
509
- if (this.isDiff(this.currentValue[this.currentSlider], val)) {
510
- this.currentValue.splice(this.currentSlider, 1, val)
511
- if (!this.lazy || !this.flag) {
512
- this.syncValue()
513
- }
514
- }
515
- }
516
- else if (this.isDiff(this.currentValue, val)) {
517
- this.currentValue = val
518
- if (!this.lazy || !this.flag) {
519
- this.syncValue()
520
- }
521
- }
522
- bool || this.setPosition()
523
- },
524
- setIndex(val) {
525
- if (Array.isArray(val) && this.isRange) {
526
- let value
527
- if (this.data) {
528
- value = [this.data[val[0]], this.data[val[1]]]
529
- }
530
- else {
531
- value = [this.spacing * val[0] + this.minimum, this.spacing * val[1] + this.minimum]
532
- }
533
- this.setValue(value)
534
- }
535
- else {
536
- val = this.spacing * val + this.minimum
537
- if (this.isRange) {
538
- this.currentSlider = val > ((this.currentValue[1] - this.currentValue[0]) / 2 + this.currentValue[0]) ? 1 : 0
539
- }
540
- this.setCurrentValue(val)
541
- }
542
- },
543
- setValue(val, speed, isInit) {
544
- if (this.isDiff(this.val, val)) {
545
- this.val = val
546
- !isInit && this.syncValue()
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
- this.$nextTick(() => {
550
- this.setPosition(speed)
551
- })
552
- },
553
- setPosition(speed) {
554
- this.flag || this.setTransitionTime(speed === undefined ? this.speed : speed)
555
- if (this.isRange) {
556
- this.currentSlider = 0
557
- this.setTransform(this.position[this.currentSlider])
558
- this.currentSlider = 1
559
- this.setTransform(this.position[this.currentSlider])
560
- }
561
- else {
562
- this.setTransform(this.position)
563
- }
564
- this.flag || this.setTransitionTime(0)
565
- },
566
- setTransform(val) {
567
- let value = (this.direction === 'vertical' ? ((this.dotSize / 2) - val) : (val - (this.dotSize / 2))) * (this.reverse ? -1 : 1)
568
- let translateValue = this.direction === 'vertical' ? `translateY(${value}px)` : `translateX(${value}px)`
569
- let processSize = `${this.currentSlider === 0 ? this.position[1] - val : val - this.position[0]}px`
570
- let processPos = `${this.currentSlider === 0 ? val : this.position[0]}px`
571
- if (this.isRange) {
572
- this.slider[this.currentSlider].style.transform = translateValue
573
- this.slider[this.currentSlider].style.WebkitTransform = translateValue
574
- this.slider[this.currentSlider].style.msTransform = translateValue
575
- if (this.direction === 'vertical') {
576
- this.$els.process.style.height = processSize
577
- this.$els.process.style[this.reverse ? 'top' : 'bottom'] = processPos
578
- }
579
- else {
580
- this.$els.process.style.width = processSize
581
- this.$els.process.style[this.reverse ? 'right' : 'left'] = processPos
582
- }
583
- }
584
- else {
585
- this.slider.style.transform = translateValue
586
- this.slider.style.WebkitTransform = translateValue
587
- this.slider.style.msTransform = translateValue
588
- if (this.direction === 'vertical') {
589
- this.$els.process.style.height = `${val}px`
590
- this.$els.process.style[this.reverse ? 'top' : 'bottom'] = 0
591
- }
592
- else {
593
- this.$els.process.style.width = `${val}px`
594
- this.$els.process.style[this.reverse ? 'right' : 'left'] = 0
595
- }
596
- }
597
- },
598
- setTransitionTime(time) {
599
- time || this.$els.process.offsetWidth
600
- if (this.isRange) {
601
- for (let i = 0; i < this.slider.length; i++) {
602
- this.slider[i].style.transitionDuration = `${time}s`
603
- this.slider[i].style.WebkitTransitionDuration = `${time}s`
604
- }
605
- this.$els.process.style.transitionDuration = `${time}s`
606
- this.$els.process.style.WebkitTransitionDuration = `${time}s`
607
- }
608
- else {
609
- this.slider.style.transitionDuration = `${time}s`
610
- this.slider.style.WebkitTransitionDuration = `${time}s`
611
- this.$els.process.style.transitionDuration = `${time}s`
612
- this.$els.process.style.WebkitTransitionDuration = `${time}s`
613
- }
614
- },
615
- syncValue() {
616
- this.$emit('callback', this.val)
617
- this.$emit('input', this.isRange ? this.val.slice() : this.val)
618
- },
619
- getValue() {
620
- return this.val
621
- },
622
- getIndex() {
623
- return this.currentIndex
624
- },
625
- getStaticData() {
626
- if (this.$els.elem) {
627
- this.size = this.direction === 'vertical' ? this.$els.elem.offsetHeight : this.$els.elem.offsetWidth
628
- this.offset = this.direction === 'vertical' ? (this.$els.elem.getBoundingClientRect().top + window.pageYOffset || document.documentElement.scrollTop) : this.$els.elem.getBoundingClientRect().left
629
- }
630
- },
631
- refresh() {
632
- if (this.$els.elem) {
633
- this.getStaticData()
634
- this.setPosition()
635
- }
636
- }
637
- },
638
- created() {
639
- window.addEventListener('resize', this.refresh)
640
- },
641
- ready() {
642
- var self = this;
643
- this.$nextTick(function(){
644
- self.getStaticData()
645
- self.setValue(self.value, 0, true)
646
- self.bindEvents()
647
- })
648
- },
649
- destroyed() {
650
- this.unbindEvents()
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
  })();