mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
fhemdoc_modular.js: first version of the static/modular commandref (Forum #87975)
git-svn-id: https://svn.fhem.de/fhem/trunk@16785 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
74260d7b51
commit
8e2c1db0b8
@ -100,7 +100,7 @@ for my $lang (@lang) {
|
|||||||
$cmdref = "docs/commandref_frame${sfx}.html";
|
$cmdref = "docs/commandref_frame${sfx}.html";
|
||||||
open(IN, $cmdref) || die("Cant open $cmdref: $!\n");
|
open(IN, $cmdref) || die("Cant open $cmdref: $!\n");
|
||||||
|
|
||||||
$cmdref = ">docs/commandref${sfx}.html";
|
$cmdref = ">docs/commandref_modular${sfx}.html";
|
||||||
open(OUT, $cmdref) || die("Cant open $cmdref: $!\n");
|
open(OUT, $cmdref) || die("Cant open $cmdref: $!\n");
|
||||||
|
|
||||||
my $linkDumped = 0;
|
my $linkDumped = 0;
|
||||||
@ -110,7 +110,7 @@ for my $lang (@lang) {
|
|||||||
if($l =~ m,\s*<title>,) {
|
if($l =~ m,\s*<title>,) {
|
||||||
print OUT << 'EOF'
|
print OUT << 'EOF'
|
||||||
<script type="text/javascript" src="../pgm2/jquery.min.js"></script>
|
<script type="text/javascript" src="../pgm2/jquery.min.js"></script>
|
||||||
<script type="text/javascript" src="../pgm2/fhemdoc_static.js"></script>
|
<script type="text/javascript" src="../pgm2/fhemdoc_modular.js"></script>
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
var fd_loadedHash={}, fd_loadedList=[], fd_all={}, fd_allCnt, fd_progress=0,
|
var fd_loadedHash={}, fd_loadedList=[], fd_all={}, fd_allCnt, fd_progress=0,
|
||||||
fd_lang, fd_offsets=[], fd_scrolled=0, fd_modLinks={}, csrfToken="X";
|
fd_lang, fd_offsets=[], fd_scrolled=0, fd_modLinks={}, csrfToken="X",
|
||||||
|
fd_mode = "FHEM";
|
||||||
|
var fd_otherSrc = { "usb":"autocreate", "createlog":"autocreate" };
|
||||||
|
|
||||||
|
|
||||||
function
|
function
|
||||||
@ -10,7 +12,8 @@ fd_status(txt)
|
|||||||
{
|
{
|
||||||
var errmsg = $("#errmsg");
|
var errmsg = $("#errmsg");
|
||||||
if(!$(errmsg).length) {
|
if(!$(errmsg).length) {
|
||||||
$('#menuScrollArea').append('<div id="errmsg">');
|
$('#menu').append('<a style="display:block; padding-top:2em" '+
|
||||||
|
'id="errmsg" href="#"></a>');
|
||||||
errmsg = $("#errmsg");
|
errmsg = $("#errmsg");
|
||||||
}
|
}
|
||||||
if(txt == "")
|
if(txt == "")
|
||||||
@ -23,6 +26,8 @@ function
|
|||||||
fd_fC(fn, callback)
|
fd_fC(fn, callback)
|
||||||
{
|
{
|
||||||
console.log("fd_fC:"+fn);
|
console.log("fd_fC:"+fn);
|
||||||
|
|
||||||
|
if(fd_mode == "FHEM") {
|
||||||
var p = location.pathname;
|
var p = location.pathname;
|
||||||
var cmd = p.substr(0,p.indexOf('/doc'))+'?cmd='+fn+csrfToken+'&XHR=1';
|
var cmd = p.substr(0,p.indexOf('/doc'))+'?cmd='+fn+csrfToken+'&XHR=1';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -36,12 +41,31 @@ fd_fC(fn, callback)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else { // static
|
||||||
|
$.ajax({
|
||||||
|
url:fn, method:'GET',
|
||||||
|
success:function(ret) {
|
||||||
|
callback('<html>'+ret+'</html>');
|
||||||
|
},
|
||||||
|
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
|
function
|
||||||
loadOneDoc(mname, lang)
|
loadOneDoc(mname, lang)
|
||||||
{
|
{
|
||||||
var origLink = mname;
|
var origLink = mname;
|
||||||
|
if(inLoadOneDoc)
|
||||||
|
return;
|
||||||
|
|
||||||
function
|
function
|
||||||
done(err, calc)
|
done(err, calc)
|
||||||
@ -56,8 +80,12 @@ loadOneDoc(mname, lang)
|
|||||||
} else {
|
} else {
|
||||||
if(calc)
|
if(calc)
|
||||||
setTimeout(calcOffsets,100);
|
setTimeout(calcOffsets,100);
|
||||||
if(!err)
|
|
||||||
|
inLoadOneDoc = true; // avoid the hashchange callback
|
||||||
setTimeout(function(){ location.href = "#"+origLink; }, 100);
|
setTimeout(function(){ location.href = "#"+origLink; }, 100);
|
||||||
|
|
||||||
|
// takes long if the complete doc is loaded
|
||||||
|
setTimeout(function(){ inLoadOneDoc = false; }, 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +94,9 @@ loadOneDoc(mname, lang)
|
|||||||
if(fd_loadedHash[mname] && fd_loadedHash[mname] == lang)
|
if(fd_loadedHash[mname] && fd_loadedHash[mname] == lang)
|
||||||
return done(false, false);
|
return done(false, false);
|
||||||
|
|
||||||
fd_fC("help "+mname+" "+lang, function(ret){
|
fd_fC(fd_mode=="FHEM" ? "help "+mname+" "+langC :
|
||||||
//console.log(mname+" "+lang+" => "+ret.length);
|
"/cref"+(lang=="EN" ? "":"_"+lang)+"/"+mname+".cref",
|
||||||
|
function(ret){
|
||||||
if(ret.indexOf("<html>") != 0 || ret.indexOf("<html>No help found") == 0)
|
if(ret.indexOf("<html>") != 0 || ret.indexOf("<html>No help found") == 0)
|
||||||
return done(true, false);
|
return done(true, false);
|
||||||
ret = ret.replace(/<\/?html>/g,'');
|
ret = ret.replace(/<\/?html>/g,'');
|
||||||
@ -96,6 +125,7 @@ loadOneDoc(mname, lang)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a hook for each <a> tag to load & scroll to the corresponding item
|
||||||
function
|
function
|
||||||
addAHooks(el)
|
addAHooks(el)
|
||||||
{
|
{
|
||||||
@ -113,6 +143,8 @@ addAHooks(el)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remember the offset of all loaded elements, to be able to dynamically show
|
||||||
|
// the correct "load <XXX> in other language" link
|
||||||
function
|
function
|
||||||
calcOffsets()
|
calcOffsets()
|
||||||
{
|
{
|
||||||
@ -124,6 +156,7 @@ calcOffsets()
|
|||||||
checkScroll();
|
checkScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show the correct otherLang, see calcOffsets
|
||||||
function
|
function
|
||||||
checkScroll()
|
checkScroll()
|
||||||
{
|
{
|
||||||
@ -153,6 +186,7 @@ checkScroll()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load the current entry in the other langueage
|
||||||
function
|
function
|
||||||
loadOtherLang()
|
loadOtherLang()
|
||||||
{
|
{
|
||||||
@ -160,9 +194,12 @@ loadOtherLang()
|
|||||||
loadOneDoc(mname, fd_loadedHash[mname]=="EN" ? "DE" : "EN");
|
loadOneDoc(mname, fd_loadedHash[mname]=="EN" ? "DE" : "EN");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the current csrf from FHEMWEB
|
||||||
function
|
function
|
||||||
fd_csrfRefresh(callback)
|
fd_csrfRefresh(callback)
|
||||||
{
|
{
|
||||||
|
if(fd_mode != "FHEM")
|
||||||
|
return;
|
||||||
console.log("fd_csrfRefresh");
|
console.log("fd_csrfRefresh");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url:location.pathname.replace(/docs.*/,'')+"?XHR=1",
|
url:location.pathname.replace(/docs.*/,'')+"?XHR=1",
|
||||||
@ -175,12 +212,17 @@ fd_csrfRefresh(callback)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var p = location.pathname;
|
var p = location.pathname.split(/[_.]/);
|
||||||
fd_lang = p.substring(p.indexOf("commandref")+11,p.indexOf(".html"));
|
fd_lang = (p[1] == "modular" ? p[2] : p[1]);
|
||||||
if(!fd_lang || fd_lang == '.')
|
if(fd_lang == "html")
|
||||||
fd_lang = "EN";
|
fd_lang = "EN";
|
||||||
|
|
||||||
|
if(location.host == "fhem.de" || location.host == "commandref.fhem.de")
|
||||||
|
fd_mode = "static";
|
||||||
|
|
||||||
|
|
||||||
$("div#modLinks").each(function(){
|
$("div#modLinks").each(function(){
|
||||||
var a1 = $(this).html().split(" ");
|
var a1 = $(this).html().split(" ");
|
||||||
for(var i1=0; i1<a1.length; i1++) {
|
for(var i1=0; i1<a1.length; i1++) {
|
||||||
@ -205,10 +247,14 @@ $(document).ready(function(){
|
|||||||
loadOneDoc($(this).html(), fd_lang);
|
loadOneDoc($(this).html(), fd_lang);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(location.hash)
|
for(var i1 in fd_otherSrc)
|
||||||
|
fd_modLinks[i1] = fd_otherSrc[i1];
|
||||||
|
|
||||||
|
if(location.hash && location.hash.length > 1)
|
||||||
loadOneDoc(location.hash.substr(1), fd_lang);
|
loadOneDoc(location.hash.substr(1), fd_lang);
|
||||||
|
|
||||||
$(window).bind('hashchange', function() {
|
$(window).bind('hashchange', function() {
|
||||||
|
if(location.hash.length > 1)
|
||||||
loadOneDoc(location.hash.substr(1), fd_lang);
|
loadOneDoc(location.hash.substr(1), fd_lang);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user