From 2b8e506f5ace4343cf7092b9b790ced35ffb12a4 Mon Sep 17 00:00:00 2001 From: Todd Tarsi Date: Sun, 23 May 2021 20:09:47 -0500 Subject: [PATCH 1/2] feat: work without any nodeIntegration requirements --- README.md | 1 - demo/app.js | 1 - index.js | 19 +++++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 69d12b4..97a7504 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ Electron-tabs uses webviews, so you first need to use the following `webPreferen ```js const mainWindow = new electron.BrowserWindow({ webPreferences: { - nodeIntegration: true, webviewTag: true } }); diff --git a/demo/app.js b/demo/app.js index f485185..d747f7e 100644 --- a/demo/app.js +++ b/demo/app.js @@ -4,7 +4,6 @@ const app = electron.app; app.on('ready', function () { const mainWindow = new electron.BrowserWindow({ webPreferences: { - nodeIntegration: true, webviewTag: true } }); diff --git a/index.js b/index.js index 8b79863..22b9e92 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,3 @@ -const EventEmitter = require("events"); - if (!document) { throw Error("electron-tabs module must be called in renderer process"); } @@ -22,6 +20,19 @@ if (!document) { document.getElementsByTagName("head")[0].appendChild(styleTag); })(); +/** + * This makes the browser EventTarget API work similar to EventEmitter + */ +class EventEmitter extends EventTarget { + emit (type, ...args) { + this.dispatchEvent(new CustomEvent(type, { detail: args })); + } + + on (type, fn) { + this.addEventListener(type, ({ detail }) => fn.apply(this, detail)); + } +} + class TabGroup extends EventEmitter { constructor (args = {}) { super(); @@ -126,8 +137,8 @@ const TabGroupPrivate = { initVisibility: function () { function toggleTabsVisibility(tab, tabGroup) { - var visibilityThreshold = this.options.visibilityThreshold; - var el = tabGroup.tabContainer.parentNode; + let visibilityThreshold = this.options.visibilityThreshold; + let el = tabGroup.tabContainer.parentNode; if (this.tabs.length >= visibilityThreshold) { el.classList.add("visible"); } else { From 0d130bb212d2e78b3596356dafe55cb4ae59683f Mon Sep 17 00:00:00 2001 From: toddtarsi Date: Sun, 18 Jul 2021 22:11:18 -0500 Subject: [PATCH 2/2] resetting let to var --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 22b9e92..9e8d4e3 100644 --- a/index.js +++ b/index.js @@ -137,8 +137,8 @@ const TabGroupPrivate = { initVisibility: function () { function toggleTabsVisibility(tab, tabGroup) { - let visibilityThreshold = this.options.visibilityThreshold; - let el = tabGroup.tabContainer.parentNode; + var visibilityThreshold = this.options.visibilityThreshold; + var el = tabGroup.tabContainer.parentNode; if (this.tabs.length >= visibilityThreshold) { el.classList.add("visible"); } else {