Set download URL via setter

This commit is contained in:
Sam Potts
2019-04-12 19:00:17 +10:00
parent e281078441
commit cdacae6697
4 changed files with 20 additions and 7 deletions

6
src/js/controls.js vendored
View File

@ -1244,8 +1244,8 @@ const controls = {
controls.focusFirstMenuItem.call(this, target, tabFocus);
},
// Set the download link
setDownloadLink() {
// Set the download URL
setDownloadUrl() {
const button = this.elements.buttons.download;
// Bail if no button
@ -1253,7 +1253,7 @@ const controls = {
return;
}
// Set download link
// Set attribute
button.setAttribute('href', this.download);
},

View File

@ -486,7 +486,7 @@ class Listeners {
// Update download link when ready and if quality changes
on.call(player, player.media, 'ready qualitychange', () => {
controls.setDownloadLink.call(player);
controls.setDownloadUrl.call(player);
});
// Proxy events to container

View File

@ -48,14 +48,14 @@ const vimeo = {
// Set intial ratio
setAspectRatio.call(this);
// Load the API if not already
// Load the SDK if not already
if (!is.object(window.Vimeo)) {
loadScript(this.config.urls.vimeo.sdk)
.then(() => {
vimeo.ready.call(this);
})
.catch(error => {
this.debug.warn('Vimeo API failed to load', error);
this.debug.warn('Vimeo SDK (player.js) failed to load', error);
});
} else {
vimeo.ready.call(this);
@ -259,7 +259,7 @@ const vimeo = {
.getVideoUrl()
.then(value => {
currentSrc = value;
controls.setDownloadLink.call(player);
controls.setDownloadUrl.call(player);
})
.catch(error => {
this.debug.warn(error);

View File

@ -823,6 +823,19 @@ class Plyr {
return is.url(download) ? download : this.source;
}
/**
* Set the download URL
*/
set download(input) {
if (!is.url(input)) {
return;
}
this.config.urls.download = input;
controls.setDownloadUrl.call(this);
}
/**
* Set the poster image for a video
* @param {String} input - the URL for the new poster image