From da72d0446e2f42d0ccea930f7bc477e776d805be Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 13 Jan 2017 11:48:01 +0100 Subject: [PATCH 1/9] License added --- LICENSE.txt | 373 +++++++++++++++++++++++++++++++++++++++ index.js | 4 + webextension/js/popup.js | 4 + 3 files changed, 381 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..14e2f77 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/index.js b/index.js index e3181ee..2c207f5 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; const { attachTo } = require("sdk/content/mod"); diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 51d3ed2..6dc4ca6 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + /* global browser, window, document, localStorage */ const CONTAINER_HIDE_SRC = "/img/container-hide.svg"; const CONTAINER_UNHIDE_SRC = "/img/container-unhide.svg"; From 9ef7b1edad0892c1d54cadcfcf7c31b35f401206 Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 13 Jan 2017 11:55:51 +0100 Subject: [PATCH 2/9] log function instead console.log() --- webextension/js/popup.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 6dc4ca6..bc3ed13 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -6,6 +6,15 @@ const CONTAINER_HIDE_SRC = "/img/container-hide.svg"; const CONTAINER_UNHIDE_SRC = "/img/container-unhide.svg"; +// Let's set it to false before releasing!!! +const DEBUG = true; + +function log(...args) { + if (DEBUG) { + console.log.call(console, ...args); + } +} + function showPanel(panelSelector) { for (let panelElement of document.querySelectorAll(".panel")) { panelElement.classList.add("hide"); @@ -46,7 +55,7 @@ function showContainerTabsPanel(identity) { method: "getTabs", userContextId: identity.userContextId, }).then(tabs => { - console.log('browser.runtime.sendMessage getTabs, tabs: ', tabs); + log('browser.runtime.sendMessage getTabs, tabs: ', tabs); // For each one, let's create a new line. let fragment = document.createDocumentFragment(); for (const tab of tabs) { @@ -98,11 +107,11 @@ document.querySelector("#onboarding-done-button").addEventListener("click", () = }); browser.runtime.sendMessage({method: "queryIdentities"}).then(identities => { - console.log('queryIdentities'); + log('queryIdentities'); let fragment = document.createDocumentFragment(); identities.forEach(identity => { - console.log('identities.forEach'); + log('identities.forEach'); let tr = document.createElement("tr"); fragment.appendChild(tr); tr.classList.add("container-panel-row"); From 82a455d3c1e32fe7023c3626fd70050c602339f6 Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 13 Jan 2017 12:06:38 +0100 Subject: [PATCH 3/9] for(const.. => for(let.. --- index.js | 20 ++++++++++---------- webextension/js/popup.js | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 2c207f5..440da34 100644 --- a/index.js +++ b/index.js @@ -64,7 +64,7 @@ let ContainerService = { }); // It can happen that this jsm is loaded after the opening a container tab. - for (const tab of tabs) { + for (let tab of tabs) { const userContextId = this._getUserContextIdFromTab(tab); if (userContextId) { ++this._identitiesState[userContextId].openTabs; @@ -160,7 +160,7 @@ let ContainerService = { _getTabList(userContextId) { let list = []; - for (const tab of tabs) { + for (let tab of tabs) { if (userContextId === this._getUserContextIdFromTab(tab)) { let object = { title: tab.title, url: tab.url, id: tab.id }; list.push(object); @@ -179,7 +179,7 @@ let ContainerService = { return; } - for (const tab of tabs) { + for (let tab of tabs) { if (args.userContextId !== this._getUserContextIdFromTab(tab)) { continue; } @@ -229,7 +229,7 @@ let ContainerService = { // Let's collect UCIs/tabs for this window. let map = new Map; - for (const tab of tabs) { + for (let tab of tabs) { if (pinnedTabs && !tabsUtils.isPinned(tab)) { // We don't have, or we already handled all the pinned tabs. break; @@ -253,7 +253,7 @@ let ContainerService = { // Let's move tabs. sortMap.forEach(tabs => { - for (const tab of tabs) { + for (let tab of tabs) { xulWindow.gBrowser.moveTabTo(tab, pos++); } }); @@ -290,7 +290,7 @@ let ContainerService = { return; } - for (const tab of tabs) { + for (let tab of tabs) { if (tab.id === args.tabId) { tab.window.activate(); tab.activate(); @@ -324,7 +324,7 @@ let ContainerService = { const newBrowserWindow = viewFor(window); // Let's move the tab to the new window. - for (const tab of list) { + for (let tab of list) { const newTab = newBrowserWindow.gBrowser.addTab("about:blank"); newBrowserWindow.gBrowser.swapBrowsersAndCloseOther(newTab, tab); // swapBrowsersAndCloseOther is an internal method of gBrowser @@ -337,7 +337,7 @@ let ContainerService = { // Let's close all the normal tab in the new window. In theory it // should be only the first tab, but maybe there are addons doing // crazy stuff. - for (const tab of window.tabs) { + for (let tab of window.tabs) { const userContextId = this._getUserContextIdFromTab(tab); if (args.userContextId !== userContextId) { newBrowserWindow.gBrowser.removeTab(viewFor(tab)); @@ -395,7 +395,7 @@ let ContainerService = { }, createIdentity(args) { - for (const arg of [ "name", "color", "icon"]) { + for (let arg of [ "name", "color", "icon"]) { if (!(arg in args)) { Promise.reject("createIdentity must be called with " + arg + " argument."); return; @@ -414,7 +414,7 @@ let ContainerService = { } let identity = ContextualIdentityService.getIdentityFromId(args.userContextId); - for (const arg of [ "name", "color", "icon"]) { + for (let arg of [ "name", "color", "icon"]) { if ((arg in args)) { identity[arg] = args[arg]; } diff --git a/webextension/js/popup.js b/webextension/js/popup.js index bc3ed13..aaf2de4 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -46,7 +46,7 @@ function showContainerTabsPanel(identity) { hideShowLabel.innerText = identity.hasHiddenTabs ? "Show these container tabs" : "Hide these container tabs"; // Let"s remove all the previous tabs. - for (const trTab of document.getElementsByClassName("container-info-tab")) { + for (let trTab of document.getElementsByClassName("container-info-tab")) { trTab.remove(); } @@ -58,7 +58,7 @@ function showContainerTabsPanel(identity) { log('browser.runtime.sendMessage getTabs, tabs: ', tabs); // For each one, let's create a new line. let fragment = document.createDocumentFragment(); - for (const tab of tabs) { + for (let tab of tabs) { let tr = document.createElement("tr"); fragment.appendChild(tr); tr.classList.add("container-info-tab"); From d2ae4b313244d58dc89beff39dc44c92ad4ae749 Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 13 Jan 2017 12:13:39 +0100 Subject: [PATCH 4/9] Fix the 'add' link --- webextension/js/popup.js | 7 +------ webextension/popup.html | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/webextension/js/popup.js b/webextension/js/popup.js index aaf2de4..6353709 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -215,7 +215,7 @@ function showDeleteContainerPanel(identity) { showPanel("#delete-container-panel"); } -document.querySelector("#add-container-link").addEventListener("click", () => { +document.querySelector(".add-container-link").addEventListener("click", () => { showPanel("#edit-container-panel"); }); @@ -235,10 +235,6 @@ document.querySelector("#edit-container-cancel-link").addEventListener("click", showEditContainersPanel(); }); -document.querySelector("#delete-container-panel-back-arrow").addEventListener("click", () => { - showEditContainersPanel(); -}); - document.querySelector("#delete-container-cancel-link").addEventListener("click", () => { showEditContainersPanel(); }); @@ -252,7 +248,6 @@ document.querySelector("#sort-containers-link").addEventListener("click", () => }); document.querySelector("#close-container-info-panel").addEventListener("click", () => { - // TODO: animation document.getElementById("container-info-panel").classList.add("hide"); document.getElementById("container-panel").classList.remove("hide"); }); diff --git a/webextension/popup.html b/webextension/popup.html index 9316540..9fd8beb 100644 --- a/webextension/popup.html +++ b/webextension/popup.html @@ -41,7 +41,7 @@ Edit Containers @@ -84,7 +84,7 @@ < Exit Edit Mode From c66fb33583620b17038dcb4ce8494029b8da1107 Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 13 Jan 2017 14:19:41 +0100 Subject: [PATCH 5/9] Refactoring of popup.js --- webextension/js/popup.js | 540 ++++++++++++++++++++++++--------------- webextension/popup.html | 3 +- 2 files changed, 338 insertions(+), 205 deletions(-) diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 6353709..5cb0980 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -3,11 +3,21 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ /* global browser, window, document, localStorage */ + const CONTAINER_HIDE_SRC = "/img/container-hide.svg"; const CONTAINER_UNHIDE_SRC = "/img/container-unhide.svg"; // Let's set it to false before releasing!!! -const DEBUG = true; +const DEBUG = false; + +// List of panels +const P_ONBOARDING_1 = "onboarding1"; +const P_ONBOARDING_2 = "onboarding2"; +const P_CONTAINERS_LIST = "containersList"; +const P_CONTAINERS_EDIT = "containersEdit"; +const P_CONTAINER_INFO = "containerInfo"; +const P_CONTAINER_EDIT = "containerEdit"; +const P_CONTAINER_DELETE = "containerDelete"; function log(...args) { if (DEBUG) { @@ -15,145 +25,290 @@ function log(...args) { } } -function showPanel(panelSelector) { - for (let panelElement of document.querySelectorAll(".panel")) { - panelElement.classList.add("hide"); - } - document.querySelector(panelSelector).classList.remove("hide"); -} +// This object controls all the panels, identities and many other things. +let Logic = { + _identities: [], + _currentIdentity: null, + _panels: {}, -function showContainerTabsPanel(identity) { - // Populating the panel: name and icon - document.getElementById("container-info-name").innerText = identity.name; + init() { + // Retrieve the list of identities. + browser.runtime.sendMessage({ + method: "queryIdentities" + }) - let icon = document.getElementById("container-info-icon"); - icon.setAttribute("data-identity-icon", identity.image); - icon.setAttribute("data-identity-color", identity.color); + .then(identities => { + this._identities = identities; + }) - // Show or not the has-tabs section. - for (let trHasTabs of document.getElementsByClassName("container-info-has-tabs")) { - trHasTabs.hidden = !identity.hasHiddenTabs && !identity.hasOpenTabs; - trHasTabs.setAttribute("data-user-context-id", identity.userContextId); - } - - let hideOrShowRow = document.querySelector("#container-info-hideorshow"); - hideOrShowRow.setAttribute("data-user-context-id", identity.userContextId); - - const hideShowIcon = document.getElementById("container-info-hideorshow-icon"); - hideShowIcon.src = identity.hasHiddenTabs ? CONTAINER_UNHIDE_SRC : CONTAINER_HIDE_SRC; - - const hideShowLabel = document.getElementById("container-info-hideorshow-label"); - hideShowLabel.innerText = identity.hasHiddenTabs ? "Show these container tabs" : "Hide these container tabs"; - - // Let"s remove all the previous tabs. - for (let trTab of document.getElementsByClassName("container-info-tab")) { - trTab.remove(); - } - - // Let"s retrieve the list of tabs. - browser.runtime.sendMessage({ - method: "getTabs", - userContextId: identity.userContextId, - }).then(tabs => { - log('browser.runtime.sendMessage getTabs, tabs: ', tabs); - // For each one, let's create a new line. - let fragment = document.createDocumentFragment(); - for (let tab of tabs) { - let tr = document.createElement("tr"); - fragment.appendChild(tr); - tr.classList.add("container-info-tab"); - tr.classList.add("clickable"); - tr.innerHTML = ` - - ${tab.title}`; - // On click, we activate this tab. - tr.addEventListener("click", () => { - browser.runtime.sendMessage({ - method: "showTab", - tabId: tab.id, - }).then(() => { - window.close(); - }); - }); - } - - document.getElementById("container-info-table").appendChild(fragment); - }) - - // Finally we are ready to show the panel. - .then(() => { - // FIXME: the animation... - document.getElementById("container-panel").classList.add("hide"); - document.getElementById("container-info-panel").classList.remove("hide"); - }); -} - -if (localStorage.getItem("onboarded2")) { - showPanel("#container-panel"); -} else if (localStorage.getItem("onboarded1")) { - showPanel(".onboarding-panel-2"); -} else { - showPanel(".onboarding-panel-1"); -} - -document.querySelector("#onboarding-next-button").addEventListener("click", () => { - localStorage.setItem("onboarded1", true); - showPanel(".onboarding-panel-2"); -}); - -document.querySelector("#onboarding-done-button").addEventListener("click", () => { - localStorage.setItem("onboarded2", true); - showPanel("#container-panel"); -}); - -browser.runtime.sendMessage({method: "queryIdentities"}).then(identities => { - log('queryIdentities'); - let fragment = document.createDocumentFragment(); - - identities.forEach(identity => { - log('identities.forEach'); - let tr = document.createElement("tr"); - fragment.appendChild(tr); - tr.classList.add("container-panel-row"); - tr.classList.add("clickable"); - tr.setAttribute("data-identity-cookie-store-id", identity.userContextId); - tr.innerHTML = ` - -
-
- - ${identity.name} - >`; - - tr.addEventListener("click", e => { - if (e.target.matches(".open-newtab")) { - browser.runtime.sendMessage({ - method: "showTabs", - userContextId: identity.userContextId - }).then(() => { - return browser.runtime.sendMessage({ - method: "openTab", - userContextId: identity.userContextId, - }); - }).then(() => { - window.close(); - }); - } else if (e.target.matches(".info")) { - showContainerTabsPanel(identity); + // Routing to the correct panel. + .then(() => { + if (localStorage.getItem("onboarded2")) { + this.showPanel(P_CONTAINERS_LIST); + } else if (localStorage.getItem("onboarded1")) { + this.showPanel(P_ONBOARDING_2); + } else { + this.showPanel(P_ONBOARDING_1); } }); - }); + }, - document.querySelector(".identities-list").appendChild(fragment); + showPanel(panel, currentIdentity = null) { + // Invalid panel... ?!? + if (!(panel in this._panels)) { + throw("Something really bad happened. Unknown panel: " + panel + "\n"); + } + + this._currentIdentity = currentIdentity; + + // Initialize the panel before showing it. + this._panels[panel].prepare().then(() => { + for (let panelElement of document.querySelectorAll(".panel")) { + panelElement.classList.add("hide"); + } + document.querySelector(this._panels[panel].panelSelector).classList.remove("hide"); + }); + }, + + registerPanel(panelName, panelObject) { + this._panels[panelName] = panelObject; + panelObject.initialize(); + }, + + identities() { + return this._identities; + }, + + currentIdentity() { + if (!this._currentIdentity) { + throw("CurrentIdentity must be set before calling Logic.currentIdentity."); + } + return this._currentIdentity; + }, +}; + +// P_ONBOARDING_1: First page for Onboarding. +// ---------------------------------------------------------------------------- + +Logic.registerPanel(P_ONBOARDING_1, { + panelSelector: ".onboarding-panel-1", + + // This method is called when the object is registered. + initialize() { + // Let's move to the next panel. + document.querySelector("#onboarding-next-button").addEventListener("click", () => { + localStorage.setItem("onboarded1", true); + Logic.showPanel(P_ONBOARDING_2); + }); + }, + + // This method is called when the panel is shown. + prepare() { + return Promise.resolve(null); + }, }); -function showEditContainersPanel() { - browser.runtime.sendMessage({method: "queryIdentities"}).then(identities => { +// P_ONBOARDING_2: Second page for Onboarding. +// ---------------------------------------------------------------------------- + +Logic.registerPanel(P_ONBOARDING_2, { + panelSelector: ".onboarding-panel-2", + + // This method is called when the object is registered. + initialize() { + // Let's move to the containers list panel. + document.querySelector("#onboarding-done-button").addEventListener("click", () => { + localStorage.setItem("onboarded2", true); + Logic.showPanel(P_CONTAINERS_LIST); + }); + }, + + // This method is called when the panel is shown. + prepare() { + return Promise.resolve(null); + }, +}); + +// P_CONTAINERS_LIST: The list of containers. The main page. +// ---------------------------------------------------------------------------- + +Logic.registerPanel(P_CONTAINERS_LIST, { + panelSelector: "#container-panel", + + // This method is called when the object is registered. + initialize() { + document.querySelector(".add-container-link").addEventListener("click", () => { + Logic.showPanel(P_CONTAINER_EDIT, {}); + }); + + document.querySelector("#edit-containers-link").addEventListener("click", () => { + Logic.showPanel(P_CONTAINERS_EDIT); + }); + + document.querySelector("#sort-containers-link").addEventListener("click", () => { + browser.runtime.sendMessage({ + method: "sortTabs" + }).then(() => { + window.close(); + }); + }); + }, + + // This method is called when the panel is shown. + prepare() { let fragment = document.createDocumentFragment(); - identities.forEach(identity => { + Logic.identities().forEach(identity => { + log('identities.forEach'); + let tr = document.createElement("tr"); + fragment.appendChild(tr); + tr.classList.add("container-panel-row"); + tr.classList.add("clickable"); + tr.setAttribute("data-identity-cookie-store-id", identity.userContextId); + tr.innerHTML = ` + +
+
+ + ${identity.name} + >`; + + tr.addEventListener("click", e => { + if (e.target.matches(".open-newtab")) { + browser.runtime.sendMessage({ + method: "showTabs", + userContextId: identity.userContextId + }).then(() => { + return browser.runtime.sendMessage({ + method: "openTab", + userContextId: identity.userContextId, + }); + }).then(() => { + window.close(); + }); + } else if (e.target.matches(".info")) { + Logic.showPanel(P_CONTAINER_INFO, identity); + } + }); + }); + + document.querySelector(".identities-list").innerHTML = ""; + document.querySelector(".identities-list").appendChild(fragment); + + return Promise.resolve(); + }, +}); + +// P_CONTAINER_INFO: More info about a container. +// ---------------------------------------------------------------------------- + +Logic.registerPanel(P_CONTAINER_INFO, { + panelSelector: "#container-info-panel", + + // This method is called when the object is registered. + initialize() { + document.querySelector("#close-container-info-panel").addEventListener("click", () => { + Logic.showPanel(P_CONTAINERS_LIST); + }); + + document.querySelector("#container-info-hideorshow").addEventListener("click", e => { + let identity = Logic.currentIdentity(); + browser.runtime.sendMessage({ + method: identity.hasHiddenTabs ? "showTabs" : "hideTabs", + userContextId: identity.userContextId + }).then(() => { + window.close(); + }); + }); + + document.querySelector("#container-info-movetabs").addEventListener("click", e => { + return browser.runtime.sendMessage({ + method: "moveTabsToWindow", + userContextId: Logic.currentIdentity().userContextId, + }).then(() => { + window.close(); + }); + }); + }, + + // This method is called when the panel is shown. + prepare() { + let identity = Logic.currentIdentity(); + + // Populating the panel: name and icon + document.getElementById("container-info-name").innerText = identity.name; + + let icon = document.getElementById("container-info-icon"); + icon.setAttribute("data-identity-icon", identity.image); + icon.setAttribute("data-identity-color", identity.color); + + // Show or not the has-tabs section. + for (let trHasTabs of document.getElementsByClassName("container-info-has-tabs")) { + trHasTabs.hidden = !identity.hasHiddenTabs && !identity.hasOpenTabs; + } + + const hideShowIcon = document.getElementById("container-info-hideorshow-icon"); + hideShowIcon.src = identity.hasHiddenTabs ? CONTAINER_UNHIDE_SRC : CONTAINER_HIDE_SRC; + + const hideShowLabel = document.getElementById("container-info-hideorshow-label"); + hideShowLabel.innerText = identity.hasHiddenTabs ? "Show these container tabs" : "Hide these container tabs"; + + // Let's remove all the previous tabs. + for (let trTab of document.getElementsByClassName("container-info-tab")) { + trTab.remove(); + } + + // Let's retrieve the list of tabs. + return browser.runtime.sendMessage({ + method: "getTabs", + userContextId: identity.userContextId, + }).then(tabs => { + log('browser.runtime.sendMessage getTabs, tabs: ', tabs); + // For each one, let's create a new line. + let fragment = document.createDocumentFragment(); + for (let tab of tabs) { + let tr = document.createElement("tr"); + fragment.appendChild(tr); + tr.classList.add("container-info-tab"); + tr.classList.add("clickable"); + tr.innerHTML = ` + + ${tab.title}`; + // On click, we activate this tab. + tr.addEventListener("click", () => { + browser.runtime.sendMessage({ + method: "showTab", + tabId: tab.id, + }).then(() => { + window.close(); + }); + }); + } + + document.getElementById("container-info-table").appendChild(fragment); + }); + }, +}); + +// P_CONTAINERS_EDIT: Makes the list editable. +// ---------------------------------------------------------------------------- + +Logic.registerPanel(P_CONTAINERS_EDIT, { + panelSelector: "#edit-containers-panel", + + // This method is called when the object is registered. + initialize() { + document.querySelector("#exit-edit-mode-link").addEventListener("click", () => { + Logic.showPanel(P_CONTAINERS_LIST); + }); + }, + + // This method is called when the panel is shown. + prepare() { + let fragment = document.createDocumentFragment(); + Logic.identities().forEach(identity => { let tr = document.createElement("tr"); fragment.appendChild(tr); tr.setAttribute("data-identity-cookie-store-id", identity.userContextId); @@ -186,92 +341,71 @@ function showEditContainersPanel() { tr.addEventListener("click", e => { if (e.target.matches(".edit-container-icon")) { - showEditContainerPanel(identity); + Logic.showPanel(P_CONTAINER_EDIT, identity); } else if (e.target.matches(".delete-container-icon")) { - showDeleteContainerPanel(identity); + Logic.showPanel(P_CONTAINER_DELETE, identity); } }); }); document.querySelector("#edit-identities-list").innerHTML = ""; document.querySelector("#edit-identities-list").appendChild(fragment); - }); - showPanel("#edit-containers-panel"); -} -function showEditContainerPanel(identity) { - document.querySelector("#edit-container-panel-name-input").value = identity.name; - showPanel("#edit-container-panel"); -} - -function showDeleteContainerPanel(identity) { - // Populating the panel: name and icon - document.getElementById("delete-container-name").innerText = identity.name; - - let icon = document.getElementById("delete-container-icon"); - icon.setAttribute("data-identity-icon", identity.image); - icon.setAttribute("data-identity-color", identity.color); - - showPanel("#delete-container-panel"); -} - -document.querySelector(".add-container-link").addEventListener("click", () => { - showPanel("#edit-container-panel"); + return Promise.resolve(null); + }, }); -document.querySelector("#edit-containers-link").addEventListener("click", () => { - showEditContainersPanel(); -}); +// P_CONTAINER_EDIT: Editor for a container. +// ---------------------------------------------------------------------------- -document.querySelector("#exit-edit-mode-link").addEventListener("click", () => { - showPanel("#container-panel"); -}); +Logic.registerPanel(P_CONTAINER_EDIT, { + panelSelector: "#edit-container-panel", -document.querySelector("#edit-container-panel-back-arrow").addEventListener("click", () => { - showEditContainersPanel(); -}); - -document.querySelector("#edit-container-cancel-link").addEventListener("click", () => { - showEditContainersPanel(); -}); - -document.querySelector("#delete-container-cancel-link").addEventListener("click", () => { - showEditContainersPanel(); -}); - -document.querySelector("#sort-containers-link").addEventListener("click", () => { - browser.runtime.sendMessage({ - method: "sortTabs" - }).then(() => { - window.close(); - }); -}); - -document.querySelector("#close-container-info-panel").addEventListener("click", () => { - document.getElementById("container-info-panel").classList.add("hide"); - document.getElementById("container-panel").classList.remove("hide"); -}); - -document.querySelector("#container-info-hideorshow").addEventListener("click", e => { - let userContextId = e.target.parentElement.getAttribute("data-user-context-id"); - browser.runtime.sendMessage({ - method: "getIdentity", - userContextId, - }).then(identity => { - return browser.runtime.sendMessage({ - method: identity.hasHiddenTabs ? "showTabs" : "hideTabs", - userContextId: identity.userContextId + // This method is called when the object is registered. + initialize() { + document.querySelector("#edit-container-panel-back-arrow").addEventListener("click", () => { + Logic.showPanel(P_CONTAINERS_EDIT); }); - }).then(() => { - window.close(); - }); + + document.querySelector("#edit-container-cancel-link").addEventListener("click", () => { + Logic.showPanel(P_CONTAINERS_EDIT); + }); + }, + + // This method is called when the panel is shown. + prepare() { + let identity = Logic.currentIdentity(); + document.querySelector("#edit-container-panel-name-input").value = identity.name; + return Promise.resolve(null); + }, }); -document.querySelector("#container-info-movetabs").addEventListener("click", e => { - return browser.runtime.sendMessage({ - method: "moveTabsToWindow", - userContextId: e.target.parentElement.getAttribute("data-user-context-id"), - }).then(() => { - window.close(); - }); +// P_CONTAINER_DELETE: Delete a container. +// ---------------------------------------------------------------------------- + +Logic.registerPanel(P_CONTAINER_DELETE, { + panelSelector: "#delete-container-panel", + + // This method is called when the object is registered. + initialize() { + document.querySelector("#delete-container-cancel-link").addEventListener("click", () => { + Logic.showPanel(P_CONTAINERS_EDIT); + }); + }, + + // This method is called when the panel is shown. + prepare() { + let identity = Logic.currentIdentity(); + + // Populating the panel: name and icon + document.getElementById("delete-container-name").innerText = identity.name; + + let icon = document.getElementById("delete-container-icon"); + icon.setAttribute("data-identity-icon", identity.image); + icon.setAttribute("data-identity-color", identity.color); + + return Promise.resolve(null); + }, }); + +Logic.init(); diff --git a/webextension/popup.html b/webextension/popup.html index 9fd8beb..85a9346 100644 --- a/webextension/popup.html +++ b/webextension/popup.html @@ -135,8 +135,7 @@
-
«
-
+

From b2bd693e814072a732130293c72695cb74f2802a Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 13 Jan 2017 14:40:27 +0100 Subject: [PATCH 6/9] delete containers --- webextension/js/popup.js | 28 +++++++++++++++++++++------- webextension/popup.html | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 5cb0980..0fdc0d1 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -33,13 +33,7 @@ let Logic = { init() { // Retrieve the list of identities. - browser.runtime.sendMessage({ - method: "queryIdentities" - }) - - .then(identities => { - this._identities = identities; - }) + this.refreshIdentities() // Routing to the correct panel. .then(() => { @@ -53,6 +47,15 @@ let Logic = { }); }, + refreshIdentities() { + return browser.runtime.sendMessage({ + method: "queryIdentities" + }) + .then(identities => { + this._identities = identities; + }); + }, + showPanel(panel, currentIdentity = null) { // Invalid panel... ?!? if (!(panel in this._panels)) { @@ -391,6 +394,17 @@ Logic.registerPanel(P_CONTAINER_DELETE, { document.querySelector("#delete-container-cancel-link").addEventListener("click", () => { Logic.showPanel(P_CONTAINERS_EDIT); }); + + document.querySelector("#delete-container-ok-link").addEventListener("click", () => { + browser.runtime.sendMessage({ + method: "removeIdentity", + userContextId: Logic.currentIdentity().userContextId, + }).then(() => { + return Logic.refreshIdentities(); + }).then(() => { + Logic.showPanel(P_CONTAINERS_EDIT); + }); + }); }, // This method is called when the panel is shown. diff --git a/webextension/popup.html b/webextension/popup.html index 85a9346..e3dbf2c 100644 --- a/webextension/popup.html +++ b/webextension/popup.html @@ -149,7 +149,7 @@ Cancel
From 0dc21cd96eb08e64699e9f4a9c345c62f9cd2033 Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 13 Jan 2017 15:24:37 +0100 Subject: [PATCH 7/9] Create/update and previous panel --- index.js | 6 +++++ webextension/js/popup.js | 57 +++++++++++++++++++++++++++++++--------- webextension/popup.html | 6 ++--- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 440da34..6cb6ab9 100644 --- a/index.js +++ b/index.js @@ -404,6 +404,12 @@ let ContainerService = { // FIXME: icon and color conversion based on FF version. const identity = ContextualIdentityService.create(args.name, args.icon, args.color); + + this._identitiesState[identity.userContextId] = { + hiddenTabUrls: [], + openTabs: 0 + }; + return Promise.resolve(this._convert(identity)); }, diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 0fdc0d1..359d567 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -29,6 +29,8 @@ function log(...args) { let Logic = { _identities: [], _currentIdentity: null, + _currentPanel: null, + _previousPanel: null, _panels: {}, init() { @@ -62,6 +64,9 @@ let Logic = { throw("Something really bad happened. Unknown panel: " + panel + "\n"); } + this._previousPanel = this._currentPanel; + this._currentPanel = panel; + this._currentIdentity = currentIdentity; // Initialize the panel before showing it. @@ -73,6 +78,14 @@ let Logic = { }); }, + showPreviousPanel() { + if (!this._previousPanel) { + throw "Current panel not set!"; + } + + this.showPanel(this._previousPanel, this._currentIdentity); + }, + registerPanel(panelName, panelObject) { this._panels[panelName] = panelObject; panelObject.initialize(); @@ -140,7 +153,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, { // This method is called when the object is registered. initialize() { - document.querySelector(".add-container-link").addEventListener("click", () => { + document.querySelector("#container-add-link").addEventListener("click", () => { Logic.showPanel(P_CONTAINER_EDIT, {}); }); @@ -167,7 +180,6 @@ Logic.registerPanel(P_CONTAINERS_LIST, { fragment.appendChild(tr); tr.classList.add("container-panel-row"); tr.classList.add("clickable"); - tr.setAttribute("data-identity-cookie-store-id", identity.userContextId); tr.innerHTML = `
{ - Logic.showPanel(P_CONTAINERS_LIST); + Logic.showPreviousPanel(); }); document.querySelector("#container-info-hideorshow").addEventListener("click", e => { @@ -303,6 +315,10 @@ Logic.registerPanel(P_CONTAINERS_EDIT, { // This method is called when the object is registered. initialize() { + document.querySelector("#edit-containers-add-link").addEventListener("click", () => { + Logic.showPanel(P_CONTAINER_EDIT, {}); + }); + document.querySelector("#exit-edit-mode-link").addEventListener("click", () => { Logic.showPanel(P_CONTAINERS_LIST); }); @@ -314,7 +330,6 @@ Logic.registerPanel(P_CONTAINERS_EDIT, { Logic.identities().forEach(identity => { let tr = document.createElement("tr"); fragment.appendChild(tr); - tr.setAttribute("data-identity-cookie-store-id", identity.userContextId); tr.classList.add("clickable"); tr.innerHTML = ` @@ -327,16 +342,12 @@ Logic.registerPanel(P_CONTAINERS_EDIT, { @@ -367,18 +378,38 @@ Logic.registerPanel(P_CONTAINER_EDIT, { // This method is called when the object is registered. initialize() { document.querySelector("#edit-container-panel-back-arrow").addEventListener("click", () => { - Logic.showPanel(P_CONTAINERS_EDIT); + Logic.showPreviousPanel(); }); document.querySelector("#edit-container-cancel-link").addEventListener("click", () => { - Logic.showPanel(P_CONTAINERS_EDIT); + Logic.showPreviousPanel(); + }); + + document.querySelector("#edit-container-ok-link").addEventListener("click", () => { + // FIXME: if the name is empty? + + let identity = Logic.currentIdentity(); + browser.runtime.sendMessage({ + method: identity.userContextId ? "updateIdentity" : "createIdentity", + userContextId: identity.userContextId || 0, + name: document.getElementById("edit-container-panel-name-input").value, + icon: identity.image || "fingerprint", + color: identity.color || "green", + }).then(() => { + return Logic.refreshIdentities(); + }).then(() => { + Logic.showPreviousPanel(); + }); }); }, // This method is called when the panel is shown. prepare() { let identity = Logic.currentIdentity(); - document.querySelector("#edit-container-panel-name-input").value = identity.name; + document.querySelector("#edit-container-panel-name-input").value = identity.name || ""; + + // FIXME: color and icon must be set. But we need the UI first. + return Promise.resolve(null); }, }); @@ -392,7 +423,7 @@ Logic.registerPanel(P_CONTAINER_DELETE, { // This method is called when the object is registered. initialize() { document.querySelector("#delete-container-cancel-link").addEventListener("click", () => { - Logic.showPanel(P_CONTAINERS_EDIT); + Logic.showPreviousPanel(); }); document.querySelector("#delete-container-ok-link").addEventListener("click", () => { @@ -402,7 +433,7 @@ Logic.registerPanel(P_CONTAINER_DELETE, { }).then(() => { return Logic.refreshIdentities(); }).then(() => { - Logic.showPanel(P_CONTAINERS_EDIT); + Logic.showPreviousPanel(); }); }); }, diff --git a/webextension/popup.html b/webextension/popup.html index e3dbf2c..2c961ce 100644 --- a/webextension/popup.html +++ b/webextension/popup.html @@ -41,7 +41,7 @@ Edit Containers
@@ -84,7 +84,7 @@ < Exit Edit Mode
@@ -126,7 +126,7 @@ Cancel
From be29b1be8111e0007621afaed97b092131f77598 Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 13 Jan 2017 15:35:08 +0100 Subject: [PATCH 8/9] Some CSS fix --- webextension/css/popup.css | 1 - webextension/js/popup.js | 5 ++--- webextension/popup.html | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/webextension/css/popup.css b/webextension/css/popup.css index bad469d..3c8f79b 100644 --- a/webextension/css/popup.css +++ b/webextension/css/popup.css @@ -79,7 +79,6 @@ table { table.unstriped tbody tr { border-bottom: 1px solid #f1f1f1; background-color: #fefefe; - cursor: pointer; } .userContext-icon { diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 359d567..297fcec 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -330,7 +330,6 @@ Logic.registerPanel(P_CONTAINERS_EDIT, { Logic.identities().forEach(identity => { let tr = document.createElement("tr"); fragment.appendChild(tr); - tr.classList.add("clickable"); tr.innerHTML = `
+ class="icon edit-container-icon clickable" /> `; diff --git a/webextension/popup.html b/webextension/popup.html index 2c961ce..856f583 100644 --- a/webextension/popup.html +++ b/webextension/popup.html @@ -57,10 +57,10 @@

-
+
Hide Container iconHide this container
-
+
Move tabs to a new window
From c176b03c0c1feea3b4e93ec1916aaed1171a5dea Mon Sep 17 00:00:00 2001 From: baku Date: Sat, 14 Jan 2017 22:13:51 +0100 Subject: [PATCH 9/9] review comments applied --- webextension/js/popup.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 297fcec..e3b3623 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -8,7 +8,7 @@ const CONTAINER_HIDE_SRC = "/img/container-hide.svg"; const CONTAINER_UNHIDE_SRC = "/img/container-unhide.svg"; // Let's set it to false before releasing!!! -const DEBUG = false; +const DEBUG = true; // List of panels const P_ONBOARDING_1 = "onboarding1"; @@ -61,7 +61,7 @@ let Logic = { showPanel(panel, currentIdentity = null) { // Invalid panel... ?!? if (!(panel in this._panels)) { - throw("Something really bad happened. Unknown panel: " + panel + "\n"); + throw new Error("Something really bad happened. Unknown panel: " + panel); } this._previousPanel = this._currentPanel; @@ -80,7 +80,7 @@ let Logic = { showPreviousPanel() { if (!this._previousPanel) { - throw "Current panel not set!"; + throw new Error("Current panel not set!"); } this.showPanel(this._previousPanel, this._currentIdentity); @@ -97,7 +97,7 @@ let Logic = { currentIdentity() { if (!this._currentIdentity) { - throw("CurrentIdentity must be set before calling Logic.currentIdentity."); + throw new Error("CurrentIdentity must be set before calling Logic.currentIdentity."); } return this._currentIdentity; }, @@ -178,8 +178,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, { log('identities.forEach'); let tr = document.createElement("tr"); fragment.appendChild(tr); - tr.classList.add("container-panel-row"); - tr.classList.add("clickable"); + tr.classList.add("container-panel-row", "clickable"); tr.innerHTML = ` `; @@ -361,8 +361,10 @@ Logic.registerPanel(P_CONTAINERS_EDIT, { }); }); - document.querySelector("#edit-identities-list").innerHTML = ""; - document.querySelector("#edit-identities-list").appendChild(fragment); + let list = document.querySelector("#edit-identities-list"); + + list.innerHTML = ""; + list.appendChild(fragment); return Promise.resolve(null); },
${tab.title}