/* (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
*
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
*
* $Id$
*
* Rewritten for bootstrap tiki 15.x 2015-2016
* Based on work by Jobi Carter keacarterdev@gmail.com
*/
$.genAutoToc = function () {
var $page = $("body"),
$top = $("#top"), $row;
var $output = $output || "#autotoc";
var toc = "";
var start = 0;
var toc_offset = parseInt(jqueryTiki.autoToc_offset);
var toc_pos = jqueryTiki.autoToc_pos;
var toc_mode = jqueryTiki.autoToc_inline;
var toc_title = "";
var toc_levels = false;
var toc_tabs = jqueryTiki.autoToc_tabs;
var toc_tabset_names = "";
var toc_tabset_panes = "";
if (typeof jqueryAutoToc !== "undefined") {
toc_offset = parseInt(jqueryAutoToc.plugin_autoToc_offset);
toc_pos = jqueryAutoToc.plugin_autoToc_pos;
toc_mode = jqueryAutoToc.plugin_autoToc_mode;
toc_title = jqueryAutoToc.plugin_autoToc_title !== 'undefined' ? "
"+ jqueryAutoToc.plugin_autoToc_title +"
" : "";
toc_tabs = jqueryAutoToc.plugin_autoToc_tabs;
toc_tabset_names = jqueryAutoToc.plugin_autoToc_tabset_names;
toc_tabset_panes = jqueryAutoToc.plugin_autoToc_tabset_panes;
if (jqueryAutoToc.plugin_autoToc_levels != null
&& jqueryAutoToc.plugin_autoToc_levels !== 'undefined') {
toc_levels = true;
}
}
else {
$('').appendTo('head');
}
//if a wiki page, and div and not printing
if ($top.length && location.href.indexOf("tiki-print.php") == -1) {
var selector = '#page-data';
var container = document.querySelector(container) || document.querySelector(selector);
var children = container.children;
if (toc_tabs === 'yes') {
//Show only headers of tabs and sections setted in the plugin
if (typeof jqueryAutoToc !== "undefined" && toc_tabset_names !== "") {
toc_tabset_names.forEach(tab_name => {
toc_tabset_panes.forEach(section =>{
selector = "#content"+tab_name+"-"+section;
var container = document.querySelector(selector);
if (container) {
subChildren = container.children;
children = Array.from(children).concat(Array.from(subChildren));
}
})
});
}
//Show all headers of all tabs of all the tabs present on the page
else {
var tabs = document.querySelectorAll("#page-data .tab-content"); //Get all the tabs available in the page
tabs.forEach(tab => {
var sections = tab.querySelectorAll(".tab-pane"); //Get all tab sections
sections.forEach(section => {
selector = "#"+section.id;
var container = document.querySelector(selector);
if (container) {
subChildren = container.children;
children = Array.from(children).concat(Array.from(subChildren));
}
})
})
}
}
if (countHeadings(children) > 0) {
$row = $("");
$container = $("");
if (toc_pos === "left" || toc_pos === "top") {
var $tocNav = $("");
var $page_data = $("#page-data").addClass("col-md-7 clearfix");
$('').appendTo('head');
}
else if (toc_pos === "right") {
var $tocNav = $("");
var $page_data = $("#page-data").addClass("col-md-8 clearfix");
}
var $nav = $("