mirror of
https://ark.sudovanilla.org/Korbs/electron-tabs.git
synced 2024-12-23 03:53:53 +00:00
Add visibilityThreshold option
This commit is contained in:
parent
fd330d3895
commit
52b6506c57
|
@ -84,6 +84,7 @@ Represents the main tab container.
|
||||||
* `closeButtonText` (default: `"✖"`): "close tab" button text.
|
* `closeButtonText` (default: `"✖"`): "close tab" button text.
|
||||||
* `newTabButtonText` (default: `"+"`): "New Tab" button text.
|
* `newTabButtonText` (default: `"+"`): "New Tab" button text.
|
||||||
* `newTab` (default: `undefined`): arguments to use when `.addTab()` is called without parameters. It can be an object or a function which returns an object. It determines the options to use when the "New Tab" button is triggered. If you leave it undefined then the "New Tab" button won't be displayed.
|
* `newTab` (default: `undefined`): arguments to use when `.addTab()` is called without parameters. It can be an object or a function which returns an object. It determines the options to use when the "New Tab" button is triggered. If you leave it undefined then the "New Tab" button won't be displayed.
|
||||||
|
* `visibilityThreshold` (default: `0`): the minimum number of tabs necessary for the tabGroup to be displayed. `0` means tabGround will always remain visible.
|
||||||
* `ready` (default: `undefined`): a callback function to call once the tab group is ready. The `TabGroup` instance is passed as the only parameter.
|
* `ready` (default: `undefined`): a callback function to call once the tab group is ready. The `TabGroup` instance is passed as the only parameter.
|
||||||
|
|
||||||
#### `tabGroup.addTab(options)`
|
#### `tabGroup.addTab(options)`
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.etabs-tabgroup.visible {
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.etabs-tabs {
|
.etabs-tabs {
|
||||||
|
|
17
index.js
17
index.js
|
@ -34,6 +34,7 @@ class TabGroup extends EventEmitter {
|
||||||
closeButtonText: args.closeButtonText || "×",
|
closeButtonText: args.closeButtonText || "×",
|
||||||
newTab: args.newTab,
|
newTab: args.newTab,
|
||||||
newTabButtonText: args.newTabButtonText || "+",
|
newTabButtonText: args.newTabButtonText || "+",
|
||||||
|
visibilityThreshold: args.visibilityThreshold || 0,
|
||||||
ready: args.ready
|
ready: args.ready
|
||||||
};
|
};
|
||||||
this.tabContainer = document.querySelector(options.tabContainerSelector);
|
this.tabContainer = document.querySelector(options.tabContainerSelector);
|
||||||
|
@ -41,6 +42,7 @@ class TabGroup extends EventEmitter {
|
||||||
this.tabs = [];
|
this.tabs = [];
|
||||||
this.newTabId = 0;
|
this.newTabId = 0;
|
||||||
TabGroupPrivate.initNewTabButton.bind(this)();
|
TabGroupPrivate.initNewTabButton.bind(this)();
|
||||||
|
TabGroupPrivate.initVisibility.bind(this)();
|
||||||
if (typeof this.options.ready === "function") {
|
if (typeof this.options.ready === "function") {
|
||||||
this.options.ready(this);
|
this.options.ready(this);
|
||||||
}
|
}
|
||||||
|
@ -122,6 +124,21 @@ const TabGroupPrivate = {
|
||||||
button.addEventListener("click", this.addTab.bind(this, undefined), false);
|
button.addEventListener("click", this.addTab.bind(this, undefined), false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
initVisibility: function () {
|
||||||
|
function toggleTabsVisibility(tab, tabGroup) {
|
||||||
|
var visibilityThreshold = this.options.visibilityThreshold;
|
||||||
|
var el = tabGroup.tabContainer.parentNode;
|
||||||
|
if (this.tabs.length >= visibilityThreshold) {
|
||||||
|
el.classList.add("visible");
|
||||||
|
} else {
|
||||||
|
el.classList.remove("visible");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on("tab-added", toggleTabsVisibility);
|
||||||
|
this.on("tab-removed", toggleTabsVisibility);
|
||||||
|
},
|
||||||
|
|
||||||
removeTab: function (tab, triggerEvent) {
|
removeTab: function (tab, triggerEvent) {
|
||||||
let id = tab.id;
|
let id = tab.id;
|
||||||
for (let i in this.tabs) {
|
for (let i in this.tabs) {
|
||||||
|
|
Loading…
Reference in a new issue