Minfied Code

This commit is contained in:
aggelosQQ 2016-09-29 13:19:57 +03:00
parent b9b79dd89d
commit 228bba1197
2 changed files with 2 additions and 231 deletions

View file

@ -1,183 +1 @@
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;t<e.length;t++)getStatic(e[t],e.length);setTimeout(function(){log(staticLoaded+"/"+e.length+" static items loaded"),staticLoaded=0},3e3)},getStatic=function(e,t){var o="#"+e.replace("statics/","").replace(".html","");$.get(e,function(t){$(o).html(t),staticLoaded+=1,log("(STATIC "+staticLoaded+") Loaded "+e)}).error(function(){log("Error loading "+e+"!","WARN"),$(o).html(errorMsg)})},loadJson=function(e,t){getJson(e,function(e){return updateOnline(e.usingCachedData?!1:!0),updateJsonItems(e),t.length>e.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+='<a href="#"><li>'+e[n]+a+"</li></a>"}else for(var n in e)o+='<a href="#"><li>'+e[n]+"</li></a>";return o},updateOnline=function(e){e?$("#status").html("The server is <font color='Green'>Online</font>!"):$("#status").html("The server is <font color='Red'>Offline</font> :/")};
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 += "<a href=\"#\"><li>" + array[i] + append + "</li></a>"
}
} else {
for (var i in array) {
result += "<a href=\"#\"><li>" + array[i] + "</li></a>"
}
}
return result;
};
var updateOnline = function(online) {
if(online) {
$('#status').html("The server is <font color='Green'>Online</font>!");
} else {
$('#status').html("The server is <font color='Red'>Offline</font> :/");
}
};

View file

@ -29,51 +29,4 @@ $(document).ready(function() {
refresh(); refresh();
}); });
$(document).ready(function() { $(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")})});
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');
});
});