Prechádzať zdrojové kódy

Explicitly list dependencies for modules

Instead of using the deps-*.js files. Builds will currently break, they still
need to be reworked.

Also moved the refreshWebkit method to utils.
JC Brand 9 rokov pred
rodič
commit
e68c51d2fa

+ 1 - 3
Gruntfile.js

@@ -61,9 +61,7 @@ module.exports = function(grunt) {
              rjs + ' -o src/build-no-jquery.js &&' +
              rjs + ' -o src/build-no-jquery.js &&' +
              rjs + ' -o src/build-no-jquery.js optimize=none out=builds/converse.nojquery.js && ' +
              rjs + ' -o src/build-no-jquery.js optimize=none out=builds/converse.nojquery.js && ' +
              rjs + ' -o src/build-no-locales-no-otr.js && ' +
              rjs + ' -o src/build-no-locales-no-otr.js && ' +
-             rjs + ' -o src/build-no-locales-no-otr.js optimize=none out=builds/converse-no-locales-no-otr.js && ' +
-             rjs + ' -o src/build-no-otr.js &&' +
-             rjs + ' -o src/build-no-otr.js optimize=none out=builds/converse-no-otr.js', callback);
+             rjs + ' -o src/build-no-locales-no-otr.js optimize=none out=builds/converse-no-locales-no-otr.js', callback);
             // XXX: It might be possible to not have separate build config files. For example:
             // XXX: It might be possible to not have separate build config files. For example:
             // 'r.js -o src/build.js paths.converse-dependencies=src/deps-no-otr paths.locales=locale/nolocales out=builds/converse-no-locales-no-otr.min.js'
             // 'r.js -o src/build.js paths.converse-dependencies=src/deps-no-otr paths.locales=locale/nolocales out=builds/converse-no-locales-no-otr.min.js'
     });
     });

+ 0 - 1
main.js

@@ -50,7 +50,6 @@ require.config({
         "converse-otr":             "src/converse-otr",
         "converse-otr":             "src/converse-otr",
         "converse-ping":            "src/converse-ping",
         "converse-ping":            "src/converse-ping",
         "converse-register":        "src/converse-register",
         "converse-register":        "src/converse-register",
-        "converse-dependencies":    "src/deps-full",
         "converse-templates":       "src/templates",
         "converse-templates":       "src/templates",
 
 
         // Off-the-record-encryption
         // Off-the-record-encryption

+ 0 - 1
src/build-no-jquery.js

@@ -5,7 +5,6 @@
     include: ['main'],
     include: ['main'],
     mainConfigFile: '../main.js',
     mainConfigFile: '../main.js',
     paths: {
     paths: {
-        "converse-dependencies":    "src/deps-full",
         "jquery":                   "src/jquery-external",
         "jquery":                   "src/jquery-external",
         "jquery-private":           "src/jquery-private-external",
         "jquery-private":           "src/jquery-private-external",
     }
     }

+ 0 - 1
src/build-no-locales-no-otr.js

@@ -6,7 +6,6 @@
     mainConfigFile: '../main.js',
     mainConfigFile: '../main.js',
     paths: {
     paths: {
         "moment_with_locales":    "components/momentjs/moment",
         "moment_with_locales":    "components/momentjs/moment",
-        "converse-dependencies":  "src/deps-no-otr",
         "locales":                "locale/nolocales"
         "locales":                "locale/nolocales"
     }
     }
 })
 })

+ 1 - 4
src/build.js

@@ -3,8 +3,5 @@
     name: "components/almond/almond.js",
     name: "components/almond/almond.js",
     out: "../builds/converse.min.js",
     out: "../builds/converse.min.js",
     include: ['main'],
     include: ['main'],
-    mainConfigFile: '../main.js',
-    paths: {
-        "converse-dependencies":    "src/deps-full"
-    }
+    mainConfigFile: '../main.js'
 })
 })

+ 32 - 36
src/converse-core.js

@@ -15,28 +15,35 @@
     //
     //
     // The dependencies are then split up and passed into the factory function,
     // The dependencies are then split up and passed into the factory function,
     // which contains and instantiates converse.js.
     // which contains and instantiates converse.js.
-    define("converse-core", ["converse-dependencies", "converse-templates"],
-        function (dependencies, templates) {
-            return factory(
-                templates,
-                dependencies.jQuery,
-                dependencies.$iq,
-                dependencies.$msg,
-                dependencies.$pres,
-                dependencies.$build,
-                dependencies.Strophe,
-                dependencies.underscore,
-                dependencies.moment,
-                dependencies.utils,
-                dependencies.SHA1.b64_sha1
-            );
-        }
-    );
-}(this, function (templates, $, $iq, $msg, $pres, $build, Strophe, _, moment, utils, b64_sha1) {
-    /* "use strict";
+    define("converse-core", [
+        "jquery",
+        "underscore",
+        "polyfill",
+        "utils",
+        "moment_with_locales",
+        "strophe",
+        "converse-templates",
+        "strophe.disco",
+        "strophe.rsm",
+        "strophe.vcard",
+        "backbone.browserStorage",
+        "backbone.overview",
+        "typeahead",
+    ], factory);
+}(this, function ($, _, dummy, utils, moment, Strophe, templates) {
+    /* 
      * Cannot use this due to Safari bug.
      * Cannot use this due to Safari bug.
      * See https://github.com/jcbrand/converse.js/issues/196
      * See https://github.com/jcbrand/converse.js/issues/196
      */
      */
+    // "use strict";
+
+    // Strophe globals
+    var $build = Strophe.$build;
+    var $iq = Strophe.$iq;
+    var $msg = Strophe.$msg;
+    var $pres = Strophe.$pres;
+    var b64_sha1 = Strophe.SHA1.b64_sha1;
+    Strophe = Strophe.Strophe;
 
 
     // Use Mustache style syntax for variable interpolation
     // Use Mustache style syntax for variable interpolation
     /* Configuration of underscore templates (this config is distinct to the
     /* Configuration of underscore templates (this config is distinct to the
@@ -61,17 +68,6 @@
         },
         },
         off: function (evt, handler) {
         off: function (evt, handler) {
             $(this).unbind(evt, handler);
             $(this).unbind(evt, handler);
-        },
-        refreshWebkit: function () {
-            /* This works around a webkit bug. Refresh the browser's viewport,
-             * otherwise chatboxes are not moved along when one is closed.
-             */
-            if ($.browser.webkit) {
-                var conversejs = document.getElementById('conversejs');
-                conversejs.style.display = 'none';
-                conversejs.offsetHeight = conversejs.offsetHeight;
-                conversejs.style.display = 'block';
-            }
         }
         }
     };
     };
 
 
@@ -1058,7 +1054,7 @@
                 this.renderToolbar().renderAvatar();
                 this.renderToolbar().renderAvatar();
                 this.$content.on('scroll', _.debounce(this.onScroll.bind(this), 100));
                 this.$content.on('scroll', _.debounce(this.onScroll.bind(this), 100));
                 converse.emit('chatBoxOpened', this);
                 converse.emit('chatBoxOpened', this);
-                window.setTimeout(converse.refreshWebkit, 50);
+                window.setTimeout(utils.refreshWebkit, 50);
                 return this.showStatusMessage();
                 return this.showStatusMessage();
             },
             },
 
 
@@ -1718,7 +1714,7 @@
                      * to make space available if need be.
                      * to make space available if need be.
                      */
                      */
                     chatboxviews.trimChats(this);
                     chatboxviews.trimChats(this);
-                    converse.refreshWebkit();
+                    utils.refreshWebkit();
                     this.$content.scrollTop(this.model.get('scroll'));
                     this.$content.scrollTop(this.model.get('scroll'));
                     this.setChatState(ACTIVE).focus();
                     this.setChatState(ACTIVE).focus();
                     converse.emit('chatBoxMaximized', this);
                     converse.emit('chatBoxMaximized', this);
@@ -1731,7 +1727,7 @@
                 this.model.save({'scroll': this.$content.scrollTop()});
                 this.model.save({'scroll': this.$content.scrollTop()});
                 // Minimizes a chat box
                 // Minimizes a chat box
                 this.setChatState(INACTIVE).model.minimize();
                 this.setChatState(INACTIVE).model.minimize();
-                this.$el.hide('fast', converse.refreshwebkit);
+                this.$el.hide('fast', utils.refreshwebkit);
                 converse.emit('chatBoxMinimized', this);
                 converse.emit('chatBoxMinimized', this);
             },
             },
 
 
@@ -1812,7 +1808,7 @@
             hide: function () {
             hide: function () {
                 if (this.$el.is(':visible') && this.$el.css('opacity') === "1") {
                 if (this.$el.is(':visible') && this.$el.css('opacity') === "1") {
                     this.$el.hide();
                     this.$el.hide();
-                    converse.refreshWebkit();
+                    utils.refreshWebkit();
                 }
                 }
                 return this;
                 return this;
             },
             },
@@ -2086,7 +2082,7 @@
 
 
             hide: function (callback) {
             hide: function (callback) {
                 this.$el.hide('fast', function () {
                 this.$el.hide('fast', function () {
-                    converse.refreshWebkit();
+                    utils.refreshWebkit();
                     converse.emit('chatBoxClosed', this);
                     converse.emit('chatBoxClosed', this);
                     converse.controlboxtoggle.show(function () {
                     converse.controlboxtoggle.show(function () {
                         if (typeof callback === "function") {
                         if (typeof callback === "function") {
@@ -2103,7 +2099,7 @@
                         if (converse.rosterview) {
                         if (converse.rosterview) {
                             converse.rosterview.update();
                             converse.rosterview.update();
                         }
                         }
-                        converse.refreshWebkit();
+                        utils.refreshWebkit();
                     }.bind(this));
                     }.bind(this));
                     converse.emit('controlBoxOpened', this);
                     converse.emit('controlBoxOpened', this);
                 }.bind(this));
                 }.bind(this));

+ 5 - 1
src/converse-ping.js

@@ -10,7 +10,11 @@
  * as specified in XEP-0199 XMPP Ping.
  * as specified in XEP-0199 XMPP Ping.
  */
  */
 (function (root, factory) {
 (function (root, factory) {
-    define("converse-ping", ["converse-core", "converse-api"], factory);
+    define("converse-ping", [
+        "converse-core",
+        "converse-api",
+        "strophe.ping"
+    ], factory);
 }(this, function (converse, converse_api) {
 }(this, function (converse, converse_api) {
     "use strict";
     "use strict";
     // Strophe methods for building stanzas
     // Strophe methods for building stanzas

+ 0 - 23
src/deps-full.js

@@ -1,23 +0,0 @@
-define("converse-dependencies", [
-    "jquery",
-    "underscore",
-    "polyfill",
-    "utils",
-    "moment_with_locales",
-    "strophe",
-    "strophe.disco",
-    "strophe.ping",
-    "strophe.rsm",
-    "strophe.vcard",
-    "backbone.browserStorage",
-    "backbone.overview",
-    "jquery.browser",
-    "typeahead"
-], function($, _, dummy, utils, moment, Strophe) {
-    return _.extend({
-        'underscore': _,
-        'jQuery': $,
-        'moment': moment,
-        'utils': utils
-    }, Strophe);
-});

+ 0 - 24
src/deps-no-otr.js

@@ -1,24 +0,0 @@
-define("converse-dependencies", [
-    "jquery",
-    "underscore",
-    "polyfill",
-    "utils",
-    "moment_with_locales",
-    "strophe",
-    "strophe.disco",
-    "strophe.ping",
-    "strophe.rsm",
-    "strophe.vcard",
-    "backbone.browserStorage",
-    "backbone.overview",
-    "jquery.browser",
-    "typeahead"
-], function($, _, dummy, utils, moment, Strophe) {
-    return _.extend({
-        'underscore': _,
-        'jQuery': $,
-        'otr': undefined,
-        'moment': moment,
-        'utils': utils
-    }, Strophe);
-});

+ 22 - 7
src/utils.js

@@ -1,11 +1,14 @@
-/*global jQuery, templates, escape, _, locales */
+/*global escape */
 (function (root, factory) {
 (function (root, factory) {
-    if (typeof define === 'function' && define.amd) {
-        define(["jquery", "underscore", "jed", "converse-templates", "locales"], factory);
-    } else {
-        root.utils = factory(jQuery, _, templates, locales);
-    }
-}(this, function ($, _, Jed, templates, locales) {
+    define([
+        "jquery",
+        "jquery.browser",
+        "underscore",
+        "jed",
+        "converse-templates",
+        "locales"
+    ], factory);
+}(this, function ($, dummy, _, Jed, templates, locales) {
     "use strict";
     "use strict";
 
 
     var XFORM_TYPE_MAP = {
     var XFORM_TYPE_MAP = {
@@ -121,6 +124,18 @@
             return str;
             return str;
         },
         },
 
 
+        refreshWebkit: function () {
+            /* This works around a webkit bug. Refreshes the browser's viewport,
+             * otherwise chatboxes are not moved along when one is closed.
+             */
+            if ($.browser.webkit) {
+                var conversejs = document.getElementById('conversejs');
+                conversejs.style.display = 'none';
+                var tmp = conversejs.offsetHeight; // jshint ignore:line
+                conversejs.style.display = 'block';
+            }
+        },
+
         webForm2xForm: function (field) {
         webForm2xForm: function (field) {
             /* Takes an HTML DOM and turns it into an XForm field.
             /* Takes an HTML DOM and turns it into an XForm field.
             *
             *