From 7caa4fb435e6e14ed71931ac27f270b75efe46fe Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 2 May 2021 01:01:09 +1200 Subject: [PATCH] Change JS timestamp clicks to be object oriented --- html/static/js/player.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/html/static/js/player.js b/html/static/js/player.js index cd53293..12bd0ab 100644 --- a/html/static/js/player.js +++ b/html/static/js/player.js @@ -3,7 +3,6 @@ import {SubscribeButton} from "/static/js/subscribe.js" const video = q("#video") const audio = q("#audio") -const timestamps = qa("a[data-clickable-timestamp]") const videoFormats = new Map() const audioFormats = new Map() @@ -223,8 +222,21 @@ document.addEventListener("keydown", event => { new SubscribeButton(q("#subscribe")) -Array.from(timestamps).forEach(el => el.addEventListener('click', event => { - event.preventDefault() - video.currentTime = event.target.getAttribute("data-clickable-timestamp") - window.history.replaceState({}, "", event.target.href) -})) +const timestamps = qa("[data-clickable-timestamp]") + +class Timestamp extends ElemJS { + constructor(element) { + super(element) + this.on("click", this.onClick.bind(this)) + } + + onClick(event) { + event.preventDefault() + video.currentTime = event.target.getAttribute("data-clickable-timestamp") + window.history.replaceState(null, "", event.target.href) + } +} + +timestamps.forEach(el => { + new Timestamp(el) +})