This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
/
index.js
101 lines (100 loc) · 3.79 KB
/
index.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
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
import Picker from './Picker'
import moment from 'moment'
import TimePicker from './TimePicker'
import Pikaday from 'pikaday'
const pickerModule = {
pick: function (options, confirmCallback, cancelCallback) {
options.height = weex && weex.config.env.scale && options.height ? +options.height.replace('px','') / weex.config.env.scale : options.height
options.data = options.items
options.defaultIndexs = options.index
options.confirmCallback = confirmCallback
options.cancelCallback = cancelCallback
options.sender = this.sender
new Picker(options)
},
pickDate: function (options, confirmCallback) {
const mask = document.createElement('div')
mask.className = 'weex-picker-mask'
const self = this
const i18n = {
previousMonth: 'Previous Month',
nextMonth: 'Next Month',
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
}
//options see https://github.com/dbushell/Pikaday#configuration.
const picker = new Pikaday({
field: options.field,
trigger: options.trigger,
bound: options.bound,
ariaLabel: options.ariaLabel,
position: options.position,
reposition: options.reposition,
container: options.container,
formatStrict: options.formatStrict,
toString: options.toString,
parse: options.parse,
firstDay: options.firstDay || null,
disableWeekends: options.disableWeekends || false,
disableDayFn: options.disableDayFn,
yearRange: options.yearRange || [1900, 2050],
showWeekNumber: options.showWeekNumber || false,
pickWholeWeek: options.pickWholeWeek || false,
isRTL: options.isRTL,
i18n: options.i18n || i18n,
yearSuffix: options.yearSuffix || '',
showMonthAfterYear: options.showMonthAfterYear,
showDaysInNextAndPreviousMonths: options.showDaysInNextAndPreviousMonths,
enableSelectionDaysInNextAndPreviousMonths: options.enableSelectionDaysInNextAndPreviousMonths,
numberOfMonths: options.numberOfMonths,
mainCalendar: options.mainCalendar,
events: options.events || [],
theme: options.theme || null,
blurFieldOnSelect: options.blurFieldOnSelect,
onOpen: options.onOpen,
onClose: options.onClose,
onDraw: options.onDraw,
keyboardInput: options.keyboardInput,
defaultDate: moment(options.value, 'YYYY-MM-DD').toDate(),
setDefaultDate: moment(options.value, 'YYYY-MM-DD').toDate(),
format: 'YYYY-MM-DD',
minDate: moment(options.min, 'YYYY-MM-DD').toDate(),
maxDate: moment(options.max, 'YYYY-MM-DD').toDate(),
onSelect: function (date) {
confirmCallback && self.sender.performCallback(confirmCallback, {
result: 'success',
data: moment(date).format('YYYY-MM-DD')
})
picker.destroy()
mask.parentNode.removeChild(mask)
}
})
mask.appendChild(picker.el)
document.body.appendChild(mask)
},
pickTime: function (options, confirmCallback) {
options.height = weex && weex.config.env.scale && options.height ? +options.height.replace('px','') / weex.config.env.scale : options.height
options.value = options.value;
options.confirmCallback = confirmCallback;
options.sender = this.sender;
new TimePicker(options);
}
}
const meta = {
picker: [{
name: 'pick',
args: ['object', 'function']
}, {
name: 'pickDate',
args: ['object', 'function']
}, {
name: 'pickTime',
args: ['object', 'function']
}]
}
export default {
init: function (Weex) {
Weex.registerApiModule('picker', pickerModule, meta)
}
}