Minor refactoring of /pad/ ; moved /*/main.js into a common file ; framework'd /code/
This commit is contained in:
@@ -49,6 +49,7 @@ define([
|
||||
var evEditableStateChange = Util.mkEvent();
|
||||
var evOnReady = Util.mkEvent();
|
||||
var evOnDefaultContentNeeded = Util.mkEvent();
|
||||
var evCreated = Util.mkEvent(true);
|
||||
|
||||
var evStart = Util.mkEvent(true);
|
||||
|
||||
@@ -60,6 +61,11 @@ define([
|
||||
var toolbar;
|
||||
var state = STATE.DISCONNECTED;
|
||||
|
||||
var toolbarContainer = options.toolbarContainer ||
|
||||
(function () { throw new Error("toolbarContainer must be specified"); }());
|
||||
var contentContainer = options.contentContainer ||
|
||||
(function () { throw new Error("contentContainer must be specified"); }());
|
||||
|
||||
|
||||
var titleRecommender = function () { return false; };
|
||||
var contentGetter = function () { return UNINITIALIZED; };
|
||||
@@ -247,9 +253,10 @@ define([
|
||||
|
||||
var setFileExporter = function (extension, fe) {
|
||||
var $export = common.createButton('export', true, {}, function () {
|
||||
var ext = (typeof(extension) === 'function') ? extension() : extension;
|
||||
var suggestion = title.suggestTitle('cryptpad-document');
|
||||
Cryptpad.prompt(Messages.exportPrompt,
|
||||
Cryptpad.fixFileName(suggestion) + '.html', function (filename)
|
||||
Cryptpad.fixFileName(suggestion) + '.' + ext, function (filename)
|
||||
{
|
||||
if (!(typeof(filename) === 'string' && filename)) { return; }
|
||||
var blob = fe();
|
||||
@@ -259,11 +266,11 @@ define([
|
||||
toolbar.$drawer.append($export);
|
||||
};
|
||||
|
||||
var setFileImporter = function (mimeType, fi) {
|
||||
var setFileImporter = function (options, fi) {
|
||||
if (readOnly) { return; }
|
||||
toolbar.$drawer.append(
|
||||
common.createButton('import', true, { accept: mimeType }, function (c) {
|
||||
evContentUpdate.fire(fi(c));
|
||||
common.createButton('import', true, options, function (c, f) {
|
||||
evContentUpdate.fire(fi(c, f));
|
||||
onLocal();
|
||||
})
|
||||
);
|
||||
@@ -275,6 +282,7 @@ define([
|
||||
};
|
||||
|
||||
nThen(function (waitFor) {
|
||||
Cryptpad.addLoadingScreen();
|
||||
SFCommon.create(waitFor(function (c) { common = c; }));
|
||||
}).nThen(function (waitFor) {
|
||||
cpNfInner = common.startRealtime({
|
||||
@@ -327,13 +335,26 @@ define([
|
||||
onConnectError();
|
||||
}
|
||||
});
|
||||
}).nThen(function (waitFor) {
|
||||
|
||||
var done = waitFor();
|
||||
var intr;
|
||||
var check = function () {
|
||||
if (!$(toolbarContainer).length) { return; }
|
||||
if (!$(contentContainer).length) { return; }
|
||||
if ($(toolbarContainer).length !== 1) { throw new Error("multiple toolbarContainers"); }
|
||||
if ($(contentContainer).length !== 1) { throw new Error("multiple contentContainers"); }
|
||||
clearInterval(intr);
|
||||
done();
|
||||
};
|
||||
intr = setInterval(function () {
|
||||
console.log('waited 50ms for toolbar and content containers');
|
||||
check();
|
||||
}, 50);
|
||||
check();
|
||||
|
||||
}).nThen(function () {
|
||||
|
||||
var $bar = $('#cke_1_toolbox'); // TODO
|
||||
|
||||
if (!$bar.length) { throw new Error(); }
|
||||
|
||||
title = common.createTitle({ getHeadingText: titleRecommender }, onLocal);
|
||||
var configTb = {
|
||||
displayed: ['userlist', 'title', 'useradmin', 'spinner', 'newpad', 'share', 'limit'],
|
||||
@@ -343,8 +364,8 @@ define([
|
||||
realtime: cpNfInner.chainpad,
|
||||
common: Cryptpad,
|
||||
sfCommon: common,
|
||||
$container: $bar,
|
||||
$contentContainer: $('#cke_1_contents'), // TODO
|
||||
$container: $(toolbarContainer),
|
||||
$contentContainer: $(contentContainer)
|
||||
};
|
||||
toolbar = Toolbar.create(configTb);
|
||||
title.setToolbar(toolbar);
|
||||
@@ -357,7 +378,7 @@ define([
|
||||
applyVal: function (val) {
|
||||
evContentUpdate.fire(JSON.parse(val) || ["BODY",{},[]]);
|
||||
},
|
||||
$toolbar: $bar
|
||||
$toolbar: $(toolbarContainer)
|
||||
};
|
||||
var $hist = common.createButton('history', true, {histConfig: histConfig});
|
||||
toolbar.$drawer.append($hist);
|
||||
@@ -447,7 +468,9 @@ define([
|
||||
title: title
|
||||
}
|
||||
}));
|
||||
evCreated.fire();
|
||||
});
|
||||
return evCreated.reg;
|
||||
};
|
||||
return { create: create };
|
||||
});
|
||||
40
www/common/sframe-app-outer.js
Normal file
40
www/common/sframe-app-outer.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// Load #1, load as little as possible because we are in a race to get the loading screen up.
|
||||
define([
|
||||
'/bower_components/nthen/index.js',
|
||||
'/api/config',
|
||||
'jquery',
|
||||
'/common/requireconfig.js',
|
||||
'/common/sframe-common-outer.js'
|
||||
], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
|
||||
var requireConfig = RequireConfig();
|
||||
|
||||
nThen(function (waitFor) {
|
||||
$(waitFor());
|
||||
}).nThen(function (waitFor) {
|
||||
var req = {
|
||||
cfg: requireConfig,
|
||||
req: [ '/common/loading.js' ],
|
||||
pfx: window.location.origin
|
||||
};
|
||||
window.rc = requireConfig;
|
||||
window.apiconf = ApiConfig;
|
||||
$('#sbox-iframe').attr('src',
|
||||
ApiConfig.httpSafeOrigin + window.location.pathname + 'inner.html?' +
|
||||
requireConfig.urlArgs + '#' + encodeURIComponent(JSON.stringify(req)));
|
||||
|
||||
// This is a cheap trick to avoid loading sframe-channel in parallel with the
|
||||
// loading screen setup.
|
||||
var done = waitFor();
|
||||
var onMsg = function (msg) {
|
||||
var data = JSON.parse(msg.data);
|
||||
if (data.q !== 'READY') { return; }
|
||||
window.removeEventListener('message', onMsg);
|
||||
var _done = done;
|
||||
done = function () { };
|
||||
_done();
|
||||
};
|
||||
window.addEventListener('message', onMsg);
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
SFCommonO.start();
|
||||
});
|
||||
});
|
||||
@@ -289,6 +289,15 @@ define([
|
||||
|
||||
Object.freeze(funcs);
|
||||
return { create: function (cb) {
|
||||
|
||||
// TODO(cjd): This is crap but this gets loaded multiple places by /code/ and it is
|
||||
// not ok with being loaded more than once.
|
||||
if (window.CryptPad_sframe_common) {
|
||||
setTimeout(function () { cb(window.CryptPad_sframe_common); });
|
||||
return;
|
||||
}
|
||||
window.CryptPad_sframe_common = funcs;
|
||||
|
||||
nThen(function (waitFor) {
|
||||
SFrameChannel.create(window.parent, waitFor(function (sfc) { ctx.sframeChan = sfc; }), true);
|
||||
// CpNfInner.start() should be here....
|
||||
|
||||
Reference in New Issue
Block a user