mirror of
https://ark.sudovanilla.org/Korbs/electron-tabs.git
synced 2024-12-23 03:53:53 +00:00
Add close button to tabs
This commit is contained in:
parent
0e4b24156a
commit
77e36dbffd
14
index.js
14
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) {
|
||||
|
|
Loading…
Reference in a new issue