about summary refs log tree commit diff
path: root/tvix/docs/mdbook-extra.js
blob: bff412e69eb2b0195f18a4615c4789ff5cdd94bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"use strict"

function main() {
	document.removeEventListener("DOMContentLoaded", main, false)

	// NOTE: this is a hacky solution but should do the job for making a
	// listenable audio link
	function playAudio(evt) {
		evt.preventDefault()
		var audio = document.createElement("audio")
		audio.addEventListener("ended", function() { audio.delete() }, false)
		audio.addEventListener("loadeddata", function() { audio.play() }, false)
		audio.src = evt.target.href
		audio.load()
	}

	var audios = document.querySelectorAll("a[href^=\"data:audio/\"]")
	Array.prototype.forEach.call(audios, function setupAudio(elem) {
		elem.setAttribute("role", "button")
		elem.addEventListener("click", playAudio, false)
	})
}

document.addEventListener("DOMContentLoaded", main, false)