class TableViewSection extends View { /** * The constructor accepts a DOM element as a parameter. If it is omitted, a new element is created using the constructor name in kebab case. */ constructor(element = null) { super(element); if (element) { this.titleLabel = element.querySelector("span.title-label"); } //Gather the table view cell instances from the markup. var cellElements = this.element.querySelectorAll("table-view-cell"); for (var i = 0; i < cellElements.length; i++) { var cellInstance = UIKit.getViewInstanceForElement(cellElements[i]); if (cellInstance) { cellInstance.section = this; } } } /** * The build function is called in the constructor when no element was passed as the base. * Override it to create custom subviews or manipulate the root element. * Don't forget to return the element in the end! */ build(element) { this.titleLabel = document.createElement("SPAN"); this.titleLabel.className = "title-label"; return element; } setTitle(title) { this.titleLabel.innerText = title; } /** * Adds the given cell to the section. * If the given before cell is also in this section, we insert the given cell before it. Otherwise, the before cell is ignored. */ addCell(cell, beforeCell = null) { cell.section = this; //If the given before cell is also in this section, we insert the cell before it. Otherwise, the before cell is ignored. this.element.insertBefore(cell.element, beforeCell && this.element.contains(beforeCell.element) ? beforeCell.element : null); } removeCell(cell) { this.element.removeChild(cell.element); cell.section = null; } } UIKit.registerViewType(TableViewSection, "table-view-section");