-
Notifications
You must be signed in to change notification settings - Fork 19
/
vue-datepicker.js
75 lines (69 loc) · 3 KB
/
vue-datepicker.js
1
2
3
4
5
6
7
8
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
import './dist/duDatepicker.css'
import duDatepicker from './dist/duDatepicker.js'
export default {
install(Vue, options) {
if (! options) options = {}
else duDatepicker.defaults(options)
// <du-datepicker /> component
Vue.component('duDatepicker', {
render(createElement) {
return createElement('input', {
domProps: {
type: 'text'
},
on: {
datechanged: e => {
this.$emit('datechanged', e)
}
}
})
},
props: {
options: { type: Object },
ready: { type: Function },
dateChanged: { type: Function },
onRangeFormat: { type: Function },
shown: { type: Function },
hidden: { type: Function }
},
methods: {
show() { duDatepicker(this.$el, 'show') },
hide() { duDatepicker(this.$el, 'hide') },
destroy() { duDatepicker(this.$el, 'destroy') },
setValue(value) { duDatepicker(this.$el, 'setValue', value) },
setTheme(theme) { duDatepicker(this.$el, 'setTheme', theme) },
setMinDate(date) { duDatepicker(this.$el, 'setMinDate', date) },
setMaxDate(date) { duDatepicker(this.$el, 'setMaxDate', date) },
setMinYear(year) { duDatepicker(this.$el, 'setMinYear', year) },
setMaxYear(year) { duDatepicker(this.$el, 'setMaxYear', year) },
setPriorYears(years) { duDatepicker(this.$el, 'setPriorYears', years) },
setLaterYears(years) { duDatepicker(this.$el, 'setLaterYears', years) },
setDisabled(dates) { duDatepicker(this.$el, 'setDisabled', dates) },
setDisabledDays(days) { duDatepicker(this.$el, 'setDisabledDays', days) },
setI18n(i18n) { duDatepicker(this.$el, 'setI18n', i18n) },
set(setters) { duDatepicker(this.$el, 'set', setters) }
},
mounted() {
let evtProps = {
events: { ready: this.ready, dateChanged: this.dateChanged, onRangeFormat: this.onRangeFormat, shown: this.shown, hidden: this.hidden }
}
// remove undefined callbacks
Object.keys(evtProps.events).forEach(key => evtProps.events[key] === undefined && delete evtProps.events[key])
// initialize
duDatepicker(this.$el, { ...this.options, ...evtProps })
},
destroyed() {
this.destroy()
}
})
// v-du-datepicker directive
Vue.directive('du-datepicker', {
bind(el, binding) {
duDatepicker(el, binding.value)
},
unbind(el) {
duDatepicker(el, 'destroy')
}
})
}
}