-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmall-player-controls.plugin.js
63 lines (52 loc) · 2.28 KB
/
small-player-controls.plugin.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function wikiaJWPlayerSmallPlayerControls(player, config, div) {
this.player = player;
this.container = div;
this.config = config;
this.muteIcon = createSVG(wikiaJWPlayerIcons.volumeOff);
this.playIcon = createSVG(wikiaJWPlayerIcons.play);
this.pauseIcon = createSVG(wikiaJWPlayerIcons.pause);
this.container.classList.add('wikia-jw-small-player-controls-plugin');
this.wikiaControlsElement = document.createElement('div');
this.wikiaControlsElement.appendChild(this.muteIcon);
this.wikiaControlsElement.appendChild(this.pauseIcon);
this.unmuteHandler = this.unmuteHandler.bind(this);
this.playHandler = this.playHandler.bind(this);
this.pauseHandler = this.pauseHandler.bind(this);
this.readyHandler = this.readyHandler.bind(this);
this.resizeHandler = this.resizeHandler.bind(this);
this.container.addEventListener('click', this.unmuteHandler);
this.pauseIcon.addEventListener('click', this.pauseHandler);
this.playIcon.addEventListener('click', this.playHandler);
this.player.on('resize', this.resizeHandler);
this.player.on('ready', this.readyHandler);
}
wikiaJWPlayerSmallPlayerControls.prototype.readyHandler = function () {
if (this.player.getWidth() <= 250) {
this.player.getContainer().classList.add('wikia-jw-small-player-controls');
this.container.appendChild(this.wikiaControlsElement);
}
};
// If click target is on play/pause button, don't unmute.
wikiaJWPlayerSmallPlayerControls.prototype.unmuteHandler = function (event) {
if (event.currentTarget.contains(event.target)) {
this.player.setMute(false);
}
};
wikiaJWPlayerSmallPlayerControls.prototype.pauseHandler = function () {
var icon = this.container.firstChild.childNodes[1];
icon.parentNode.replaceChild(this.playIcon, icon);
this.player.pause();
};
wikiaJWPlayerSmallPlayerControls.prototype.playHandler = function () {
var icon = this.container.firstChild.childNodes[1];
icon.parentNode.replaceChild(this.pauseIcon, icon);
this.player.play();
};
wikiaJWPlayerSmallPlayerControls.prototype.resizeHandler = function (playerDimensions) {
if (playerDimensions.width > 250) {
this.player.getContainer().classList.remove('wikia-jw-small-player-controls');
}
};
wikiaJWPlayerSmallPlayerControls.register = function () {
jwplayer().registerPlugin('smallPlayerControls', '8.0.0', wikiaJWPlayerSmallPlayerControls);
};