diff --git a/www/common/common-util.js b/www/common/common-util.js index 262de76e9..22f20f710 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -1,7 +1,5 @@ (function (window) { -define([], function () { - var Util = window.CryptPad_Util = {}; - + var Util = {}; Util.mkAsync = function (f) { return function () { var args = Array.prototype.slice.call(arguments); @@ -349,6 +347,14 @@ define([], function () { return false; }; - return Util; -}); -}(self)); + if (typeof(module) !== 'undefined' && module.exports) { + module.exports = Util; + } else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) { + define([], function () { + window.CryptPad_Util = Util; + return Util; + }); + } else { + window.CryptPad_Util = Util; + } +}(typeof(self) !== 'undefined'? self: this)); diff --git a/www/common/rpc.js b/www/common/rpc.js index c0452b80a..b82345a24 100644 --- a/www/common/rpc.js +++ b/www/common/rpc.js @@ -1,9 +1,5 @@ -define([ - '/common/common-util.js', - '/bower_components/tweetnacl/nacl-fast.min.js', -], function (Util) { - var Nacl = window.nacl; - +(function () { +var factory = function (Util, Nacl) { var uid = Util.uid; var signMsg = function (data, signKey) { var buffer = Nacl.util.decodeUTF8(JSON.stringify(data)); @@ -337,4 +333,18 @@ types of messages: }; return { create: create, createAnonymous: createAnonymous }; -}); +}; + + if (typeof(module) !== 'undefined' && module.exports) { + module.exports = factory(require("./common-util"), require("tweetnacl")); + } else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) { + define([ + '/common/common-util.js', + '/bower_components/tweetnacl/nacl-fast.min.js', + ], function (Util) { + return factory(Util, window.Nacl); + }); + } else { + // I'm not gonna bother supporting any other kind of instanciation + } +}());