From 77e36dbffd7373b05fc417a27f898bd1737afd83 Mon Sep 17 00:00:00 2001 From: Thomas Brouard Date: Mon, 31 Oct 2016 17:45:03 +0100 Subject: [PATCH] Add close button to tabs --- index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index dc96e6f..44e80ac 100644 --- a/index.js +++ b/index.js @@ -84,6 +84,7 @@ class Tab { this.id = id; this.title = args.title; this.iconURL = args.iconURL; + this.closable = args.closable === false ? false : true; this.webviewAttributes = args.webviewAttributes || {}; this.webviewAttributes.src = args.src; this.tabElements = {}; @@ -105,10 +106,10 @@ class Tab { this.setTitle(this.title); this.setIcon(this.iconURL); + this.setButtons(); tab.addEventListener("click", this.activate.bind(this), false); this.tabGroup.tabContainer.appendChild(this.tab); - // TODO: close button // TODO: handle middle click } @@ -146,6 +147,17 @@ class Tab { return this.iconURL; } + setButtons () { + let container = this.tabElements.buttons; + let tabClass = this.tabGroup.options.tabClass; + if (this.closable) { + let button = container.appendChild(document.createElement("button")); + button.classList.add(`${tabClass}-button-close`); + button.innerHTML = "❌"; + button.addEventListener("click", this.close.bind(this), false); + } + } + activate () { let activeTab = this.tabGroup.getActiveTab(); if (activeTab) {