diff options
author | Sam Potts <sam@potts.es> | 2018-06-11 16:54:20 +1000 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2018-06-11 16:54:20 +1000 |
commit | 3fad6ed42cfa77740fbe17ca61a5c5a106a73578 (patch) | |
tree | 2479d6d174ab910fc0475ce9b3723e3d6634f65a /src/js/plyr.js | |
parent | 38f10d4cc67b3109189699f7e65189a852064236 (diff) | |
parent | 38f954ef179d559095eeca5cbd5fd08fae211d34 (diff) | |
download | plyr-3fad6ed42cfa77740fbe17ca61a5c5a106a73578.tar.lz plyr-3fad6ed42cfa77740fbe17ca61a5c5a106a73578.tar.xz plyr-3fad6ed42cfa77740fbe17ca61a5c5a106a73578.zip |
Merge branch 'develop' into a11y-improvements
# Conflicts:
# demo/dist/demo.css
# dist/plyr.css
# dist/plyr.js.map
# dist/plyr.min.js
# dist/plyr.min.js.map
# dist/plyr.polyfilled.js.map
# dist/plyr.polyfilled.min.js
# dist/plyr.polyfilled.min.js.map
# src/js/captions.js
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r-- | src/js/plyr.js | 76 |
1 files changed, 25 insertions, 51 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index 65f24239..9418acd0 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1,6 +1,6 @@ // ========================================================================== // Plyr -// plyr.js v3.3.10 +// plyr.js v3.3.11 // https://github.com/sampotts/plyr // License: The MIT License (MIT) // ========================================================================== @@ -84,7 +84,8 @@ class Plyr { // Captions this.captions = { active: null, - currentTrack: null, + currentTrack: -1, + meta: new WeakMap(), }; // Fullscreen @@ -96,7 +97,6 @@ class Plyr { this.options = { speed: [], quality: [], - captions: [], }; // Debugging @@ -851,61 +851,35 @@ class Plyr { } /** - * Set the captions language - * @param {string} - Two character ISO language code (e.g. EN, FR, PT, etc) + * Set the caption track by index + * @param {number} - Caption index */ - set language(input) { - // Nothing specified - if (!utils.is.string(input)) { - return; - } - - // If empty string is passed, assume disable captions - if (utils.is.empty(input)) { - this.toggleCaptions(false); - return; - } - - // Normalize - const language = input.toLowerCase(); - - // Check for support - if (!this.options.captions.includes(language)) { - this.debug.warn(`Unsupported language option: ${language}`); - return; - } - - // Ensure captions are enabled - this.toggleCaptions(true); - - // Enabled only - if (language === 'enabled') { - return; - } - - // If nothing to change, bail - if (this.language === language) { - return; - } - - // Update config - this.captions.language = language; - - // Clear caption - captions.setText.call(this, null); + set currentTrack(input) { + captions.set.call(this, input); + } - // Update captions - captions.setLanguage.call(this); + /** + * Get the current caption track index (-1 if disabled) + */ + get currentTrack() { + const { active, currentTrack } = this.captions; + return active ? currentTrack : -1; + } - // Trigger an event - utils.dispatchEvent.call(this, this.media, 'languagechange'); + /** + * Set the wanted language for captions + * Since tracks can be added later it won't update the actual caption track until there is a matching track + * @param {string} - Two character ISO language code (e.g. EN, FR, PT, etc) + */ + set language(input) { + captions.setLanguage.call(this, input); } /** - * Get the current captions language + * Get the current track's language */ get language() { - return this.captions.language; + return (captions.getCurrentTrack.call(this) || {}).language; } /** @@ -1156,7 +1130,7 @@ class Plyr { } else if (utils.is.nodeList(selector)) { targets = Array.from(selector); } else if (utils.is.array(selector)) { - targets = selector.filter(i => utils.is.element(i)); + targets = selector.filter(utils.is.element); } if (utils.is.empty(targets)) { |