TOC html

From Redazione
Jump to navigation Jump to search
Line 56: Line 56:
  
  
var wiki_list = []
+
var wiki_list = []
  
  
function walk_through_TOC(children,parent,depth) {
+
function walk_through_TOC(children,parent,depth) {
depth++
+
depth++
  
if(!children || !Object.keys(children).length) {
+
if(!children || !Object.keys(children).length) {
return
+
return
}
+
}
  
for(var value of children) {
+
for(var value of children) {
  
if(value.path) {
+
if(value.path) {
var repeat = depth
+
var repeat = depth
  
// '&&' does not work !
+
// '&&' does not work !
if(parent) {
+
if(parent) {
if(!parent.path) {
+
if(!parent.path) {
var regExp = new RegExp('\\b' + parent.text + '$')
+
var regExp = new RegExp('\\b' + parent.text + '$')
if(regExp.test(value.path)) {
+
if(regExp.test(value.path)) {
repeat--;
+
repeat--;
}
 
 
}
 
}
 
}
 
}
wiki_list.push('#'.repeat(repeat) + '[[' + value.path + '|' + value.text + ']]')
 
 
}
 
}
 +
wiki_list.push('#'.repeat(repeat) + '[[' + value.path + '|' + value.text + ']]')
 +
}
  
 
 
if(value.children) {
+
if(value.children) {
walk_through_TOC(value.children,value,depth);
+
walk_through_TOC(value.children,value,depth);
}
+
}
 
 
}
 
 
}
 
}
 +
}
  
  
 +
var contents = $ci('#TOC_contents').val();
  
var contents = $ci('#TOC_contents').val();
+
contents = decodeURIComponent(window.atob(contents));
//.replace(/^<nowiki>/,'').replace(/<\/nowiki>$/,'')
 
  
console.log('1')
 
console.log(contents)
 
contents = decodeURIComponent(escape(window.atob(contents)));
 
//contents = JSON.parse(window.atob(decodeURIComponent(contents)));
 
console.log('2')
 
console.log(contents)
 
console.log(typeof contents)
 
 
if(contents) {
 
if(contents) {
console.log('3')
+
contents = JSON.parse(contents)
contents = JSON.parse(contents)
+
 
console.log('4')
 
 
Frontend_Index.translate_index_rec(contents,'from');
 
Frontend_Index.translate_index_rec(contents,'from');
  
Line 131: Line 123:
 
index_obj_saved = tree.toDict(true).children;
 
index_obj_saved = tree.toDict(true).children;
  
 
console.log(index_obj_saved)
 
 
Frontend_Index.translate_index_rec(index_obj_saved,'to');
 
Frontend_Index.translate_index_rec(index_obj_saved,'to');
  
 +
walk_through_TOC(index_obj_saved,null,0);
  
console.log(index_obj_saved)
+
index_obj_saved = btoa(encodeURIComponent(JSON.stringify(index_obj_saved)));
 
 
walk_through_TOC(index_obj_saved,null,0)
 
 
 
console.log(wiki_list)
 
 
 
//index_obj_saved = btoa(JSON.stringify(encodeURIComponent(index_obj_saved)))
 
 
 
index_obj_saved = btoa(unescape(encodeURIComponent(JSON.stringify(index_obj_saved))))
 
 
 
console.log(index_obj_saved)
 
 
 
//return false
 
  
 
$ci('#TOC_contents').val(index_obj_saved)
 
$ci('#TOC_contents').val(index_obj_saved)
  
  
$ci('#pf_free_text').val(wiki_list.join("\n"))
+
$ci('#pf_free_text').val(`
 +
<!--
 +
The content of this page is created automatically.
 +
Don't edit it without the form, since any additional content
 +
will be lost!
 +
-->
 +
` + wiki_list.join("\n"))
  
  
// ***attention !!!
 
// otherwise pageforms will not retrieve it!
 
$ci('input').removeAttr('disabled');
 
 
return true;
 
return true;
 +
 
});
 
});
  

Revision as of 17:52, 16 July 2020

tree placeholder