mirror of
https://ark.sudovanilla.org/Korbs/electron-tabs.git
synced 2024-12-23 03:53:53 +00:00
parent
a2761ab147
commit
b579379d88
14
README.md
14
README.md
|
@ -94,6 +94,20 @@ Retrieve an instance of `Tab` from its `id` (return `null` if not found).
|
||||||
|
|
||||||
Return the currently active tab (otherwise return `null`).
|
Return the currently active tab (otherwise return `null`).
|
||||||
|
|
||||||
|
#### `tabGroup.getTabs()`
|
||||||
|
|
||||||
|
Return all registered tabs.
|
||||||
|
|
||||||
|
#### `tabGroup.eachTab(fn, thisArg)`
|
||||||
|
|
||||||
|
Loop through the list of tabs in `tabGroup` and execute the `fn` function for each tab. `fn` is called with the following parameters:
|
||||||
|
|
||||||
|
* `currentTab`: the current tab object.
|
||||||
|
* `index`: the index of the current tab being processed.
|
||||||
|
* `tabs`: the full array of tabs (similar to `tabGroup.getTabs()`).
|
||||||
|
|
||||||
|
`thisArg` (optional) is the value to use as `this` when executing `fn`.
|
||||||
|
|
||||||
### Tab
|
### Tab
|
||||||
|
|
||||||
Instances of `Tab` are returned by the `tabGroup.addTab()` method.
|
Instances of `Tab` are returned by the `tabGroup.addTab()` method.
|
||||||
|
|
23
index.js
23
index.js
|
@ -76,6 +76,15 @@ class TabGroup extends EventEmitter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTabs () {
|
||||||
|
return this.tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
eachTab (fn) {
|
||||||
|
this.tabs.forEach(fn);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
getActiveTab () {
|
getActiveTab () {
|
||||||
if (this.tabs.length === 0) return null;
|
if (this.tabs.length === 0) return null;
|
||||||
return this.tabs[0];
|
return this.tabs[0];
|
||||||
|
@ -157,12 +166,12 @@ class Tab extends EventEmitter {
|
||||||
if (this.isClosed) return;
|
if (this.isClosed) return;
|
||||||
return this.title;
|
return this.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
setBadge (badge) {
|
setBadge (badge) {
|
||||||
if (this.isClosed) return;
|
if (this.isClosed) return;
|
||||||
let span = this.tabElements.badge;
|
let span = this.tabElements.badge;
|
||||||
this.badge = badge;
|
this.badge = badge;
|
||||||
|
|
||||||
if (badge) {
|
if (badge) {
|
||||||
span.innerHTML = badge;
|
span.innerHTML = badge;
|
||||||
span.classList.remove('hidden');
|
span.classList.remove('hidden');
|
||||||
|
@ -172,12 +181,12 @@ class Tab extends EventEmitter {
|
||||||
|
|
||||||
this.emit("badge-changed", badge, this);
|
this.emit("badge-changed", badge, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getBadge () {
|
getBadge () {
|
||||||
if (this.isClosed) return;
|
if (this.isClosed) return;
|
||||||
return this.badge;
|
return this.badge;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIcon (iconURL, icon) {
|
setIcon (iconURL, icon) {
|
||||||
if (this.isClosed) return;
|
if (this.isClosed) return;
|
||||||
this.iconURL = iconURL;
|
this.iconURL = iconURL;
|
||||||
|
@ -318,13 +327,13 @@ const TabPrivate = {
|
||||||
|
|
||||||
initWebview: function () {
|
initWebview: function () {
|
||||||
this.webview = document.createElement("webview");
|
this.webview = document.createElement("webview");
|
||||||
|
|
||||||
const tabWebviewDidFinishLoadHandler = function (e) {
|
const tabWebviewDidFinishLoadHandler = function (e) {
|
||||||
this.emit("webview-ready", this);
|
this.emit("webview-ready", this);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.webview.addEventListener("did-finish-load", tabWebviewDidFinishLoadHandler.bind(this), false);
|
this.webview.addEventListener("did-finish-load", tabWebviewDidFinishLoadHandler.bind(this), false);
|
||||||
|
|
||||||
this.webview.classList.add(this.tabGroup.options.viewClass);
|
this.webview.classList.add(this.tabGroup.options.viewClass);
|
||||||
if (this.webviewAttributes) {
|
if (this.webviewAttributes) {
|
||||||
let attrs = this.webviewAttributes;
|
let attrs = this.webviewAttributes;
|
||||||
|
@ -332,7 +341,7 @@ const TabPrivate = {
|
||||||
this.webview.setAttribute(key, attrs[key]);
|
this.webview.setAttribute(key, attrs[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tabGroup.viewContainer.appendChild(this.webview);
|
this.tabGroup.viewContainer.appendChild(this.webview);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue