summaryrefslogtreecommitdiffstats
path: root/application/basilisk/base/content/newtab/customize.js
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-07-18 08:24:24 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-07-18 08:24:24 +0200
commitfc61780b35af913801d72086456f493f63197da6 (patch)
treef85891288a7bd988da9f0f15ae64e5c63f00d493 /application/basilisk/base/content/newtab/customize.js
parent69f7f9e5f1475891ce11cc4f431692f965b0cd30 (diff)
parent50d3e596bbe89c95615f96eb71f6bc5be737a1db (diff)
downloadUXP-fc61780b35af913801d72086456f493f63197da6.tar
UXP-fc61780b35af913801d72086456f493f63197da6.tar.gz
UXP-fc61780b35af913801d72086456f493f63197da6.tar.lz
UXP-fc61780b35af913801d72086456f493f63197da6.tar.xz
UXP-fc61780b35af913801d72086456f493f63197da6.zip
Merge commit '50d3e596bbe89c95615f96eb71f6bc5be737a1db' into Basilisk-releasev2018.07.18
# Conflicts: # browser/app/profile/firefox.js # browser/components/preferences/jar.mn
Diffstat (limited to 'application/basilisk/base/content/newtab/customize.js')
-rw-r--r--application/basilisk/base/content/newtab/customize.js124
1 files changed, 124 insertions, 0 deletions
diff --git a/application/basilisk/base/content/newtab/customize.js b/application/basilisk/base/content/newtab/customize.js
new file mode 100644
index 000000000..39724fa91
--- /dev/null
+++ b/application/basilisk/base/content/newtab/customize.js
@@ -0,0 +1,124 @@
+#ifdef 0
+/* 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/. */
+#endif
+
+var gCustomize = {
+ _nodeIDSuffixes: [
+ "blank",
+ "button",
+ "classic",
+ "enhanced",
+ "panel",
+ "overlay",
+ "learn"
+ ],
+
+ _nodes: {},
+
+ init: function() {
+ for (let idSuffix of this._nodeIDSuffixes) {
+ this._nodes[idSuffix] = document.getElementById("newtab-customize-" + idSuffix);
+ }
+
+ this._nodes.button.addEventListener("click", e => this.showPanel(e));
+ this._nodes.blank.addEventListener("click", this);
+ this._nodes.classic.addEventListener("click", this);
+ this._nodes.learn.addEventListener("click", this);
+
+ this.updateSelected();
+ },
+
+ hidePanel: function() {
+ this._nodes.overlay.addEventListener("transitionend", function onTransitionEnd() {
+ gCustomize._nodes.overlay.removeEventListener("transitionend", onTransitionEnd);
+ gCustomize._nodes.overlay.style.display = "none";
+ });
+ this._nodes.overlay.style.opacity = 0;
+ this._nodes.button.removeAttribute("active");
+ this._nodes.panel.removeAttribute("open");
+ document.removeEventListener("click", this);
+ document.removeEventListener("keydown", this);
+ },
+
+ showPanel: function(event) {
+ if (this._nodes.panel.getAttribute("open") == "true") {
+ return;
+ }
+
+ let {panel, button, overlay} = this._nodes;
+ overlay.style.display = "block";
+ panel.setAttribute("open", "true");
+ button.setAttribute("active", "true");
+ setTimeout(() => {
+ // Wait for display update to take place, then animate.
+ overlay.style.opacity = 0.8;
+ }, 0);
+
+ document.addEventListener("click", this);
+ document.addEventListener("keydown", this);
+
+ // Stop the event propogation to prevent panel from immediately closing
+ // via the document click event that we just added.
+ event.stopPropagation();
+ },
+
+ handleEvent: function(event) {
+ switch (event.type) {
+ case "click":
+ this.onClick(event);
+ break;
+ case "keydown":
+ this.onKeyDown(event);
+ break;
+ }
+ },
+
+ onClick: function(event) {
+ if (event.currentTarget == document) {
+ if (!this._nodes.panel.contains(event.target)) {
+ this.hidePanel();
+ }
+ }
+ switch (event.currentTarget.id) {
+ case "newtab-customize-blank":
+ sendAsyncMessage("NewTab:Customize", {enabled: false, enhanced: false});
+ break;
+ case "newtab-customize-classic":
+ sendAsyncMessage("NewTab:Customize", {enabled: true, enhanced: false});
+ break;
+ case "newtab-customize-enhanced":
+ sendAsyncMessage("NewTab:Customize", {enabled: true, enhanced: !gAllPages.enhanced});
+ break;
+ case "newtab-customize-learn":
+ this.showLearn();
+ break;
+ }
+ },
+
+ onKeyDown: function(event) {
+ if (event.keyCode == event.DOM_VK_ESCAPE) {
+ this.hidePanel();
+ }
+ },
+
+ showLearn: function() {
+ window.open(TILES_INTRO_LINK, 'new_window');
+ this.hidePanel();
+ },
+
+ updateSelected: function() {
+ let {enabled} = gAllPages;
+ let selected = enabled ? "classic" : "blank";
+ ["classic", "blank"].forEach(id => {
+ let node = this._nodes[id];
+ if (id == selected) {
+ node.setAttribute("selected", true);
+ }
+ else {
+ node.removeAttribute("selected");
+ }
+ });
+ },
+};