aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorSam Potts <me@sampotts.me>2018-01-05 10:37:38 +1100
committerSam Potts <me@sampotts.me>2018-01-05 10:37:38 +1100
commite14e2cfaff8acb9a11719d8f5e5684ca7ff48a02 (patch)
tree71eba78d319de41582cd3ebbdb9c7acd88c09667 /src/js
parent04119b27e69472cce70c7f5b5359c6b45ad718f9 (diff)
parent92cb9e22e24d52e1843a5865651f7b2c5a00d47a (diff)
downloadplyr-e14e2cfaff8acb9a11719d8f5e5684ca7ff48a02.tar.lz
plyr-e14e2cfaff8acb9a11719d8f5e5684ca7ff48a02.tar.xz
plyr-e14e2cfaff8acb9a11719d8f5e5684ca7ff48a02.zip
Merge branch 'develop' of https://github.com/Selz/plyr into develop
Diffstat (limited to 'src/js')
-rw-r--r--src/js/defaults.js1
-rw-r--r--src/js/listeners.js8
-rw-r--r--src/js/plyr.js9
-rw-r--r--src/js/ui.js25
4 files changed, 42 insertions, 1 deletions
diff --git a/src/js/defaults.js b/src/js/defaults.js
index b7dcbf4f..15fadac7 100644
--- a/src/js/defaults.js
+++ b/src/js/defaults.js
@@ -305,6 +305,7 @@ const defaults = {
stopped: 'plyr--stopped',
playing: 'plyr--playing',
loading: 'plyr--loading',
+ error: 'plyr--has-error',
hover: 'plyr--hover',
tooltip: 'plyr__tooltip',
hidden: 'plyr__sr-only',
diff --git a/src/js/listeners.js b/src/js/listeners.js
index 0d57f5e1..b3ccc1c6 100644
--- a/src/js/listeners.js
+++ b/src/js/listeners.js
@@ -221,6 +221,11 @@ const listeners = {
utils.on(document, fullscreen.eventType, event => {
this.toggleFullscreen(event);
});
+
+ // Fullscreen toggle on double click
+ utils.on(this.elements.container, 'dblclick', event => {
+ this.toggleFullscreen(event);
+ });
}
},
@@ -263,6 +268,9 @@ const listeners = {
// Loading
utils.on(this.media, 'stalled waiting canplay seeked playing', event => ui.checkLoading.call(this, event));
+ // Check if media failed to load
+ // utils.on(this.media, 'play', event => ui.checkFailed.call(this, event));
+
// Click video
if (this.supported.ui && this.config.clickToPlay && !this.isAudio) {
// Re-fetch the wrapper
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 7766cc47..e6df286c 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -35,7 +35,11 @@ let scrollPosition = {
class Plyr {
constructor(target, options) {
this.timers = {};
+
+ // State
this.ready = false;
+ this.loading = false;
+ this.failed = false;
// Set the media element
this.media = target;
@@ -809,6 +813,11 @@ class Plyr {
* @param {event} event
*/
toggleFullscreen(event) {
+ // Video only
+ if (this.isAudio) {
+ return;
+ }
+
// Check for native support
if (fullscreen.enabled) {
if (utils.is.event(event) && event.type === fullscreen.eventType) {
diff --git a/src/js/ui.js b/src/js/ui.js
index 44f1a367..7a45a6c3 100644
--- a/src/js/ui.js
+++ b/src/js/ui.js
@@ -153,7 +153,7 @@ const ui = {
// Check if media is loading
checkLoading(event) {
- this.loading = [
+ this.loading = this.media.networkState === 2 || [
'stalled',
'waiting',
].includes(event.type);
@@ -171,6 +171,29 @@ const ui = {
}, this.loading ? 250 : 0);
},
+ // Check if media failed to load
+ checkFailed() {
+ // https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/networkState
+ this.failed = this.media.networkState === 3;
+
+ if (this.failed) {
+ utils.toggleClass(this.elements.container, this.config.classNames.loading, false);
+ utils.toggleClass(this.elements.container, this.config.classNames.error, true);
+ }
+
+ // Clear timer
+ clearTimeout(this.timers.failed);
+
+ // Timer to prevent flicker when seeking
+ this.timers.loading = setTimeout(() => {
+ // Toggle container class hook
+ utils.toggleClass(this.elements.container, this.config.classNames.loading, this.loading);
+
+ // Show controls if loading, hide if done
+ this.toggleControls(this.loading);
+ }, this.loading ? 250 : 0);
+ },
+
// Update volume UI and storage
updateVolume() {
if (!this.supported.ui) {