'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 resize = function() { var h = $(window).height(); var offset = 111; if ($(window).width() < 992) { offset = 112; } $('.scrollable').height(h - offset + 'px'); var types = ['research', 'hr', 'upgrades']; if ($(window).width() < 992) { for (var i = 0; i < types.length; i++) { if ($('#' + types[i] + 'Content').parent().attr('id') == types[i] + 'Large') { $('#' + types[i] + 'Content').detach().appendTo('#' + types[i]); } } } else { for (var i = 0; i < types.length; i++) { if ($('#' + types[i] + 'Content').parent().attr('id') != types[i] + 'Large') { $('#' + types[i] + 'Content').detach().appendTo('#' + types[i] + 'Large'); } } } if ($(window).width() < 600) { var newWidth = Math.max($(window).width() - ($(window).height() - 90 + 10), 300); $('#column-lab').width($(window).width() - newWidth); $('#column-tabs').width(newWidth); } else { $('#column-lab').removeAttr('style'); $('#column-tabs').removeAttr('style'); } if ($(window).width() >= 1200) { if (detector.width != 500) { $('#detector').width(500).height(500); detector.init(500); } } else if ($(window).width() < 768 && $(window).height() - 90 < 300) { var newWidth = $(window).width() - Math.max($(window).width() - ($(window).height() - 90 + 10), 300) - 10; if (detector.width != newWidth) { $('#detector').width(newWidth).height(newWidth); detector.init(newWidth); } } else if ($(window).width() < 992) { if (detector.width != 300) { $('#detector').width(300).height(300); detector.init(300); } } else { if (detector.width != 400) { $('#detector').width(400).height(400); detector.init(400); } } } $(window).resize(resize); resize(); }); /** Show a bootstrap modal with dynamic content. */ var showModal = function(title, text, level) { var $modal = $('#infoBox'); $modal.find('#infoBoxLabel').html(title); $modal.find('.modal-body').html(text); $modal.modal({show: true}); }; /** Display only the elements with data-min-level above a certain * threshold. */ var showLevels = function(level) { $('#infoBox').find('[data-min-level]').each(function() { if (level >= $(this).data('min-level')) { $(this).show(); } else { $(this).hide(); } }); }; var showUpdateValue = function(ident, num) { if (num != 0) { var formatted = Helpers.formatNumberPostfix(num); var insert; if (num > 0) { insert = $("
") .attr("class", "update-plus") .html("+" + formatted); } else { insert = $("") .attr("class", "update-minus") .html(formatted); } showUpdate(ident, insert); } } var showUpdate = function(ident, insert) { var elem = $(ident); elem.append(insert); insert.animate({ "bottom":"+=30px", "opacity": 0 }, { duration: 500, complete: function() { $(this).remove(); }}); } var showAchievement = function(obj) { var alert = '