'use strict';
/** Define UI specific stuff.
*/
var UI = (function () {
/** Resize the scrollable containers and make sure they are resized whenever
* the window is resized.
* Also introduce FastClick for faster clicking on mobile.
*/
$(function() {
FastClick.attach(document.body);
var offset = 0;
var h = $(window).height();
$('.scrollable').height(h - offset + 'px');
$(window).resize(function() {
var h = $(window).height();
$('.scrollable').height(h - offset + 'px');
});
});
/** Show a bootstrap modal with dynamic content. */
var showModal = function(title, text) {
var $modal = $('#infoBox');
$modal.find('#infoBoxLabel').html(title);
$modal.find('.modal-body').html(text);
$modal.modal({show: true});
};
var showUpdateValue = function(ident, num) {
if (num != 0) {
var formatted = Helpers.formatNumberPostfix(num);
var insert;
if (num > 0) {
insert = $("
';
alert += '';
alert += ' Your saved state out of date. Restart to use latest version of the game.';
alert += '
';
alert = $(alert);
alert.find('a').click(function ()
{
if (window.confirm('Do you really want to restart the game? All progress will be lost.')) {
ObjectStorage.clear();
window.location.reload(true);
}
})
$('#messages-container').append(alert);
}
}
if (typeof $.cookie('cookielaw') === 'undefined') {
var alert = '
';
alert += '';
alert += ' Particle Clicker uses local storage to store your current progress.';
alert += '
';
alert = $(alert);
alert.find('button').click(function ()
{
$.cookie('cookielaw', 'informed', { expires: 365 });
$('#cookielaw').slideUp(300, function() { $('#cookielaw').remove(); });
})
$('#messages-container').append(alert);
}
return {
showModal: showModal,
showUpdateValue: showUpdateValue,
validateVersion: validateVersion
}
})();
// I don't know what this is for, so I leave it here for the moment...
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document)
document.addEventListener("visibilitychange", onchange);
else if ((hidden = "mozHidden") in document)
document.addEventListener("mozvisibilitychange", onchange);
else if ((hidden = "webkitHidden") in document)
document.addEventListener("webkitvisibilitychange", onchange);
else if ((hidden = "msHidden") in document)
document.addEventListener("msvisibilitychange", onchange);
// IE 9 and lower:
else if ('onfocusin' in document)
document.onfocusin = document.onfocusout = onchange;
// All others:
else
window.onpageshow = window.onpagehide
= window.onfocus = window.onblur = onchange;
function onchange (evt) {
var v = 'visible', h = 'hidden',
evtMap = {
focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
};
evt = evt || window.event;
if (evt.type in evtMap)
detector.visible = evtMap[evt.type] == 'visible';
else
detector.visible = !this[hidden];
}
})();