Disable the long-press menu (#176)
This commit is contained in:
parent
e970cd4baa
commit
3a2e351661
1 changed files with 46 additions and 19 deletions
65
index.js
65
index.js
|
@ -738,6 +738,10 @@ ContainerWindow.prototype = {
|
||||||
_timeoutId: 0,
|
_timeoutId: 0,
|
||||||
_fileMenuElements: [],
|
_fileMenuElements: [],
|
||||||
_contextMenuElements: [],
|
_contextMenuElements: [],
|
||||||
|
_plusButtonElements: [],
|
||||||
|
_plusButtonTooltip: "",
|
||||||
|
_overflowPlusButtonElements: [],
|
||||||
|
_overflowPlusButtonTooltip: "",
|
||||||
|
|
||||||
_init(window) {
|
_init(window) {
|
||||||
this._window = window;
|
this._window = window;
|
||||||
|
@ -760,10 +764,16 @@ ContainerWindow.prototype = {
|
||||||
|
|
||||||
const mainPopupSetElement = this._window.document.getElementById("mainPopupSet");
|
const mainPopupSetElement = this._window.document.getElementById("mainPopupSet");
|
||||||
const button = this._window.document.getAnonymousElementByAttribute(tabsElement, "anonid", "tabs-newtab-button");
|
const button = this._window.document.getAnonymousElementByAttribute(tabsElement, "anonid", "tabs-newtab-button");
|
||||||
|
this._disableElement(button, "_plusButtonElements");
|
||||||
|
|
||||||
const overflowButton = this._window.document.getElementById("new-tab-button");
|
const overflowButton = this._window.document.getElementById("new-tab-button");
|
||||||
|
this._disableElement(overflowButton, "_overflowPlusButtonElements");
|
||||||
|
|
||||||
// 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._plusButtonTooltip = button.getAttribute("tooltip");
|
||||||
button.setAttribute("tooltip", "");
|
button.setAttribute("tooltip", "");
|
||||||
|
|
||||||
|
this._overflowPlusButtonTooltip = overflowButton.getAttribute("tooltip");
|
||||||
overflowButton.setAttribute("tooltip", "");
|
overflowButton.setAttribute("tooltip", "");
|
||||||
|
|
||||||
// Let's remove all the previous panels.
|
// Let's remove all the previous panels.
|
||||||
|
@ -882,23 +892,10 @@ ContainerWindow.prototype = {
|
||||||
// Generic menu configuration.
|
// Generic menu configuration.
|
||||||
_configureMenu(menuId, excludedContainerCb, clickCb, arrayName) {
|
_configureMenu(menuId, excludedContainerCb, clickCb, arrayName) {
|
||||||
const menu = this._window.document.getElementById(menuId);
|
const menu = this._window.document.getElementById(menuId);
|
||||||
// containerAddonMagic attribute is a custom attribute we set in order to
|
if (!this._disableElement(menu, arrayName)) {
|
||||||
// know if this menu has been already converted.
|
|
||||||
if (!menu) {
|
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't want to recreate the menu each time.
|
|
||||||
if (this[arrayName].length) {
|
|
||||||
return Promise.resolve(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let's store the previous elements so that we can repopulate it in case
|
|
||||||
// the addon is uninstalled.
|
|
||||||
while (menu.firstChild) {
|
|
||||||
this[arrayName].push(menu.removeChild(menu.firstChild));
|
|
||||||
}
|
|
||||||
|
|
||||||
const menupopup = this._window.document.createElementNS(XUL_NS, "menupopup");
|
const menupopup = this._window.document.createElementNS(XUL_NS, "menupopup");
|
||||||
menu.appendChild(menupopup);
|
menu.appendChild(menupopup);
|
||||||
|
|
||||||
|
@ -980,10 +977,22 @@ ContainerWindow.prototype = {
|
||||||
// CSS must be removed.
|
// CSS must be removed.
|
||||||
detachFrom(this._style, this._window);
|
detachFrom(this._style, this._window);
|
||||||
|
|
||||||
|
this._shutdownPlusButtonMenu();
|
||||||
this._shutdownFileMenu();
|
this._shutdownFileMenu();
|
||||||
this._shutdownContextMenu();
|
this._shutdownContextMenu();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_shutdownPlusButtonMenu() {
|
||||||
|
const tabsElement = this._window.document.getElementById("tabbrowser-tabs");
|
||||||
|
const button = this._window.document.getAnonymousElementByAttribute(tabsElement, "anonid", "tabs-newtab-button");
|
||||||
|
this._shutdownElement(button, "_plusButtonElements");
|
||||||
|
button.setAttribute("tooltip", this._plusButtonTooltip);
|
||||||
|
|
||||||
|
const overflowButton = this._window.document.getElementById("new-tab-button");
|
||||||
|
this._shutdownElement(overflowButton, "_overflowPlusButtonElements");
|
||||||
|
overflowButton.setAttribute("tooltip", this._overflowPlusButtonTooltip);
|
||||||
|
},
|
||||||
|
|
||||||
_shutdownFileMenu() {
|
_shutdownFileMenu() {
|
||||||
this._shutdownMenu("menu_newUserContext", "_fileMenuElements");
|
this._shutdownMenu("menu_newUserContext", "_fileMenuElements");
|
||||||
},
|
},
|
||||||
|
@ -995,16 +1004,34 @@ ContainerWindow.prototype = {
|
||||||
|
|
||||||
_shutdownMenu(menuId, arrayName) {
|
_shutdownMenu(menuId, arrayName) {
|
||||||
const menu = this._window.document.getElementById(menuId);
|
const menu = this._window.document.getElementById(menuId);
|
||||||
|
this._shutdownElement(menu, arrayName);
|
||||||
|
},
|
||||||
|
|
||||||
|
_shutdownElement(element, arrayName) {
|
||||||
// Let's remove our elements.
|
// Let's remove our elements.
|
||||||
while (menu.firstChild) {
|
while (element.firstChild) {
|
||||||
menu.firstChild.remove();
|
element.firstChild.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let element of this[arrayName]) { // eslint-disable-line prefer-const
|
for (let e of this[arrayName]) { // eslint-disable-line prefer-const
|
||||||
menu.appendChild(element);
|
element.appendChild(e);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
_disableElement(element, arrayName) {
|
||||||
|
// Nothing to disable.
|
||||||
|
if (!element || this[arrayName].length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let's store the previous elements so that we can repopulate it in case
|
||||||
|
// the addon is uninstalled.
|
||||||
|
while (element.firstChild) {
|
||||||
|
this[arrayName].push(element.removeChild(element.firstChild));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// uninstall/install events ---------------------------------------------------
|
// uninstall/install events ---------------------------------------------------
|
||||||
|
|
Loading…
Add table
Reference in a new issue