Don't create sfcommon a second time in code and slide
This commit is contained in:
parent
4fc1079d67
commit
88a04fdb07
@ -4,6 +4,7 @@ define([
|
|||||||
'/bower_components/nthen/index.js',
|
'/bower_components/nthen/index.js',
|
||||||
'/common/sframe-common.js',
|
'/common/sframe-common.js',
|
||||||
'/common/sframe-app-framework.js',
|
'/common/sframe-app-framework.js',
|
||||||
|
'/common/sframe-common-codemirror.js',
|
||||||
'/common/common-util.js',
|
'/common/common-util.js',
|
||||||
'/common/common-hash.js',
|
'/common/common-hash.js',
|
||||||
'/common/modes.js',
|
'/common/modes.js',
|
||||||
@ -42,6 +43,7 @@ define([
|
|||||||
nThen,
|
nThen,
|
||||||
SFCommon,
|
SFCommon,
|
||||||
Framework,
|
Framework,
|
||||||
|
SFCodeMirror,
|
||||||
Util,
|
Util,
|
||||||
Hash,
|
Hash,
|
||||||
Modes,
|
Modes,
|
||||||
@ -258,11 +260,11 @@ define([
|
|||||||
mkFilePicker(framework, editor, evModeChange);
|
mkFilePicker(framework, editor, evModeChange);
|
||||||
|
|
||||||
if (!framework.isReadOnly()) {
|
if (!framework.isReadOnly()) {
|
||||||
CodeMirror.configureTheme(function () {
|
CodeMirror.configureTheme(common, function () {
|
||||||
CodeMirror.configureLanguage(null, evModeChange.fire);
|
CodeMirror.configureLanguage(common, null, evModeChange.fire);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
CodeMirror.configureTheme();
|
CodeMirror.configureTheme(common);
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
@ -345,7 +347,6 @@ define([
|
|||||||
var main = function () {
|
var main = function () {
|
||||||
var CodeMirror;
|
var CodeMirror;
|
||||||
var editor;
|
var editor;
|
||||||
var common;
|
|
||||||
var framework;
|
var framework;
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
@ -370,20 +371,14 @@ define([
|
|||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
$(waitFor());
|
$(waitFor());
|
||||||
// TODO(cjd): This is crap but we cannot bring up codemirror until after
|
|
||||||
// the CryptPad Common is up and we can't bring up framework
|
|
||||||
// without codemirror.
|
|
||||||
SFCommon.create(waitFor(function (c) { common = c; }));
|
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
CodeMirror = common.initCodeMirrorApp(null, CMeditor);
|
CodeMirror = SFCodeMirror.create(null, CMeditor);
|
||||||
$('#cp-app-code-container').addClass('cp-app-code-fullpage');
|
$('#cp-app-code-container').addClass('cp-app-code-fullpage');
|
||||||
editor = CodeMirror.editor;
|
editor = CodeMirror.editor;
|
||||||
}).nThen(waitFor());
|
}).nThen(waitFor());
|
||||||
|
|
||||||
}).nThen(function (waitFor) {
|
|
||||||
common.getSframeChannel().onReady(waitFor());
|
|
||||||
}).nThen(function (/*waitFor*/) {
|
}).nThen(function (/*waitFor*/) {
|
||||||
common.isPresentUrl(function (err, val) {
|
framework._.sfCommon.isPresentUrl(function (err, val) {
|
||||||
andThen2(editor, CodeMirror, framework, val);
|
andThen2(editor, CodeMirror, framework, val);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -103,7 +103,7 @@ define([
|
|||||||
return text.trim();
|
return text.trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.create = function (Common, defaultMode, CMeditor) {
|
module.create = function (defaultMode, CMeditor) {
|
||||||
var exp = {};
|
var exp = {};
|
||||||
|
|
||||||
var CodeMirror = exp.CodeMirror = CMeditor;
|
var CodeMirror = exp.CodeMirror = CMeditor;
|
||||||
@ -195,7 +195,7 @@ define([
|
|||||||
return module.getHeadingText(editor);
|
return module.getHeadingText(editor);
|
||||||
};
|
};
|
||||||
|
|
||||||
exp.configureLanguage = function (cb, onModeChanged) {
|
exp.configureLanguage = function (Common, cb, onModeChanged) {
|
||||||
var options = [];
|
var options = [];
|
||||||
Modes.list.forEach(function (l) {
|
Modes.list.forEach(function (l) {
|
||||||
options.push({
|
options.push({
|
||||||
@ -227,7 +227,7 @@ define([
|
|||||||
if (cb) { cb(); }
|
if (cb) { cb(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
exp.configureTheme = function (cb) {
|
exp.configureTheme = function (Common, cb) {
|
||||||
/* Remember the user's last choice of theme using localStorage */
|
/* Remember the user's last choice of theme using localStorage */
|
||||||
var themeKey = ['codemirror', 'theme'];
|
var themeKey = ['codemirror', 'theme'];
|
||||||
|
|
||||||
|
|||||||
@ -329,13 +329,10 @@ define([
|
|||||||
Object.freeze(funcs);
|
Object.freeze(funcs);
|
||||||
return { create: function (cb) {
|
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) {
|
if (window.CryptPad_sframe_common) {
|
||||||
setTimeout(function () { cb(window.CryptPad_sframe_common); });
|
throw new Error("Sframe-common should only be created once");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
window.CryptPad_sframe_common = funcs;
|
window.CryptPad_sframe_common = true;
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
SFrameChannel.create(window.parent, waitFor(function (sfc) { ctx.sframeChan = sfc; }), true);
|
SFrameChannel.create(window.parent, waitFor(function (sfc) { ctx.sframeChan = sfc; }), true);
|
||||||
|
|||||||
@ -5,6 +5,7 @@ define([
|
|||||||
'/common/sframe-common.js',
|
'/common/sframe-common.js',
|
||||||
'/slide/slide.js',
|
'/slide/slide.js',
|
||||||
'/common/sframe-app-framework.js',
|
'/common/sframe-app-framework.js',
|
||||||
|
'/common/sframe-common-codemirror.js',
|
||||||
'/common/common-util.js',
|
'/common/common-util.js',
|
||||||
'/common/common-hash.js',
|
'/common/common-hash.js',
|
||||||
'/common/common-interface.js',
|
'/common/common-interface.js',
|
||||||
@ -48,6 +49,7 @@ define([
|
|||||||
SFCommon,
|
SFCommon,
|
||||||
Slide,
|
Slide,
|
||||||
Framework,
|
Framework,
|
||||||
|
SFCodeMirror,
|
||||||
Util,
|
Util,
|
||||||
Hash,
|
Hash,
|
||||||
UI,
|
UI,
|
||||||
@ -464,7 +466,7 @@ define([
|
|||||||
mkSlidePreviewPane(framework, $contentContainer);
|
mkSlidePreviewPane(framework, $contentContainer);
|
||||||
mkMarkdownToolbar(framework, editor);
|
mkMarkdownToolbar(framework, editor);
|
||||||
|
|
||||||
CodeMirror.configureTheme();
|
CodeMirror.configureTheme(common);
|
||||||
|
|
||||||
framework.onContentUpdate(function (newContent) {
|
framework.onContentUpdate(function (newContent) {
|
||||||
CodeMirror.contentUpdate(newContent);
|
CodeMirror.contentUpdate(newContent);
|
||||||
@ -550,7 +552,6 @@ define([
|
|||||||
var main = function () {
|
var main = function () {
|
||||||
var CodeMirror;
|
var CodeMirror;
|
||||||
var editor;
|
var editor;
|
||||||
var common;
|
|
||||||
var framework;
|
var framework;
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
@ -573,20 +574,14 @@ define([
|
|||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
$(waitFor());
|
$(waitFor());
|
||||||
// TODO(cjd): This is crap but we cannot bring up codemirror until after
|
|
||||||
// the CryptPad Common is up and we can't bring up framework
|
|
||||||
// without codemirror.
|
|
||||||
SFCommon.create(waitFor(function (c) { common = c; }));
|
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
CodeMirror = common.initCodeMirrorApp(null, CMeditor);
|
CodeMirror = SFCodeMirror.create(null, CMeditor);
|
||||||
$('.CodeMirror').addClass('fullPage');
|
$('.CodeMirror').addClass('fullPage');
|
||||||
editor = CodeMirror.editor;
|
editor = CodeMirror.editor;
|
||||||
}).nThen(waitFor());
|
}).nThen(waitFor());
|
||||||
|
|
||||||
}).nThen(function (waitFor) {
|
|
||||||
common.getSframeChannel().onReady(waitFor());
|
|
||||||
}).nThen(function (/*waitFor*/) {
|
}).nThen(function (/*waitFor*/) {
|
||||||
common.isPresentUrl(function (err, val) {
|
framework._.sfCommon.isPresentUrl(function (err, val) {
|
||||||
andThen2(editor, CodeMirror, framework, val);
|
andThen2(editor, CodeMirror, framework, val);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user