TOC html

From Redazione
Jump to navigation Jump to search
 
(17 intermediate revisions by the same user not shown)
Line 17: Line 17:
 
-->
 
-->
  
−
<div id="TOC_tree">tree placeholder</div>
+
 
 +
<!--------------------------path-------------------------->
 +
 
 +
<div class="ci_form_section">
 +
<span class="ci_form_section_label">
 +
Target url
 +
</span>
 +
 
 +
<input class="ci_form_input" type="text" placeholder="" name="Form TOC[target url]" value="">
 +
 
 +
<span class="ci_form_section_help">
 +
Enter the target url of this set of pages, e.g.: https://culturaitaliana.org/organizations/Centro_italiano_Barcellona
 +
</span>
 +
 
 +
</div>
 +
 
 +
 
 +
 
 +
<div id="TOC_tree"></div>
  
 
<!--
 
<!--
Line 55: Line 73:
 
$ci(function() {
 
$ci(function() {
  
−
// https://stackoverflow.com/questions/25003217/using-encodeuri-vs-escape-for-utf-8-strings-in-javascript
 
−
var utf8_to_latin1 = function (s) {
 
−
    return unescape(encodeURIComponent(s));
 
−
};
 
−
var latin1_to_utf8 = function (s) {
 
−
    return decodeURIComponent(escape(s));
 
−
};
 
  
 
var wiki_list = []
 
var wiki_list = []
Line 67: Line 78:
  
 
function walk_through_TOC(children,parent,depth) {
 
function walk_through_TOC(children,parent,depth) {
−
depth++
 
  
 
if(!children || !Object.keys(children).length) {
 
if(!children || !Object.keys(children).length) {
 
return
 
return
 
}
 
}
 +
 +
 +
depth++
 +
  
 
for(var value of children) {
 
for(var value of children) {
  
 +
// '&&' does not work !
 
if(value.path) {
 
if(value.path) {
−
var repeat = depth
 
  
−
// '&&' does not work !
+
if(value.state.selected) {
−
if(parent) {
+
wiki_list.push('#'.repeat(depth) + '[[' + value.path + '|' + value.text + ']]')
−
if(!parent.path) {
+
}
−
var regExp = new RegExp('\\b' + parent.text + '$')
+
 
−
if(regExp.test(value.path)) {
+
} else {
−
repeat--;
+
 
−
}
+
if(value.state.selected) {
−
}
+
wiki_list.push('#'.repeat(depth) + value.text)
 
}
 
}
−
wiki_list.push('#'.repeat(repeat) + '[[' + value.path + '|' + value.text + ']]')
+
 
 
}
 
}
  
Line 96: Line 110:
 
 
 
}
 
}
 +
 +
 
}
 
}
−
 
  
 
var contents = $ci('#TOC_contents').val();
 
var contents = $ci('#TOC_contents').val();
  
−
contents = latin1_to_utf8(window.atob(contents));
+
contents = TOC_functions.base64_to_utf8(contents);
  
 
if(contents) {
 
if(contents) {
−
contents = JSON.parse(contents)
+
contents = JSON.parse(contents);
  
−
Frontend_Index.translate_index_rec(contents,'from');
+
TOC_functions.translate_TOC_rec(contents,'from');
  
  
Line 115: Line 130:
 
checkbox: function(event, data) {
 
checkbox: function(event, data) {
 
// Hide checkboxes for folders
 
// Hide checkboxes for folders
−
return data.node.isFolder() ? false : true;
+
return data.node.isFolder()? false: true;
 
},
 
},
−
   dnd5: Frontend_Index.fancytree_dnd5_conf
+
   dnd5: TOC_functions.fancytree_dnd5_conf
 
});
 
});
 
}
 
}
Line 128: Line 143:
 
}
 
}
  
−
index_obj_saved = tree.toDict(true).children;
+
var index_obj_saved = tree.toDict(true).children;
  
−
Frontend_Index.translate_index_rec(index_obj_saved,'to');
+
TOC_functions.translate_TOC_rec(index_obj_saved,'to');
  
 +
// create wiki_list
 
walk_through_TOC(index_obj_saved,null,0);
 
walk_through_TOC(index_obj_saved,null,0);
  
−
index_obj_saved = utf8_to_latin1(JSON.stringify(index_obj_saved));
 
  
−
$ci('#TOC_contents').val(btoa(index_obj_saved))
+
index_obj_saved = TOC_functions.utf8_to_base64(JSON.stringify(index_obj_saved));
  
  
−
$ci('#pf_free_text').val(`
+
$ci('#TOC_contents').val(index_obj_saved)
−
<!--  
+
var today = new Date();
−
The content of this page is created automatically.
+
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
 +
var time = today.getHours() + ":" + (today.getMinutes() + '').padStart(2, '0') + ":" + (today.getSeconds() + '').padStart(2, '0');
 +
 
 +
 
 +
$ci('#pf_free_text').val(`<!--  
 +
The content of this page has been created automatically on ` + date + ` at ` + time + `.  
 
Don't edit it without the form, since any additional content  
 
Don't edit it without the form, since any additional content  
−
will be lost!
+
will be lost on the next automatic update!
−
-->
+
-->` + wiki_list.join("\n") + `
−
` + wiki_list.join("\n"))
+
 
 +
[[Category:TOCs]]`)
  
  

Latest revision as of 22:35, 13 February 2021

Enter the target url of this set of pages, e.g.: https://culturaitaliana.org/organizations/Centro_italiano_Barcellona