Clean up
This commit is contained in:
parent
bc7a6ebdde
commit
9fbbb474db
@ -1,7 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
# v1.5.0
|
||||
- *Beta* Vimeo support (please report bugs) (fixes #8)
|
||||
- Vimeo support (fixes #8)
|
||||
- New options for initialization (you can now pass a selector, HTMLElement or NodeList) (fixes #118)
|
||||
- Switched to BEM methodology (you will need to change CSS and probably HTML)
|
||||
- Decoupled CSS and JS hooks (fixes #129)
|
||||
|
2
dist/plyr.css
vendored
2
dist/plyr.css
vendored
File diff suppressed because one or more lines are too long
2
dist/plyr.js
vendored
2
dist/plyr.js
vendored
File diff suppressed because one or more lines are too long
2
docs/dist/docs.css
vendored
2
docs/dist/docs.css
vendored
File diff suppressed because one or more lines are too long
@ -20,12 +20,12 @@
|
||||
<nav>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://github.com/selz/plyr" target="_blank" class="btn btn--primary" data-shr-network="github">
|
||||
<a href="https://github.com/selz/plyr" target="_blank" class="btn btn--large btn--primary" data-shr-network="github">
|
||||
<svg class="icon"><use xlink:href="#icon-github"/></svg>Download on GitHub
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://twitter.com/intent/tweet?text=A+simple+HTML5+media+player+with+custom+controls+and+WebVTT+captions.&url=http%3A%2F%2Fplyr.io&via=Sam_Potts" target="_blank" class="btn btn--twitter" data-shr-network="twitter">
|
||||
<a href="https://twitter.com/intent/tweet?text=A+simple+HTML5+media+player+with+custom+controls+and+WebVTT+captions.&url=http%3A%2F%2Fplyr.io&via=Sam_Potts" target="_blank" class="btn btn--large btn--twitter" data-shr-network="twitter">
|
||||
<svg class="icon"><use xlink:href="#icon-twitter"/></svg>Tweet
|
||||
</a>
|
||||
</li>
|
||||
@ -46,7 +46,7 @@
|
||||
<button type="button" class="btn btn--youtube" data-source="youtube"><svg class="icon"><use xlink:href="#icon-youtube"/></svg>YouTube</button>
|
||||
</li>
|
||||
<li>
|
||||
<button type="button" class="btn btn--vimeo" data-source="vimeo"><svg class="icon"><use xlink:href="#icon-vimeo"/></svg>Vimeo <sup>BETA</sup></button>
|
||||
<button type="button" class="btn btn--vimeo" data-source="vimeo"><svg class="icon"><use xlink:href="#icon-vimeo"/></svg>Vimeo</button>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
@ -98,13 +98,14 @@ nav {
|
||||
|
||||
// Buttons
|
||||
.btn {
|
||||
padding: (@padding-base / 2) @padding-base;
|
||||
padding: (@padding-base / 2) ((@padding-base / 2) + 2);
|
||||
background: linear-gradient(lighten(@body-background, 2%), darken(@body-background, 3%));
|
||||
border: 1px solid @gray-light;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0, .05);
|
||||
text-shadow: 0 1px 1px #fff;
|
||||
color: @gray;
|
||||
transition: background .1s ease, color .1s ease;
|
||||
.font-size(@font-size-small);
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
@ -112,16 +113,15 @@ nav {
|
||||
color: @gray;
|
||||
outline: 0;
|
||||
}
|
||||
&--youtube .icon {
|
||||
color: @color-youtube;
|
||||
}
|
||||
&--vimeo .icon {
|
||||
color: @color-vimeo;
|
||||
}
|
||||
&--twitter .icon {
|
||||
color: @color-twitter;
|
||||
}
|
||||
}
|
||||
|
||||
// Sizes
|
||||
.btn--large {
|
||||
padding: (@padding-base / 2) @padding-base;
|
||||
.font-size();
|
||||
}
|
||||
|
||||
// Styles
|
||||
.btn--primary {
|
||||
background-image: linear-gradient(@link-color, darken(@link-color, 5%));
|
||||
background-color: @link-color;
|
||||
@ -136,9 +136,14 @@ nav {
|
||||
border-color: darken(@link-color, 20%);
|
||||
}
|
||||
}
|
||||
.btn--small {
|
||||
padding-top: ceil(@padding-base / 3);
|
||||
padding-bottom: ceil(@padding-base / 3);
|
||||
.btn--youtube .icon {
|
||||
color: @color-youtube;
|
||||
}
|
||||
.btn--vimeo .icon {
|
||||
color: @color-vimeo;
|
||||
}
|
||||
.btn--twitter .icon {
|
||||
color: @color-twitter;
|
||||
}
|
||||
|
||||
// Count bubble
|
||||
|
@ -5,6 +5,8 @@
|
||||
video,
|
||||
.plyr__video-embed {
|
||||
border-radius: @border-radius-base;
|
||||
max-width: 100%;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.plyr__video-embed {
|
||||
-webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
|
||||
|
@ -20,3 +20,7 @@ a .icon,
|
||||
.btn .icon {
|
||||
margin-right: (@padding-base / 2);
|
||||
}
|
||||
.btn:not(.btn-large) .icon {
|
||||
width: (@icon-size - 2);
|
||||
height: (@icon-size - 2);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ h2 {
|
||||
.font-smoothing();
|
||||
}
|
||||
h1 {
|
||||
.font-size(64);
|
||||
.font-size(@font-size-h1);
|
||||
color: #3498DB;
|
||||
}
|
||||
|
||||
@ -24,11 +24,7 @@ small {
|
||||
small {
|
||||
display: block;
|
||||
padding: 0 (@padding-base / 2);
|
||||
.font-size(14);
|
||||
}
|
||||
sup {
|
||||
vertical-align: 2px;
|
||||
.font-size(9);
|
||||
.font-size(@font-size-small);
|
||||
}
|
||||
|
||||
// Lists
|
||||
|
@ -18,6 +18,11 @@
|
||||
// Base
|
||||
@body-background: @off-white;
|
||||
|
||||
// Type
|
||||
@font-size-base: 16;
|
||||
@font-size-small: 14;
|
||||
@font-size-h1: 64;
|
||||
|
||||
// Elements
|
||||
@link-color: @blue;
|
||||
@padding-base: 20px;
|
||||
|
184
src/js/plyr.js
184
src/js/plyr.js
@ -980,6 +980,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle style hook
|
||||
function _toggleStyleHook() {
|
||||
_toggleClass(plyr.container, defaults.selectors.container.replace('.', ''), plyr.supported.full);
|
||||
}
|
||||
|
||||
// Setup aria attribute for play and iframe title
|
||||
function _setTitle(iframe) {
|
||||
// Find the current text
|
||||
@ -1136,20 +1141,11 @@
|
||||
|
||||
// When embeds are ready
|
||||
function _embedReady() {
|
||||
// Inject and update UI
|
||||
if (plyr.supported.full) {
|
||||
// Only setup controls once
|
||||
if (!plyr.container.querySelectorAll(config.selectors.controls.wrapper).length) {
|
||||
// Setup the UI
|
||||
_setupInterface();
|
||||
}
|
||||
}
|
||||
|
||||
// Set title
|
||||
_setTitle(_getElement('iframe'));
|
||||
|
||||
// Set the volume
|
||||
_setVolume();
|
||||
_updateVolume();
|
||||
}
|
||||
|
||||
// Handle YouTube API ready
|
||||
@ -1165,7 +1161,7 @@
|
||||
plyr.embed = new YT.Player(container.id, {
|
||||
videoId: videoId,
|
||||
playerVars: {
|
||||
autoplay: (config.autoplay ? 1 : 0),
|
||||
autoplay: 0,
|
||||
controls: (plyr.supported.full ? 0 : 1),
|
||||
rel: 0,
|
||||
showinfo: 0,
|
||||
@ -1196,7 +1192,7 @@
|
||||
plyr.media.paused = true;
|
||||
};
|
||||
plyr.media.duration = instance.getDuration();
|
||||
plyr.media.paused = !config.autoplay;
|
||||
plyr.media.paused = true;
|
||||
plyr.media.currentTime = instance.getCurrentTime();
|
||||
plyr.media.muted = instance.isMuted();
|
||||
|
||||
@ -1224,9 +1220,7 @@
|
||||
_embedReady();
|
||||
|
||||
// Display duration if available
|
||||
if (config.displayDuration) {
|
||||
_displayDuration();
|
||||
}
|
||||
},
|
||||
'onStateChange': function(event) {
|
||||
// Get the instance
|
||||
@ -1250,6 +1244,7 @@
|
||||
|
||||
case 1:
|
||||
plyr.media.paused = false;
|
||||
plyr.media.seeking = false;
|
||||
_triggerEvent(plyr.media, 'play');
|
||||
|
||||
// Poll to get playback progress
|
||||
@ -1259,7 +1254,7 @@
|
||||
|
||||
// Trigger timeupdate
|
||||
_triggerEvent(plyr.media, 'timeupdate');
|
||||
}, 200);
|
||||
}, 100);
|
||||
|
||||
break;
|
||||
|
||||
@ -1293,7 +1288,7 @@
|
||||
plyr.embed.api('stop');
|
||||
plyr.media.paused = true;
|
||||
};
|
||||
plyr.media.paused = !config.autoplay;
|
||||
plyr.media.paused = true;
|
||||
plyr.media.currentTime = 0;
|
||||
|
||||
// Update UI
|
||||
@ -1310,9 +1305,7 @@
|
||||
plyr.media.duration = value;
|
||||
|
||||
// Display duration if available
|
||||
if (plyr.supported.full && config.displayDuration) {
|
||||
_displayDuration();
|
||||
}
|
||||
});
|
||||
|
||||
plyr.embed.addEvent('play', function() {
|
||||
@ -1326,6 +1319,7 @@
|
||||
});
|
||||
|
||||
plyr.embed.addEvent('playProgress', function(data) {
|
||||
plyr.media.seeking = false;
|
||||
plyr.media.currentTime = data.seconds;
|
||||
_triggerEvent(plyr.media, 'timeupdate');
|
||||
});
|
||||
@ -1352,7 +1346,10 @@
|
||||
|
||||
// Setup captions
|
||||
function _setupCaptions() {
|
||||
if (plyr.type === 'video') {
|
||||
if (plyr.type !== 'video') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Inject the container
|
||||
if (!_getElement(config.selectors.captions)) {
|
||||
plyr.videoContainer.insertAdjacentHTML('afterbegin', '<div class="' + _getClassname(config.selectors.captions) + '"><span></span></div>');
|
||||
@ -1498,10 +1495,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup fullscreen
|
||||
function _setupFullscreen() {
|
||||
if (!plyr.supported.full) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((plyr.type != 'audio' || config.fullscreen.allowAudio) && config.fullscreen.enabled) {
|
||||
// Check for native support
|
||||
var nativeSupport = fullscreen.supportsFullScreen;
|
||||
@ -1609,24 +1609,28 @@
|
||||
}
|
||||
catch(e) {}
|
||||
|
||||
// Trigger timeupdate for embed and restore pause state
|
||||
if ('embed' in plyr) {
|
||||
// Embeds
|
||||
if(_inArray(config.types.embed, plyr.type)) {
|
||||
// YouTube
|
||||
if (plyr.type === 'youtube') {
|
||||
switch(plyr.type) {
|
||||
case 'youtube':
|
||||
plyr.embed.seekTo(targetTime);
|
||||
}
|
||||
break;
|
||||
|
||||
// Vimeo
|
||||
if (plyr.type === 'vimeo') {
|
||||
case 'vimeo':
|
||||
plyr.embed.api('seekTo', targetTime);
|
||||
break;
|
||||
}
|
||||
|
||||
// Trigger timeupdate
|
||||
_triggerEvent(plyr.media, 'timeupdate');
|
||||
|
||||
if (paused) {
|
||||
_pause();
|
||||
}
|
||||
|
||||
// Trigger timeupdate for embeds
|
||||
_triggerEvent(plyr.media, 'timeupdate');
|
||||
|
||||
// Set seeking flag
|
||||
plyr.media.seeking = true;
|
||||
}
|
||||
|
||||
// Logging
|
||||
@ -1754,24 +1758,20 @@
|
||||
// Set mute on the player
|
||||
plyr.media.muted = muted;
|
||||
|
||||
// Embeds
|
||||
if(_inArray(config.types.embed, plyr.type)) {
|
||||
// YouTube
|
||||
if (plyr.type === 'youtube') {
|
||||
switch(plyr.type) {
|
||||
case 'youtube':
|
||||
plyr.embed[plyr.media.muted ? 'mute' : 'unMute']();
|
||||
break;
|
||||
|
||||
// Trigger timeupdate
|
||||
_triggerEvent(plyr.media, 'volumechange');
|
||||
case 'vimeo':
|
||||
plyr.embed.api('setVolume', plyr.media.muted ? 0 : parseFloat(config.volume / 10));
|
||||
break;
|
||||
}
|
||||
|
||||
// Vimeo
|
||||
if (plyr.type === 'vimeo') {
|
||||
if (plyr.media.muted) {
|
||||
plyr.embed.api('setVolume', 0);
|
||||
}
|
||||
else {
|
||||
plyr.embed.api('setVolume', parseFloat(config.volume / 10));
|
||||
}
|
||||
|
||||
// Trigger timeupdate
|
||||
// Trigger volumechange for embeds
|
||||
_triggerEvent(plyr.media, 'volumechange');
|
||||
}
|
||||
}
|
||||
@ -1803,18 +1803,20 @@
|
||||
// Store in config
|
||||
config.volume = volume;
|
||||
|
||||
// Embeds
|
||||
if(_inArray(config.types.embed, plyr.type)) {
|
||||
// YouTube
|
||||
if (plyr.type === 'youtube') {
|
||||
switch(plyr.type) {
|
||||
case 'youtube':
|
||||
plyr.embed.setVolume(plyr.media.volume * 100);
|
||||
}
|
||||
break;
|
||||
|
||||
// Vimeo
|
||||
if (plyr.type === 'vimeo') {
|
||||
case 'vimeo':
|
||||
plyr.embed.api('setVolume', plyr.media.volume);
|
||||
break;
|
||||
}
|
||||
|
||||
// Trigger volumechange for embeds
|
||||
if ('embed' in plyr) {
|
||||
_triggerEvent(plyr.media, 'volumechange');
|
||||
}
|
||||
|
||||
@ -1970,6 +1972,10 @@
|
||||
|
||||
// Show the duration on metadataloaded
|
||||
function _displayDuration() {
|
||||
if (!plyr.supported.full) {
|
||||
return;
|
||||
}
|
||||
|
||||
var duration = plyr.media.duration || 0;
|
||||
|
||||
// If there's only one time display, display duration there
|
||||
@ -1988,6 +1994,11 @@
|
||||
// Duration
|
||||
_updateTimeDisplay(plyr.media.currentTime, plyr.currentTime);
|
||||
|
||||
// Ignore updates while seeking
|
||||
if(event && event.type == 'timeupdate' && plyr.media.seeking) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Playing progress
|
||||
_updateProgress(event);
|
||||
}
|
||||
@ -2041,7 +2052,7 @@
|
||||
window.clearInterval(plyr.timer.buffering);
|
||||
window.clearInterval(plyr.timer.playing);
|
||||
}
|
||||
else if (plyr.type === 'video') {
|
||||
else if (plyr.type === 'video' && plyr.videoContainer) {
|
||||
// Remove video wrapper
|
||||
_remove(plyr.videoContainer);
|
||||
}
|
||||
@ -2105,6 +2116,7 @@
|
||||
// Restore class hooks
|
||||
_toggleClass(plyr.container, config.classes.fullscreen.active, plyr.isFullscreen);
|
||||
_toggleClass(plyr.container, config.classes.captions.active, plyr.captionsEnabled);
|
||||
_toggleStyleHook();
|
||||
|
||||
// Autoplay the new source?
|
||||
config.autoplay = (source.autoplay || config.autoplay);
|
||||
@ -2117,41 +2129,29 @@
|
||||
// Set up from scratch
|
||||
_setupMedia();
|
||||
|
||||
// Trigger media updated
|
||||
_mediaUpdated();
|
||||
|
||||
// HTML5 stuff
|
||||
if (_inArray(config.types.html5, plyr.type)) {
|
||||
// Set volume
|
||||
_setVolume();
|
||||
_updateVolume();
|
||||
|
||||
// UI updates
|
||||
if (plyr.supported.full) {
|
||||
// Reset time display
|
||||
_timeUpdate();
|
||||
|
||||
// Update the UI
|
||||
_checkPlaying();
|
||||
}
|
||||
|
||||
// Setup captions
|
||||
if ('tracks' in source) {
|
||||
_insertChildElements('track', source.tracks);
|
||||
|
||||
// Captions
|
||||
_setupCaptions();
|
||||
}
|
||||
|
||||
// Load HTML5 sources
|
||||
plyr.media.load();
|
||||
|
||||
// Display duration if available
|
||||
_displayDuration();
|
||||
|
||||
// Setup interface
|
||||
_setupInterface();
|
||||
}
|
||||
|
||||
// Play if autoplay attribute is present
|
||||
if (config.autoplay) {
|
||||
_play();
|
||||
}
|
||||
}
|
||||
|
||||
// Set aria title and iframe title
|
||||
if ('title' in source) {
|
||||
config.title = source.title;
|
||||
_setTitle();
|
||||
@ -2376,9 +2376,6 @@
|
||||
// Get the media element
|
||||
plyr.media = plyr.container.querySelectorAll('audio, video, div')[0];
|
||||
|
||||
// Add style hook
|
||||
_toggleClass(plyr.container, defaults.selectors.container.replace('.', ''), true);
|
||||
|
||||
// Get original classname
|
||||
plyr.originalClassName = plyr.container.className;
|
||||
|
||||
@ -2403,6 +2400,9 @@
|
||||
// Check for full support
|
||||
plyr.supported = api.supported(plyr.type);
|
||||
|
||||
// Add style hook
|
||||
_toggleStyleHook();
|
||||
|
||||
// If no native support, bail
|
||||
if (!plyr.supported.basic) {
|
||||
return false;
|
||||
@ -2415,7 +2415,7 @@
|
||||
_setupMedia();
|
||||
|
||||
// Setup interface
|
||||
if (plyr.type == 'video' || plyr.type == 'audio') {
|
||||
if (_inArray(config.types.html5, plyr.type)) {
|
||||
// Bail if no support
|
||||
if (!plyr.supported.full) {
|
||||
// Successful setup
|
||||
@ -2428,11 +2428,6 @@
|
||||
// Setup UI
|
||||
_setupInterface();
|
||||
|
||||
// Display duration if available
|
||||
if (config.displayDuration) {
|
||||
_displayDuration();
|
||||
}
|
||||
|
||||
// Set title on button and frame
|
||||
_setTitle();
|
||||
}
|
||||
@ -2442,31 +2437,40 @@
|
||||
}
|
||||
|
||||
function _setupInterface() {
|
||||
// Don't setup interface if no support
|
||||
if (!plyr.supported.full) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Inject custom controls
|
||||
if (!plyr.container.querySelectorAll(config.selectors.controls.wrapper).length) {
|
||||
// Inject custom controls
|
||||
_injectControls();
|
||||
}
|
||||
|
||||
// Find the elements
|
||||
if (!_findElements()) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Captions
|
||||
_setupCaptions();
|
||||
|
||||
// Media updated
|
||||
_mediaUpdated();
|
||||
|
||||
// Set volume
|
||||
_setVolume();
|
||||
_updateVolume();
|
||||
}
|
||||
|
||||
function _mediaUpdated() {
|
||||
// Setup fullscreen
|
||||
_setupFullscreen();
|
||||
|
||||
// Listeners
|
||||
_listeners();
|
||||
|
||||
// Captions
|
||||
_setupCaptions();
|
||||
|
||||
// Set volume
|
||||
_setVolume();
|
||||
_updateVolume();
|
||||
|
||||
// Reset time display
|
||||
_timeUpdate();
|
||||
|
||||
// Update the UI
|
||||
_checkPlaying();
|
||||
}
|
||||
|
||||
// Initialize instance
|
||||
|
@ -583,7 +583,7 @@
|
||||
// Hide sound controls on iOS
|
||||
// It's not supported to change volume using JavaScript:
|
||||
// https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html
|
||||
&--is-ios &-volume,
|
||||
&--is-ios &__volume,
|
||||
&--is-ios [data-plyr='mute'],
|
||||
&--is-ios.plyr--audio &__controls--right {
|
||||
display: none;
|
||||
|
Loading…
x
Reference in New Issue
Block a user