@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,328 @@
|
|
|
1
|
+
describe('Datepicker - API methods', function () {
|
|
2
|
+
let clock;
|
|
3
|
+
let input;
|
|
4
|
+
let dp;
|
|
5
|
+
let picker;
|
|
6
|
+
|
|
7
|
+
beforeEach(function () {
|
|
8
|
+
clock = sinon.useFakeTimers({now: new Date(2020, 2, 14)});
|
|
9
|
+
input = parseHTML('<input type="text" value="04/22/2020">').firstChild;
|
|
10
|
+
testContainer.appendChild(input);
|
|
11
|
+
dp = new Datepicker(input);
|
|
12
|
+
picker = document.querySelector('.datepicker');
|
|
13
|
+
input.focus(); // Activate for visibility checks
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(function () {
|
|
17
|
+
if (input.datepicker) {
|
|
18
|
+
dp.destroy();
|
|
19
|
+
}
|
|
20
|
+
testContainer.removeChild(input);
|
|
21
|
+
clock.restore();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('getDate()', function () {
|
|
25
|
+
it('returns a Date object of selected date', function () {
|
|
26
|
+
const date = dp.getDate();
|
|
27
|
+
expect(date, 'to be a date');
|
|
28
|
+
expect(date.getTime(), 'to be', dateValue(2020, 3, 22));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('returns a formatted date stirng of selected date if the format is specified', function () {
|
|
32
|
+
expect(dp.getDate('yyyy-mm-dd'), 'to be', '2020-04-22');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('returns undefined if no date is selected', function () {
|
|
36
|
+
dp.destroy();
|
|
37
|
+
input.value = '';
|
|
38
|
+
dp = new Datepicker(input);
|
|
39
|
+
|
|
40
|
+
expect(dp.getDate(), 'to be undefined');
|
|
41
|
+
expect(dp.getDate('yyyy-mm-dd'), 'to be undefined');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('setDate()', function () {
|
|
46
|
+
it('changes the selected date to given date', function () {
|
|
47
|
+
const spyChnageEvent = sinon.spy();
|
|
48
|
+
input.addEventListener('change', spyChnageEvent);
|
|
49
|
+
|
|
50
|
+
const viewSwitdh = getViewSwitch(picker);
|
|
51
|
+
const date = new Date(2019, 11, 23);
|
|
52
|
+
dp.setDate(date);
|
|
53
|
+
|
|
54
|
+
expect(dp.dates, 'to equal', [date.getTime()]);
|
|
55
|
+
expect(input.value, 'to be', '12/23/2019');
|
|
56
|
+
expect(viewSwitdh.textContent, 'to be', 'December 2019');
|
|
57
|
+
|
|
58
|
+
let cells = getCells(picker);
|
|
59
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[22]]);
|
|
60
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[22]]);
|
|
61
|
+
expect(cells[22].textContent, 'to be', '23');
|
|
62
|
+
|
|
63
|
+
dp.setDate('04/22/2020');
|
|
64
|
+
|
|
65
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 3, 22)]);
|
|
66
|
+
expect(input.value, 'to be', '04/22/2020');
|
|
67
|
+
expect(viewSwitdh.textContent, 'to be', 'April 2020');
|
|
68
|
+
|
|
69
|
+
cells = getCells(picker);
|
|
70
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[24]]);
|
|
71
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[24]]);
|
|
72
|
+
expect(cells[24].textContent, 'to be', '22');
|
|
73
|
+
|
|
74
|
+
// change by api call should not be a trigger of change event
|
|
75
|
+
// (issue #24)
|
|
76
|
+
expect(spyChnageEvent.called, 'to be false');
|
|
77
|
+
input.removeEventListener('change', spyChnageEvent);
|
|
78
|
+
|
|
79
|
+
// change the view to the selected daye's days view
|
|
80
|
+
// (issue #33)
|
|
81
|
+
dp.picker.changeFocus(dateValue(2021, 3, 20)).changeView(2).render();
|
|
82
|
+
dp.setDate('02/14/2020');
|
|
83
|
+
|
|
84
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
85
|
+
expect(input.value, 'to be', '02/14/2020');
|
|
86
|
+
expect(viewSwitdh.textContent, 'to be', 'February 2020');
|
|
87
|
+
|
|
88
|
+
cells = getCells(picker);
|
|
89
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
|
|
90
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
|
|
91
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('does nothing if no date or invalid date is given', function () {
|
|
95
|
+
const viewSwitdh = getViewSwitch(picker);
|
|
96
|
+
const origDates = [dateValue(2020, 3, 22)];
|
|
97
|
+
|
|
98
|
+
dp.setDate();
|
|
99
|
+
expect(dp.dates, 'to equal', origDates);
|
|
100
|
+
expect(input.value, 'to be', '04/22/2020');
|
|
101
|
+
expect(viewSwitdh.textContent, 'to be', 'April 2020');
|
|
102
|
+
|
|
103
|
+
const cells = getCells(picker);
|
|
104
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[24]]);
|
|
105
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[24]]);
|
|
106
|
+
expect(cells[24].textContent, 'to be', '22');
|
|
107
|
+
|
|
108
|
+
dp.setDate('');
|
|
109
|
+
expect(dp.dates, 'to equal', origDates);
|
|
110
|
+
expect(input.value, 'to be', '04/22/2020');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('clears the selection if no dates + clear: true option are given', function () {
|
|
114
|
+
const spyChnageEvent = sinon.spy();
|
|
115
|
+
input.addEventListener('change', spyChnageEvent);
|
|
116
|
+
|
|
117
|
+
const viewSwitdh = getViewSwitch(picker);
|
|
118
|
+
const today = dateUtils.today();
|
|
119
|
+
|
|
120
|
+
dp.setDate({clear: true});
|
|
121
|
+
expect(dp.dates, 'to equal', []);
|
|
122
|
+
expect(input.value, 'to be', '');
|
|
123
|
+
expect(viewSwitdh.textContent, 'to be', Datepicker.formatDate(today, 'MM yyyy'));
|
|
124
|
+
|
|
125
|
+
// view date is changed to the default view date (current date)
|
|
126
|
+
const cells = getCells(picker);
|
|
127
|
+
const todayCell = filterCells(cells, el => el.dataset.date == today)[0];
|
|
128
|
+
expect(todayCell.textContent, 'to be', Datepicker.formatDate(today, 'd'));
|
|
129
|
+
expect(filterCells(cells, '.selected'), 'to equal', []);
|
|
130
|
+
expect(filterCells(cells, '.focused'), 'to equal', [todayCell]);
|
|
131
|
+
|
|
132
|
+
// change by api call should not be a trigger of change event
|
|
133
|
+
// (issue #24)
|
|
134
|
+
expect(spyChnageEvent.called, 'to be false');
|
|
135
|
+
input.removeEventListener('change', spyChnageEvent);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('omits updating the picker UI if render option = false', function () {
|
|
139
|
+
const date = new Date(2019, 11, 23);
|
|
140
|
+
dp.setDate(date, {render: false});
|
|
141
|
+
|
|
142
|
+
expect(dp.dates, 'to equal', [date.getTime()]);
|
|
143
|
+
expect(input.value, 'to be', '12/23/2019');
|
|
144
|
+
|
|
145
|
+
const cells = getCells(picker);
|
|
146
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[24]]);
|
|
147
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[24]]);
|
|
148
|
+
expect(cells[24].textContent, 'to be', '22');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('hides the picker if both render and autohide options are true', function () {
|
|
152
|
+
let date = new Date(2019, 11, 23);
|
|
153
|
+
dp.setDate(date, {render: false, autohide: true});
|
|
154
|
+
|
|
155
|
+
expect(dp.dates, 'to equal', [date.getTime()]);
|
|
156
|
+
expect(input.value, 'to be', '12/23/2019');
|
|
157
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'April 2020');
|
|
158
|
+
expect(filterCells(getCells(picker), '.selected')[0].textContent, 'to be', '22');
|
|
159
|
+
expect(isVisible(picker), 'to be true');
|
|
160
|
+
|
|
161
|
+
date = new Date(2018, 6, 14);
|
|
162
|
+
dp.setDate(date, {autohide: true});
|
|
163
|
+
|
|
164
|
+
expect(dp.dates, 'to equal', [date.getTime()]);
|
|
165
|
+
expect(input.value, 'to be', '07/14/2018');
|
|
166
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'July 2018');
|
|
167
|
+
expect(filterCells(getCells(picker), '.selected')[0].textContent, 'to be', '14');
|
|
168
|
+
expect(isVisible(picker), 'to be false');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('update()', function () {
|
|
173
|
+
it('updates the selected date with the input element\'s value', function () {
|
|
174
|
+
const viewSwitdh = getViewSwitch(picker);
|
|
175
|
+
const date = new Date(2019, 11, 23);
|
|
176
|
+
input.value = '12/23/2019';
|
|
177
|
+
dp.update();
|
|
178
|
+
|
|
179
|
+
expect(dp.dates, 'to equal', [date.getTime()]);
|
|
180
|
+
expect(input.value, 'to be', '12/23/2019');
|
|
181
|
+
expect(viewSwitdh.textContent, 'to be', 'December 2019');
|
|
182
|
+
|
|
183
|
+
let cells = getCells(picker);
|
|
184
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[22]]);
|
|
185
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[22]]);
|
|
186
|
+
expect(cells[22].textContent, 'to be', '23');
|
|
187
|
+
|
|
188
|
+
// change the view to the selected daye's days view
|
|
189
|
+
// (issue #33)
|
|
190
|
+
dp.picker.changeFocus(dateValue(2021, 3, 20)).changeView(2).render();
|
|
191
|
+
input.value = '02/14/2020';
|
|
192
|
+
dp.update();
|
|
193
|
+
|
|
194
|
+
expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
|
|
195
|
+
expect(input.value, 'to be', '02/14/2020');
|
|
196
|
+
expect(viewSwitdh.textContent, 'to be', 'February 2020');
|
|
197
|
+
|
|
198
|
+
cells = getCells(picker);
|
|
199
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
|
|
200
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
|
|
201
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('notmalizes iput text\'s format', function () {
|
|
205
|
+
const date = new Date(2020, 6, 4);
|
|
206
|
+
input.value = '7 4 2020';
|
|
207
|
+
|
|
208
|
+
dp.update();
|
|
209
|
+
expect(dp.dates, 'to equal', [date.getTime()]);
|
|
210
|
+
expect(input.value, 'to be', '07/04/2020');
|
|
211
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'July 2020');
|
|
212
|
+
expect(filterCells(getCells(picker), '.selected')[0].textContent, 'to be', '4');
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('refresh()', function () {
|
|
217
|
+
it('refreshes the input element and picker UI to refrect the internal data', function () {
|
|
218
|
+
const spyChnageEvent = sinon.spy();
|
|
219
|
+
input.addEventListener('change', spyChnageEvent);
|
|
220
|
+
|
|
221
|
+
dp.dates = [dateValue(2020, 1, 14)];
|
|
222
|
+
dp.refresh();
|
|
223
|
+
|
|
224
|
+
expect(input.value, 'to be', '02/14/2020');
|
|
225
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'February 2020');
|
|
226
|
+
|
|
227
|
+
const cells = getCells(picker);
|
|
228
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
|
|
229
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
|
|
230
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
231
|
+
|
|
232
|
+
// change by api call should not be a trigger of change event
|
|
233
|
+
// (issue #24)
|
|
234
|
+
expect(spyChnageEvent.called, 'to be false');
|
|
235
|
+
input.removeEventListener('change', spyChnageEvent);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('also changes the view back to the selected date\'s days view', function () {
|
|
239
|
+
dp.dates = [dateValue(2020, 1, 14)];
|
|
240
|
+
dp.picker.changeFocus(dateValue(2021, 3, 20)).changeView(2).render();
|
|
241
|
+
dp.refresh();
|
|
242
|
+
|
|
243
|
+
expect(input.value, 'to be', '02/14/2020');
|
|
244
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'February 2020');
|
|
245
|
+
|
|
246
|
+
let cells = getCells(picker);
|
|
247
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
|
|
248
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
|
|
249
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
250
|
+
|
|
251
|
+
// go back to the current date's days view if no date is selected
|
|
252
|
+
dp.dates = [];
|
|
253
|
+
dp.picker.changeFocus(dateValue(2019, 10, 22)).update().changeView(1).render();
|
|
254
|
+
dp.refresh();
|
|
255
|
+
|
|
256
|
+
expect(input.value, 'to be', '');
|
|
257
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'March 2020');
|
|
258
|
+
|
|
259
|
+
cells = getCells(picker);
|
|
260
|
+
expect(filterCells(cells, '.selected'), 'to equal', []);
|
|
261
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[13]]);
|
|
262
|
+
expect(cells[13].textContent, 'to be', '14');
|
|
263
|
+
|
|
264
|
+
clock.restore();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('refresh only picker UI if target: "picker" is passed', function () {
|
|
268
|
+
dp.dates = [dateValue(2020, 1, 14)];
|
|
269
|
+
dp.refresh('picker');
|
|
270
|
+
|
|
271
|
+
expect(input.value, 'to be', '04/22/2020');
|
|
272
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'February 2020');
|
|
273
|
+
|
|
274
|
+
const cells = getCells(picker);
|
|
275
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
|
|
276
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
|
|
277
|
+
expect(cells[19].textContent, 'to be', '14');
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('refresh only input element if target: "input" is passed', function () {
|
|
281
|
+
dp.dates = [dateValue(2020, 1, 14)];
|
|
282
|
+
dp.refresh('input');
|
|
283
|
+
|
|
284
|
+
expect(input.value, 'to be', '02/14/2020');
|
|
285
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'April 2020');
|
|
286
|
+
|
|
287
|
+
const cells = getCells(picker);
|
|
288
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[24]]);
|
|
289
|
+
expect(filterCells(cells, '.focused'), 'to equal', [cells[24]]);
|
|
290
|
+
expect(cells[24].textContent, 'to be', '22');
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('re-renders the picker regardless of its state if forceRender true is passed', function () {
|
|
294
|
+
let cells = getCells(picker);
|
|
295
|
+
cells[16].classList.add('foo');
|
|
296
|
+
cells[12].textContent = '♥︎';
|
|
297
|
+
dp.dates = [dateValue(2020, 3, 10)];
|
|
298
|
+
dp.refresh('picker');
|
|
299
|
+
|
|
300
|
+
cells = getCells(picker);
|
|
301
|
+
expect(input.value, 'to be', '04/22/2020');
|
|
302
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'April 2020');
|
|
303
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[12]]);
|
|
304
|
+
expect(filterCells(cells, '.foo'), 'to equal', [cells[16]]);
|
|
305
|
+
expect(cells[12].textContent, 'to be', '♥︎');
|
|
306
|
+
|
|
307
|
+
dp.refresh('picker', true);
|
|
308
|
+
|
|
309
|
+
cells = getCells(picker);
|
|
310
|
+
expect(input.value, 'to be', '04/22/2020');
|
|
311
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'April 2020');
|
|
312
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[12]]);
|
|
313
|
+
expect(filterCells(cells, '.foo'), 'to equal', []);
|
|
314
|
+
expect(cells[12].textContent, 'to be', '10');
|
|
315
|
+
|
|
316
|
+
cells[16].classList.add('foo');
|
|
317
|
+
cells[12].textContent = '♥︎';
|
|
318
|
+
dp.refresh(true);
|
|
319
|
+
|
|
320
|
+
cells = getCells(picker);
|
|
321
|
+
expect(input.value, 'to be', '04/10/2020');
|
|
322
|
+
expect(getViewSwitch(picker).textContent, 'to be', 'April 2020');
|
|
323
|
+
expect(filterCells(cells, '.selected'), 'to equal', [cells[12]]);
|
|
324
|
+
expect(filterCells(cells, '.foo'), 'to equal', []);
|
|
325
|
+
expect(cells[12].textContent, 'to be', '10');
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
var dateUtils = (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function stripTime(timeValue) {
|
|
5
|
+
return new Date(timeValue).setHours(0, 0, 0, 0);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function today() {
|
|
9
|
+
return new Date().setHours(0, 0, 0, 0);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Get the time value of the start of given date or year, month and day
|
|
13
|
+
function dateValue(...args) {
|
|
14
|
+
switch (args.length) {
|
|
15
|
+
case 0:
|
|
16
|
+
return today();
|
|
17
|
+
case 1:
|
|
18
|
+
return stripTime(args[0]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// use setFullYear() to keep 2-digit year from being mapped to 1900-1999
|
|
22
|
+
const newDate = new Date(0);
|
|
23
|
+
newDate.setFullYear(...args);
|
|
24
|
+
return newDate.setHours(0, 0, 0, 0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function addDays(date, amount) {
|
|
28
|
+
const newDate = new Date(date);
|
|
29
|
+
return newDate.setDate(newDate.getDate() + amount);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function addWeeks(date, amount) {
|
|
33
|
+
return addDays(date, amount * 7);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function addMonths(date, amount) {
|
|
37
|
+
// If the day of the date is not in the new month, the last day of the new
|
|
38
|
+
// month will be returned. e.g. Jan 31 + 1 month → Feb 28 (not Mar 03)
|
|
39
|
+
const newDate = new Date(date);
|
|
40
|
+
const monthsToSet = newDate.getMonth() + amount;
|
|
41
|
+
let expectedMonth = monthsToSet % 12;
|
|
42
|
+
if (expectedMonth < 0) {
|
|
43
|
+
expectedMonth += 12;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const time = newDate.setMonth(monthsToSet);
|
|
47
|
+
return newDate.getMonth() !== expectedMonth ? newDate.setDate(0) : time;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function addYears(date, amount) {
|
|
51
|
+
// If the date is Feb 29 and the new year is not a leap year, Feb 28 of the
|
|
52
|
+
// new year will be returned.
|
|
53
|
+
const newDate = new Date(date);
|
|
54
|
+
const expectedMonth = newDate.getMonth();
|
|
55
|
+
const time = newDate.setFullYear(newDate.getFullYear() + amount);
|
|
56
|
+
return expectedMonth === 1 && newDate.getMonth() === 2 ? newDate.setDate(0) : time;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Calculate the distance bettwen 2 days of the week
|
|
60
|
+
function dayDiff(day, from) {
|
|
61
|
+
return (day - from + 7) % 7;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Get the date of the specified day of the week of given base date
|
|
65
|
+
function dayOfTheWeekOf(baseDate, dayOfWeek, weekStart = 0) {
|
|
66
|
+
const baseDay = new Date(baseDate).getDay();
|
|
67
|
+
return addDays(baseDate, dayDiff(dayOfWeek, weekStart) - dayDiff(baseDay, weekStart));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Get the ISO week of a date
|
|
71
|
+
function getWeek(date) {
|
|
72
|
+
// start of ISO week is Monday
|
|
73
|
+
const thuOfTheWeek = dayOfTheWeekOf(date, 4, 1);
|
|
74
|
+
// 1st week == the week where the 4th of January is in
|
|
75
|
+
const firstThu = dayOfTheWeekOf(new Date(thuOfTheWeek).setMonth(0, 4), 4, 1);
|
|
76
|
+
return Math.round((thuOfTheWeek - firstThu) / 604800000) + 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Get the start year of the period of years that includes given date
|
|
80
|
+
// years: length of the year period
|
|
81
|
+
function startOfYearPeriod(date, years) {
|
|
82
|
+
/* @see https://en.wikipedia.org/wiki/Year_zero#ISO_8601 */
|
|
83
|
+
const year = new Date(date).getFullYear();
|
|
84
|
+
return Math.floor(year / years) * years;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.addDays = addDays;
|
|
88
|
+
exports.addMonths = addMonths;
|
|
89
|
+
exports.addWeeks = addWeeks;
|
|
90
|
+
exports.addYears = addYears;
|
|
91
|
+
exports.dateValue = dateValue;
|
|
92
|
+
exports.dayOfTheWeekOf = dayOfTheWeekOf;
|
|
93
|
+
exports.getWeek = getWeek;
|
|
94
|
+
exports.startOfYearPeriod = startOfYearPeriod;
|
|
95
|
+
exports.stripTime = stripTime;
|
|
96
|
+
exports.today = today;
|
|
97
|
+
|
|
98
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
99
|
+
|
|
100
|
+
return exports;
|
|
101
|
+
|
|
102
|
+
})({});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var domUtils = (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const range = document.createRange();
|
|
5
|
+
|
|
6
|
+
function parseHTML(html) {
|
|
7
|
+
return range.createContextualFragment(html);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// equivalent to jQuery's :visble
|
|
11
|
+
function isVisible(el) {
|
|
12
|
+
return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function hideElement(el) {
|
|
16
|
+
if (el.style.display === 'none') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// back up the existing display setting in data-style-display
|
|
20
|
+
if (el.style.display) {
|
|
21
|
+
el.dataset.styleDisplay = el.style.display;
|
|
22
|
+
}
|
|
23
|
+
el.style.display = 'none';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function showElement(el) {
|
|
27
|
+
if (el.style.display !== 'none') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (el.dataset.styleDisplay) {
|
|
31
|
+
// restore backed-up dispay property
|
|
32
|
+
el.style.display = el.dataset.styleDisplay;
|
|
33
|
+
delete el.dataset.styleDisplay;
|
|
34
|
+
} else {
|
|
35
|
+
el.style.display = '';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function emptyChildNodes(el) {
|
|
40
|
+
if (el.firstChild) {
|
|
41
|
+
el.removeChild(el.firstChild);
|
|
42
|
+
emptyChildNodes(el);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function replaceChildNodes(el, newChildNodes) {
|
|
47
|
+
emptyChildNodes(el);
|
|
48
|
+
if (newChildNodes instanceof DocumentFragment) {
|
|
49
|
+
el.appendChild(newChildNodes);
|
|
50
|
+
} else if (typeof newChildNodes === 'string') {
|
|
51
|
+
el.appendChild(parseHTML(newChildNodes));
|
|
52
|
+
} else if (typeof newChildNodes.forEach === 'function') {
|
|
53
|
+
newChildNodes.forEach((node) => {
|
|
54
|
+
el.appendChild(node);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exports.emptyChildNodes = emptyChildNodes;
|
|
60
|
+
exports.hideElement = hideElement;
|
|
61
|
+
exports.isVisible = isVisible;
|
|
62
|
+
exports.parseHTML = parseHTML;
|
|
63
|
+
exports.replaceChildNodes = replaceChildNodes;
|
|
64
|
+
exports.showElement = showElement;
|
|
65
|
+
|
|
66
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
67
|
+
|
|
68
|
+
return exports;
|
|
69
|
+
|
|
70
|
+
})({});
|