jellyfin-web/dashboard-ui/themes/halloween/theme.js

118 lines
3.1 KiB
JavaScript
Raw Normal View History

2015-10-12 23:31:20 -07:00
(function () {
2015-10-14 10:52:49 -07:00
var lastSound = 0;
2015-10-25 22:29:32 -07:00
var iconCreated;
var destroyed;
var currentSound;
2015-10-26 09:21:00 -07:00
var cancelKey = 'cancelHalloween2015';
var cancelValue = '6';
2015-10-12 23:31:20 -07:00
function onPageShow() {
var page = this;
2015-10-25 22:29:32 -07:00
if (!destroyed) {
if (appStorage.getItem(cancelKey) == cancelValue) {
2015-10-14 15:35:32 -07:00
2015-10-25 22:29:32 -07:00
destroyed = true;
return;
2015-10-14 15:35:32 -07:00
}
2015-10-14 10:52:49 -07:00
2015-11-30 10:21:52 -07:00
require(['css!themes/halloween/style.css']);
2015-10-25 22:29:32 -07:00
2015-11-28 13:48:35 -07:00
if (!browserInfo.mobile) {
2015-10-25 22:29:32 -07:00
if (!page.classList.contains('itemDetailPage')) {
Backdrops.setBackdropUrl(page, 'themes/halloween/bg.jpg');
}
if (lastSound == 0) {
playSound('http://github.com/MediaBrowser/Emby.Resources/raw/master/themes/halloween/monsterparadefade.mp3', .1);
} else if ((new Date().getTime() - lastSound) > 30000) {
playSound('http://github.com/MediaBrowser/Emby.Resources/raw/master/themes/halloween/howl.wav');
}
2015-10-14 15:35:32 -07:00
}
2015-10-25 22:29:32 -07:00
addIcon();
}
}
function addIcon() {
if (iconCreated) {
return;
}
iconCreated = true;
var elem = document.createElement('paper-icon-button');
elem.icon = 'info';
elem.classList.add('halloweenInfoButton');
$(elem).on('click', onIconClick);
var viewMenuSecondary = document.querySelector('.viewMenuSecondary');
if (viewMenuSecondary) {
viewMenuSecondary.insertBefore(elem, viewMenuSecondary.childNodes[0]);
2015-10-14 10:52:49 -07:00
}
2015-10-12 23:31:20 -07:00
}
2015-10-25 22:29:32 -07:00
function onIconClick() {
2015-12-04 12:58:30 -07:00
require(['dialog'], function (dialog) {
dialog({
2015-10-25 22:29:32 -07:00
2015-12-04 12:58:30 -07:00
title: "Happy Halloween",
message: "Happy Halloween from the Emby Team. We hope your Halloween is spooktacular! Would you like to allow the Halloween theme to continue?",
callback: function (result) {
2015-10-25 22:29:32 -07:00
2015-12-04 12:58:30 -07:00
if (result == 1) {
destroyTheme();
}
},
2015-10-25 22:29:32 -07:00
2015-12-04 12:58:30 -07:00
buttons: [Globalize.translate('ButtonYes'), Globalize.translate('ButtonNo')]
});
2015-10-25 22:29:32 -07:00
});
}
function destroyTheme() {
destroyed = true;
var halloweenInfoButton = document.querySelector('.halloweenInfoButton');
if (halloweenInfoButton) {
halloweenInfoButton.parentNode.removeChild(halloweenInfoButton);
}
if (currentSound) {
currentSound.stop();
}
Dashboard.removeStylesheet('themes/halloween/style.css');
Backdrops.clear();
appStorage.setItem(cancelKey, cancelValue);
}
2015-10-12 23:31:20 -07:00
pageClassOn('pageshow', "libraryPage", onPageShow);
if ($($.mobile.activePage)[0].classList.contains('libraryPage')) {
onPageShow.call($($.mobile.activePage)[0]);
}
2015-10-14 10:52:49 -07:00
function playSound(path, volume) {
require(['howler'], function (howler) {
var sound = new Howl({
urls: [path],
volume: volume || .3
});
sound.play();
2015-10-25 22:29:32 -07:00
currentSound = sound;
2015-10-14 10:52:49 -07:00
lastSound = new Date().getTime();
});
}
2015-10-12 23:31:20 -07:00
})();