mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-21 16:05:02 +02:00
Make timestamps.js re-useable
This commit is contained in:
22
docs/_static/timestamps.js
vendored
22
docs/_static/timestamps.js
vendored
@@ -1,29 +1,35 @@
|
||||
/*jshint esversion: 6 */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
function init_timestamps() {
|
||||
document.querySelectorAll('.timestamp-list').forEach(loc => {
|
||||
var dl = loc.querySelector('dl');
|
||||
document.querySelectorAll('.video-with-timestamps').forEach(loc => {
|
||||
if (loc.dataset.inited === 'true') return;
|
||||
loc.dataset.inited = 'true';
|
||||
const container_id = loc.id;
|
||||
const dl = loc.querySelector('dl');
|
||||
dl.querySelectorAll('dt').forEach(dt => {
|
||||
dt.innerHTML = '<a href="javascript:void(0)" style="text-decoration: none"><time>' + dt.innerHTML + '</time></a>';
|
||||
dt.style.display = 'inline';
|
||||
});
|
||||
dl.addEventListener('click', handle_timestamp_click);
|
||||
dl.addEventListener('click', handle_timestamp_click.bind(null, container_id));
|
||||
});
|
||||
}
|
||||
|
||||
function handle_timestamp_click(e) {
|
||||
function handle_timestamp_click(container_id, e) {
|
||||
if (e.target.tagName.toUpperCase() === 'TIME') {
|
||||
const timestamp = e.target.textContent;
|
||||
if (timestamp) {
|
||||
const [minutes, seconds] = timestamp.split(':');
|
||||
const totalSeconds = parseInt(minutes) * 60 + parseInt(seconds);
|
||||
const video = document.querySelector('video');
|
||||
video.currentTime = totalSeconds;
|
||||
const total_seconds = parseInt(minutes) * 60 + parseInt(seconds);
|
||||
const video = document.querySelector('#' + container_id + ' video');
|
||||
video.currentTime = total_seconds;
|
||||
video.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', init_timestamps);
|
||||
init_timestamps();
|
||||
document.addEventListener('DOMContentloaded', init_timestamps);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user