-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (35 loc) · 1.14 KB
/
index.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
var eventlistener = require('eventlistener');
function wallpaperPlugin (gardrPluginApi, options) {
gardrPluginApi.on('item:afterrender', onBannerRendered);
}
function onBannerRendered (item) {
if (item.rendered.wallpaperimage) {
createWallpaperByUrl(item.rendered.wallpaperimage, item.rendered.wallpapertiling, item.rendered.wallpapercolor);
if (item.rendered.wallpaperclick) {
listenToBodyClicks(item.rendered.wallpaperclick);
}
}
else if (item.rendered.wallpapercolor) {
createWallpaperByColor(item.rendered.wallpapercolor);
}
}
function createWallpaperByUrl (url, tiling, color) {
var repeat = (tiling === 'yes' || tiling === 'true') ? 'repeat' : 'no-repeat';
var css = 'url(' + url + ') 50% 0% ' + repeat + ' fixed ' + (color || '');
setBodyBackground(css);
}
function listenToBodyClicks (url) {
var body = document.body;
eventlistener.add(body, 'click', function (e) {
if (e.target === body) {
window.open(url, '_blank');
}
});
}
function createWallpaperByColor (color) {
setBodyBackground(color);
}
function setBodyBackground (background) {
document.body.style.background = background;
}
module.exports = wallpaperPlugin;