diff options
author | Sam Potts <sam@potts.es> | 2017-11-07 23:21:35 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2017-11-07 23:21:35 +1100 |
commit | 3f41a0cf5417a3047aafa27894b57fb740d7d7da (patch) | |
tree | c1feaa0c6dda3dbec2741e50227f4cd4285f9c38 /src/js/plyr.js | |
parent | fae4ca12e02b87f54b1ee7a88815d0b150c46370 (diff) | |
parent | 84505da84ba97ae1b189f9c695228d324e9dc3b8 (diff) | |
download | plyr-3f41a0cf5417a3047aafa27894b57fb740d7d7da.tar.lz plyr-3f41a0cf5417a3047aafa27894b57fb740d7d7da.tar.xz plyr-3f41a0cf5417a3047aafa27894b57fb740d7d7da.zip |
Merge branch 'develop' of github.com:Selz/plyr into develop
# Conflicts:
# readme.md
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r-- | src/js/plyr.js | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index 5c28887e..355fe5cb 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -13,6 +13,7 @@ import utils from './utils'; import captions from './captions'; import controls from './controls'; import fullscreen from './fullscreen'; +import listeners from './listeners'; import media from './media'; import storage from './storage'; import source from './source'; @@ -78,7 +79,6 @@ class Plyr { }; // Captions - // TODO: captions.enabled should be in config? this.captions = { enabled: null, tracks: null, @@ -192,10 +192,7 @@ class Plyr { return; } - // Sniff out the browser - this.browser = utils.getBrowser(); - - // Load saved settings from localStorage + // Setup local storage for user settings storage.setup.call(this); // Check for support again but with type @@ -217,6 +214,9 @@ class Plyr { // Allow focus to be captured this.elements.container.setAttribute('tabindex', 0); + // Global listeners + listeners.global.call(this); + // Add style hook ui.addStyleHook.call(this); @@ -237,17 +237,27 @@ class Plyr { } } + // --------------------------------------- // API // --------------------------------------- + /** + * If the player is HTML5 + */ get isHTML5() { return types.html5.includes(this.type); } + + /** + * If the player is an embed - e.g. YouTube or Vimeo + */ get isEmbed() { return types.embed.includes(this.type); } - // Play + /** + * Play the media + */ play() { if ('play' in this.media) { this.media.play(); @@ -257,7 +267,9 @@ class Plyr { return this; } - // Pause + /** + * Pause the media + */ pause() { if ('pause' in this.media) { this.media.pause(); @@ -267,7 +279,10 @@ class Plyr { return this; } - // Toggle playback + /** + * Toggle playback based on current status + * @param {boolean} toggle + */ togglePlay(toggle) { // True toggle if nothing passed if ((!utils.is.boolean(toggle) && this.media.paused) || toggle) { @@ -277,31 +292,43 @@ class Plyr { return this.pause(); } - // Stop + /** + * Stop playback + */ stop() { return this.restart().pause(); } - // Restart + /** + * Restart playback + */ restart() { this.currentTime = 0; return this; } - // Rewind + /** + * Rewind + * @param {number} seekTime - how far to rewind in seconds. Defaults to the config.seekTime + */ rewind(seekTime) { this.currentTime = this.currentTime - (utils.is.number(seekTime) ? seekTime : this.config.seekTime); return this; } - // Fast forward + /** + * Fast forward + * @param {number} seekTime - how far to fast forward in seconds. Defaults to the config.seekTime + */ forward(seekTime) { this.currentTime = this.currentTime + (utils.is.number(seekTime) ? seekTime : this.config.seekTime); return this; } - // Seek to time - // The input parameter can be an event or a number + /** + * Seek to a time + * @param {number} input - where to seek to in seconds. Defaults to 0 (the start) + */ set currentTime(input) { let targetTime = 0; @@ -327,7 +354,9 @@ class Plyr { return Number(this.media.currentTime); } - // Duration + /** + * Get the duration of the current media + */ get duration() { // Faux duration set via config const fauxDuration = parseInt(this.config.duration, 10); @@ -339,7 +368,10 @@ class Plyr { return !Number.isNaN(fauxDuration) ? fauxDuration : realDuration; } - // Volume + /** + * Set the player volume + * @param {number} value - must be between 0 and 1. Defaults to the value from local storage and config.volume if not set in storage + */ set volume(value) { let volume = value; const max = 1; @@ -377,6 +409,9 @@ class Plyr { } } + /** + * Get the current player volume + */ get volume() { return this.media.volume; } |