aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/utils')
-rw-r--r--src/js/utils/browser.js1
-rw-r--r--src/js/utils/events.js8
-rw-r--r--src/js/utils/is.js2
-rw-r--r--src/js/utils/style.js40
-rw-r--r--src/js/utils/time.js6
-rw-r--r--src/js/utils/urls.js4
6 files changed, 52 insertions, 9 deletions
diff --git a/src/js/utils/browser.js b/src/js/utils/browser.js
index d574f683..11705074 100644
--- a/src/js/utils/browser.js
+++ b/src/js/utils/browser.js
@@ -5,6 +5,7 @@
const browser = {
isIE: /* @cc_on!@ */ false || !!document.documentMode,
+ isEdge: window.navigator.userAgent.includes('Edge'),
isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/.test(navigator.userAgent),
isIPhone: /(iPhone|iPod)/gi.test(navigator.platform),
isIos: /(iPad|iPhone|iPod)/gi.test(navigator.platform),
diff --git a/src/js/utils/events.js b/src/js/utils/events.js
index 9f734f04..d304c312 100644
--- a/src/js/utils/events.js
+++ b/src/js/utils/events.js
@@ -73,10 +73,10 @@ export function off(element, events = '', callback, passive = true, capture = fa
// Bind once-only event handler
export function once(element, events = '', callback, passive = true, capture = false) {
- function onceCallback(...args) {
+ const onceCallback = (...args) => {
off(element, events, onceCallback, passive, capture);
callback.apply(this, args);
- }
+ };
toggleListener.call(this, element, events, onceCallback, true, passive, capture);
}
@@ -114,7 +114,7 @@ export function unbindListeners() {
// Run method when / if player is ready
export function ready() {
- return new Promise(
- resolve => (this.ready ? setTimeout(resolve, 0) : on.call(this, this.elements.container, 'ready', resolve)),
+ return new Promise(resolve =>
+ this.ready ? setTimeout(resolve, 0) : on.call(this, this.elements.container, 'ready', resolve),
).then(() => {});
}
diff --git a/src/js/utils/is.js b/src/js/utils/is.js
index ab28f2ab..b005cd31 100644
--- a/src/js/utils/is.js
+++ b/src/js/utils/is.js
@@ -19,6 +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 isEmpty = input =>
isNullOrUndefined(input) ||
@@ -65,6 +66,7 @@ export default {
keyboardEvent: isKeyboardEvent,
cue: isCue,
track: isTrack,
+ promise: isPromise,
url: isUrl,
empty: isEmpty,
};
diff --git a/src/js/utils/style.js b/src/js/utils/style.js
new file mode 100644
index 00000000..a8eb393b
--- /dev/null
+++ b/src/js/utils/style.js
@@ -0,0 +1,40 @@
+// ==========================================================================
+// Style utils
+// ==========================================================================
+
+import is from './is';
+
+/* function reduceAspectRatio(width, height) {
+ const getRatio = (w, h) => (h === 0 ? w : getRatio(h, w % h));
+ const ratio = getRatio(width, height);
+ return `${width / ratio}:${height / ratio}`;
+} */
+
+// Set aspect ratio for responsive container
+export function setAspectRatio(input) {
+ let ratio = input;
+
+ if (!is.string(ratio) && !is.nullOrUndefined(this.embed)) {
+ ({ ratio } = this.embed);
+ }
+
+ if (!is.string(ratio)) {
+ ({ ratio } = this.config);
+ }
+
+ const [x, y] = ratio.split(':').map(Number);
+ const padding = (100 / x) * y;
+
+ this.elements.wrapper.style.paddingBottom = `${padding}%`;
+
+ // For Vimeo we have an extra <div> to hide the standard controls and UI
+ if (this.isVimeo && this.supported.ui) {
+ const height = 240;
+ const offset = (height - padding) / (height / 50);
+ this.media.style.transform = `translateY(-${offset}%)`;
+ }
+
+ return { padding, ratio };
+}
+
+export default { setAspectRatio };
diff --git a/src/js/utils/time.js b/src/js/utils/time.js
index 7c9860fd..2deccf65 100644
--- a/src/js/utils/time.js
+++ b/src/js/utils/time.js
@@ -5,9 +5,9 @@
import is from './is';
// Time helpers
-export const getHours = value => parseInt((value / 60 / 60) % 60, 10);
-export const getMinutes = value => parseInt((value / 60) % 60, 10);
-export const getSeconds = value => parseInt(value % 60, 10);
+export const getHours = value => Math.trunc((value / 60 / 60) % 60, 10);
+export const getMinutes = value => Math.trunc((value / 60) % 60, 10);
+export const getSeconds = value => Math.trunc(value % 60, 10);
// Format time to UI friendly string
export function formatTime(time = 0, displayHours = false, inverted = false) {
diff --git a/src/js/utils/urls.js b/src/js/utils/urls.js
index 3ebe622e..843c6aa6 100644
--- a/src/js/utils/urls.js
+++ b/src/js/utils/urls.js
@@ -6,8 +6,8 @@ import is from './is';
/**
* Parse a string to a URL object
- * @param {string} input - the URL to be parsed
- * @param {boolean} safe - failsafe parsing
+ * @param {String} input - the URL to be parsed
+ * @param {Boolean} safe - failsafe parsing
*/
export function parseUrl(input, safe = true) {
let url = input;