Commit 67c99f60 authored by JC Brand's avatar JC Brand

Don't put define in try/catch. Breaks optimizer.

Add check HAS_CSPRNG instead of the previous check
parent 518c0fca
...@@ -12,31 +12,6 @@ ...@@ -12,31 +12,6 @@
console = { log: function () {}, error: function () {} }; console = { log: function () {}, error: function () {} };
} }
if (typeof define === 'function' && define.amd) { 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",
"locales",
"backbone.localStorage",
"jquery.tinysort",
"strophe",
"strophe.muc",
"strophe.roster",
"strophe.vcard",
"strophe.disco"
];
try {
define("converse", [ define("converse", [
"crypto", "crypto",
"otr", "otr",
...@@ -48,13 +23,14 @@ ...@@ -48,13 +23,14 @@
"strophe.roster", "strophe.roster",
"strophe.vcard", "strophe.vcard",
"strophe.disco" "strophe.disco"
], on_load); ], function(CryptoJS, otr) {
} catch (e) { // Use Mustache style syntax for variable interpolation
console.log(e); _.templateSettings = {
// Don't load crypto stuff if the browser doesn't have a CSRNG evaluate : /\{\[([\s\S]+?)\]\}/g,
dependencies.splice(0, 2); interpolate : /\{\{([\s\S]+?)\}\}/g
define("converse", dependencies, on_load); };
} return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
});
} else { } else {
// Browser globals // Browser globals
_.templateSettings = { _.templateSettings = {
...@@ -77,11 +53,10 @@ ...@@ -77,11 +53,10 @@
var KEY = { var KEY = {
ENTER: 13 ENTER: 13
}; };
var HAS_CRYPTO = ( var HAS_CSPRNG = ((typeof crypto === 'undefined') || (
(typeof CryptoJS !== "undefined") && (typeof crypto.randomBytes !== 'function') &&
(typeof OTR !== "undefined") && (typeof crypto.getRandomValues !== 'function')
(typeof DSA !== "undefined") ));
);
// Default configuration values // Default configuration values
// ---------------------------- // ----------------------------
...@@ -134,7 +109,7 @@ ...@@ -134,7 +109,7 @@
])); ]));
// Only allow OTR if we have the capability // Only allow OTR if we have the capability
this.allow_otr = this.allow_otr && HAS_CRYPTO; this.allow_otr = this.allow_otr && HAS_CSPRNG;
// Translation machinery // Translation machinery
// --------------------- // ---------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment