This commit is contained in:
Sam Potts 2017-11-09 19:40:45 +11:00
parent 86a5724bdb
commit f878581c8f
14 changed files with 78 additions and 59 deletions

2
dist/plyr.css vendored

File diff suppressed because one or more lines are too long

2
dist/plyr.js vendored

File diff suppressed because one or more lines are too long

2
dist/plyr.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -115,6 +115,7 @@ const captions = {
utils.off(track, 'cuechange', event => captions.setCue.call(this, event)); utils.off(track, 'cuechange', event => captions.setCue.call(this, event));
// Hide captions // Hide captions
// eslint-disable-next-line
track.mode = 'hidden'; track.mode = 'hidden';
}); });

10
src/js/controls.js vendored
View File

@ -195,12 +195,18 @@ const controls = {
if (utils.is.string(iconToggled)) { if (utils.is.string(iconToggled)) {
button.appendChild( button.appendChild(
controls.createIcon.call(this, iconToggled, { controls.createIcon.call(this, iconToggled, {
class: `icon--${iconToggled}`, class: 'icon--pressed',
}) })
); );
button.appendChild(
controls.createIcon.call(this, iconDefault, {
class: 'icon--not-pressed',
})
);
} else {
button.appendChild(controls.createIcon.call(this, iconDefault));
} }
button.appendChild(controls.createIcon.call(this, iconDefault));
button.appendChild(controls.createLabel.call(this, labelKey)); button.appendChild(controls.createLabel.call(this, labelKey));
utils.setAttributes(button, attributes); utils.setAttributes(button, attributes);

View File

@ -268,7 +268,6 @@ const defaults = {
type: 'plyr--{0}', type: 'plyr--{0}',
stopped: 'plyr--stopped', stopped: 'plyr--stopped',
playing: 'plyr--playing', playing: 'plyr--playing',
muted: 'plyr--muted',
loading: 'plyr--loading', loading: 'plyr--loading',
hover: 'plyr--hover', hover: 'plyr--hover',
tooltip: 'plyr__tooltip', tooltip: 'plyr__tooltip',

View File

@ -300,7 +300,7 @@ const listeners = {
// Update UI // Update UI
controls.updateSetting.call(this, 'speed'); controls.updateSetting.call(this, 'speed');
// Save speed to localStorage // Save to storage
storage.set.call(this, { speed: this.speed }); storage.set.call(this, { speed: this.speed });
}); });
@ -309,20 +309,20 @@ const listeners = {
// Update UI // Update UI
controls.updateSetting.call(this, 'quality'); controls.updateSetting.call(this, 'quality');
// Save speed to localStorage // Save to storage
storage.set.call(this, { quality: this.quality }); storage.set.call(this, { quality: this.quality });
}); });
// Caption language change // Caption language change
utils.on(this.media, 'captionchange', () => { utils.on(this.media, 'captionchange', () => {
// Save speed to localStorage // Save to storage
storage.set.call(this, { language: this.language }); storage.set.call(this, { language: this.language });
}); });
// Volume change // Volume change
utils.on(this.media, 'volumechange', () => { utils.on(this.media, 'volumechange', () => {
// Save speed to localStorage // Save to storage
storage.set.call(this, { volume: this.volume }); storage.set.call(this, { volume: this.volume, muted: this.muted });
}); });
// Captions toggle // Captions toggle
@ -330,7 +330,7 @@ const listeners = {
// Update UI // Update UI
controls.updateSetting.call(this, 'captions'); controls.updateSetting.call(this, 'captions');
// Save speed to localStorage // Save to storage
storage.set.call(this, { captions: this.captions.enabled }); storage.set.call(this, { captions: this.captions.enabled });
}); });

View File

@ -145,13 +145,16 @@ const vimeo = {
}); });
// Muted // Muted
let { muted } = player.config;
Object.defineProperty(player.media, 'muted', { Object.defineProperty(player.media, 'muted', {
get() { get() {
return volume === 0; return muted;
}, },
set(input) { set(input) {
const toggle = utils.is.boolean(input) ? input : false; const toggle = utils.is.boolean(input) ? input : false;
player.volume = toggle ? 0 : player.config.volume; muted = toggle;
player.embed.setVolume(toggle ? 0 : player.config.volume);
utils.dispatchEvent.call(player, player.media, 'volumechange');
}, },
}); });

View File

@ -168,7 +168,7 @@ const youtube = {
}); });
// Volume // Volume
let volume = instance.getVolume() / 100; let { volume } = player.config;
Object.defineProperty(player.media, 'volume', { Object.defineProperty(player.media, 'volume', {
get() { get() {
return volume; return volume;
@ -181,13 +181,14 @@ const youtube = {
}); });
// Muted // Muted
player.media.muted = instance.isMuted(); let { muted } = player.config;
Object.defineProperty(player.media, 'muted', { Object.defineProperty(player.media, 'muted', {
get() { get() {
return instance.isMuted(); return muted;
}, },
set(input) { set(input) {
const toggle = utils.is.boolean(input) ? input : false; const toggle = utils.is.boolean(input) ? input : muted;
muted = toggle;
instance[toggle ? 'mute' : 'unMute'](); instance[toggle ? 'mute' : 'unMute']();
utils.dispatchEvent.call(player, player.media, 'volumechange'); utils.dispatchEvent.call(player, player.media, 'volumechange');
}, },

View File

@ -280,6 +280,10 @@ class Plyr {
return this; return this;
} }
get paused() {
return this.media.paused;
}
/** /**
* Toggle playback based on current status * Toggle playback based on current status
* @param {boolean} toggle * @param {boolean} toggle
@ -355,6 +359,10 @@ class Plyr {
return Number(this.media.currentTime); return Number(this.media.currentTime);
} }
get seeking() {
return this.media.seeking;
}
/** /**
* Get the duration of the current media * Get the duration of the current media
*/ */
@ -407,8 +415,10 @@ class Plyr {
// Set the player volume // Set the player volume
this.media.volume = volume; this.media.volume = volume;
// Toggle muted state // If muted, and we're increasing volume, reset muted state
this.muted = volume === 0; if (this.muted && volume > 0) {
this.muted = false;
}
} }
/** /**
@ -434,11 +444,17 @@ class Plyr {
// Toggle mute // Toggle mute
set muted(mute) { set muted(mute) {
// If the method is called without parameter, toggle based on current value let toggle = mute;
const toggle = utils.is.boolean(mute) ? mute : this.config.muted;
// Set button state // Load muted state from storage
utils.toggleState(this.elements.buttons.mute, toggle); if (!utils.is.boolean(toggle)) {
toggle = storage.get.call(this).muted;
}
// Use config if all else fails
if (!utils.is.boolean(toggle)) {
toggle = this.config.muted;
}
// Update config // Update config
this.config.muted = toggle; this.config.muted = toggle;

View File

@ -110,7 +110,7 @@ const ui = {
} }
// If there's only one time display, display duration there // If there's only one time display, display duration there
if (!this.elements.display.duration && this.config.displayDuration && this.media.paused) { if (!this.elements.display.duration && this.config.displayDuration && this.paused) {
ui.updateTimeDisplay.call(this, this.duration, this.elements.display.currentTime); ui.updateTimeDisplay.call(this, this.duration, this.elements.display.currentTime);
} }
@ -164,30 +164,27 @@ const ui = {
// Check playing state // Check playing state
checkPlaying() { checkPlaying() {
utils.toggleClass(this.elements.container, this.config.classNames.playing, !this.media.paused); utils.toggleClass(this.elements.container, this.config.classNames.playing, !this.paused);
utils.toggleClass(this.elements.container, this.config.classNames.stopped, this.media.paused); utils.toggleClass(this.elements.container, this.config.classNames.stopped, this.paused);
this.toggleControls(this.media.paused); this.toggleControls(this.paused);
}, },
// Update volume UI and storage // Update volume UI and storage
updateVolume() { updateVolume() {
// Update the <input type="range"> if present if (!this.supported.ui) {
if (this.supported.ui) { return;
const value = this.muted ? 0 : this.volume;
if (utils.is.htmlElement(this.elements.inputs.volume)) {
ui.setRange.call(this, this.elements.inputs.volume, value);
}
} }
// Toggle class if muted // Update range
utils.toggleClass(this.elements.container, this.config.classNames.muted, this.muted); if (utils.is.htmlElement(this.elements.inputs.volume)) {
ui.setRange.call(this, this.elements.inputs.volume, this.muted ? 0 : this.volume);
}
// Update checkbox for mute state // Update checkbox for mute state
if (this.supported.ui && utils.is.htmlElement(this.elements.buttons.mute)) { if (utils.is.htmlElement(this.elements.buttons.mute)) {
utils.toggleState(this.elements.buttons.mute, this.muted); utils.toggleState(this.elements.buttons.mute, this.muted || this.volume === 0);
} }
}, },
@ -214,6 +211,7 @@ const ui = {
return; return;
} }
// eslint-disable-next-line
target.value = value; target.value = value;
// Webkit range fill // Webkit range fill
@ -312,6 +310,7 @@ const ui = {
const display = `${(displayHours ? `${hours}:` : '') + mins}:${secs}`; const display = `${(displayHours ? `${hours}:` : '') + mins}:${secs}`;
// Render // Render
// eslint-disable-next-line
element.textContent = display; element.textContent = display;
// Return for looping // Return for looping

View File

@ -536,19 +536,17 @@ const utils = {
// Toggle aria-pressed state on a toggle button // Toggle aria-pressed state on a toggle button
// http://www.ssbbartgroup.com/blog/how-not-to-misuse-aria-states-properties-and-roles // http://www.ssbbartgroup.com/blog/how-not-to-misuse-aria-states-properties-and-roles
toggleState(target, state) { toggleState(element, input) {
// Bail if no target // Bail if no target
if (!target) { if (!utils.is.htmlElement(element)) {
return null; return;
} }
// Get state // Get state
const newState = utils.is.boolean(state) ? state : !target.getAttribute('aria-pressed'); const state = utils.is.boolean(input) ? input : !element.getAttribute('aria-pressed');
// Set the attribute on target // Set the attribute on target
target.setAttribute('aria-pressed', newState); element.setAttribute('aria-pressed', state);
return newState;
}, },
// Get percentage // Get percentage

View File

@ -21,9 +21,7 @@
} }
// Hide toggle icons by default // Hide toggle icons by default
.icon--exit-fullscreen, .icon--pressed {
.icon--muted,
.icon--captions-on {
display: none; display: none;
} }
@ -33,6 +31,14 @@
} }
} }
// Change icons on state change
.plyr__control[aria-pressed='true'] .icon--pressed {
display: block;
}
.plyr__control[aria-pressed='true'] .icon--not-pressed {
display: none;
}
// Audio styles // Audio styles
.plyr--audio .plyr__control { .plyr--audio .plyr__control {
&.plyr__tab-focus, &.plyr__tab-focus,

View File

@ -102,16 +102,6 @@
display: inline-block; display: inline-block;
} }
// Change icons on state change
.plyr--muted .plyr__control .icon--muted,
.plyr--captions-active .plyr__control .icon--captions-on {
display: block;
& + svg {
display: none;
}
}
// Some options are hidden by default // Some options are hidden by default
.plyr [data-plyr='captions'], .plyr [data-plyr='captions'],
.plyr [data-plyr='pip'], .plyr [data-plyr='pip'],