nehan
Version:
Html layout engine for paged-media written in Typescript
44 lines • 1.61 kB
JavaScript
export class LayoutOutlineParser {
static parseSection(section, callbacks) {
callbacks = callbacks || {};
if (section.isRoot()) {
return this.parseSectionRoot(section, callbacks);
}
if (section.isNode()) {
return this.parseSectionNode(section, callbacks);
}
return this.parseSectionLeaf(section, callbacks);
}
static parseSectionRoot(section, callbacks) {
let root = callbacks.onRoot ?
callbacks.onRoot() :
document.createElement("ul");
this.appendSectionChildren(root, section.children, callbacks);
return root;
}
static parseSectionNode(section, callbacks) {
let li = document.createElement("li");
let ul = document.createElement("ul");
let title = callbacks.onSection ?
callbacks.onSection(section) :
document.createTextNode(section.title);
li.appendChild(title);
this.appendSectionChildren(ul, section.children, callbacks);
li.appendChild(ul);
return li;
}
static parseSectionLeaf(section, callbacks) {
let li = document.createElement("li");
let title = callbacks.onSection ?
callbacks.onSection(section) :
document.createTextNode(section.title);
li.appendChild(title);
return li;
}
static appendSectionChildren(parent, children, callbacks) {
children.forEach(child => {
parent.appendChild(this.parseSection(child, callbacks));
});
}
}
//# sourceMappingURL=layout-outline-parser.js.map