[extensions-web] js: Put all require-js-like modules in a consistent format



commit e442be9433068aa3f2de50fbe459a7da919cd8d1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Mar 30 21:38:40 2012 -0400

    js: Put all require-js-like modules in a consistent format
    
    Use a variable, "exports", to define the exports of a module, like CommonJS.

 sweettooth/static/js/diff.js           |    6 +++---
 sweettooth/static/js/extensionUtils.js |   10 +++++-----
 sweettooth/static/js/hashParamUtils.js |   22 ++++++++++------------
 sweettooth/static/js/messages.js       |   17 +++++++----------
 sweettooth/static/js/modal.js          |    8 +++-----
 sweettooth/static/js/paginatorUtils.js |   12 +++++-------
 sweettooth/static/js/templates.js      |   11 ++++++-----
 7 files changed, 39 insertions(+), 47 deletions(-)
---
diff --git a/sweettooth/static/js/diff.js b/sweettooth/static/js/diff.js
index 8d04668..f6d9727 100644
--- a/sweettooth/static/js/diff.js
+++ b/sweettooth/static/js/diff.js
@@ -1,6 +1,7 @@
 "use strict";
 
 define(['jquery'], function($) {
+    var exports = {};
 
     // Each table row has four columns:
     // ===================================================================
@@ -177,7 +178,7 @@ define(['jquery'], function($) {
         'replace': buildReplaceChunk
     };
 
-    function buildDiffTable(chunks, oldContents, newContents) {
+    exports.buildDiffTable = function(chunks, oldContents, newContents) {
         var $table = $('<table>', {'class': 'code'});
 
         $.each(chunks, function() {
@@ -187,6 +188,5 @@ define(['jquery'], function($) {
         return $table;
     };
 
-    return { buildDiffTable: buildDiffTable };
-
+    return exports;
 });
diff --git a/sweettooth/static/js/extensionUtils.js b/sweettooth/static/js/extensionUtils.js
index c15d6a0..9eb2be7 100644
--- a/sweettooth/static/js/extensionUtils.js
+++ b/sweettooth/static/js/extensionUtils.js
@@ -2,13 +2,13 @@
 
 define([], function() {
 
-    var module = {};
+    var exports = {};
 
     // ExtensionState is stolen and should be kept in sync with the Shell.
     // Licensed under GPL2+
     // See: http://git.gnome.org/browse/gnome-shell/tree/js/ui/extensionSystem.js
 
-    module.ExtensionState = {
+    exports.ExtensionState = {
         ENABLED: 1,
         DISABLED: 2,
         ERROR: 3,
@@ -21,7 +21,7 @@ define([], function() {
         UNINSTALLED: 99
     };
 
-    module.grabProperExtensionVersion = function(map, current) {
+    exports.grabProperExtensionVersion = function(map, current) {
         if (!map)
             return null;
 
@@ -53,7 +53,7 @@ define([], function() {
         }
     };
 
-    module.findNextHighestVersion = function(map, current) {
+    exports.findNextHighestVersion = function(map, current) {
         function saneParseInt(p) {
             return parseInt(p, 10);
         }
@@ -86,6 +86,6 @@ define([], function() {
                 'version': nextHighestParts.join('.')};
     };
 
-    return module;
+    return exports;
 
 });
diff --git a/sweettooth/static/js/hashParamUtils.js b/sweettooth/static/js/hashParamUtils.js
index 49eaf0c..0c258d5 100644
--- a/sweettooth/static/js/hashParamUtils.js
+++ b/sweettooth/static/js/hashParamUtils.js
@@ -1,8 +1,9 @@
 "use strict";
 
 define(["jquery"], function($) {
+    var exports = {};
 
-    function getHashParams() {
+    var getHashParams = exports.getHashParams = function() {
         var hash = window.location.hash;
         if (!hash)
             return {};
@@ -24,23 +25,20 @@ define(["jquery"], function($) {
         }
 
         return obj;
-    }
+    };
 
-    function setHashParam(name, value) {
+    var setHashParams = exports.setHashParams = function(obj) {
+        window.location.hash = $.param(obj);
+    };
+
+    var setHashParam = exports.setHashParam = function(name, value) {
         var hp = getHashParams();
         if (value === undefined)
             delete hp[name];
         else
             hp[name] = value;
         setHashParams(hp);
-    }
-
-    function setHashParams(obj) {
-        window.location.hash = $.param(obj);
-    }
-
-    return { getHashParams: getHashParams,
-             setHashParam:  setHashParam,
-             setHashParams: setHashParams };
+    };
 
+    return exports;
 });
diff --git a/sweettooth/static/js/messages.js b/sweettooth/static/js/messages.js
index 75a1d4c..2bcc199 100644
--- a/sweettooth/static/js/messages.js
+++ b/sweettooth/static/js/messages.js
@@ -1,6 +1,8 @@
 "use strict";
 
 define(['jquery'], function($) {
+    var exports = {};
+
     var $container = $('#message_container');
 
     var SORT_ORDER = ['error', 'warning', 'info'];
@@ -34,7 +36,7 @@ define(['jquery'], function($) {
         $container.append(messages);
     }
 
-    function addMessage(tag, message) {
+    var addMessage = exports.addMessage = function(tag, message) {
         var message = $('<p>').addClass('message').addClass(tag)
             .append(message).appendTo($container);
 
@@ -43,22 +45,17 @@ define(['jquery'], function($) {
         return message;
     }
 
-    function addInfo(message) {
+    exports.addInfo = function(message) {
         return addMessage('info', message);
     }
 
-    function addWarning(message) {
+    exports.addWarning = function(message) {
         return addMessage('info', message);
     }
 
-    function addError(message) {
+    exports.addError = function(message) {
         return addMessage('error', message);
     }
 
-    return {
-        addMessage: addMessage,
-        addError: addError,
-        addWarning: addWarning,
-        addInfo: addInfo
-    };
+    return exports;
 });
diff --git a/sweettooth/static/js/modal.js b/sweettooth/static/js/modal.js
index f52ca4f..ebf8ed7 100644
--- a/sweettooth/static/js/modal.js
+++ b/sweettooth/static/js/modal.js
@@ -1,6 +1,7 @@
 "use strict";
 
 define(['jquery'], function($) {
+    var exports = {};
 
     // jQuery doesn't support events in the capturing phase natively.
     // This is a trick that fires jQuery's event handler during the
@@ -9,7 +10,7 @@ define(['jquery'], function($) {
         $.event.handle.apply(document.body, arguments);
     }
 
-    function activateModal(elem, closeFunction) {
+    exports.activateModal = function(elem, closeFunction) {
         $(document.body).click(function(e) {
             // If the user clicked inside the modal popup, don't
             // close it.
@@ -29,8 +30,5 @@ define(['jquery'], function($) {
         document.body.addEventListener('click', captureHandler, true);
     }
 
-    return {
-        activateModal: activateModal
-    };
-
+    return exports;
 });
diff --git a/sweettooth/static/js/paginatorUtils.js b/sweettooth/static/js/paginatorUtils.js
index 6ea565a..e493736 100644
--- a/sweettooth/static/js/paginatorUtils.js
+++ b/sweettooth/static/js/paginatorUtils.js
@@ -1,10 +1,9 @@
 "use strict";
 
 define(['jquery', 'hashParamUtils'], function($, hashParamUtils) {
+    var exports = {};
 
-    var module = {};
-
-    var makeLink = module.makeLink = function(pageNumber, styleClass, text) {
+    function makeLink(pageNumber, styleClass, text) {
         styleClass = styleClass === undefined ? "" : styleClass;
         text = text === undefined ? pageNumber.toString() : text;
 
@@ -13,9 +12,9 @@ define(['jquery', 'hashParamUtils'], function($, hashParamUtils) {
 
         return $('<a>', {'class': 'number ' + styleClass,
                          'href': '#' + $.param(hp)}).text(text);
-    };
+    }
 
-    var buildPaginator = module.buildPaginator = function(page, numPages, context) {
+    exports.buildPaginator = function(page, numPages, context) {
         var number = page;
         var contextLeft = Math.max(number-context, 2);
         var contextRight = Math.min(number+context+2, numPages);
@@ -48,6 +47,5 @@ define(['jquery', 'hashParamUtils'], function($, hashParamUtils) {
         return $('<div>', {'class': 'paginator'}).append($elem);
     };
 
-    return module;
-
+    return exports;
 });
diff --git a/sweettooth/static/js/templates.js b/sweettooth/static/js/templates.js
index 3e9cbb6..e3f54f4 100644
--- a/sweettooth/static/js/templates.js
+++ b/sweettooth/static/js/templates.js
@@ -1,9 +1,10 @@
 "use strict";
 
 define(['templates/templatedata', 'mustache'], function(templatedata) {
-    var module = {};
-    var partials = module._P = {};
-    module._T = templatedata;
+
+    var exports = {};
+    var partials = exports._P = {};
+    exports._T = templatedata;
 
     function compile(template) {
         // We have our own template caching, don't use Mustache's.
@@ -32,6 +33,6 @@ define(['templates/templatedata', 'mustache'], function(templatedata) {
         return out;
     }
 
-    _compileTemplateData(templatedata, module, "");
-    return module;
+    _compileTemplateData(templatedata, exports, "");
+    return exports;
 });



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]