forked from Dan503/time-input-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (40 loc) · 1.3 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
var apply_default = require('./core/setters/apply_default');
var update_time = require('./core/setters/update_time');
var set_data_attribute = require('./core/setters/set_data_attribute');
var bind_events = require('./core/events/bind_events');
var switch_times = require('./core/setters/switch_times');
var get_label = require('./core/getters/get_label');
var create_a11y_block = require('./core/accessibility/create_a11y_block');
var accessibility_block_created = false;
var $a11y;
function TimePolyfill($input) {
$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;
}
var label = 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;
if (module) module.exports = TimePolyfill;