diff options
Diffstat (limited to 'src/js/utils')
-rw-r--r-- | src/js/utils/arrays.js | 8 | ||||
-rw-r--r-- | src/js/utils/elements.js | 34 | ||||
-rw-r--r-- | src/js/utils/events.js | 4 | ||||
-rw-r--r-- | src/js/utils/style.js | 5 | ||||
-rw-r--r-- | src/js/utils/time.js | 2 |
5 files changed, 13 insertions, 40 deletions
diff --git a/src/js/utils/arrays.js b/src/js/utils/arrays.js index 69ef242c..c0d69626 100644 --- a/src/js/utils/arrays.js +++ b/src/js/utils/arrays.js @@ -21,3 +21,11 @@ export function closest(array, value) { return array.reduce((prev, curr) => (Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev)); } + +export function fillRange(start, end, step = 1) { + const len = Math.floor((end - start) / step) + 1; + + return Array(len) + .fill() + .map((_, idx) => start + idx * step); +} diff --git a/src/js/utils/elements.js b/src/js/utils/elements.js index 4f10938e..b88aad0c 100644 --- a/src/js/utils/elements.js +++ b/src/js/utils/elements.js @@ -2,7 +2,6 @@ // Element utils // ========================================================================== -import { toggleListener } from './events'; import is from './is'; import { extend } from './objects'; @@ -248,39 +247,6 @@ export function getElement(selector) { return this.elements.container.querySelector(selector); } -// Trap focus inside container -export function trapFocus(element = null, toggle = false) { - if (!is.element(element)) { - return; - } - - const focusable = getElements.call(this, 'button:not(:disabled), input:not(:disabled), [tabindex]'); - const first = focusable[0]; - const last = focusable[focusable.length - 1]; - - const trap = event => { - // Bail if not tab key or not fullscreen - if (event.key !== 'Tab' || event.keyCode !== 9) { - return; - } - - // Get the current focused element - const focused = document.activeElement; - - if (focused === last && !event.shiftKey) { - // Move focus to first element that can be tabbed if Shift isn't used - first.focus(); - event.preventDefault(); - } else if (focused === first && event.shiftKey) { - // Move focus to last element that can be tabbed if Shift is used - last.focus(); - event.preventDefault(); - } - }; - - toggleListener.call(this, this.elements.container, 'keydown', trap, toggle, false); -} - // Set focus and tab focus class export function setFocus(element = null, tabFocus = false) { if (!is.element(element)) { diff --git a/src/js/utils/events.js b/src/js/utils/events.js index 87c35d26..31571b2d 100644 --- a/src/js/utils/events.js +++ b/src/js/utils/events.js @@ -90,9 +90,7 @@ export function triggerEvent(element, type = '', bubbles = false, detail = {}) { // Create and dispatch the event const event = new CustomEvent(type, { bubbles, - detail: Object.assign({}, detail, { - plyr: this, - }), + detail: { ...detail, plyr: this,}, }); // Dispatch the event diff --git a/src/js/utils/style.js b/src/js/utils/style.js index 941db8f2..17a033fe 100644 --- a/src/js/utils/style.js +++ b/src/js/utils/style.js @@ -56,11 +56,12 @@ export function setAspectRatio(input) { return {}; } + const { wrapper } = this.elements; const ratio = getAspectRatio.call(this, input); const [w, h] = is.array(ratio) ? ratio : [0, 0]; const padding = (100 / w) * h; - this.elements.wrapper.style.paddingBottom = `${padding}%`; + wrapper.style.paddingBottom = `${padding}%`; // For Vimeo we have an extra <div> to hide the standard controls and UI if (this.isVimeo && this.supported.ui) { @@ -68,7 +69,7 @@ export function setAspectRatio(input) { const offset = (height - padding) / (height / 50); this.media.style.transform = `translateY(-${offset}%)`; } else if (this.isHTML5) { - this.elements.wrapper.classList.toggle(this.config.classNames.videoFixedRatio, ratio !== null); + wrapper.classList.toggle(this.config.classNames.videoFixedRatio, ratio !== null); } return { padding, ratio }; diff --git a/src/js/utils/time.js b/src/js/utils/time.js index ffca88b2..17228de5 100644 --- a/src/js/utils/time.js +++ b/src/js/utils/time.js @@ -13,7 +13,7 @@ export const getSeconds = value => Math.trunc(value % 60, 10); export function formatTime(time = 0, displayHours = false, inverted = false) { // Bail if the value isn't a number if (!is.number(time)) { - return formatTime(null, displayHours, inverted); + return formatTime(undefined, displayHours, inverted); } // Format time component to add leading zero |