diff options
author | Sacha Chua <sacha@sachachua.com> | 2021-01-27 01:13:11 -0500 |
---|---|---|
committer | Sacha Chua <sacha@sachachua.com> | 2021-01-27 01:13:11 -0500 |
commit | 468b90e681bbca2c7e2095c0b6df48bbb4cf7041 (patch) | |
tree | d728c420b872e05280ccff15b669b277a599f6d7 | |
parent | 5526f551cb278f8342be49cc15576d2889bbb6a1 (diff) | |
download | emacsconf-wiki-468b90e681bbca2c7e2095c0b6df48bbb4cf7041.tar.xz emacsconf-wiki-468b90e681bbca2c7e2095c0b6df48bbb4cf7041.zip |
Fiddle with page JS
-rw-r--r-- | templates/page.tmpl | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/templates/page.tmpl b/templates/page.tmpl index 44b6a957..a764202d 100644 --- a/templates/page.tmpl +++ b/templates/page.tmpl @@ -73,21 +73,35 @@ function parseSeconds(timeString) { return timeString.split(":").reduce(function(prev, o) { return prev * 60 + parseFloat(o); - }); + }, 0); } window.onload = function initScript() { - mainVideo = document.getElementById("mainVideo"); - qnaVideo = document.getElementById("qnaVideo"); - timestamps = document.getElementsByClassName("time-link"); - let len = timestamps.length; - for (let i = 0; i < len; i++) { - timestamps[i].onclick = function () { - const videoType = this.href.split("/").pop(); - const video = (videoType == "#mainVideo") ? mainVideo : qnaVideo; - video.currentTime = parseSeconds(this.innerText) - }; + mainVideo = document.getElementById("mainVideo"); + qnaVideo = document.getElementById("qnaVideo"); + timestamps = document.getElementsByClassName("time-link"); + let len = timestamps.length; + for (let i = 0; i < len; i++) { + timestamps[i].onclick = function () { + const videoType = this.href.split("/").pop(); + const video = (videoType == "#mainVideo") ? mainVideo : qnaVideo; + video.currentTime = parseSeconds(this.innerText) + }; + } + let handleSubtitleClick = function(event) { + let video = event.target.attributes['data-video'].value; + let start = event.target.attributes['data-start'].value + let videoElem = document.getElementById(video); + if (videoElem) { + videoElem.currentTime = parseSeconds(start); } + } + + let subtitles = document.getElementsByClassName('subtitle'); + for (let i = 0; i < subtitles.length; i++) { + subtitles[i].onclick = handleSubtitleClick; + } + } // @license-end </script> |