@farberg/reveal-template 1.0.57 → 1.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,36 +1,60 @@
|
|
|
1
|
+
function initSlide(slide) {
|
|
2
|
+
let players = []
|
|
3
|
+
|
|
4
|
+
let asciinemaElements = slide.getElementsByTagName("asciinema")
|
|
5
|
+
|
|
6
|
+
for (let el of asciinemaElements) {
|
|
7
|
+
console.log("Found asciinema element: ", el)
|
|
8
|
+
|
|
9
|
+
//Make element invisible
|
|
10
|
+
el.style.display = "none"
|
|
11
|
+
|
|
12
|
+
//Create player
|
|
13
|
+
const source = el.getAttribute('src')
|
|
14
|
+
const conf = el.getAttribute('data-conf')
|
|
15
|
+
const div = document.createElement('div')
|
|
16
|
+
|
|
17
|
+
div.setAttribute('data-farberg-asciinema', 'true')
|
|
18
|
+
|
|
19
|
+
console.log("Playing", source, "with options", conf)
|
|
20
|
+
players.push(AsciinemaPlayer.create(source, div, JSON.parse(conf)))
|
|
21
|
+
|
|
22
|
+
el.parentNode.insertBefore(div, el.nextSibling)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return players
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function destroyPlayer(slide, players) {
|
|
29
|
+
//remove elements from dom with attribute data-farberg-asciinema
|
|
30
|
+
let elementsToRemove = slide.querySelectorAll('[data-farberg-asciinema]')
|
|
31
|
+
console.log("Removing", elementsToRemove.length, "elements with attribute data-farberg-asciinema")
|
|
32
|
+
|
|
33
|
+
for (let el of elementsToRemove)
|
|
34
|
+
el.parentNode.removeChild(el)
|
|
35
|
+
|
|
36
|
+
//destroy players
|
|
37
|
+
console.log("Destroying", players.length, "players")
|
|
38
|
+
players.forEach(player => player.dispose())
|
|
39
|
+
}
|
|
1
40
|
|
|
2
41
|
export default () => {
|
|
3
42
|
|
|
4
43
|
return {
|
|
5
44
|
id: 'asciinema',
|
|
6
45
|
init: (deck) => {
|
|
7
|
-
|
|
8
46
|
deck.on('ready', () => {
|
|
47
|
+
let currentPlayers = undefined
|
|
9
48
|
|
|
10
|
-
deck.
|
|
11
|
-
|
|
12
|
-
// Workaround to get elements into an array before they are replaced
|
|
13
|
-
const els = []
|
|
14
|
-
for (let el of deck.getRevealElement().getElementsByTagName("asciinema")) {
|
|
15
|
-
els.push(el)
|
|
16
|
-
}
|
|
49
|
+
currentPlayers = initSlide(deck.getCurrentSlide())
|
|
17
50
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const conf = el.getAttribute('data-conf')
|
|
22
|
-
const div = document.createElement('div')
|
|
23
|
-
|
|
24
|
-
el.parentElement.replaceChild(div, el)
|
|
51
|
+
deck.addEventListener('slidechanged', function (event) {
|
|
52
|
+
if (event.previousSlide)
|
|
53
|
+
destroyPlayer(event.previousSlide, currentPlayers)
|
|
25
54
|
|
|
26
|
-
|
|
27
|
-
console.log(AsciinemaPlayer.create(source, div, JSON.parse(conf)));
|
|
28
|
-
}
|
|
55
|
+
currentPlayers = initSlide(event.currentSlide)
|
|
29
56
|
})
|
|
30
|
-
|
|
31
|
-
|
|
32
57
|
})
|
|
33
|
-
|
|
34
58
|
}
|
|
35
59
|
}
|
|
36
60
|
}
|