Bug 1023734 - make show() method sane and remove hide() method in about:accounts. r=ttaubert
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 12 Jun 2014 13:01:04 +1000
changeset 188332 4bfd917b48393172dbce48302f8c32d5f393e976
parent 188331 354a7e95abb84cdb6b25e85a8b70da8b610016c7
child 188333 be0de0e5b9857ea0440dd8cba47c28bd874f7e61
push id26951
push useremorley@mozilla.com
push dateThu, 12 Jun 2014 14:07:43 +0000
treeherdermozilla-central@4f98802de6ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert
bugs1023734
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1023734 - make show() method sane and remove hide() method in about:accounts. r=ttaubert
browser/base/content/aboutaccounts/aboutaccounts.js
--- a/browser/base/content/aboutaccounts/aboutaccounts.js
+++ b/browser/base/content/aboutaccounts/aboutaccounts.js
@@ -165,17 +165,17 @@ let wrapper = {
               .getService(Ci.nsISupports)
               .wrappedJSObject;
     xps.whenLoaded().then(() => {
       return fxAccounts.setSignedInUser(accountData);
     }).then(() => {
       // If the user data is verified, we want it to immediately look like
       // they are signed in without waiting for messages to bounce around.
       if (accountData.verified) {
-        showManage();
+        show("stage", "manage");
       }
       this.injectData("message", { status: "login" });
       // until we sort out a better UX, just leave the jelly page in place.
       // If the account email is not yet verified, it will tell the user to
       // go check their email, but then it will *not* change state after
       // the verification completes (the browser will begin syncing, but
       // won't notify the user). If the email has already been verified,
       // the jelly will say "Welcome! You are successfully signed in as
@@ -265,18 +265,16 @@ function handleOldSync() {
     .QueryInterface(Ci.nsIInterfaceRequestor)
     .getInterface(Ci.nsIDOMWindow)
     .QueryInterface(Ci.nsIDOMChromeWindow);
   let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "old-sync";
   chromeWin.switchToTabHavingURI(url, true);
 }
 
 function getStarted() {
-  hide("intro");
-  hide("stage");
   show("remote");
 }
 
 function openPrefs() {
   window.openPreferences("paneSync");
 }
 
 function init() {
@@ -284,66 +282,77 @@ function init() {
     // tests in particular might cause the window to start closing before
     // getSignedInUser has returned.
     if (window.closed) {
       return;
     }
     if (window.location.href.contains("action=signin")) {
       if (user) {
         // asking to sign-in when already signed in just shows manage.
-        showManage();
+        show("stage", "manage");
       } else {
         show("remote");
         wrapper.init(fxAccounts.getAccountsSignInURI());
       }
     } else if (window.location.href.contains("action=signup")) {
       if (user) {
         // asking to sign-up when already signed in just shows manage.
-        showManage();
+        show("stage", "manage");
       } else {
         show("remote");
         wrapper.init();
       }
     } else if (window.location.href.contains("action=reauth")) {
       // ideally we would only show this when we know the user is in a
       // "must reauthenticate" state - but we don't.
       // As the email address will be included in the URL returned from
       // promiseAccountsForceSigninURI, just always show it.
       fxAccounts.promiseAccountsForceSigninURI().then(url => {
         show("remote");
         wrapper.init(url);
       });
     } else {
       // No action specified
       if (user) {
-        showManage();
+        show("stage", "manage");
         let sb = Services.strings.createBundle("chrome://browser/locale/syncSetup.properties");
         document.title = sb.GetStringFromName("manage.pageTitle");
       } else {
-        show("stage");
-        show("intro");
+        show("stage", "intro");
         // load the remote frame in the background
         wrapper.init();
       }
     }
   });
 }
 
-function show(id) {
-  document.getElementById(id).style.display = 'block';
-}
-function hide(id) {
-  document.getElementById(id).style.display = 'none';
-}
-
-function showManage() {
-  show("stage");
-  show("manage");
-  hide("remote");
-  hide("intro");
+// Causes the "top-level" element with |id| to be shown - all other top-level
+// elements are hidden.  Optionally, ensures that only 1 "second-level" element
+// inside the top-level one is shown.
+function show(id, childId) {
+  // top-level items are either <div> or <iframe>
+  let allTop = document.querySelectorAll("body > div, iframe");
+  for (let elt of allTop) {
+    if (elt.getAttribute("id") == id) {
+      elt.style.display = 'block';
+    } else {
+      elt.style.display = 'none';
+    }
+  }
+  if (childId) {
+    // child items are all <div>
+    let allSecond = document.querySelectorAll("#" + id + " > div");
+    for (let elt of allSecond) {
+      if (elt.getAttribute("id") == childId) {
+        elt.style.display = 'block';
+      } else {
+        elt.style.display = 'none';
+      }
+    }
+  }
 }
 
 document.addEventListener("DOMContentLoaded", function onload() {
   document.removeEventListener("DOMContentLoaded", onload, true);
   init();
   var buttonGetStarted = document.getElementById('buttonGetStarted');
   buttonGetStarted.addEventListener('click', getStarted);