git.schokokeks.org
Repositories
Help
Report an Issue
fs-draft.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
579dbe0
Branches
Tags
master
midgard
vorlage
fs-draft.git
source
logic
client
toc.js
advanced
bfadmin-master
commited
579dbe0
at 2016-04-25 20:27:11
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 dom_header = document.querySelector(selector); dom_header.textContent = path.map(x => (x+1).toString()).join(".") + " " + this.title; } 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 ) ); } ) ) ); } }