convert title to typescript

This commit is contained in:
Niklas Fiekas 2017-05-19 11:15:18 +02:00
parent f6f88cad96
commit bd5aebb171
2 changed files with 53 additions and 52 deletions

View file

@ -1,52 +0,0 @@
var game = require('game').game;
var status = require('game').status;
var initialTitle = document.title;
var curFaviconIdx = 0;
var F = [
'/assets/images/favicon-32-white.png',
'/assets/images/favicon-32-black.png'
].map(function(path, i) {
return function() {
if (curFaviconIdx !== i) {
document.getElementById('favicon').href = path;
curFaviconIdx = i;
}
};
});
var tickerTimer = undefined;
function resetTicker() {
tickerTimer = clearTimeout(tickerTimer);
F[0]();
}
function startTicker() {
function tick() {
if (!document.hasFocus()) {
F[1 - curFaviconIdx]();
tickerTimer = setTimeout(tick, 1000);
}
}
if (!tickerTimer) tickerTimer = setTimeout(tick, 200);
};
module.exports = {
init: function(ctrl) { window.addEventListener('focus', resetTicker); },
set: function(ctrl, text) {
if (ctrl.data.player.spectator) return;
if (!text) {
if (status.finished(ctrl.data)) {
text = ctrl.trans('gameOver');
} else if (game.isPlayerTurn(ctrl.data)) {
text = ctrl.trans('yourTurn');
if (!document.hasFocus()) startTicker();
} else {
text = ctrl.trans('waitingForOpponent');
resetTicker();
}
}
document.title = text + " - " + initialTitle;
}
};

53
ui/round2/src/title.ts Normal file
View file

@ -0,0 +1,53 @@
import { game, status } from 'game';
const initialTitle = document.title;
var curFaviconIdx = 0;
const F = [
'/assets/images/favicon-32-white.png',
'/assets/images/favicon-32-black.png'
].map(function(path, i) {
return function() {
if (curFaviconIdx !== i) {
const favicon = document.getElementById('favicon') as HTMLAnchorElement;
favicon.href = path;
curFaviconIdx = i;
}
};
});
var tickerTimer;
function resetTicker() {
tickerTimer = clearTimeout(tickerTimer);
F[0]();
}
function startTicker() {
function tick() {
if (!document.hasFocus()) {
F[1 - curFaviconIdx]();
tickerTimer = setTimeout(tick, 1000);
}
}
if (!tickerTimer) tickerTimer = setTimeout(tick, 200);
}
export function init() {
window.addEventListener('focus', resetTicker);
}
export function set(ctrl, text) {
if (ctrl.data.player.spectator) return;
if (!text) {
if (status.finished(ctrl.data)) {
text = ctrl.trans('gameOver');
} else if (game.isPlayerTurn(ctrl.data)) {
text = ctrl.trans('yourTurn');
if (!document.hasFocus()) startTicker();
} else {
text = ctrl.trans('waitingForOpponent');
resetTicker();
}
}
document.title = text + " - " + initialTitle;
}