generated from daviddarnes/component-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
is-playing.js
31 lines (26 loc) · 826 Bytes
/
is-playing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class IsPlaying extends HTMLElement {
static register(tagName) {
if ("customElements" in window) {
customElements.define(tagName || "is-playing", IsPlaying);
}
}
connectedCallback() {
this.players.forEach((player) => {
player.addEventListener("playing", (event) => this.playing(event.target));
player.addEventListener("pause", (event) => this.stopped(event.target));
player.addEventListener("ended", (event) => this.stopped(event.target));
});
}
playing(player) {
player.setAttribute("playing", "");
this.setAttribute("playing", player.getAttribute("id") || "");
}
stopped(player) {
player.removeAttribute("playing");
this.removeAttribute("playing");
}
get players() {
return this.querySelectorAll("audio, video");
}
}
IsPlaying.register();