From d1dff12514ce04cd8110246b9d1ca698ae85ed3f Mon Sep 17 00:00:00 2001
From: Shane Tomlinson <stomlinson@mozilla.com>
Date: Mon, 18 Jun 2012 11:50:12 +0100
Subject: [PATCH] Update the about page and about code to conform with the
 standards used elsewhere.

* Make the about code use a PageModule.
* Include the about module in the static_resources instead of including it separately.
* Start the about module when looking at the about page.
* Add ultra basic unit test for about page.
---
 lib/static_resources.js                    |  3 +-
 resources/static/pages/about.js            | 32 +++++++++++++++------
 resources/static/pages/start.js            | 12 +++++---
 resources/static/test/cases/pages/about.js | 33 ++++++++++++++++++++++
 resources/views/about.ejs                  |  1 -
 resources/views/test.ejs                   |  2 ++
 6 files changed, 68 insertions(+), 15 deletions(-)
 create mode 100644 resources/static/test/cases/pages/about.js

diff --git a/lib/static_resources.js b/lib/static_resources.js
index 9c0b1e951..b994c3842 100644
--- a/lib/static_resources.js
+++ b/lib/static_resources.js
@@ -68,7 +68,8 @@ var browserid_js = und.flatten([
     '/pages/forgot.js',
     '/pages/manage_account.js',
     '/pages/signin.js',
-    '/pages/signup.js'
+    '/pages/signup.js',
+    '/pages/about.js'
   ]
 ]);
 
diff --git a/resources/static/pages/about.js b/resources/static/pages/about.js
index 1dd98088e..974106253 100644
--- a/resources/static/pages/about.js
+++ b/resources/static/pages/about.js
@@ -3,22 +3,23 @@
  * 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/. */
 
-(function($) {
+BrowserID.about = (function() {
+  "use strict";
 
-  // Homepage half blurbs should be same height when they're next to eachother
-  $(window).load(function(){
+  var bid = BrowserID;
+
+  function resize() {
     // Get tallest blurb
     var tallestBlurb = 0
-    //var blurbPadding = parseInt($('.half').css('paddingTop')) * 2;
 
-    $('.half').each(function(index){
+    $('.half').each(function(index) {
       var $this = $(this);
 
-      if(index == 0){
+      if (index == 0) {
         tallestBlurb = $this.height();
       } else {
-        
-        if( $this.height() < tallestBlurb ){
+
+        if ($this.height() < tallestBlurb) {
           $this.css('min-height', tallestBlurb);
         } else {
           $('.half.first').css('min-height', $this.height());
@@ -26,6 +27,19 @@
 
       }
     });
+  }
+
+  var Module = bid.Modules.PageModule.extend({
+    start: function(options) {
+      var self=this;
+
+      Module.sc.start.call(self, options);
+      resize();
+
+      // The half heights can change every time there is a window resize.
+      self.bind(window, "resize", resize);
+    }
   });
 
-})(jQuery);
+  return Module;
+}());
diff --git a/resources/static/pages/start.js b/resources/static/pages/start.js
index f6bb1b258..62f92b774 100644
--- a/resources/static/pages/start.js
+++ b/resources/static/pages/start.js
@@ -90,7 +90,7 @@ $(function() {
     // footer remains at the bottom of the screen.
     var paddingTop = 0, paddingBottom = 0;
 
-    if(paddingAddedToMinHeight()) {
+    if (paddingAddedToMinHeight()) {
       paddingTop = parseInt($("#content").css("padding-top") || 0, 10);
       paddingBottom = parseInt($("#content").css("padding-bottom") || 0, 10);
     }
@@ -107,7 +107,7 @@ $(function() {
   moduleManager.register("development", Development);
   moduleManager.start("development");
 
-  if(shouldCheckCookies(path)) {
+  if (shouldCheckCookies(path)) {
     // do a cookie check on every page except the main page.
     moduleManager.register("cookie_check", CookieCheck);
     moduleManager.start("cookie_check", { ready: start });
@@ -120,7 +120,7 @@ $(function() {
   function start(status) {
     // If cookies are disabled, do not run any of the page specific code and
     // instead just show the error message.
-    if(!status) return;
+    if (!status) return;
 
 
     if (!path || path === "/") {
@@ -144,13 +144,17 @@ $(function() {
         verifyFunction: "verifyEmail"
       });
     }
-    else if(path === "/verify_email_address") {
+    else if (path === "/verify_email_address") {
       var module = bid.verifySecondaryAddress.create();
       module.start({
         token: token,
         verifyFunction: "verifyUser"
       });
     }
+    else if (path === "/about") {
+      var module = bid.about.create();
+      module.start({});
+    }
     else {
       // Instead of throwing a hard error here, adding a message to the console
       // to let developers know something is up.
diff --git a/resources/static/test/cases/pages/about.js b/resources/static/test/cases/pages/about.js
new file mode 100644
index 000000000..298642ce3
--- /dev/null
+++ b/resources/static/test/cases/pages/about.js
@@ -0,0 +1,33 @@
+/*jshint browsers:true, forin: true, laxbreak: true */
+/*global test: true, start: true, module: true, ok: true, equal: true, BrowserID:true */
+/* 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/. */
+(function() {
+  "use strict";
+
+  var bid = BrowserID,
+      testHelpers = bid.TestHelpers,
+      controller;
+
+  module("pages/about", {
+    setup: function() {
+      testHelpers.setup();
+      bid.Renderer.render("#page_head", "site/about", {});
+    },
+    teardown: function() {
+      testHelpers.teardown();
+    }
+  });
+
+  function createController(options, callback) {
+    controller = BrowserID.about.create();
+    controller.start(options);
+  }
+
+  test("start - no errors", function() {
+    createController({});
+    ok(controller, "controller created");
+  });
+
+}());
diff --git a/resources/views/about.ejs b/resources/views/about.ejs
index 1717fe6ab..dfdeba036 100644
--- a/resources/views/about.ejs
+++ b/resources/views/about.ejs
@@ -46,4 +46,3 @@
     </div><!-- #dashboard -->
 </div>
 
-<%- cachify_js('/pages/about.js') %>
\ No newline at end of file
diff --git a/resources/views/test.ejs b/resources/views/test.ejs
index 7f05abc23..da1332fe1 100644
--- a/resources/views/test.ejs
+++ b/resources/views/test.ejs
@@ -143,6 +143,7 @@
     <script src="/pages/manage_account.js"></script>
     <script src="/pages/signin.js"></script>
     <script src="/pages/signup.js"></script>
+    <script src="/pages/about.js"></script>
 
     <script src="testHelpers/helpers.js"></script>
 
@@ -179,6 +180,7 @@
     <script src="cases/pages/signin.js"></script>
     <script src="cases/pages/signup.js"></script>
     <script src="cases/pages/manage_account.js"></script>
+    <script src="cases/pages/about.js"></script>
 
     <script src="cases/resources/internal_api.js"></script>
     <script src="cases/resources/helpers.js"></script>
-- 
GitLab