aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js')
-rw-r--r--src/js/defaults.js2
-rw-r--r--src/js/plyr.js12
-rw-r--r--src/js/plyr.polyfilled.js2
-rw-r--r--src/js/storage.js21
-rw-r--r--src/js/utils.js59
5 files changed, 32 insertions, 64 deletions
diff --git a/src/js/defaults.js b/src/js/defaults.js
index a7d017ef..e08fa3da 100644
--- a/src/js/defaults.js
+++ b/src/js/defaults.js
@@ -56,7 +56,7 @@ const defaults = {
// Sprite (for icons)
loadSprite: true,
iconPrefix: 'plyr',
- iconUrl: 'https://cdn.plyr.io/3.0.0-beta.20/plyr.svg',
+ iconUrl: 'https://cdn.plyr.io/3.0.2/plyr.svg',
// Blank video (used to prevent errors on source change)
blankVideo: 'https://cdn.plyr.io/static/blank.mp4',
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 00b7a007..bd4ec020 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -1,6 +1,6 @@
// ==========================================================================
// Plyr
-// plyr.js v3.0.0-beta.20
+// plyr.js v3.0.2
// https://github.com/sampotts/plyr
// License: The MIT License (MIT)
// ==========================================================================
@@ -315,6 +315,10 @@ class Plyr {
* Play the media, or play the advertisement (if they are not blocked)
*/
play() {
+ if (!utils.is.function(this.media.play)) {
+ return null;
+ }
+
// If ads are enabled, wait for them first
if (this.ads.enabled && !this.ads.initialized) {
return this.ads.managerPromise.then(() => this.ads.play()).catch(() => this.media.play());
@@ -328,7 +332,7 @@ class Plyr {
* Pause the media
*/
pause() {
- if (!this.playing) {
+ if (!this.playing || !utils.is.function(this.media.pause)) {
return;
}
@@ -470,7 +474,7 @@ class Plyr {
const fauxDuration = parseInt(this.config.duration, 10);
// True duration
- const realDuration = Number(this.media.duration);
+ const realDuration = this.media ? Number(this.media.duration) : 0;
// If custom duration is funky, use regular duration
return !Number.isNaN(fauxDuration) ? fauxDuration : realDuration;
@@ -1135,7 +1139,7 @@ class Plyr {
clearInterval(this.timers.playing);
// Destroy YouTube API
- if (this.embed !== null) {
+ if (this.embed !== null && utils.is.function(this.embed.destroy)) {
this.embed.destroy();
}
diff --git a/src/js/plyr.polyfilled.js b/src/js/plyr.polyfilled.js
index 9dfec20f..5a540207 100644
--- a/src/js/plyr.polyfilled.js
+++ b/src/js/plyr.polyfilled.js
@@ -1,6 +1,6 @@
// ==========================================================================
// Plyr Polyfilled Build
-// plyr.js v3.0.0-beta.20
+// plyr.js v3.0.2
// https://github.com/sampotts/plyr
// License: The MIT License (MIT)
// ==========================================================================
diff --git a/src/js/storage.js b/src/js/storage.js
index 5f663ab5..5b914331 100644
--- a/src/js/storage.js
+++ b/src/js/storage.js
@@ -12,17 +12,18 @@ class Storage {
// Check for actual support (see if we can use it)
static get supported() {
- if (!('localStorage' in window)) {
- return false;
- }
+ try {
+ if (!('localStorage' in window)) {
+ return false;
+ }
- const test = '___test';
+ const test = '___test';
- // Try to use it (it might be disabled, e.g. user is in private mode)
- // see: https://github.com/sampotts/plyr/issues/131
- try {
+ // Try to use it (it might be disabled, e.g. user is in private mode)
+ // see: https://github.com/sampotts/plyr/issues/131
window.localStorage.setItem(test, test);
window.localStorage.removeItem(test);
+
return true;
} catch (e) {
return false;
@@ -30,9 +31,13 @@ class Storage {
}
get(key) {
+ if (!Storage.supported) {
+ return null;
+ }
+
const store = window.localStorage.getItem(this.key);
- if (!Storage.supported || utils.is.empty(store)) {
+ if (utils.is.empty(store)) {
return null;
}
diff --git a/src/js/utils.js b/src/js/utils.js
index 37dd6461..593e2bca 100644
--- a/src/js/utils.js
+++ b/src/js/utils.js
@@ -2,6 +2,8 @@
// Plyr utils
// ==========================================================================
+import loadjs from 'loadjs';
+
import support from './support';
import { providers } from './types';
@@ -97,11 +99,10 @@ const utils = {
if (responseType === 'text') {
try {
resolve(JSON.parse(request.responseText));
- } catch(e) {
+ } catch (e) {
resolve(request.responseText);
}
- }
- else {
+ } else {
resolve(request.response);
}
});
@@ -125,52 +126,10 @@ const utils = {
// Load an external script
loadScript(url) {
return new Promise((resolve, reject) => {
- const current = document.querySelector(`script[src="${url}"]`);
-
- // Check script is not already referenced, if so wait for load
- if (current !== null) {
- current.callbacks = current.callbacks || [];
- current.callbacks.push(resolve);
- return;
- }
-
- // Build the element
- const element = document.createElement('script');
-
- // Callback queue
- element.callbacks = element.callbacks || [];
- element.callbacks.push(resolve);
-
- // Error queue
- element.errors = element.errors || [];
- element.errors.push(reject);
-
- // Bind callback
- element.addEventListener(
- 'load',
- event => {
- element.callbacks.forEach(cb => cb.call(null, event));
- element.callbacks = null;
- },
- false,
- );
-
- // Bind error handling
- element.addEventListener(
- 'error',
- event => {
- element.errors.forEach(err => err.call(null, event));
- element.errors = null;
- },
- false,
- );
-
- // Set the URL after binding callback
- element.src = url;
-
- // Inject
- const first = document.getElementsByTagName('script')[0];
- first.parentNode.insertBefore(element, first);
+ loadjs(url, {
+ success: resolve,
+ error: reject,
+ });
});
},
@@ -576,7 +535,7 @@ const utils = {
// Toggle event listener
toggleListener(elements, event, callback, toggle, passive, capture) {
// Bail if no elemetns, event, or callback
- if (utils.is.empty(elements) || utils.is.empty(event) || !utils.is.function(callback)) {
+ if (utils.is.empty(elements) || utils.is.empty(event) || !utils.is.function(callback)) {
return;
}