Simplify further using Maps to remove string key
This commit is contained in:
parent
76f934cae4
commit
aa4268a518
1 changed files with 31 additions and 29 deletions
60
index.js
60
index.js
|
@ -865,8 +865,8 @@ ContainerWindow.prototype = {
|
||||||
_style: null,
|
_style: null,
|
||||||
_panelElement: null,
|
_panelElement: null,
|
||||||
_timeoutId: 0,
|
_timeoutId: 0,
|
||||||
_elementCache: {},
|
_elementCache: new Map(),
|
||||||
_tooltipCache: {},
|
_tooltipCache: new Map(),
|
||||||
_plusButton: null,
|
_plusButton: null,
|
||||||
_overflowPlusButton: null,
|
_overflowPlusButton: null,
|
||||||
_tabsElement: null,
|
_tabsElement: null,
|
||||||
|
@ -918,11 +918,11 @@ ContainerWindow.prototype = {
|
||||||
this._panelElement.openPopup(buttonElement);
|
this._panelElement.openPopup(buttonElement);
|
||||||
},
|
},
|
||||||
|
|
||||||
_configurePlusButtonMenuElement(name, buttonElement) {
|
_configurePlusButtonMenuElement(buttonElement) {
|
||||||
// Let's remove the tooltip because it can go over our panel.
|
// Let's remove the tooltip because it can go over our panel.
|
||||||
this._tooltipCache[name] = buttonElement.getAttribute("tooltip");
|
this._tooltipCache.set(buttonElement, buttonElement.getAttribute("tooltip"));
|
||||||
buttonElement.setAttribute("tooltip", "");
|
buttonElement.setAttribute("tooltip", "");
|
||||||
this._disableElement(buttonElement, name);
|
this._disableElement(buttonElement);
|
||||||
|
|
||||||
buttonElement.addEventListener("mouseover", this);
|
buttonElement.addEventListener("mouseover", this);
|
||||||
buttonElement.addEventListener("click", this);
|
buttonElement.addEventListener("click", this);
|
||||||
|
@ -947,8 +947,8 @@ ContainerWindow.prototype = {
|
||||||
this._panelElement.setAttribute("consumeoutsideclicks", "never");
|
this._panelElement.setAttribute("consumeoutsideclicks", "never");
|
||||||
mainPopupSetElement.appendChild(this._panelElement);
|
mainPopupSetElement.appendChild(this._panelElement);
|
||||||
|
|
||||||
this._configurePlusButtonMenuElement("plusButton", this._plusButton);
|
this._configurePlusButtonMenuElement(this._plusButton);
|
||||||
this._configurePlusButtonMenuElement("overflowPlusButton", this._overflowPlusButton);
|
this._configurePlusButtonMenuElement(this._overflowPlusButton);
|
||||||
|
|
||||||
this._panelElement.addEventListener("mouseout", this);
|
this._panelElement.addEventListener("mouseout", this);
|
||||||
|
|
||||||
|
@ -1007,7 +1007,7 @@ ContainerWindow.prototype = {
|
||||||
userContextId: userContextId,
|
userContextId: userContextId,
|
||||||
source: "file-menu"
|
source: "file-menu"
|
||||||
});
|
});
|
||||||
}, "fileMenu");
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_configureContextMenu() {
|
_configureContextMenu() {
|
||||||
|
@ -1021,16 +1021,15 @@ ContainerWindow.prototype = {
|
||||||
// This is a super internal method. Hopefully it will be stable in the
|
// This is a super internal method. Hopefully it will be stable in the
|
||||||
// next FF releases.
|
// next FF releases.
|
||||||
this._window.gContextMenu.openLinkInTab(e);
|
this._window.gContextMenu.openLinkInTab(e);
|
||||||
},
|
}
|
||||||
"contextMenu"
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Generic menu configuration.
|
// Generic menu configuration.
|
||||||
_configureMenu(menuId, excludedContainerCb, clickCb, elementKey) {
|
_configureMenu(menuId, excludedContainerCb, clickCb) {
|
||||||
const menu = this._window.document.getElementById(menuId);
|
const menu = this._window.document.getElementById(menuId);
|
||||||
this._disableElement(menu, elementKey);
|
this._disableElement(menu);
|
||||||
if (!this._disableElement(menu, elementKey)) {
|
if (!this._disableElement(menu)) {
|
||||||
// Delete stale menu that isn't native elements
|
// Delete stale menu that isn't native elements
|
||||||
while (menu.firstChild) {
|
while (menu.firstChild) {
|
||||||
menu.removeChild(menu.firstChild);
|
menu.removeChild(menu.firstChild);
|
||||||
|
@ -1120,9 +1119,9 @@ ContainerWindow.prototype = {
|
||||||
this._shutdownContextMenu();
|
this._shutdownContextMenu();
|
||||||
},
|
},
|
||||||
|
|
||||||
_shutDownPlusButtonMenuElement(name, buttonElement) {
|
_shutDownPlusButtonMenuElement(buttonElement) {
|
||||||
this._shutdownElement(buttonElement, name);
|
this._shutdownElement(buttonElement);
|
||||||
buttonElement.setAttribute("tooltip", this._tooltipCache[name]);
|
buttonElement.setAttribute("tooltip", this._tooltipCache.get(buttonElement));
|
||||||
|
|
||||||
buttonElement.removeEventListener("mouseover", this);
|
buttonElement.removeEventListener("mouseover", this);
|
||||||
buttonElement.removeEventListener("click", this);
|
buttonElement.removeEventListener("click", this);
|
||||||
|
@ -1130,48 +1129,51 @@ ContainerWindow.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_shutdownPlusButtonMenu() {
|
_shutdownPlusButtonMenu() {
|
||||||
this._shutDownPlusButtonMenuElement("plusButton", this._plusButton);
|
this._shutDownPlusButtonMenuElement(this._plusButton);
|
||||||
this._shutDownPlusButtonMenuElement("overflowPlusButton", this._overflowPlusButton);
|
this._shutDownPlusButtonMenuElement(this._overflowPlusButton);
|
||||||
},
|
},
|
||||||
|
|
||||||
_shutdownFileMenu() {
|
_shutdownFileMenu() {
|
||||||
this._shutdownMenu("menu_newUserContext", "fileMenu");
|
this._shutdownMenu("menu_newUserContext");
|
||||||
},
|
},
|
||||||
|
|
||||||
_shutdownContextMenu() {
|
_shutdownContextMenu() {
|
||||||
this._shutdownMenu("context-openlinkinusercontext-menu",
|
this._shutdownMenu("context-openlinkinusercontext-menu");
|
||||||
"contextMenu");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_shutdownMenu(menuId, elementKey) {
|
_shutdownMenu(menuId) {
|
||||||
const menu = this._window.document.getElementById(menuId);
|
const menu = this._window.document.getElementById(menuId);
|
||||||
this._shutdownElement(menu, elementKey);
|
this._shutdownElement(menu);
|
||||||
},
|
},
|
||||||
|
|
||||||
_shutdownElement(element, elementKey) {
|
_shutdownElement(element) {
|
||||||
// Let's remove our elements.
|
// Let's remove our elements.
|
||||||
while (element.firstChild) {
|
while (element.firstChild) {
|
||||||
element.firstChild.remove();
|
element.firstChild.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let e of this._elementCache[elementKey]) { // eslint-disable-line prefer-const
|
const elementCache = this._elementCache.get(element);
|
||||||
|
|
||||||
|
for (let e of elementCache) { // eslint-disable-line prefer-const
|
||||||
element.appendChild(e);
|
element.appendChild(e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_disableElement(element, elementKey) {
|
_disableElement(element) {
|
||||||
// Nothing to disable.
|
// Nothing to disable.
|
||||||
if (!element || this._elementCache[elementKey]) {
|
if (!element || this._elementCache.has(element)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this._elementCache[elementKey] = [];
|
const cacheArray = [];
|
||||||
|
|
||||||
// Let's store the previous elements so that we can repopulate it in case
|
// Let's store the previous elements so that we can repopulate it in case
|
||||||
// the addon is uninstalled.
|
// the addon is uninstalled.
|
||||||
while (element.firstChild) {
|
while (element.firstChild) {
|
||||||
this._elementCache[elementKey].push(element.removeChild(element.firstChild));
|
cacheArray.push(element.removeChild(element.firstChild));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._elementCache.set(element, cacheArray);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue