From 230f542b54c0d0beba2912b38f0f5c43d4379842 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sun, 13 Mar 2022 12:04:16 +0100 Subject: [PATCH] custom link component --- frontend/script.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) 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); }