67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
function getE(name){
|
|
return document.getElementById(name);
|
|
}
|
|
|
|
function escapeHTML(str) {
|
|
return str
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/\"/g, '"')
|
|
.replace(/\'/g, ''')
|
|
.replace(/\//g, '/')
|
|
}
|
|
|
|
function showMessage(msg, closeAfter){
|
|
var errorE = getE("error");
|
|
errorE.innerHTML = msg;
|
|
|
|
errorE.classList.remove('hide');
|
|
errorE.classList.add('show');
|
|
|
|
if(closeAfter !== undefined){
|
|
setTimeout(function(){
|
|
errorE.innerHTML = "";
|
|
errorE.classList.remove('show');
|
|
errorE.classList.add('hide');
|
|
},closeAfter);
|
|
}
|
|
}
|
|
|
|
|
|
function getResponse(adr, callback, timeoutCallback, timeout, method){
|
|
|
|
if(timeoutCallback === undefined) {
|
|
timeoutCallback = function(){
|
|
showMessage(_("Timeout loading") +" "+adr);
|
|
};
|
|
}
|
|
if(timeout === undefined) timeout = 8000;
|
|
if(method === undefined) method = "GET";
|
|
var xmlhttp = new XMLHttpRequest();
|
|
xmlhttp.onreadystatechange = function() {
|
|
if(xmlhttp.readyState == 4){
|
|
if(xmlhttp.status == 200){
|
|
callback(xmlhttp.responseText);
|
|
}
|
|
else timeoutCallback();
|
|
}
|
|
};
|
|
xmlhttp.open(method, adr, true);
|
|
xmlhttp.send();
|
|
xmlhttp.timeout = timeout;
|
|
xmlhttp.ontimeout = timeoutCallback;
|
|
|
|
xmlhttp.onabort = function(e) {
|
|
showMessage(_("ABORT")+" "+adr);
|
|
};
|
|
xmlhttp.onerror = function(e) {
|
|
showMessage(_("ERROR loading")+" "+adr +" :: "+ this.statusText);
|
|
};
|
|
|
|
}
|
|
|
|
function _(l10nid) {
|
|
return l10n.jsStrings[l10nid];
|
|
}
|