diff --git a/frontend/script.js b/frontend/script.js index e6e1cdf..7840429 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -27,7 +27,18 @@ const canPlayType = (canPlayTypeRaw === "maybe") || (canPlayTypeRaw === "probably"); if(canPlayType) { const Button = videojs.getComponent("Button"); - const Component = videojs.getComponent("Component"); + const DownloadButton = videojs.extend(videojs.getComponent("Component"), { + createEl: () => { + const elem = document.createElement("a"); + elem.href = info.download; + elem.classList.add("vjs-control"); + elem.classList.add("vjs-button"); + elem.classList.add("fas"); + elem.classList.add("fa-download"); + elem.classList.add("vjs-big-download"); + return elem; + } + }) const cbutton = {}; cbutton.clickHandler = (ev) => { @@ -35,9 +46,8 @@ } const bigCastButtonWrapper = new Button(player, cbutton); - const bigDownloadButtonWrapper = new Component(player); - bigDownloadButtonWrapper.el_ = document.createElement("a"); - + const bigDownloadButtonWrapper = new DownloadButton(player); + const bigCastButton = bigCastButtonWrapper.el(); const bigDownloadButton = bigDownloadButtonWrapper.el(); @@ -47,14 +57,8 @@ bigCastButton.classList.add("fa-chromecast"); bigCastButton.classList.add("vjs-big-chromecast"); player.addChild(bigCastButtonWrapper); - + if(info.download) { - bigDownloadButton.href = info.download; - bigDownloadButton.classList.add("vjs-control"); - bigDownloadButton.classList.add("vjs-button"); - bigDownloadButton.classList.add("fas"); - bigDownloadButton.classList.add("fa-download"); - bigDownloadButton.classList.add("vjs-big-download"); player.addChild(bigDownloadButtonWrapper); }