"use strict";
// $Id$
var fd_loadedHash={}, fd_loadedList=[], fd_all={}, fd_allCnt, fd_progress=0,
fd_lang, fd_offsets=[], fd_scrolled=0, fd_modLinks={}, csrfToken="X",
fd_mode = "FHEM";
var fd_otherSrc = { "usb":"autocreate", "createlog":"autocreate" };
function
fd_status(txt)
{
var errmsg = $("#errmsg");
if(!$(errmsg).length) {
$('#menu').append('');
errmsg = $("#errmsg");
}
if(txt == "")
$(errmsg).remove();
else
$(errmsg).html(txt);
}
function
fd_fC(fn, callback)
{
console.log("fd_fC:"+fn);
if(fd_mode == "FHEM") {
var p = location.pathname;
var cmd = p.substr(0,p.indexOf('/doc'))+'?cmd='+fn+csrfToken+'&XHR=1';
$.ajax({
url:cmd, method:'POST', cache:false, success:callback,
error:function(xhr, status, err) {
if(xhr.status == 400 && csrfToken) {
csrfToken = "";
fd_csrfRefresh(function(){fd_fC(fn, callback)});
} else {
console.log("FAIL ERR:"+xhr.status+" STAT:"+status);
}
}
});
} else { // static
$.ajax({
url:fn, method:'GET',
success:function(ret) {
callback(''+ret+'');
},
error:function(xhr, status, err) {
callback("");
console.log("FAIL ERR:"+xhr.status+" STAT:"+status);
fd_status("Cannot load "+fn);
setTimeout(function(){ fd_status("") }, 5000);
}
});
}
}
// Dynamically load the codumentation of one module.
var inLoadOneDoc = false;
function
loadOneDoc(mname, lang)
{
var origLink = mname;
if(inLoadOneDoc)
return;
function
done(err, calc)
{
if(fd_progress) {
fd_status(fd_progress+" / "+fd_allCnt);
if(++fd_progress > fd_allCnt) {
fd_progress = 0;
setTimeout(calcOffsets,100); // Firefox returns wrong offsets
fd_status("");
}
} else {
if(calc)
setTimeout(calcOffsets,100);
inLoadOneDoc = true; // avoid the hashchange callback
setTimeout(function(){ location.href = "#"+origLink; }, 100);
// takes long if the complete doc is loaded
setTimeout(function(){ inLoadOneDoc = false; }, 2000);
}
}
if(fd_modLinks[mname])
mname = fd_modLinks[mname];
if(fd_loadedHash[mname] && fd_loadedHash[mname] == lang)
return done(false, false);
fd_fC(fd_mode=="FHEM" ? "help "+mname+" "+lang :
"/cref"+(lang=="EN" ? "":"_"+lang)+"/"+mname+".cref",
function(ret){
if(ret.indexOf("") != 0 || ret.indexOf("No help found") == 0)
return done(true, false);
ret = ret.replace(/<\/?html>/g,'');
ret = ret.replace(/Keine deutsche Hilfe gefunden!
/,'');
ret = '