From e98e4141c52f84cf1f24acade5ad5c4b56de25de Mon Sep 17 00:00:00 2001 From: Thomas Brouard Date: Tue, 1 Nov 2016 11:17:57 +0100 Subject: [PATCH] Chainable methods --- index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index df05087..ecfbcc2 100644 --- a/index.js +++ b/index.js @@ -76,12 +76,14 @@ class TabGroup extends EventEmitter { if (triggerEvent) { this.emit("tab-removed", tab, this); } + return this; } setActiveTab (tab) { this.removeTab(tab); this.tabs.unshift(tab); this.emit("tab-active", tab, this); + return this; } getActiveTab () { @@ -90,8 +92,10 @@ class TabGroup extends EventEmitter { } activateRecentTab (tab) { - if (this.tabs.length === 0) return null; - this.tabs[0].activate(); + if (this.tabs.length > 0) { + this.tabs[0].activate(); + } + return this; } } @@ -148,6 +152,7 @@ class Tab extends EventEmitter { span.innerHTML = title; this.title = title; this.emit("title-changed", title, this); + return this; } getTitle () { @@ -163,6 +168,7 @@ class Tab extends EventEmitter { span.innerHTML = ``; } this.emit("icon-changed", iconURL, this); + return this; } getIcon () { @@ -201,16 +207,19 @@ class Tab extends EventEmitter { this.tab.classList.add("active"); this.webview.classList.add("visible"); this.emit("active", this); + return this; } show () { if (this.isClosed) return; this.tab.classList.add("visible"); + return this; } hide () { if (this.isClosed) return; this.tab.classList.remove("visible"); + return this; } flash (flag) { @@ -222,6 +231,7 @@ class Tab extends EventEmitter { this.tab.classList.remove("flash"); this.emit("flash-end", this); } + return this; } move (index) {