diff --git a/js/functions.js b/js/functions.js index d42ce24..56b5311 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1,183 +1 @@ - -var log = function (message, level) { - level = level || "INFO"; - var time = moment().format("DD MMM HH:mm:ss"); - console.log(time + " [" + level.toUpperCase() + "] " + message); -}; - -log("Scripts loaded"); - -var staticLoaded = 0; -var jsonLoaded = 0; -var playerCount = 0; -var errorMsg = "Error loading content!"; - -var loadStatic = function (contentArray) { - for (var i = 0; i < contentArray.length; i++) { - getStatic(contentArray[i], contentArray.length); - } - setTimeout(function() { - log(staticLoaded + "/" + contentArray.length + " static items loaded"); - staticLoaded = 0; - }, 3000); -}; - -var getStatic = function (contentPath, totalLength) { - - var name = "#" + contentPath.replace("statics/", "").replace(".html", ""); - - // Async ajax request - $.get(contentPath, function (data) { - $(name).html(data); - staticLoaded += 1; - log("(STATIC " + staticLoaded + ") Loaded " + contentPath); - }) - - // Error handling - .error(function() { - log("Error loading " + contentPath + "!", "WARN"); - $(name).html(errorMsg); - }); - -}; - -var loadJson = function(jsonUrl, jsonContent) { - getJson(jsonUrl, function (data) { - if (data["usingCachedData"]) { - updateOnline(false); - } else { - updateOnline(true); - } - - updateJsonItems(data); - - // If items are missing, don't store in cache - if (jsonContent.length > data.length) { - log("JSON data incomplete, not storing in cache!", "WARN"); - return; - } - - $.cookies.set("jsondata", data, {expiresAt: moment().add('days', 15).toDate()}); - - log("Updated JSON data cache"); - - }, function (error) { - updateOnline(false); - - log("Error loading " + jsonUrl + "!", "WARN"); - - var data = $.cookies.get("jsondata"); - - // No cache - if (data == null) { - log("No cached JSON items found!", "WARN"); - - for (var i in jsonContent) { - $("#" + jsonContent[i]).html(errorMsg); - } - return; - } - - log("Loading JSON items from cache...", "WARN"); - - // Load from cache - updateJsonItems(data); - }); - - setTimeout(function() { - log(jsonLoaded + "/" + jsonContent.length + " JSON items loaded"); - jsonLoaded = 0; - }, 3000); -}; - -var getJson = function (url, successHandler, errorHandler) { // http://mathiasbynens.be/notes/xhr-responsetype-json - if (!url) { - return; - } - - successHandler = successHandler || function () {}; - errorHandler = errorHandler || function () {}; - - var xhr = typeof XMLHttpRequest != 'undefined' ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); - - xhr.open('get', url, true); - - xhr.onreadystatechange = function () { - var data; - - if (xhr.readyState != 4) { // 4 = done - return; - } - - if (xhr.status != 200) { - return; - } - - data = JSON.parse (xhr.responseText); - successHandler(data); - }; - - xhr.onerror = function () { - errorHandler(9001); - }; - - xhr.timeout = 2500; - xhr.ontimeout = function () { - errorHandler(9001); - }; - - xhr.send(); -}; - -var updateJsonItems = function (data) { - - for (var i in jsonContent) { - - var current = jsonContent[i]; - var names = data[current]; - - if (names == null || names.length == 0) { - log("Error loading " + current + "!", "WARN"); - $("#" + current).html(errorMsg); - continue; - } - - $("#" + current).html(parseArray(names, current)); - jsonLoaded += 1; - log("(JSON " + jsonLoaded + ") Loaded " + current); - } -}; - -var parseArray = function (array, type) { - var result = ""; - - if (type == "developers") { - for (var i in array) { - var append = " - "; - - if (array[i] == "Madgeek1450") { - append += "TFM Creator"; - } else if (array[i] == "DarthSalamon") { - append += "Lead Developer"; - } else { - append += "Developer"; - } - - result += "
  • " + array[i] + append + "
  • " - } - - } else { - for (var i in array) { - result += "
  • " + array[i] + "
  • " - } - } - return result; -}; - -var updateOnline = function(online) { - if(online) { - $('#status').html("The server is Online!"); - } else { - $('#status').html("The server is Offline :/"); - } -}; +var log=function(e,t){t=t||"INFO";var o=moment().format("DD MMM HH:mm:ss");console.log(o+" ["+t.toUpperCase()+"] "+e)};log("Scripts loaded");var staticLoaded=0,jsonLoaded=0,playerCount=0,errorMsg="Error loading content!",loadStatic=function(e){for(var t=0;te.length?void log("JSON data incomplete, not storing in cache!","WARN"):($.cookies.set("jsondata",e,{expiresAt:moment().add("days",15).toDate()}),void log("Updated JSON data cache"))},function(o){updateOnline(!1),log("Error loading "+e+"!","WARN");var n=$.cookies.get("jsondata");if(null!=n)log("Loading JSON items from cache...","WARN"),updateJsonItems(n);else{log("No cached JSON items found!","WARN");for(var a in t)$("#"+t[a]).html(errorMsg)}}),setTimeout(function(){log(jsonLoaded+"/"+t.length+" JSON items loaded"),jsonLoaded=0},3e3)},getJson=function(e,t,o){if(e){t=t||function(){},o=o||function(){};var n="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");n.open("get",e,!0),n.onreadystatechange=function(){var e;4==n.readyState&&200==n.status&&(e=JSON.parse(n.responseText),t(e))},n.onerror=function(){o(9001)},n.timeout=2500,n.ontimeout=function(){o(9001)},n.send()}},updateJsonItems=function(e){for(var t in jsonContent){var o=jsonContent[t],n=e[o];null!=n&&0!=n.length?($("#"+o).html(parseArray(n,o)),jsonLoaded+=1,log("(JSON "+jsonLoaded+") Loaded "+o)):(log("Error loading "+o+"!","WARN"),$("#"+o).html(errorMsg))}},parseArray=function(e,t){var o="";if("developers"==t)for(var n in e){var a=" - ";a+="Madgeek1450"==e[n]?"TFM Creator":"DarthSalamon"==e[n]?"Lead Developer":"Developer",o+='
  • '+e[n]+a+"
  • "}else for(var n in e)o+='
  • '+e[n]+"
  • ";return o},updateOnline=function(e){e?$("#status").html("The server is Online!"):$("#status").html("The server is Offline :/")}; \ No newline at end of file diff --git a/js/main.js b/js/main.js index 4c12eec..248030f 100644 --- a/js/main.js +++ b/js/main.js @@ -29,51 +29,4 @@ $(document).ready(function() { refresh(); }); -$(document).ready(function() { - var currentYear = (new Date).getFullYear(); - - $("#curYear").text((new Date).getFullYear()); -}); - -$(document).ready(function() { - $('.one').click(function() { - $('.a').fadeToggle(300); - $(".one i").toggleClass('fa-chevron-right', 1000); - $(".one i").toggleClass('fa-chevron-down', 1000); - }); - $('.two').click(function() { - $('.b').fadeToggle(300); - $(".two i").toggleClass('fa-chevron-right'); - $(".two i").toggleClass('fa-chevron-down'); - }); - $('.three').click(function() { - $('.c').fadeToggle(300); - $(".three i").toggleClass('fa-chevron-right'); - $(".three i").toggleClass('fa-chevron-down'); - }); - $('.four').click(function() { - $('.d').fadeToggle(300); - $(".four i").toggleClass('fa-chevron-right'); - $(".four i").toggleClass('fa-chevron-down'); - }); - $('.five').click(function() { - $('.e').fadeToggle(300); - $(".five i").toggleClass('fa-chevron-right'); - $(".five i").toggleClass('fa-chevron-down'); - }); - $('.six').click(function() { - $('.f').fadeToggle(300); - $(".six i").toggleClass('fa-chevron-right'); - $(".six i").toggleClass('fa-chevron-down'); - }); - $('.seven').click(function() { - $('.g').fadeToggle(300); - $(".seven i").toggleClass('fa-chevron-right'); - $(".seven i").toggleClass('fa-chevron-down'); - }); - $('.eight').click(function() { - $('.h').fadeToggle(300); - $(".eight i").toggleClass('fa-chevron-right'); - $(".eight i").toggleClass('fa-chevron-down'); - }); -}); \ No newline at end of file +$(document).ready(function(){(new Date).getFullYear();$("#curYear").text((new Date).getFullYear())}),$(document).ready(function(){$(".one").click(function(){$(".a").fadeToggle(300),$(".one i").toggleClass("fa-chevron-right",1e3),$(".one i").toggleClass("fa-chevron-down",1e3)}),$(".two").click(function(){$(".b").fadeToggle(300),$(".two i").toggleClass("fa-chevron-right"),$(".two i").toggleClass("fa-chevron-down")}),$(".three").click(function(){$(".c").fadeToggle(300),$(".three i").toggleClass("fa-chevron-right"),$(".three i").toggleClass("fa-chevron-down")}),$(".four").click(function(){$(".d").fadeToggle(300),$(".four i").toggleClass("fa-chevron-right"),$(".four i").toggleClass("fa-chevron-down")}),$(".five").click(function(){$(".e").fadeToggle(300),$(".five i").toggleClass("fa-chevron-right"),$(".five i").toggleClass("fa-chevron-down")}),$(".six").click(function(){$(".f").fadeToggle(300),$(".six i").toggleClass("fa-chevron-right"),$(".six i").toggleClass("fa-chevron-down")}),$(".seven").click(function(){$(".g").fadeToggle(300),$(".seven i").toggleClass("fa-chevron-right"),$(".seven i").toggleClass("fa-chevron-down")}),$(".eight").click(function(){$(".h").fadeToggle(300),$(".eight i").toggleClass("fa-chevron-right"),$(".eight i").toggleClass("fa-chevron-down")})}); \ No newline at end of file