-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatermark.plugin.js
53 lines (44 loc) · 1.61 KB
/
watermark.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
function WikiaJWPlayerWatermarkPlugin(player, config, div) {
this.player = player;
this.container = div;
this.config = config;
this.watermarkElement = this.getWatermarkElement();
this.watermarkElement.addEventListener('click', function () {
player.trigger('watermarkClicked');
});
this.container.classList.add('wikia-watermark-container');
this.container.appendChild(this.watermarkElement);
this.isEnabled = !!this.player.getPlaylistItem(0).watermark;
this.player.on('play', this.update.bind(this));
this.player.on('pause', this.update.bind(this));
this.player.on('idle', this.update.bind(this));
this.player.on('relatedVideoPlay', this.onVideoChange.bind(this));
}
/**
* prepares watermark link with icon
*/
WikiaJWPlayerWatermarkPlugin.prototype.getWatermarkElement = function () {
var watermarkImage = wikiaJWPlayerIcons['fandomLogo'];
var watermarkElement = document.createElement('a');
watermarkElement.classList.add('wikia-watermark');
watermarkElement.innerHTML = watermarkImage;
watermarkElement.href = 'https://fandom.com';
return watermarkElement;
};
WikiaJWPlayerWatermarkPlugin.prototype.update = function () {
if (this.isEnabled && this.player.getState() === 'playing') {
this.container.style.display = 'block';
} else {
this.container.style.display = '';
}
};
/**
* hides the entire plugin (button and settings menu)
*/
WikiaJWPlayerWatermarkPlugin.prototype.onVideoChange = function (data) {
this.isEnabled = !!data.item.watermark;
this.update();
};
WikiaJWPlayerWatermarkPlugin.register = function () {
jwplayer().registerPlugin('wikiaWatermark', '8.0.0', WikiaJWPlayerWatermarkPlugin);
};