Skip to content

Commit

Permalink
Merge pull request #36 from Dan503/FIX/#35-webpack-5-compatibility
Browse files Browse the repository at this point in the history
FIX for #35: Webpack 5 compatibility
  • Loading branch information
Dan503 authored Jan 15, 2022
2 parents e9a88c5 + d96f495 commit 98e519b
Show file tree
Hide file tree
Showing 54 changed files with 3,558 additions and 3,010 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ An accessible polyfill for `<input type='time'/>` elements.
Demo available here: https://dan503.github.io/time-input-polyfill/

<details>
<summary>The recommended version is <code>1.0.10</code> or higher.</summary>
<summary>The recommended version is <code>1.0.11</code> or higher.</summary>

<p>If the recommended version in this documentation is out of sync with the npm version, this is because npm only allows readme edits to be committed through full releases. To prevent needless cache invalidation, I'll only update the recommended version number when there are actual changes to the polyfill code. The current recommended version is <code>1.0.10</code>. As long as you are using a version that is equal to or higher than that, you are using the latest version of the polyfill.</p>
<p>If the recommended version in this documentation is out of sync with the npm version, this is because npm only allows readme edits to be committed through full releases. To prevent needless cache invalidation, I'll only update the recommended version number when there are actual changes to the polyfill code. The current recommended version is <code>1.0.11</code>. As long as you are using a version that is equal to or higher than that, you are using the latest version of the polyfill.</p>

</details>

Expand Down Expand Up @@ -59,7 +59,7 @@ You didn't load the actual polyfill onto the page, you loaded a much smaller aut
1. The initialiser checks if the browser supports `input[type="time"]` elements.
2. If it **does**, it skips the rest of the functionality.
3. If it does **not**, it will:
1. load `https://cdn.jsdelivr.net/npm/[email protected].10/dist/time-input-polyfill.min.js` (the actual polyfill).
1. load `https://cdn.jsdelivr.net/npm/[email protected].11/dist/time-input-polyfill.min.js` (the actual polyfill).
2. Collect all existing `input[type="time"]` elements on the page.
3. Loop through each `input[type="time"]` element and apply the polyfill to it.

Expand Down Expand Up @@ -103,7 +103,7 @@ if (!supportsTime) {
First check for `input[type="time"]` support.

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].10/core/helpers/supportsTime.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].11/core/helpers/supportsTime.js"></script>
```

```js
Expand All @@ -115,8 +115,8 @@ if (!supportsTime) {
Then gather a list of all `input[type="time"]` elements on the page, and loop through them to apply the polyfill.

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].10/core/helpers/supportsTime.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].10/dist/time-input-polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].11/core/helpers/supportsTime.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].11/dist/time-input-polyfill.min.js"></script>
```

```js
Expand Down
6 changes: 3 additions & 3 deletions auto.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import supports_time from './core/helpers/supportsTime'
import loadJS from './core/helpers/loadJS'
import supports_time from './core/helpers/supportsTime.js'
import loadJS from './core/helpers/loadJS.js'

document.addEventListener('DOMContentLoaded', () => {
if (!supports_time) {
loadJS(
'https://cdn.jsdelivr.net/npm/[email protected].10/dist/time-input-polyfill.min.js',
'https://cdn.jsdelivr.net/npm/[email protected].11/dist/time-input-polyfill.min.js',
() => {
var $inputs = [].slice.call(
document.querySelectorAll('input[type="time"]')
Expand Down
8 changes: 4 additions & 4 deletions core/accessibility/update_a11y.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import get_current_segment from '../getters/get_current_segment'
import get_values from '../getters/get_values'
import get_current_segment from '../getters/get_current_segment.js'
import get_values from '../getters/get_values.js'

export default function update_a11y($input, announcementArray) {
// Timeout helps ensure that the input has stabilized
setTimeout(function() {
setTimeout(function () {
var current_segment = get_current_segment($input)
var values = get_values($input)
var value = values[current_segment]
Expand All @@ -21,7 +21,7 @@ export default function update_a11y($input, announcementArray) {
update: '$segmentValue.',
}

var textArray = announcementArray.map(function(providedString) {
var textArray = announcementArray.map(function (providedString) {
if (announcements[providedString]) {
return announcements[providedString]
}
Expand Down
6 changes: 3 additions & 3 deletions core/converters/convert_to_12hr_time.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import convert_number from './convert_number'
import convert_hours_to_12hr_time from './convert_hours_to_12hr_time'
import leading_zero from './leading_zero'
import convert_number from './convert_number.js'
import convert_hours_to_12hr_time from './convert_hours_to_12hr_time.js'
import leading_zero from './leading_zero.js'

export default function convert_to_12hr_time(timeString_24hr) {
if (timeString_24hr === '') return '--:-- --'
Expand Down
2 changes: 1 addition & 1 deletion core/converters/convert_to_24hr_time.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import leading_zero from './leading_zero'
import leading_zero from './leading_zero.js'

export default function convert_to_24hr_time(timeString_12hr) {
if (/-/.test(timeString_12hr)) return ''
Expand Down
56 changes: 28 additions & 28 deletions core/events/bind_events.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
import values from '../helpers/values'
import values from '../helpers/values.js'

import select_segment from '../selectors/select_segment'
import select_segment from '../selectors/select_segment.js'

import next_segment from '../selectors/next_segment'
import prev_segment from '../selectors/prev_segment'
import select_cursor_segment from '../selectors/select_cursor_segment'
import next_segment from '../selectors/next_segment.js'
import prev_segment from '../selectors/prev_segment.js'
import select_cursor_segment from '../selectors/select_cursor_segment.js'

import get_current_segment from '../getters/get_current_segment'
import get_current_segment from '../getters/get_current_segment.js'

import reset from '../setters/reset'
import manual_number_entry from '../setters/manual_number_entry'
import clear_segment from '../setters/clear_segment'
import increment_current_segment from '../setters/increment_current_segment'
import decrement_current_segment from '../setters/decrement_current_segment'
import set_mode from '../setters/set_mode'
import switch_times from '../setters/switch_times'
import reset from '../setters/reset.js'
import manual_number_entry from '../setters/manual_number_entry.js'
import clear_segment from '../setters/clear_segment.js'
import increment_current_segment from '../setters/increment_current_segment.js'
import decrement_current_segment from '../setters/decrement_current_segment.js'
import set_mode from '../setters/set_mode.js'
import switch_times from '../setters/switch_times.js'

import handle_tab from '../events/handle_tab'
import handle_tab from '../events/handle_tab.js'

import all_number_keys from '../static-values/all_number_keys'
import named_keys from '../static-values/named_keys'
import all_number_keys from '../static-values/all_number_keys.js'
import named_keys from '../static-values/named_keys.js'

import update_a11y from '../accessibility/update_a11y'
import update_a11y from '../accessibility/update_a11y.js'

export default function bind_events($input) {
var prev_value = ''

var shiftKey = false

document.addEventListener('keydown', function(e) {
document.addEventListener('keydown', function (e) {
shiftKey = e.shiftKey
})
document.addEventListener('keyup', function(e) {
document.addEventListener('keyup', function (e) {
shiftKey = e.shiftKey
})

if ($input.form) {
$input.form.addEventListener('submit', function() {
$input.form.addEventListener('submit', function () {
auto_swap($input)
})
}

var focused_via_click = false

$input.addEventListener('mousedown', function() {
$input.addEventListener('mousedown', function () {
focused_via_click = true
})

// Turns the IE clear button into a reset button
$input.addEventListener('mouseup', function() {
setTimeout(function() {
$input.addEventListener('mouseup', function () {
setTimeout(function () {
if ($input.value === '') reset($input)
}, 1)
})

$input.addEventListener('click', function(e) {
$input.addEventListener('click', function (e) {
select_cursor_segment($input)
})

$input.addEventListener('blur', function() {
$input.addEventListener('blur', function () {
var current_value = $input.dataset.value
if (current_value !== prev_value) {
prev_value = current_value
}
focused_via_click = false
})

$input.addEventListener('focus', function(e) {
$input.addEventListener('focus', function (e) {
if (!focused_via_click) {
e.preventDefault()
var segment = shiftKey ? 'mode' : 'hrs'
Expand All @@ -75,7 +75,7 @@ export default function bind_events($input) {
update_a11y($input, ['initial', 'select'])
})

$input.addEventListener('keydown', function(e) {
$input.addEventListener('keydown', function (e) {
var is_enter_key = e.which === 13
if (is_enter_key) return true

Expand Down Expand Up @@ -143,7 +143,7 @@ export default function bind_events($input) {
function auto_swap($input) {
if ($input.polyfill.autoSwap) {
switch_times($input, 24)
setTimeout(function() {
setTimeout(function () {
switch_times($input, 12)
}, 1)
}
Expand Down
6 changes: 3 additions & 3 deletions core/events/handle_tab.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import get_current_segment from '../getters/get_current_segment'
import prev_segment from '../selectors/prev_segment'
import next_segment from '../selectors/next_segment'
import get_current_segment from '../getters/get_current_segment.js'
import prev_segment from '../selectors/prev_segment.js'
import next_segment from '../selectors/next_segment.js'

export default function handle_tab($input, e) {
var current_segment = get_current_segment($input)
Expand Down
2 changes: 1 addition & 1 deletion core/events/trigger_both_events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import trigger_event from './trigger_event'
import trigger_event from './trigger_event.js'

// It seems that oninput and onchange are treated the same way by browsers :/
export default function trigger_both_events($input) {
Expand Down
2 changes: 1 addition & 1 deletion core/events/trigger_event.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import create_event from './create_event'
import create_event from './create_event.js'

var inputEvent = create_event('input')
var changeEvent = create_event('change')
Expand Down
4 changes: 2 additions & 2 deletions core/getters/get_current_segment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ranges from '../static-values/ranges'
import get_selected_range from './get_selected_range'
import ranges from '../static-values/ranges.js'
import get_selected_range from './get_selected_range.js'

export default function get_current_segment($input) {
var selection = get_selected_range($input)
Expand Down
2 changes: 1 addition & 1 deletion core/getters/get_label.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import get_ancestors from './get_ancestors'
import get_ancestors from './get_ancestors.js'

export default function get_label($input) {
var labelText =
Expand Down
2 changes: 1 addition & 1 deletion core/getters/get_values.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import convert_number from '../converters/convert_number'
import convert_number from '../converters/convert_number.js'

export default function get_values($input, timeString) {
var value = timeString ? timeString : $input.value
Expand Down
2 changes: 1 addition & 1 deletion core/selectors/_$$.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import toArray from '../converters/toArray'
import toArray from '../converters/toArray.js'

export default function _$$(selector) {
var elements = document.querySelectorAll(selector)
Expand Down
2 changes: 1 addition & 1 deletion core/selectors/next_segment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import traverse from './traverse'
import traverse from './traverse.js'

export default function next_segment($input) {
traverse($input, 'next')
Expand Down
2 changes: 1 addition & 1 deletion core/selectors/prev_segment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import traverse from './traverse'
import traverse from './traverse.js'

export default function prev_segment($input) {
traverse($input, 'prev')
Expand Down
4 changes: 2 additions & 2 deletions core/selectors/select_cursor_segment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import get_current_segment from '../getters/get_current_segment'
import select_segment from './select_segment'
import get_current_segment from '../getters/get_current_segment.js'
import select_segment from './select_segment.js'

export default function select_cursor_segment($input) {
var current_segment = get_current_segment($input)
Expand Down
10 changes: 5 additions & 5 deletions core/selectors/traverse.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import get_current_segment from '../getters/get_current_segment'
import select_segment from '../selectors/select_segment'
import get_current_segment from '../getters/get_current_segment.js'
import select_segment from '../selectors/select_segment.js'

import manual_entry_log from '../helpers/manual_entry_log'
import segments from '../static-values/segments'
import manual_entry_log from '../helpers/manual_entry_log.js'
import segments from '../static-values/segments.js'

import update_a11y from '../accessibility/update_a11y'
import update_a11y from '../accessibility/update_a11y.js'

export default function traverse($input, direction) {
var segment = get_current_segment($input)
Expand Down
4 changes: 2 additions & 2 deletions core/setters/apply_default.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// I need to keep this separate from reset so that
// I can reset without attracting focus

import set_data_attribute from '../setters/set_data_attribute'
import trigger_both_events from '../events/trigger_both_events'
import set_data_attribute from '../setters/set_data_attribute.js'
import trigger_both_events from '../events/trigger_both_events.js'

export default function apply_default($input) {
$input.value = '--:-- --'
Expand Down
4 changes: 2 additions & 2 deletions core/setters/clear_segment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import set_segment from './set_segment'
import update_a11y from '../accessibility/update_a11y'
import set_segment from './set_segment.js'
import update_a11y from '../accessibility/update_a11y.js'

export default function clear_segment($input, segment) {
set_segment($input, segment, '--')
Expand Down
6 changes: 3 additions & 3 deletions core/setters/decrement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import switch_mode from './switch_mode'
import nudge_time_segment from './nudge_time_segment'
import update_a11y from '../accessibility/update_a11y'
import switch_mode from './switch_mode.js'
import nudge_time_segment from './nudge_time_segment.js'
import update_a11y from '../accessibility/update_a11y.js'

export default function decrement($input, segment) {
if (segment === 'mode') {
Expand Down
4 changes: 2 additions & 2 deletions core/setters/decrement_current_segment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import get_current_segment from '../getters/get_current_segment'
import decrement from '../setters/decrement'
import get_current_segment from '../getters/get_current_segment.js'
import decrement from '../setters/decrement.js'

export default function decrement_current_segment($input) {
var current_segment = get_current_segment($input)
Expand Down
6 changes: 3 additions & 3 deletions core/setters/increment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import switch_mode from './switch_mode'
import nudge_time_segment from './nudge_time_segment'
import update_a11y from '../accessibility/update_a11y'
import switch_mode from './switch_mode.js'
import nudge_time_segment from './nudge_time_segment.js'
import update_a11y from '../accessibility/update_a11y.js'

export default function increment($input, segment) {
if (segment === 'mode') {
Expand Down
4 changes: 2 additions & 2 deletions core/setters/increment_current_segment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import get_current_segment from '../getters/get_current_segment'
import increment from '../setters/increment'
import get_current_segment from '../getters/get_current_segment.js'
import increment from '../setters/increment.js'

export default function increment_current_segment($input) {
var current_segment = get_current_segment($input)
Expand Down
10 changes: 5 additions & 5 deletions core/setters/manual_number_entry.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import get_current_segment from '../getters/get_current_segment'
import set_segment from './set_segment'
import next_segment from '../selectors/next_segment'
import get_current_segment from '../getters/get_current_segment.js'
import set_segment from './set_segment.js'
import next_segment from '../selectors/next_segment.js'

import manual_entry_log from '../helpers/manual_entry_log'
import sorted_number_keys from '../static-values/sorted_number_keys'
import manual_entry_log from '../helpers/manual_entry_log.js'
import sorted_number_keys from '../static-values/sorted_number_keys.js'

export default function manual_number_entry($input, key) {
var key_value = sorted_number_keys[key]
Expand Down
8 changes: 4 additions & 4 deletions core/setters/nudge_time_segment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import get_values from '../getters/get_values'
import convert_hours_to_12hr_time from '../converters/convert_hours_to_12hr_time'
import leading_zero from '../converters/leading_zero'
import set_segment from './set_segment'
import get_values from '../getters/get_values.js'
import convert_hours_to_12hr_time from '../converters/convert_hours_to_12hr_time.js'
import leading_zero from '../converters/leading_zero.js'
import set_segment from './set_segment.js'

export default function nudge_time_segment($input, segment, direction) {
var current_values = get_values($input)
Expand Down
4 changes: 2 additions & 2 deletions core/setters/reset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import apply_default from './apply_default'
import select_segment from '../selectors/select_segment'
import apply_default from './apply_default.js'
import select_segment from '../selectors/select_segment.js'

export default function reset($input) {
apply_default($input)
Expand Down
2 changes: 1 addition & 1 deletion core/setters/set_data_attribute.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import convert_to_24hr_time from '../converters/convert_to_24hr_time'
import convert_to_24hr_time from '../converters/convert_to_24hr_time.js'

export default function set_data_attribute($input, timeString_12hr) {
var filteredString =
Expand Down
4 changes: 2 additions & 2 deletions core/setters/set_mode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import get_current_segment from '../getters/get_current_segment'
import set_segment from './set_segment'
import get_current_segment from '../getters/get_current_segment.js'
import set_segment from './set_segment.js'

export default function set_mode($input, type) {
var segment = get_current_segment($input)
Expand Down
Loading

0 comments on commit 98e519b

Please sign in to comment.