summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/enable-devtools-popup.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/framework/enable-devtools-popup.js')
-rw-r--r--devtools/client/framework/enable-devtools-popup.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/devtools/client/framework/enable-devtools-popup.js b/devtools/client/framework/enable-devtools-popup.js
new file mode 100644
index 0000000000..a4f7a9e1ef
--- /dev/null
+++ b/devtools/client/framework/enable-devtools-popup.js
@@ -0,0 +1,40 @@
+/* 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/. */
+
+"use strict";
+
+/**
+ * Helper dedicated to toggle a popup triggered by pressing F12 if DevTools have
+ * never been opened by the user.
+ *
+ * This popup should be anchored below the main hamburger menu of Firefox,
+ * which contains the Browser Tools menu.
+ *
+ * This is part of the OFF12 experiment which tries to disable F12 by default to
+ * reduce accidental usage of DevTools and increase retention of non DevTools
+ * users.
+ */
+exports.toggleEnableDevToolsPopup = function (doc) {
+ // The popup is initially wrapped in a template tag to avoid loading
+ // resources on startup. Unwrap it the first time we show the notification.
+ const panelWrapper = doc.getElementById("wrapper-enable-devtools-popup");
+ if (panelWrapper) {
+ panelWrapper.replaceWith(panelWrapper.content);
+ }
+
+ const popup = doc.getElementById("enable-devtools-popup");
+
+ // Use the icon of the Firefox menu in order to be aligned with the
+ // position of the hamburger menu.
+ const anchor = doc
+ .getElementById("PanelUI-menu-button")
+ .querySelector(".toolbarbutton-icon");
+
+ const isVisible = popup.state === "open";
+ if (isVisible) {
+ popup.hidePopup();
+ } else {
+ popup.openPopup(anchor, "bottomcenter topright");
+ }
+};