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

125 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-10-30 09:30:16 -07:00
define(['appSettings', 'backdrop', 'browser', 'globalize', 'require', 'paper-icon-button-light'], function (appSettings, backdrop, browser, globalize, require) {
'use strict';
2015-10-12 23:31:20 -07:00
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) {
2016-10-18 23:27:02 -07:00
if (appSettings.get(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
2016-10-18 23:27:02 -07:00
if (!browser.mobile) {
2015-10-25 22:29:32 -07:00
2016-10-30 09:30:16 -07:00
require(['css!./style.css']);
2015-10-25 22:29:32 -07:00
if (!page.classList.contains('itemDetailPage')) {
2016-10-18 23:27:02 -07:00
backdrop.setBackdrop('themes/halloween/bg.jpg');
2015-10-25 22:29:32 -07:00
}
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');
}
2016-10-30 09:30:16 -07:00
addIcon();
}
2015-10-25 22:29:32 -07:00
}
}
function addIcon() {
if (iconCreated) {
return;
}
iconCreated = true;
var viewMenuSecondary = document.querySelector('.viewMenuSecondary');
if (viewMenuSecondary) {
2015-10-12 23:31:20 -07:00
2016-10-18 23:27:02 -07:00
var html = '<button is="paper-icon-button-light" class="halloweenInfoButton"><i class="md-icon">info</i></button>';
2015-10-25 22:29:32 -07:00
2016-10-18 23:27:02 -07:00
viewMenuSecondary.insertAdjacentHTML('afterbegin', html);
2015-10-25 22:29:32 -07:00
2016-10-18 23:27:02 -07:00
viewMenuSecondary.querySelector('.halloweenInfoButton').addEventListener('click', onIconClick);
}
}
2015-10-25 22:29:32 -07:00
2016-10-18 23:27:02 -07:00
function onIconClick() {
2015-12-14 08:43:03 -07:00
2016-10-18 23:27:02 -07:00
require(['dialog'], function (dialog) {
dialog({
title: "Happy Halloween",
text: "Happy Halloween from the Emby Team. We hope your Halloween is spooktacular! Would you like to allow the Halloween theme to continue?",
buttons: [
{
id: 'yes',
name: globalize.translate('ButtonYes'),
type: 'submit'
},
{
id: 'no',
name: globalize.translate('ButtonNo'),
type: 'cancel'
}
]
}).then(function (result) {
if (result == 'no') {
destroyTheme();
}
});
});
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();
}
2016-10-18 23:27:02 -07:00
backdrop.clear();
appSettings.set(cancelKey, cancelValue);
2016-10-30 09:30:16 -07:00
window.location.reload(true);
2015-10-25 22:29:32 -07:00
}
2015-10-12 23:31:20 -07:00
pageClassOn('pageshow', "libraryPage", onPageShow);
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();
});
}
2016-10-18 23:27:02 -07:00
});