git.schokokeks.org
Repositories
Help
Report an Issue
fs-draft.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
a2ab2b8
Branches
Tags
master
midgard
vorlage
fs-draft.git
source
logic
toc.js
weitere anpassungen
Christian Fraß
commited
a2ab2b8
at 2018-08-22 10:21:45
toc.js
Blame
History
Raw
"use strict"; class class_contentnode { constructor(id, title, children) { this.id = id; this.title = title; this.children = children; } generate(path = []) { let that = this; let dom_fragment = document.createDocumentFragment(); { if (this.title != null) { let dom_link = document.createElement("a"); dom_link.setAttribute("href", "#" + that.id); dom_link.textContent = path.map(x => (x+1).toString()).join(".") + " " + this.title; dom_fragment.appendChild(dom_link); } } { let dom_list = document.createElement("ol"); this.children.forEach ( function (child, index) { if (child != null) { let dom_element = document.createElement("li"); dom_element.appendChild(child.generate(path.concat(index))); dom_list.appendChild(dom_element); } } ); dom_fragment.appendChild(dom_list); } return dom_fragment; } adjust(path = []) { if (this.id != null) { let selector = ("#" + this.id + " > header"); let text = path.map(x => (x+1).toString()).join(".") + " " + this.title; let dom_header = document.querySelector(selector); dom_header.textContent = ""; let dom_link = document.createElement("a"); dom_link.classList.add("jumplabel"); dom_link.setAttribute("href", "#" + this.id); dom_link.textContent = text; // dom_link.textContent = " #"; dom_header.appendChild(dom_link); } this.children.forEach((child, index) => child.adjust(path.concat([index]))); } static read(dom_context = document, classes = ["chapter","section","subsection"], id = null, title = null) { return ( new class_contentnode ( id, title, (classes.length == 0) ? [] : convert_to_list(dom_context.querySelectorAll("section" + ("." + classes[0]) + ":not(.pseudo)")).map ( function (dom_context_) { return ( class_contentnode.read ( dom_context_, classes.slice(1), dom_context_.getAttribute("id"), dom_context_.querySelector("header").textContent ) ); } ) ) ); } }