aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-05-08 22:22:09 +1000
committerSam Potts <sam@potts.es>2018-05-08 22:22:09 +1000
commite1ff516219e88d1264ab2a3dc2748e76940ec50a (patch)
treef8f46e1f38bdfb28d8ccc146a4d014ca1ca05a31 /src/js/utils.js
parent44b30380f71f03c8944e42b24c7ce3e92a0f2eea (diff)
parentf687b81b70a73835f0190fbfa17a0fbbfcd28b7a (diff)
downloadplyr-e1ff516219e88d1264ab2a3dc2748e76940ec50a.tar.lz
plyr-e1ff516219e88d1264ab2a3dc2748e76940ec50a.tar.xz
plyr-e1ff516219e88d1264ab2a3dc2748e76940ec50a.zip
Merge branch 'master' into beta
Diffstat (limited to 'src/js/utils.js')
-rw-r--r--src/js/utils.js74
1 files changed, 14 insertions, 60 deletions
diff --git a/src/js/utils.js b/src/js/utils.js
index fca40f53..d46a7601 100644
--- a/src/js/utils.js
+++ b/src/js/utils.js
@@ -3,7 +3,6 @@
// ==========================================================================
import loadjs from 'loadjs';
-
import support from './support';
import { providers } from './types';
@@ -269,14 +268,14 @@ const utils = {
parent.appendChild(utils.createElement(type, attributes, text));
},
- // Remove an element
+ // Remove element(s)
removeElement(element) {
- if (!utils.is.element(element) || !utils.is.element(element.parentNode)) {
+ if (utils.is.nodeList(element) || utils.is.array(element)) {
+ Array.from(element).forEach(utils.removeElement);
return;
}
- if (utils.is.nodeList(element) || utils.is.array(element)) {
- Array.from(element).forEach(utils.removeElement);
+ if (!utils.is.element(element) || !utils.is.element(element.parentNode)) {
return;
}
@@ -435,60 +434,6 @@ const utils = {
return this.elements.container.querySelector(selector);
},
- // Find the UI controls and store references in custom controls
- // TODO: Allow settings menus with custom controls
- findElements() {
- try {
- this.elements.controls = utils.getElement.call(this, this.config.selectors.controls.wrapper);
-
- // Buttons
- this.elements.buttons = {
- play: utils.getElements.call(this, this.config.selectors.buttons.play),
- pause: utils.getElement.call(this, this.config.selectors.buttons.pause),
- restart: utils.getElement.call(this, this.config.selectors.buttons.restart),
- rewind: utils.getElement.call(this, this.config.selectors.buttons.rewind),
- fastForward: utils.getElement.call(this, this.config.selectors.buttons.fastForward),
- mute: utils.getElement.call(this, this.config.selectors.buttons.mute),
- pip: utils.getElement.call(this, this.config.selectors.buttons.pip),
- airplay: utils.getElement.call(this, this.config.selectors.buttons.airplay),
- settings: utils.getElement.call(this, this.config.selectors.buttons.settings),
- captions: utils.getElement.call(this, this.config.selectors.buttons.captions),
- fullscreen: utils.getElement.call(this, this.config.selectors.buttons.fullscreen),
- };
-
- // Progress
- this.elements.progress = utils.getElement.call(this, this.config.selectors.progress);
-
- // Inputs
- this.elements.inputs = {
- seek: utils.getElement.call(this, this.config.selectors.inputs.seek),
- volume: utils.getElement.call(this, this.config.selectors.inputs.volume),
- };
-
- // Display
- this.elements.display = {
- buffer: utils.getElement.call(this, this.config.selectors.display.buffer),
- currentTime: utils.getElement.call(this, this.config.selectors.display.currentTime),
- duration: utils.getElement.call(this, this.config.selectors.display.duration),
- };
-
- // Seek tooltip
- if (utils.is.element(this.elements.progress)) {
- this.elements.display.seekTooltip = this.elements.progress.querySelector(`.${this.config.classNames.tooltip}`);
- }
-
- return true;
- } catch (error) {
- // Log it
- this.debug.warn('It looks like there is a problem with your custom controls HTML', error);
-
- // Restore native video controls
- this.toggleNativeControls(true);
-
- return false;
- }
- },
-
// Get the focused element
getFocusElement() {
let focused = document.activeElement;
@@ -632,6 +577,15 @@ const utils = {
element.setAttribute('aria-pressed', state);
},
+ // Format string
+ format(input, ...args) {
+ if (utils.is.empty(input)) {
+ return input;
+ }
+
+ return input.toString().replace(/{(\d+)}/g, (match, i) => utils.is.string(args[i]) ? args[i] : '');
+ },
+
// Get percentage
getPercentage(current, max) {
if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) {
@@ -769,7 +723,7 @@ const utils = {
}
// Vimeo
- if (/^https?:\/\/player.vimeo.com\/video\/\d{8,}(?=\b|\/)/.test(url)) {
+ if (/^https?:\/\/player.vimeo.com\/video\/\d{0,9}(?=\b|\/)/.test(url)) {
return providers.vimeo;
}