diff options
author | Sam Potts <sam@potts.es> | 2018-05-31 23:39:51 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-31 23:39:51 +1000 |
commit | fb22a90d33ad991e1f6de22f201c3b49f54168c1 (patch) | |
tree | 8cc30e7af53cd44f8cb5f035e16f9d6d9804cc39 /dist/plyr.js | |
parent | d70a787af19ece0b9eeeba60d947225c73ded291 (diff) | |
parent | 108bd3dfa078cf22c0446373830e86cba586919c (diff) | |
download | plyr-fb22a90d33ad991e1f6de22f201c3b49f54168c1.tar.lz plyr-fb22a90d33ad991e1f6de22f201c3b49f54168c1.tar.xz plyr-fb22a90d33ad991e1f6de22f201c3b49f54168c1.zip |
Merge pull request #993 from sampotts/develop
v3.3.10
Diffstat (limited to 'dist/plyr.js')
-rw-r--r-- | dist/plyr.js | 221 |
1 files changed, 108 insertions, 113 deletions
diff --git a/dist/plyr.js b/dist/plyr.js index 9d473bc5..aae4d632 100644 --- a/dist/plyr.js +++ b/dist/plyr.js @@ -1300,6 +1300,14 @@ var utils = { }, + // Get a nested value in an object + getDeep: function getDeep(object, path) { + return path.split('.').reduce(function (obj, key) { + return obj && obj[key]; + }, object); + }, + + // Get the closest value in an array closest: function closest(array, value) { if (!utils.is.array(array) || !array.length) { @@ -1719,6 +1727,13 @@ var html5 = { player.media.src = supported[0].getAttribute('src'); + // Restore time + var onLoadedMetaData = function onLoadedMetaData() { + player.currentTime = currentTime; + player.off('loadedmetadata', onLoadedMetaData); + }; + player.on('loadedmetadata', onLoadedMetaData); + // Load new source player.media.load(); @@ -1727,9 +1742,6 @@ var html5 = { player.play(); } - // Restore time - player.currentTime = currentTime; - // Trigger change event utils.dispatchEvent.call(player, player.media, 'qualitychange', false, { quality: input @@ -1771,11 +1783,15 @@ var i18n = { var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - if (utils.is.empty(key) || utils.is.empty(config) || !Object.keys(config.i18n).includes(key)) { + if (utils.is.empty(key) || utils.is.empty(config)) { return ''; } - var string = config.i18n[key]; + var string = utils.getDeep(config.i18n, key); + + if (utils.is.empty(string)) { + return ''; + } var replace = { '{seektime}': config.seekTime, @@ -2449,27 +2465,7 @@ var controls = { // Get the badge HTML for HD, 4K etc var getBadge = function getBadge(quality) { - var label = ''; - - switch (quality) { - case 2160: - label = '4K'; - break; - - case 1440: - case 1080: - case 720: - label = 'HD'; - break; - - case 576: - case 480: - label = 'SD'; - break; - - default: - break; - } + var label = i18n.get('qualityBadge.' + quality, _this3.config); if (!label.length) { return null; @@ -2492,7 +2488,6 @@ var controls = { // Translate a value into a nice label - // TODO: Localisation getLabel: function getLabel(setting, value) { switch (setting) { case 'speed': @@ -2500,7 +2495,13 @@ var controls = { case 'quality': if (utils.is.number(value)) { - return value + 'p'; + var label = i18n.get('qualityLabel.' + value, this.config); + + if (!label.length) { + return value + 'p'; + } + + return label; } return utils.toTitleCase(value); @@ -2660,12 +2661,7 @@ var controls = { // Generate options tracks.forEach(function (track) { - controls.createMenuItem.call(_this4, track.language, list, 'language', track.label, track.language !== 'enabled' ? controls.createBadge.call(_this4, track.language.toUpperCase()) : null, track.language.toLowerCase() === _this4.captions.language.toLowerCase()); - }); - - // Store reference - this.options.captions = tracks.map(function (track) { - return track.language; + controls.createMenuItem.call(_this4, track.language, list, 'language', track.label, track.language !== 'enabled' ? controls.createBadge.call(_this4, track.language.toUpperCase()) : null, track.language.toLowerCase() === _this4.language); }); controls.updateSetting.call(this, type, list); @@ -3268,28 +3264,6 @@ var captions = { return; } - // Set default language if not set - var stored = this.storage.get('language'); - - if (!utils.is.empty(stored)) { - this.captions.language = stored; - } - - if (utils.is.empty(this.captions.language)) { - this.captions.language = this.config.captions.language.toLowerCase(); - } - - // Set captions enabled state if not set - if (!utils.is.boolean(this.captions.active)) { - var active = this.storage.get('captions'); - - if (utils.is.boolean(active)) { - this.captions.active = active; - } else { - this.captions.active = this.config.captions.active; - } - } - // Only Vimeo and HTML5 video supported at this point if (!this.isVideo || this.isYouTube || this.isHTML5 && !support.textTracks) { // Clear menu and hide @@ -3307,17 +3281,6 @@ var captions = { utils.insertAfter(this.elements.captions, this.elements.wrapper); } - // Set the class hook - utils.toggleClass(this.elements.container, this.config.classNames.captions.enabled, !utils.is.empty(captions.getTracks.call(this))); - - // Get tracks - var tracks = captions.getTracks.call(this); - - // If no caption file exists, hide container for caption text - if (utils.is.empty(tracks)) { - return; - } - // Get browser info var browser = utils.getBrowser(); @@ -3340,14 +3303,52 @@ var captions = { }); } - // Set language - captions.setLanguage.call(this); + // Try to load the value from storage + var active = this.storage.get('captions'); - // Enable UI - captions.show.call(this); + // Otherwise fall back to the default config + if (!utils.is.boolean(active)) { + active = this.config.captions.active; + } + + // Set toggled state + this.toggleCaptions(active); + + // Watch changes to textTracks and update captions menu + if (this.config.captions.update) { + utils.on(this.media.textTracks, 'addtrack removetrack', captions.update.bind(this)); + } + + // Update available languages in list next tick (the event must not be triggered before the listeners) + setTimeout(captions.update.bind(this), 0); + }, + update: function update() { + // Update tracks + var tracks = captions.getTracks.call(this); + this.options.captions = tracks.map(function (_ref) { + var language = _ref.language; + return language; + }); + + // Set language if it hasn't been set already + if (!this.language) { + var language = this.config.captions.language; - // Set available languages in list - if (utils.is.array(this.config.controls) && this.config.controls.includes('settings') && this.config.settings.includes('captions')) { + if (language === 'auto') { + var _split = (navigator.language || navigator.userLanguage).split('-'); + + var _split2 = slicedToArray(_split, 1); + + language = _split2[0]; + } + this.language = this.storage.get('language') || (language || '').toLowerCase(); + } + + // Toggle the class hooks + utils.toggleClass(this.elements.container, this.config.classNames.captions.enabled, !utils.is.empty(captions.getTracks.call(this))); + + // Update available languages in list + if ((this.config.controls || []).includes('settings') && this.config.settings.includes('captions')) { controls.setCaptionsMenu.call(this); } }, @@ -3508,25 +3509,6 @@ var captions = { } else { this.debug.warn('No captions element to render to'); } - }, - - - // Display captions container and button (for initialization) - show: function show() { - // Try to load the value from storage - var active = this.storage.get('captions'); - - // Otherwise fall back to the default config - if (!utils.is.boolean(active)) { - active = this.config.captions.active; - } else { - this.captions.active = active; - } - - if (active) { - utils.toggleClass(this.elements.container, this.config.classNames.captions.active, true); - utils.toggleState(this.elements.buttons.captions, true); - } } }; @@ -3667,7 +3649,10 @@ var defaults$1 = { // Captions settings captions: { active: false, - language: (navigator.language || navigator.userLanguage).split('-')[0] + language: 'auto', + // Listen to new tracks added after Plyr is initialized. + // This is needed for streaming captions, but may result in unselectable options + update: false }, // Fullscreen settings @@ -3724,7 +3709,15 @@ var defaults$1 = { reset: 'Reset', disabled: 'Disabled', enabled: 'Enabled', - advertisement: 'Ad' + advertisement: 'Ad', + qualityBadge: { + 2160: '4K', + 1440: 'HD', + 1080: 'HD', + 720: 'HD', + 576: 'SD', + 480: 'SD' + } }, // URLs @@ -3812,9 +3805,8 @@ var defaults$1 = { display: { currentTime: '.plyr__time--current', duration: '.plyr__time--duration', - buffer: '.plyr__progress--buffer', - played: '.plyr__progress--played', - loop: '.plyr__progress--loop', + buffer: '.plyr__progress__buffer', + loop: '.plyr__progress__loop', // Used later volume: '.plyr__volume--display' }, progress: '.plyr__progress', @@ -4183,8 +4175,10 @@ var ui = { // Remove native controls ui.toggleNativeControls.call(this); - // Captions - captions.setup.call(this); + // Setup captions for HTML5 + if (this.isHTML5) { + captions.setup.call(this); + } // Reset volume this.volume = null; @@ -4237,6 +4231,12 @@ var ui = { if (this.poster && this.elements.poster && !this.elements.poster.style.backgroundImage) { ui.setPoster.call(this, this.poster); } + + // Manually set the duration if user has overridden it. + // The event listeners for it doesn't get called if preload is disabled (#701) + if (this.config.duration) { + controls.durationUpdate.call(this); + } }, @@ -7294,24 +7294,19 @@ var Plyr = function () { } // If the method is called without parameter, toggle based on current value - var show = utils.is.boolean(input) ? input : !this.elements.container.classList.contains(this.config.classNames.captions.active); - - // Nothing to change... - if (this.captions.active === show) { - return; - } - - // Set global - this.captions.active = show; + var active = utils.is.boolean(input) ? input : !this.elements.container.classList.contains(this.config.classNames.captions.active); // Toggle state - utils.toggleState(this.elements.buttons.captions, this.captions.active); + utils.toggleState(this.elements.buttons.captions, active); // Add class hook - utils.toggleClass(this.elements.container, this.config.classNames.captions.active, this.captions.active); + utils.toggleClass(this.elements.container, this.config.classNames.captions.active, active); - // Trigger an event - utils.dispatchEvent.call(this, this.media, this.captions.active ? 'captionsenabled' : 'captionsdisabled'); + // Update state and trigger event + if (active !== this.captions.active) { + this.captions.active = active; + utils.dispatchEvent.call(this, this.media, this.captions.active ? 'captionsenabled' : 'captionsdisabled'); + } } /** @@ -7843,7 +7838,7 @@ var Plyr = function () { quality = Number(input); } - if (!utils.is.number(quality) || quality === 0) { + if (!utils.is.number(quality)) { quality = this.storage.get('quality'); } |