Example #1
0
  render(): void {
    super.render()
    empty(this.el)

    const len = this.model.tabs.length
    if (len == 0)
      return
    else if (this.model.active >= len)
      this.model.active = len - 1

    const tabs = this.model.tabs.map((tab, i) => li({}, span({data: {index: i}}, tab.title)))
    tabs[this.model.active].classList.add("bk-bs-active")
    const tabsEl = ul({class: ["bk-bs-nav", "bk-bs-nav-tabs"]}, tabs)
    this.el.appendChild(tabsEl)

    const panels = this.model.tabs.map((_tab) => div({class: "bk-bs-tab-pane"}))
    panels[this.model.active].classList.add("bk-bs-active")
    const panelsEl = div({class: "bk-bs-tab-content"}, panels)
    this.el.appendChild(panelsEl)

    tabsEl.addEventListener("click", (event) => {
      event.preventDefault()

      if (event.target != event.currentTarget) {
        const el = event.target

        const old_active = this.model.active
        const new_active = parseInt(el.dataset.index)

        if (old_active != new_active) {
          tabs[old_active].classList.remove("bk-bs-active")
          panels[old_active].classList.remove("bk-bs-active")

          tabs[new_active].classList.add("bk-bs-active")
          panels[new_active].classList.add("bk-bs-active")

          this.model.active = new_active
          if (this.model.callback != null)
            this.model.callback.execute(this.model)
        }
      }
    })

    for (const [child, panelEl] of zip(this.model.children, panels))
      panelEl.appendChild(this.child_views[child.id].el)
  }
 const _widths = function(fmt_strings) {
   const sizes = (fmt_strings.map((fmt_string) => _strftime(now, fmt_string).length));
   const sorted = sortBy(zip(sizes, fmt_strings), function(...args) { const [size,] = args[0]; return size; });
   return unzip(sorted);
 };