aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/utils')
-rw-r--r--src/js/utils/animation.js16
-rw-r--r--src/js/utils/elements.js43
-rw-r--r--src/js/utils/events.js4
-rw-r--r--src/js/utils/is.js2
-rw-r--r--src/js/utils/load-image.js (renamed from src/js/utils/loadImage.js)0
-rw-r--r--src/js/utils/load-script.js (renamed from src/js/utils/loadScript.js)0
-rw-r--r--src/js/utils/load-sprite.js (renamed from src/js/utils/loadSprite.js)0
-rw-r--r--src/js/utils/promise.js14
-rw-r--r--src/js/utils/style.js16
-rw-r--r--src/js/utils/time.js2
10 files changed, 35 insertions, 62 deletions
diff --git a/src/js/utils/animation.js b/src/js/utils/animation.js
index 6b950b61..3f721b5a 100644
--- a/src/js/utils/animation.js
+++ b/src/js/utils/animation.js
@@ -2,7 +2,6 @@
// Animation utils
// ==========================================================================
-import { toggleHidden } from './elements';
import is from './is';
export const transitionEndEvent = (() => {
@@ -21,14 +20,19 @@ export const transitionEndEvent = (() => {
})();
// Force repaint of element
-export function repaint(element) {
+export function repaint(element, delay) {
setTimeout(() => {
try {
- toggleHidden(element, true);
- element.offsetHeight; // eslint-disable-line
- toggleHidden(element, false);
+ // eslint-disable-next-line no-param-reassign
+ element.hidden = true;
+
+ // eslint-disable-next-line no-unused-expressions
+ element.offsetHeight;
+
+ // eslint-disable-next-line no-param-reassign
+ element.hidden = false;
} catch (e) {
// Do nothing
}
- }, 0);
+ }, delay);
}
diff --git a/src/js/utils/elements.js b/src/js/utils/elements.js
index 98b44f13..bdf18bfd 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';
@@ -192,11 +191,8 @@ export function toggleHidden(element, hidden) {
hide = !element.hidden;
}
- if (hide) {
- element.setAttribute('hidden', '');
- } else {
- element.removeAttribute('hidden');
- }
+ // eslint-disable-next-line no-param-reassign
+ element.hidden = hide;
}
// Mirror Element.classList.toggle, with IE compatibility for "force" argument
@@ -225,7 +221,7 @@ export function hasClass(element, className) {
// Element matches selector
export function matches(element, selector) {
- const prototype = { Element };
+ const {prototype} = Element;
function match() {
return Array.from(document.querySelectorAll(selector)).includes(this);
@@ -251,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/is.js b/src/js/utils/is.js
index b005cd31..24f176cc 100644
--- a/src/js/utils/is.js
+++ b/src/js/utils/is.js
@@ -19,7 +19,7 @@ const isEvent = input => instanceOf(input, Event);
const isKeyboardEvent = input => instanceOf(input, KeyboardEvent);
const isCue = input => instanceOf(input, window.TextTrackCue) || instanceOf(input, window.VTTCue);
const isTrack = input => instanceOf(input, TextTrack) || (!isNullOrUndefined(input) && isString(input.kind));
-const isPromise = input => instanceOf(input, Promise);
+const isPromise = input => instanceOf(input, Promise) && isFunction(input.then);
const isEmpty = input =>
isNullOrUndefined(input) ||
diff --git a/src/js/utils/loadImage.js b/src/js/utils/load-image.js
index 8acd2496..8acd2496 100644
--- a/src/js/utils/loadImage.js
+++ b/src/js/utils/load-image.js
diff --git a/src/js/utils/loadScript.js b/src/js/utils/load-script.js
index 81ae36f4..81ae36f4 100644
--- a/src/js/utils/loadScript.js
+++ b/src/js/utils/load-script.js
diff --git a/src/js/utils/loadSprite.js b/src/js/utils/load-sprite.js
index fe4add00..fe4add00 100644
--- a/src/js/utils/loadSprite.js
+++ b/src/js/utils/load-sprite.js
diff --git a/src/js/utils/promise.js b/src/js/utils/promise.js
new file mode 100644
index 00000000..f45b46ab
--- /dev/null
+++ b/src/js/utils/promise.js
@@ -0,0 +1,14 @@
+import is from './is';
+/**
+ * Silence a Promise-like object.
+ * This is useful for avoiding non-harmful, but potentially confusing "uncaught
+ * play promise" rejection error messages.
+ * @param {Object} value An object that may or may not be `Promise`-like.
+ */
+export function silencePromise(value) {
+ if (is.promise(value)) {
+ value.then(null, () => {});
+ }
+}
+
+export default { silencePromise };
diff --git a/src/js/utils/style.js b/src/js/utils/style.js
index 6f3069c9..17a033fe 100644
--- a/src/js/utils/style.js
+++ b/src/js/utils/style.js
@@ -27,15 +27,8 @@ export function reduceAspectRatio(ratio) {
}
export function getAspectRatio(input) {
- const parse = ratio => {
- if (!validateRatio(ratio)) {
- return null;
- }
-
- return ratio.split(':').map(Number);
- };
-
- // Provided ratio
+ const parse = ratio => (validateRatio(ratio) ? ratio.split(':').map(Number) : null);
+ // Try provided ratio
let ratio = parse(input);
// Get from config
@@ -63,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) {
@@ -75,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