diff --git a/www/common/LessLoader.js b/www/common/LessLoader.js index f7e4f6985..3275c88b5 100644 --- a/www/common/LessLoader.js +++ b/www/common/LessLoader.js @@ -9,18 +9,20 @@ define([ var module = { exports: {} }; var key = Config.requireConf.urlArgs; var localStorage = {}; - try { - localStorage = window.localStorage || {}; - if (localStorage['LESS_CACHE'] !== key) { - Object.keys(localStorage).forEach(function (k) { - if (k.indexOf('LESS_CACHE|') !== 0) { return; } - delete localStorage[k]; - }); - localStorage['LESS_CACHE'] = key; + if (!window.cryptpadCache) { + try { + localStorage = window.localStorage || {}; + if (localStorage['LESS_CACHE'] !== key) { + Object.keys(localStorage).forEach(function (k) { + if (k.indexOf('LESS_CACHE|') !== 0) { return; } + delete localStorage[k]; + }); + localStorage['LESS_CACHE'] = key; + } + } catch (e) { + console.error(e); + localStorage = {}; } - } catch (e) { - console.error(e); - localStorage = {}; } var cacheGet = function (k, cb) { diff --git a/www/common/common-util.js b/www/common/common-util.js index f6ec8d4df..4015fbfe4 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -18,7 +18,8 @@ define([], function () { fire: function () { if (fired) { return; } fired = true; - handlers.forEach(function (h) { h(); }); + var args = Array.prototype.slice.call(arguments); + handlers.forEach(function (h) { h.apply(null, args); }); } }; }; diff --git a/www/common/sframe-chainpad-netflux-inner.js b/www/common/sframe-chainpad-netflux-inner.js index 787da1ca3..7e0eb2a57 100644 --- a/www/common/sframe-chainpad-netflux-inner.js +++ b/www/common/sframe-chainpad-netflux-inner.js @@ -46,7 +46,21 @@ define([ var metadataMgr = config.metadataMgr; config = undefined; - var chainpad; + var chainpad = ChainPad.create({ + userName: userName, + initialState: initialState, + transformFunction: transformFunction, + validateContent: validateContent, + avgSyncMilliseconds: avgSyncMilliseconds, + logLevel: logLevel + }); + chainpad.onMessage(function(message, cb) { + sframeChan.query('Q_RT_MESSAGE', message, cb); + }); + chainpad.onPatch(function () { + onRemote({ realtime: chainpad }); + }); + var myID; var isReady = false; var evConnected = Util.mkEvent(true); @@ -67,33 +81,20 @@ define([ sframeChan.on('EV_RT_DISCONNECT', function () { isReady = false; - if (chainpad) { chainpad.abort(); } + chainpad.abort(); onConnectionChange({ state: false }); }); sframeChan.on('EV_RT_CONNECT', function (content) { //content.members.forEach(userList.onJoin); - myID = content.myID; isReady = false; - if (chainpad) { + if (myID) { // it's a reconnect - if (chainpad) { chainpad.start(); } + myID = content.myID; + chainpad.start(); onConnectionChange({ state: true, myId: myID }); return; } - chainpad = ChainPad.create({ - userName: userName, - initialState: initialState, - transformFunction: transformFunction, - validateContent: validateContent, - avgSyncMilliseconds: avgSyncMilliseconds, - logLevel: logLevel - }); - chainpad.onMessage(function(message, cb) { - sframeChan.query('Q_RT_MESSAGE', message, cb); - }); - chainpad.onPatch(function () { - onRemote({ realtime: chainpad }); - }); + myID = content.myID; onInit({ myID: myID, realtime: chainpad, @@ -130,7 +131,8 @@ define([ getMyID: function () { return myID; }, metadataMgr: metadataMgr, whenRealtimeSyncs: whenRealtimeSyncs, - onInfiniteSpinner: evInfiniteSpinner.reg + onInfiniteSpinner: evInfiniteSpinner.reg, + chainpad: chainpad, }); }; return Object.freeze(module.exports);