-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.mjs
53 lines (42 loc) · 1.31 KB
/
index.mjs
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
import apply_default from './core/setters/apply_default.js'
import update_time from './core/setters/update_time.js'
import set_data_attribute from './core/setters/set_data_attribute.js'
import bind_events from './core/events/bind_events.js'
import switch_times from './core/setters/switch_times.js'
import get_label from './core/getters/get_label.js'
import create_a11y_block from './core/accessibility/create_a11y_block.js'
var accessibility_block_created = false
var $a11y
function TimePolyfill($input, $label) {
$input.setAttribute('autocomplete', 'off')
// Prevent screen reader from announcing the default stuff
$input.setAttribute('aria-hidden', true)
if (!accessibility_block_created) {
$a11y = create_a11y_block()
accessibility_block_created = true
}
const label = $label ? $label.textContent : get_label($input)
$input.polyfill = {
$a11y: $a11y,
label: label,
autoSwap: true,
update: function () {
update_time($input)
},
swap: function (forcedFormat) {
switch_times($input, forcedFormat)
},
}
if ($input.value === '' || /--/.test($input.value)) {
apply_default($input)
set_data_attribute($input, '')
} else {
update_time($input)
set_data_attribute($input, $input.value)
}
bind_events($input)
}
if (window) {
window.TimePolyfill = TimePolyfill
}
export default TimePolyfill