Browse Source

We can't not load the crypto libs, breaks r.js optimizer

JC Brand 11 năm trước cách đây
mục cha
commit
518c0fca8a
3 tập tin đã thay đổi với 30 bổ sung21 xóa
  1. 28 19
      converse.js
  2. 0 0
      converse.min.js
  3. 2 2
      index.html

+ 28 - 19
converse.js

@@ -12,6 +12,18 @@
         console = { log: function () {}, error: function () {} };
     }
     if (typeof define === 'function' && define.amd) {
+        var on_load = function(CryptoJS, otr) {
+            // Use Mustache style syntax for variable interpolation
+            _.templateSettings = {
+                evaluate : /\{\[([\s\S]+?)\]\}/g,
+                interpolate : /\{\{([\s\S]+?)\}\}/g
+            };
+            if (typeof otr !== "undefined") {
+                return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
+            } else {
+                return factory(jQuery, _, undefined, undefined, undefined, console);
+            }
+        };
         var dependencies = [
             "crypto",
             "otr",
@@ -24,28 +36,25 @@
             "strophe.vcard",
             "strophe.disco"
         ];
-
-        if ((typeof crypto === 'undefined') ||
-            (    (typeof crypto.randomBytes !== 'function') &&
-                 (typeof crypto.getRandomValues !== 'function')
-            )) {
+        try {
+            define("converse", [
+                "crypto",
+                "otr",
+                "locales",
+                "backbone.localStorage",
+                "jquery.tinysort",
+                "strophe",
+                "strophe.muc",
+                "strophe.roster",
+                "strophe.vcard",
+                "strophe.disco"
+            ], on_load);
+        } catch (e) {
+            console.log(e);
             // Don't load crypto stuff if the browser doesn't have a CSRNG
             dependencies.splice(0, 2);
+            define("converse", dependencies, on_load);
         }
-        define("converse", dependencies, function(CryptoJS, otr) {
-                // Use Mustache style syntax for variable interpolation
-                _.templateSettings = {
-                    evaluate : /\{\[([\s\S]+?)\]\}/g,
-                    interpolate : /\{\{([\s\S]+?)\}\}/g
-                };
-                if (typeof otr !== "undefined") {
-                    return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
-                } else {
-                    return factory(jQuery, _, undefined, undefined, undefined, console);
-                }
-
-            }
-        );
     } else {
         // Browser globals
         _.templateSettings = {

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
converse.min.js


+ 2 - 2
index.html

@@ -6,8 +6,8 @@
     <meta name="description" content="Converse.js: Open Source Browser-Based Instant Messaging" />
     <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
     <link rel="stylesheet" type="text/css" media="screen" href="converse.css">
-    <script data-main="main" src="components/requirejs/require.js"></script>
-    <!-- <script src="converse.min.js"></script>-->
+    <!--<script data-main="main" src="components/requirejs/require.js"></script>-->
+    <script src="converse.min.js"></script>
     <title>Converse.js</title>
 </head>
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác