@ohos-ports/flowbite-datepicker 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -0
- package/.eslintrc.js +73 -0
- package/.stylelintrc +12 -0
- package/CHANGELOG.md +72 -0
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/demo/index.html +582 -0
- package/demo/live-demo.js +471 -0
- package/dist/DateRangePicker.cjs.js +2996 -0
- package/dist/DateRangePicker.esm.js +2994 -0
- package/dist/DateRangePicker.umd.js +3002 -0
- package/dist/Datepicker.cjs.js +2778 -0
- package/dist/Datepicker.esm.js +2776 -0
- package/dist/Datepicker.umd.js +2784 -0
- package/dist/css/datepicker-bs4.css +276 -0
- package/dist/css/datepicker-bs4.min.css +1 -0
- package/dist/css/datepicker-bs5.css +276 -0
- package/dist/css/datepicker-bs5.min.css +1 -0
- package/dist/css/datepicker-bulma.css +258 -0
- package/dist/css/datepicker-bulma.min.css +1 -0
- package/dist/css/datepicker-foundation.css +262 -0
- package/dist/css/datepicker-foundation.min.css +1 -0
- package/dist/css/datepicker.css +306 -0
- package/dist/css/datepicker.min.css +1403 -0
- package/dist/js/datepicker-full.js +2777 -0
- package/dist/js/datepicker-full.min.js +1 -0
- package/dist/js/datepicker.js +2569 -0
- package/dist/js/datepicker.min.js +1 -0
- package/dist/js/locales/ar-tn.js +15 -0
- package/dist/js/locales/ar.js +15 -0
- package/dist/js/locales/az.js +14 -0
- package/dist/js/locales/bg.js +14 -0
- package/dist/js/locales/bm.js +18 -0
- package/dist/js/locales/bn.js +19 -0
- package/dist/js/locales/br.js +18 -0
- package/dist/js/locales/bs.js +15 -0
- package/dist/js/locales/ca.js +18 -0
- package/dist/js/locales/cs.js +19 -0
- package/dist/js/locales/cy.js +14 -0
- package/dist/js/locales/da.js +19 -0
- package/dist/js/locales/de.js +18 -0
- package/dist/js/locales/el.js +16 -0
- package/dist/js/locales/en-AU.js +18 -0
- package/dist/js/locales/en-CA.js +18 -0
- package/dist/js/locales/en-GB.js +18 -0
- package/dist/js/locales/en-IE.js +17 -0
- package/dist/js/locales/en-NZ.js +17 -0
- package/dist/js/locales/en-ZA.js +17 -0
- package/dist/js/locales/eo.js +17 -0
- package/dist/js/locales/es.js +18 -0
- package/dist/js/locales/et.js +18 -0
- package/dist/js/locales/eu.js +18 -0
- package/dist/js/locales/fa.js +17 -0
- package/dist/js/locales/fi.js +17 -0
- package/dist/js/locales/fo.js +15 -0
- package/dist/js/locales/fr-CH.js +21 -0
- package/dist/js/locales/fr.js +18 -0
- package/dist/js/locales/gl.js +16 -0
- package/dist/js/locales/he.js +15 -0
- package/dist/js/locales/hi.js +18 -0
- package/dist/js/locales/hr.js +13 -0
- package/dist/js/locales/hu.js +18 -0
- package/dist/js/locales/hy.js +18 -0
- package/dist/js/locales/id.js +15 -0
- package/dist/js/locales/is.js +14 -0
- package/dist/js/locales/it-CH.js +20 -0
- package/dist/js/locales/it.js +18 -0
- package/dist/js/locales/ja.js +17 -0
- package/dist/js/locales/ka.js +17 -0
- package/dist/js/locales/kk.js +15 -0
- package/dist/js/locales/km.js +15 -0
- package/dist/js/locales/ko.js +18 -0
- package/dist/js/locales/lt.js +19 -0
- package/dist/js/locales/lv.js +18 -0
- package/dist/js/locales/me.js +17 -0
- package/dist/js/locales/mk.js +15 -0
- package/dist/js/locales/mn.js +17 -0
- package/dist/js/locales/mr.js +18 -0
- package/dist/js/locales/ms.js +15 -0
- package/dist/js/locales/nl-BE.js +18 -0
- package/dist/js/locales/nl.js +18 -0
- package/dist/js/locales/no.js +18 -0
- package/dist/js/locales/oc.js +17 -0
- package/dist/js/locales/pl.js +17 -0
- package/dist/js/locales/pt-BR.js +17 -0
- package/dist/js/locales/pt.js +18 -0
- package/dist/js/locales/ro.js +17 -0
- package/dist/js/locales/ru.js +18 -0
- package/dist/js/locales/si.js +18 -0
- package/dist/js/locales/sk.js +18 -0
- package/dist/js/locales/sl.js +15 -0
- package/dist/js/locales/sq.js +18 -0
- package/dist/js/locales/sr-latn.js +16 -0
- package/dist/js/locales/sr.js +16 -0
- package/dist/js/locales/sv.js +17 -0
- package/dist/js/locales/sw.js +15 -0
- package/dist/js/locales/ta.js +18 -0
- package/dist/js/locales/tg.js +19 -0
- package/dist/js/locales/th.js +14 -0
- package/dist/js/locales/tk.js +18 -0
- package/dist/js/locales/tr.js +17 -0
- package/dist/js/locales/uk.js +17 -0
- package/dist/js/locales/uz-cyrl.js +18 -0
- package/dist/js/locales/uz-latn.js +18 -0
- package/dist/js/locales/vi.js +16 -0
- package/dist/js/locales/zh-CN.js +19 -0
- package/dist/js/locales/zh-TW.js +18 -0
- package/dist/locales/index.cjs.js +1028 -0
- package/dist/locales/index.esm.js +1028 -0
- package/dist/main.cjs.js +2999 -0
- package/dist/main.esm.js +2994 -0
- package/dist/main.umd.js +3005 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +266 -0
- package/docs/_sidebar.md +6 -0
- package/docs/api.md +284 -0
- package/docs/date-string+format.md +90 -0
- package/docs/i18n.md +99 -0
- package/docs/images/datepicker-inline.jpg +0 -0
- package/docs/images/datepicker.jpg +0 -0
- package/docs/images/multidate.jpg +0 -0
- package/docs/images/picker-structure.jpg +0 -0
- package/docs/images/rangepicker.jpg +0 -0
- package/docs/images/view-days.jpg +0 -0
- package/docs/images/view-decades.jpg +0 -0
- package/docs/images/view-months.jpg +0 -0
- package/docs/images/view-years.jpg +0 -0
- package/docs/index.html +26 -0
- package/docs/options.md +354 -0
- package/docs/overview.md +174 -0
- package/extras/twoDigitToFullYear/test/twoDigitToFullYear.js +58 -0
- package/extras/twoDigitToFullYear/twoDigitToFullYear.js +26 -0
- package/js/DateRangePicker.js +210 -0
- package/js/Datepicker.js +487 -0
- package/js/datepicker-full.js +5 -0
- package/js/events/functions.js +48 -0
- package/js/events/inputFieldListeners.js +206 -0
- package/js/events/otherListeners.js +15 -0
- package/js/events/pickerListeners.js +70 -0
- package/js/i18n/base-locales.js +13 -0
- package/js/i18n/locales/ar-tn.js +15 -0
- package/js/i18n/locales/ar.js +15 -0
- package/js/i18n/locales/az.js +14 -0
- package/js/i18n/locales/bg.js +14 -0
- package/js/i18n/locales/bm.js +18 -0
- package/js/i18n/locales/bn.js +19 -0
- package/js/i18n/locales/br.js +18 -0
- package/js/i18n/locales/bs.js +15 -0
- package/js/i18n/locales/ca.js +18 -0
- package/js/i18n/locales/cs.js +19 -0
- package/js/i18n/locales/cy.js +14 -0
- package/js/i18n/locales/da.js +19 -0
- package/js/i18n/locales/de.js +18 -0
- package/js/i18n/locales/el.js +16 -0
- package/js/i18n/locales/en-AU.js +18 -0
- package/js/i18n/locales/en-CA.js +18 -0
- package/js/i18n/locales/en-GB.js +18 -0
- package/js/i18n/locales/en-IE.js +17 -0
- package/js/i18n/locales/en-NZ.js +17 -0
- package/js/i18n/locales/en-ZA.js +17 -0
- package/js/i18n/locales/eo.js +17 -0
- package/js/i18n/locales/es.js +18 -0
- package/js/i18n/locales/et.js +18 -0
- package/js/i18n/locales/eu.js +18 -0
- package/js/i18n/locales/fa.js +17 -0
- package/js/i18n/locales/fi.js +17 -0
- package/js/i18n/locales/fo.js +15 -0
- package/js/i18n/locales/fr-CH.js +21 -0
- package/js/i18n/locales/fr.js +18 -0
- package/js/i18n/locales/gl.js +16 -0
- package/js/i18n/locales/he.js +15 -0
- package/js/i18n/locales/hi.js +18 -0
- package/js/i18n/locales/hr.js +13 -0
- package/js/i18n/locales/hu.js +18 -0
- package/js/i18n/locales/hy.js +18 -0
- package/js/i18n/locales/id.js +15 -0
- package/js/i18n/locales/is.js +14 -0
- package/js/i18n/locales/it-CH.js +20 -0
- package/js/i18n/locales/it.js +18 -0
- package/js/i18n/locales/ja.js +17 -0
- package/js/i18n/locales/ka.js +17 -0
- package/js/i18n/locales/kk.js +15 -0
- package/js/i18n/locales/km.js +15 -0
- package/js/i18n/locales/ko.js +18 -0
- package/js/i18n/locales/lt.js +19 -0
- package/js/i18n/locales/lv.js +18 -0
- package/js/i18n/locales/me.js +17 -0
- package/js/i18n/locales/mk.js +15 -0
- package/js/i18n/locales/mn.js +17 -0
- package/js/i18n/locales/mr.js +18 -0
- package/js/i18n/locales/ms.js +15 -0
- package/js/i18n/locales/nl-BE.js +18 -0
- package/js/i18n/locales/nl.js +18 -0
- package/js/i18n/locales/no.js +18 -0
- package/js/i18n/locales/oc.js +17 -0
- package/js/i18n/locales/pl.js +17 -0
- package/js/i18n/locales/pt-BR.js +17 -0
- package/js/i18n/locales/pt.js +18 -0
- package/js/i18n/locales/ro.js +17 -0
- package/js/i18n/locales/ru.js +18 -0
- package/js/i18n/locales/si.js +18 -0
- package/js/i18n/locales/sk.js +18 -0
- package/js/i18n/locales/sl.js +15 -0
- package/js/i18n/locales/sq.js +18 -0
- package/js/i18n/locales/sr-latn.js +16 -0
- package/js/i18n/locales/sr.js +16 -0
- package/js/i18n/locales/sv.js +17 -0
- package/js/i18n/locales/sw.js +15 -0
- package/js/i18n/locales/ta.js +18 -0
- package/js/i18n/locales/tg.js +19 -0
- package/js/i18n/locales/th.js +14 -0
- package/js/i18n/locales/tk.js +18 -0
- package/js/i18n/locales/tr.js +17 -0
- package/js/i18n/locales/uk.js +17 -0
- package/js/i18n/locales/uz-cyrl.js +18 -0
- package/js/i18n/locales/uz-latn.js +18 -0
- package/js/i18n/locales/vi.js +16 -0
- package/js/i18n/locales/zh-CN.js +19 -0
- package/js/i18n/locales/zh-TW.js +18 -0
- package/js/lib/date-format.js +185 -0
- package/js/lib/date.js +82 -0
- package/js/lib/dom.js +55 -0
- package/js/lib/event.js +68 -0
- package/js/lib/utils.js +61 -0
- package/js/main.js +4 -0
- package/js/options/defaultOptions.js +38 -0
- package/js/options/processOptions.js +263 -0
- package/js/picker/Picker.js +334 -0
- package/js/picker/templates/calendarWeeksTemplate.js +8 -0
- package/js/picker/templates/daysTemplate.js +8 -0
- package/js/picker/templates/pickerTemplate.js +23 -0
- package/js/picker/views/DaysView.js +250 -0
- package/js/picker/views/MonthsView.js +198 -0
- package/js/picker/views/View.js +55 -0
- package/js/picker/views/YearsView.js +170 -0
- package/package.json +81 -0
- package/postcss.config.js +5 -0
- package/rollup.config.js +75 -0
- package/sass/_mixins.scss +12 -0
- package/sass/datepicker-bs4.scss +91 -0
- package/sass/datepicker-bs5.scss +91 -0
- package/sass/datepicker-bulma.scss +69 -0
- package/sass/datepicker-foundation.scss +66 -0
- package/sass/datepicker.scss +436 -0
- package/sass/index-bs4.scss +5 -0
- package/sass/index-bs5.scss +5 -0
- package/sass/index-bulma.scss +6 -0
- package/sass/index-foundation.scss +3 -0
- package/scripts/build-css.js +39 -0
- package/scripts/build-locales.js +57 -0
- package/scripts/convert-bsdp-locales.js +65 -0
- package/scripts/minify-css.js +31 -0
- package/scripts/minify-js.js +17 -0
- package/style.css +10 -0
- package/tailwind.config.js +16 -0
- package/tailwind.css +1389 -0
- package/test/DateRangePicker/DateRangePicker.js +547 -0
- package/test/DateRangePicker/api-methods.js +415 -0
- package/test/DateRangePicker/date-selection.js +472 -0
- package/test/DateRangePicker/options.js +308 -0
- package/test/Datepicker/Datepicker-object.js +236 -0
- package/test/Datepicker/api-methods.js +328 -0
- package/test/_utils/date.js +102 -0
- package/test/_utils/dom.js +70 -0
- package/test/events.js +785 -0
- package/test/inline-mode.js +45 -0
- package/test/keyboard-operation/arrow-down.js +293 -0
- package/test/keyboard-operation/arrow-left.js +255 -0
- package/test/keyboard-operation/arrow-right.js +215 -0
- package/test/keyboard-operation/arrow-up.js +461 -0
- package/test/keyboard-operation/edit-mode.js +458 -0
- package/test/keyboard-operation/keyboard-operation.js +146 -0
- package/test/mouse-operation.js +580 -0
- package/test/options/before-show.js +635 -0
- package/test/options/bulma-datepicker.sublime-workspace +1280 -0
- package/test/options/buttons.js +383 -0
- package/test/options/date-restrictions.js +802 -0
- package/test/options/format.js +281 -0
- package/test/options/multidate.js +380 -0
- package/test/options/options.js +727 -0
- package/test/options/orientation.js +410 -0
- package/test/options/pick-levle+view.js +357 -0
- package/test/test.html +94 -0
- package/test/unit/DateRangePicker.js +192 -0
- package/test/unit/Datepicker.js +307 -0
- package/test/unit/_setup.js +28 -0
- package/test/unit/lib/date-format.js +310 -0
- package/test/unit/lib/date.js +211 -0
- package/test/unit/lib/dom.js +142 -0
- package/test/unit/lib/event.js +207 -0
- package/test/unit/lib/utils.js +135 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "initialize|on[A-Z]*" }]*/
|
|
2
|
+
const {Datepicker, DateRangePicker} = FlowbiteDatepicker;
|
|
3
|
+
|
|
4
|
+
var templates = {
|
|
5
|
+
input: `<div class="field">
|
|
6
|
+
<div class="control">
|
|
7
|
+
<input type="text" class="input date">
|
|
8
|
+
</div>
|
|
9
|
+
</div>`,
|
|
10
|
+
inline: `<div class="date"></div>`,
|
|
11
|
+
range: `<div class="field has-addons date">
|
|
12
|
+
<div class="control">
|
|
13
|
+
<input type="text" name="range-start" class="input">
|
|
14
|
+
</div>
|
|
15
|
+
<div class="control">
|
|
16
|
+
<a class="button is-static">to</a>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="control">
|
|
19
|
+
<input type="text" name="range-end" class="input">
|
|
20
|
+
</div>
|
|
21
|
+
</div>`,
|
|
22
|
+
};
|
|
23
|
+
var beforeShowFns = {
|
|
24
|
+
beforeShowDay(date) {
|
|
25
|
+
if (date.getMonth() == new Date().getMonth()) {
|
|
26
|
+
switch (date.getDate()) {
|
|
27
|
+
case 4:
|
|
28
|
+
return {
|
|
29
|
+
content: '<span class="tooltip" data-tooltip="Example tooltip">4</span>',
|
|
30
|
+
classes: 'has-background-info'
|
|
31
|
+
};
|
|
32
|
+
case 8:
|
|
33
|
+
return false;
|
|
34
|
+
case 12:
|
|
35
|
+
return "has-text-success";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
beforeShowMonth(date) {
|
|
40
|
+
switch (date.getMonth()) {
|
|
41
|
+
case 6:
|
|
42
|
+
if (date.getFullYear() === new Date().getFullYear()) {
|
|
43
|
+
return {content: '🎉'};
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case 8:
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
beforeShowYear(date) {
|
|
51
|
+
switch (date.getFullYear()) {
|
|
52
|
+
case 2017:
|
|
53
|
+
return false;
|
|
54
|
+
case 2020:
|
|
55
|
+
return {content: '<span class="tooltip is-tooltip-bottom" data-tooltip="Tooltip text">2020</span>'};
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
beforeShowDecade(date) {
|
|
59
|
+
switch (date.getFullYear()) {
|
|
60
|
+
case 2000:
|
|
61
|
+
return false;
|
|
62
|
+
case 2100:
|
|
63
|
+
return {
|
|
64
|
+
content: '💯',
|
|
65
|
+
classes: 'is-background-success',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
var buttonClass;
|
|
71
|
+
|
|
72
|
+
const today = new Date().setHours(0, 0, 0, 0);
|
|
73
|
+
const defaultOptions = {
|
|
74
|
+
allowOneSidedRange: false,
|
|
75
|
+
autohide: false,
|
|
76
|
+
beforeShowDay: null,
|
|
77
|
+
beforeShowDecade: null,
|
|
78
|
+
beforeShowMonth: null,
|
|
79
|
+
beforeShowYear: null,
|
|
80
|
+
calendarWeeks: false,
|
|
81
|
+
clearBtn: false,
|
|
82
|
+
dateDelimiter: ',',
|
|
83
|
+
datesDisabled: [],
|
|
84
|
+
daysOfWeekDisabled: [],
|
|
85
|
+
daysOfWeekHighlighted: [],
|
|
86
|
+
defaultViewDate: today,
|
|
87
|
+
disableTouchKeyboard: false,
|
|
88
|
+
format: 'mm/dd/yyyy',
|
|
89
|
+
language: 'en',
|
|
90
|
+
maxDate: null,
|
|
91
|
+
maxNumberOfDates: 1,
|
|
92
|
+
maxView: 3,
|
|
93
|
+
minDate: null,
|
|
94
|
+
nextArrow: '»',
|
|
95
|
+
orientation: 'auto',
|
|
96
|
+
pickLevel: 0,
|
|
97
|
+
prevArrow: '«',
|
|
98
|
+
showDaysOfWeek: true,
|
|
99
|
+
showOnClick: true,
|
|
100
|
+
showOnFocus: true,
|
|
101
|
+
startView: 0,
|
|
102
|
+
title: '',
|
|
103
|
+
todayBtn: false,
|
|
104
|
+
todayHighlight: false,
|
|
105
|
+
updateOnBlur: true,
|
|
106
|
+
weekStart: 0,
|
|
107
|
+
};
|
|
108
|
+
const languages = {
|
|
109
|
+
'ar-tn': 'Arabic-Tunisia',
|
|
110
|
+
ar: 'Arabic',
|
|
111
|
+
az: 'Azerbaijani',
|
|
112
|
+
bg: 'Bulgarian',
|
|
113
|
+
bm: 'Bamanankan',
|
|
114
|
+
bn: 'Bengali (Bangla)',
|
|
115
|
+
br: 'Breton',
|
|
116
|
+
bs: 'Bosnian',
|
|
117
|
+
ca: 'Catalan',
|
|
118
|
+
cs: 'Czech',
|
|
119
|
+
cy: 'Welsh',
|
|
120
|
+
da: 'Danish',
|
|
121
|
+
de: 'German',
|
|
122
|
+
el: 'Greek',
|
|
123
|
+
'en-AU': 'Australian English',
|
|
124
|
+
'en-CA': 'Canadian English',
|
|
125
|
+
'en-GB': 'British English',
|
|
126
|
+
'en-IE': 'Irish English',
|
|
127
|
+
'en-NZ': 'New Zealand English',
|
|
128
|
+
'en-ZA': 'South African English',
|
|
129
|
+
eo: 'Esperanto',
|
|
130
|
+
es: 'Spanish',
|
|
131
|
+
et: 'Estonian',
|
|
132
|
+
eu: 'Basque',
|
|
133
|
+
fa: 'Persian',
|
|
134
|
+
fi: 'Finnish',
|
|
135
|
+
fo: 'Faroese',
|
|
136
|
+
'fr-CH': 'French (Switzerland)',
|
|
137
|
+
fr: 'French',
|
|
138
|
+
gl: 'Galician',
|
|
139
|
+
he: 'Hebrew',
|
|
140
|
+
hi: 'Hindi',
|
|
141
|
+
hr: 'Croatian',
|
|
142
|
+
hu: 'Hungarian',
|
|
143
|
+
hy: 'Armenian',
|
|
144
|
+
id: 'Bahasa',
|
|
145
|
+
is: 'Icelandic',
|
|
146
|
+
'it-CH': 'Italian (Switzerland)',
|
|
147
|
+
it: 'Italian',
|
|
148
|
+
ja: 'Japanese',
|
|
149
|
+
ka: 'Georgian',
|
|
150
|
+
kk: 'Kazakh',
|
|
151
|
+
km: 'Khmer',
|
|
152
|
+
ko: 'Korean',
|
|
153
|
+
lt: 'Lithuanian',
|
|
154
|
+
lv: 'Latvian',
|
|
155
|
+
me: 'Montenegrin',
|
|
156
|
+
mk: 'Macedonian',
|
|
157
|
+
mn: 'Mongolian',
|
|
158
|
+
mr: 'Marathi',
|
|
159
|
+
ms: 'Malay',
|
|
160
|
+
'nl-BE': 'Belgium-Dutch',
|
|
161
|
+
nl: 'Dutch',
|
|
162
|
+
no: 'Norwegian',
|
|
163
|
+
oc: 'Occitan',
|
|
164
|
+
pl: 'Polish',
|
|
165
|
+
'pt-BR': 'Brazilian',
|
|
166
|
+
pt: 'Portuguese',
|
|
167
|
+
ro: 'Romanian',
|
|
168
|
+
ru: 'Russian',
|
|
169
|
+
si: 'Sinhala',
|
|
170
|
+
sk: 'Slovak',
|
|
171
|
+
sl: 'Slovene',
|
|
172
|
+
sq: 'Albanian',
|
|
173
|
+
'sr-latn': 'Serbian latin',
|
|
174
|
+
sr: 'Serbian cyrillic',
|
|
175
|
+
sv: 'Swedish',
|
|
176
|
+
sw: 'Swahili',
|
|
177
|
+
ta: 'Tamil',
|
|
178
|
+
tg: 'Tajik',
|
|
179
|
+
th: 'Thai',
|
|
180
|
+
tk: 'Turkmen',
|
|
181
|
+
tr: 'Turkish',
|
|
182
|
+
uk: 'Ukrainian',
|
|
183
|
+
'uz-cyrl': 'Uzbek cyrillic',
|
|
184
|
+
'uz-latn': 'Uzbek latin',
|
|
185
|
+
vi: 'Vietnamese',
|
|
186
|
+
'zh-CN': 'Simplified Chinese',
|
|
187
|
+
'zh-TW': 'Traditional Chinese',
|
|
188
|
+
};
|
|
189
|
+
const range = document.createRange();
|
|
190
|
+
const sandbox = document.getElementById('sandbox');
|
|
191
|
+
const options = document.getElementById('options');
|
|
192
|
+
const jsonFields = ['datesDisabled'];
|
|
193
|
+
|
|
194
|
+
function parseHTML(html) {
|
|
195
|
+
return range.createContextualFragment(html);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function getBeforeShowFnSrc(name) {
|
|
199
|
+
return beforeShowFns[name].toString();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function switchPicker(type) {
|
|
203
|
+
const options = buttonClass ? {buttonClass} : {};
|
|
204
|
+
if (window.demoPicker) {
|
|
205
|
+
const currentOpts = window.demoPicker instanceof DateRangePicker
|
|
206
|
+
? window.demoPicker.datepickers[0]._options
|
|
207
|
+
: window.demoPicker._options;
|
|
208
|
+
Object.keys(defaultOptions).reduce((opts, key) => {
|
|
209
|
+
if (key in currentOpts && String(currentOpts[key] !== String(defaultOptions[key]))) {
|
|
210
|
+
opts[key] = currentOpts[key];
|
|
211
|
+
}
|
|
212
|
+
return opts;
|
|
213
|
+
}, options);
|
|
214
|
+
|
|
215
|
+
window.demoPicker.destroy();
|
|
216
|
+
sandbox.removeChild(sandbox.firstChild);
|
|
217
|
+
}
|
|
218
|
+
sandbox.appendChild(parseHTML(templates[type]));
|
|
219
|
+
|
|
220
|
+
const el = sandbox.querySelector('.date');
|
|
221
|
+
window.demoPicker = type === 'range'
|
|
222
|
+
? new DateRangePicker(el, options)
|
|
223
|
+
: new Datepicker(el, options);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const setOptions = function setOptions(name, value) {
|
|
227
|
+
window.demoPicker.setOptions({[name]: value});
|
|
228
|
+
refreshOptionForm();
|
|
229
|
+
};
|
|
230
|
+
const refreshOptionForm = function refreshOptionForm() {
|
|
231
|
+
const demoPicker = window.demoPicker;
|
|
232
|
+
const rangePicker = demoPicker instanceof DateRangePicker;
|
|
233
|
+
const datepicker = rangePicker ? demoPicker.datepickers[0] : demoPicker;
|
|
234
|
+
const optsForm = document.getElementById('options');
|
|
235
|
+
const {config, _options} = datepicker;
|
|
236
|
+
const configDefaults = {
|
|
237
|
+
minDate: new Date(today).setFullYear(0, 0, 1),
|
|
238
|
+
maxDate: undefined,
|
|
239
|
+
};
|
|
240
|
+
const formElemByName = name => optsForm.querySelector(`[name="${name}"]`);
|
|
241
|
+
const formatDate = val => Datepicker.formatDate(val, config.format, config.lang);
|
|
242
|
+
|
|
243
|
+
if (!rangePicker) {
|
|
244
|
+
const allowOneSided = formElemByName('allowOneSidedRange');
|
|
245
|
+
if (allowOneSided.checked) {
|
|
246
|
+
allowOneSided.checked = false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
Object.entries(datepicker.config).forEach(entry => {
|
|
250
|
+
const [key, val] = entry;
|
|
251
|
+
let el;
|
|
252
|
+
switch (key) {
|
|
253
|
+
case 'format':
|
|
254
|
+
case 'weekStart':
|
|
255
|
+
el = formElemByName(key);
|
|
256
|
+
if (el.value || val !== defaultOptions[key]) {
|
|
257
|
+
el.value = val;
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
case 'minDate':
|
|
261
|
+
case 'maxDate':
|
|
262
|
+
el = formElemByName(key);
|
|
263
|
+
if (val === configDefaults[key]) {
|
|
264
|
+
if (!el.value || el.value === 'null') {
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
if (_options[key] === null) {
|
|
268
|
+
el.value = '';
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
el.value = formatDate(val);
|
|
273
|
+
break;
|
|
274
|
+
case 'datesDisabled':
|
|
275
|
+
el = formElemByName(key);
|
|
276
|
+
if (val.length === 0) {
|
|
277
|
+
if (!el.value || el.value === '[]') {
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
if (String(_options.datesDisabled) === '[]') {
|
|
281
|
+
el.value = '';
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
el.value = JSON.stringify(val.map(item => formatDate(item)));
|
|
286
|
+
break;
|
|
287
|
+
case 'daysOfWeekDisabled':
|
|
288
|
+
case 'daysOfWeekHighlighted':
|
|
289
|
+
optsForm.querySelectorAll(`[name=${key}`).forEach(chkbox => {
|
|
290
|
+
chkbox.checked = val.includes(Number.parseInt(chkbox.value, 10));
|
|
291
|
+
});
|
|
292
|
+
break;
|
|
293
|
+
case 'defaultViewDate':
|
|
294
|
+
el = formElemByName(key);
|
|
295
|
+
if (val === defaultOptions[key]) {
|
|
296
|
+
if (!el.value || el.value === 'today') {
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
if (_options[key] === 'today') {
|
|
300
|
+
el.value = '';
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
el.value = formatDate(val);
|
|
305
|
+
break;
|
|
306
|
+
case 'maxView':
|
|
307
|
+
case 'pickLevel':
|
|
308
|
+
case 'startView':
|
|
309
|
+
formElemByName(key).value = val;
|
|
310
|
+
break;
|
|
311
|
+
case 'maxNumberOfDates':
|
|
312
|
+
el = formElemByName(key);
|
|
313
|
+
if (rangePicker) {
|
|
314
|
+
if (el.value) {
|
|
315
|
+
el.value = '';
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
if (el.value || val !== defaultOptions[key]) {
|
|
320
|
+
el.value = val;
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
const handleArrayOption = function handleArrayOption(name) {
|
|
327
|
+
const checkedInputs = options.querySelectorAll(`input[name=${name}]:checked`);
|
|
328
|
+
setOptions(name, Array.from(checkedInputs).map(el => Number(el.value)));
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
function updateOption(name, value) {
|
|
332
|
+
switch (name) {
|
|
333
|
+
case 'beforeShowDay':
|
|
334
|
+
case 'beforeShowMonth':
|
|
335
|
+
case 'beforeShowYear':
|
|
336
|
+
case 'beforeShowDecade':
|
|
337
|
+
setOptions(name, value ? beforeShowFns[name] : null);
|
|
338
|
+
return;
|
|
339
|
+
case 'daysOfWeekDisabled':
|
|
340
|
+
case 'daysOfWeekHighlighted':
|
|
341
|
+
handleArrayOption(name, value);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
let newValue;
|
|
346
|
+
if (typeof value === 'string') {
|
|
347
|
+
switch (value) {
|
|
348
|
+
case '':
|
|
349
|
+
newValue = defaultOptions[name];
|
|
350
|
+
break;
|
|
351
|
+
case 'null':
|
|
352
|
+
newValue = null;
|
|
353
|
+
break;
|
|
354
|
+
case 'false':
|
|
355
|
+
newValue = false;
|
|
356
|
+
break;
|
|
357
|
+
case 'true':
|
|
358
|
+
newValue = true;
|
|
359
|
+
break;
|
|
360
|
+
default:
|
|
361
|
+
newValue = Number(value);
|
|
362
|
+
if (isNaN(newValue)) {
|
|
363
|
+
newValue = value;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
newValue = value;
|
|
368
|
+
}
|
|
369
|
+
setOptions(name, newValue);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function addError(el, message) {
|
|
373
|
+
const field = el.parentElement.parentElement;
|
|
374
|
+
field.appendChild(parseHTML(`<p class="help is-danger">${message}</p>`));
|
|
375
|
+
el.classList.add('is-danger');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function removeErrors(el) {
|
|
379
|
+
const field = el.parentElement.parentElement;
|
|
380
|
+
field.querySelectorAll('.help.is-danger').forEach((errMsg) => {
|
|
381
|
+
field.removeChild(errMsg);
|
|
382
|
+
});
|
|
383
|
+
el.classList.remove('is-danger');
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function onChangeType(ev) {
|
|
387
|
+
switchPicker(ev.target.value);
|
|
388
|
+
refreshOptionForm();
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function onChnageDirection(ev) {
|
|
392
|
+
const defaultDir = window.getComputedStyle(document.body).direction;
|
|
393
|
+
const dir = ev.target.value;
|
|
394
|
+
const mainElem = document.querySelector('main');
|
|
395
|
+
|
|
396
|
+
if (dir !== defaultDir) {
|
|
397
|
+
mainElem.dir = dir;
|
|
398
|
+
} else {
|
|
399
|
+
mainElem.removeAttribute('dir');
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function onChangeInputOption(ev) {
|
|
404
|
+
updateOption(ev.target.name, ev.target.value);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function onChangeTextareaOption(ev) {
|
|
408
|
+
let {value, name} = ev.target;
|
|
409
|
+
if (jsonFields.includes(name)) {
|
|
410
|
+
removeErrors(ev.target);
|
|
411
|
+
if (value.length > 0) {
|
|
412
|
+
try {
|
|
413
|
+
value = JSON.parse(value);
|
|
414
|
+
} catch (err) {
|
|
415
|
+
addError(ev.target, 'Invalid JSON string');
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (name === 'datesDisabled') {
|
|
421
|
+
if (value && !Array.isArray(value)) {
|
|
422
|
+
addError(ev.target, 'This option must be an array');
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
updateOption(name, value);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function onClickCheckboxOptions(ev) {
|
|
430
|
+
ev.stopPropagation();
|
|
431
|
+
|
|
432
|
+
let checkbox;
|
|
433
|
+
let checked;
|
|
434
|
+
if (ev.target.tagName === 'INPUT') {
|
|
435
|
+
checkbox = ev.target;
|
|
436
|
+
checked = checkbox.checked;
|
|
437
|
+
} else {
|
|
438
|
+
ev.preventDefault();
|
|
439
|
+
checkbox = ev.currentTarget.querySelector('input');
|
|
440
|
+
checked = checkbox.checked = !checkbox.checked;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const value = checkbox.value === 'true' ? checked : checkbox.value;
|
|
444
|
+
updateOption(checkbox.name, value);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function initialize() {
|
|
448
|
+
// load languages
|
|
449
|
+
const selectElem = options.querySelector('select[name=language]');
|
|
450
|
+
Object.keys(languages).forEach((lang) => {
|
|
451
|
+
document.body.appendChild(parseHTML(`<script src="../dist/js/locales/${lang}.js"></script>`));
|
|
452
|
+
selectElem.appendChild(parseHTML(`<option value="${lang}">${lang} – ${languages[lang]}</option>`));
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
document.querySelector('.toggle-btn').addEventListener('click', () => {
|
|
456
|
+
document.body.classList.toggle('open');
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
document.querySelectorAll('.code-wrap pre').forEach((el) => {
|
|
460
|
+
el.textContent = getBeforeShowFnSrc(el.id.replace('code-', ''));
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// collapsibles
|
|
464
|
+
document.querySelectorAll('.collapse-button').forEach((el) => {
|
|
465
|
+
el.addEventListener('click', () => {
|
|
466
|
+
const target = document.getElementById(el.dataset.target);
|
|
467
|
+
el.classList.toggle('is-active');
|
|
468
|
+
target.classList.toggle('is-active');
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
}
|