convert title to typescript
This commit is contained in:
parent
f6f88cad96
commit
bd5aebb171
|
@ -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
53
ui/round2/src/title.ts
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue