Minor refactoring of /pad/ ; moved /*/main.js into a common file ; framework'd /code/
This commit is contained in:
parent
6dbc02e81a
commit
f95acda758
@ -5,7 +5,7 @@
|
|||||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="referrer" content="no-referrer" />
|
<meta name="referrer" content="no-referrer" />
|
||||||
<script async data-bootload="main.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
<script async data-bootload="/common/sframe-app-outer.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
|
|||||||
@ -1,24 +1,15 @@
|
|||||||
define([
|
define([
|
||||||
'jquery',
|
'jquery',
|
||||||
'/bower_components/chainpad-crypto/crypto.js',
|
|
||||||
'/bower_components/textpatcher/TextPatcher.js',
|
'/bower_components/textpatcher/TextPatcher.js',
|
||||||
'/common/toolbar3.js',
|
|
||||||
'json.sortify',
|
|
||||||
'/bower_components/chainpad-json-validator/json-ot.js',
|
|
||||||
'/common/cryptpad-common.js',
|
'/common/cryptpad-common.js',
|
||||||
'/common/cryptget.js',
|
|
||||||
'/common/diffMarked.js',
|
'/common/diffMarked.js',
|
||||||
'/bower_components/nthen/index.js',
|
'/bower_components/nthen/index.js',
|
||||||
'/common/sframe-common.js',
|
'/common/sframe-common.js',
|
||||||
'/api/config',
|
'/common/sframe-app-framework.js',
|
||||||
'/common/common-realtime.js',
|
'/common/common-util.js',
|
||||||
|
'/common/modes.js',
|
||||||
'cm/lib/codemirror',
|
'cm/lib/codemirror',
|
||||||
|
|
||||||
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
|
|
||||||
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
|
||||||
'less!/customize/src/less2/main.less',
|
|
||||||
|
|
||||||
'css!cm/lib/codemirror.css',
|
'css!cm/lib/codemirror.css',
|
||||||
'css!cm/addon/dialog/dialog.css',
|
'css!cm/addon/dialog/dialog.css',
|
||||||
'css!cm/addon/fold/foldgutter.css',
|
'css!cm/addon/fold/foldgutter.css',
|
||||||
@ -47,81 +38,78 @@ define([
|
|||||||
|
|
||||||
], function (
|
], function (
|
||||||
$,
|
$,
|
||||||
Crypto,
|
|
||||||
TextPatcher,
|
TextPatcher,
|
||||||
Toolbar,
|
|
||||||
JSONSortify,
|
|
||||||
JsonOT,
|
|
||||||
Cryptpad,
|
Cryptpad,
|
||||||
Cryptget,
|
|
||||||
DiffMd,
|
DiffMd,
|
||||||
nThen,
|
nThen,
|
||||||
SFCommon,
|
SFCommon,
|
||||||
ApiConfig,
|
Framework,
|
||||||
CommonRealtime,
|
Util,
|
||||||
|
Modes,
|
||||||
CMeditor)
|
CMeditor)
|
||||||
{
|
{
|
||||||
window.CodeMirror = CMeditor;
|
window.CodeMirror = CMeditor;
|
||||||
var Messages = Cryptpad.Messages;
|
var Messages = Cryptpad.Messages;
|
||||||
|
|
||||||
var APP = window.APP = {
|
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
|
||||||
Cryptpad: Cryptpad,
|
|
||||||
};
|
|
||||||
|
|
||||||
var stringify = function (obj) {
|
var MEDIA_TAG_MODES = Object.freeze([
|
||||||
return JSONSortify(obj);
|
'markdown',
|
||||||
};
|
'html',
|
||||||
|
'htmlembedded',
|
||||||
|
'htmlmixed',
|
||||||
|
'index.html',
|
||||||
|
'php',
|
||||||
|
'velocity',
|
||||||
|
'xml',
|
||||||
|
]);
|
||||||
|
|
||||||
var toolbar;
|
var mkPreviewPane = function (editor, CodeMirror, framework) {
|
||||||
|
|
||||||
var onConnectError = function () {
|
|
||||||
Cryptpad.errorLoadingScreen(Messages.websocketError);
|
|
||||||
};
|
|
||||||
|
|
||||||
var andThen = function (editor, CodeMirror, common) {
|
|
||||||
var readOnly = false;
|
|
||||||
var cpNfInner;
|
|
||||||
var metadataMgr;
|
|
||||||
var $bar = $('#cme_toolbox');
|
|
||||||
|
|
||||||
var isHistoryMode = false;
|
|
||||||
|
|
||||||
var setEditable = APP.setEditable = function (bool) {
|
|
||||||
if (readOnly && bool) { return; }
|
|
||||||
editor.setOption('readOnly', !bool);
|
|
||||||
};
|
|
||||||
|
|
||||||
var Title;
|
|
||||||
|
|
||||||
var config = {
|
|
||||||
readOnly: readOnly,
|
|
||||||
transformFunction: JsonOT.validate,
|
|
||||||
// cryptpad debug logging (default is 1)
|
|
||||||
// logLevel: 0,
|
|
||||||
validateContent: function (content) {
|
|
||||||
try {
|
|
||||||
JSON.parse(content);
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Failed to parse, rejecting patch");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
|
|
||||||
|
|
||||||
var setHistory = function (bool, update) {
|
|
||||||
isHistoryMode = bool;
|
|
||||||
setEditable(!bool);
|
|
||||||
if (!bool && update) {
|
|
||||||
config.onRemote();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var $contentContainer = $('#cp-app-code-editor');
|
|
||||||
var $previewContainer = $('#cp-app-code-preview');
|
var $previewContainer = $('#cp-app-code-preview');
|
||||||
var $preview = $('#cp-app-code-preview-content');
|
var $preview = $('#cp-app-code-preview-content');
|
||||||
|
var $codeMirror = $('.CodeMirror');
|
||||||
|
var forceDrawPreview = function () {
|
||||||
|
try {
|
||||||
|
DiffMd.apply(DiffMd.render(editor.getValue()), $preview);
|
||||||
|
} catch (e) { console.error(e); }
|
||||||
|
};
|
||||||
|
var drawPreview = Util.throttle(function () {
|
||||||
|
if (CodeMirror.highlightMode !== 'markdown') { return; }
|
||||||
|
if (!$previewContainer.is(':visible')) { return; }
|
||||||
|
forceDrawPreview();
|
||||||
|
}, 150);
|
||||||
|
|
||||||
|
var $previewButton = framework._.sfCommon.createButton(null, true);
|
||||||
|
$previewButton.removeClass('fa-question').addClass('fa-eye');
|
||||||
|
$previewButton.attr('title', Messages.previewButtonTitle);
|
||||||
|
var previewTo;
|
||||||
|
$previewButton.click(function () {
|
||||||
|
clearTimeout(previewTo);
|
||||||
|
$codeMirror.addClass('transition');
|
||||||
|
previewTo = setTimeout(function () {
|
||||||
|
$codeMirror.removeClass('transition');
|
||||||
|
}, 500);
|
||||||
|
if (CodeMirror.highlightMode !== 'markdown') {
|
||||||
|
$previewContainer.show();
|
||||||
|
}
|
||||||
|
$previewContainer.toggle();
|
||||||
|
if ($previewContainer.is(':visible')) {
|
||||||
|
forceDrawPreview();
|
||||||
|
$codeMirror.removeClass('cp-ap-code-fullpage');
|
||||||
|
$previewButton.addClass('cp-toolbar-button-active');
|
||||||
|
framework._.sfCommon.setPadAttribute('previewMode', true, function (e) {
|
||||||
|
if (e) { return console.log(e); }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$codeMirror.addClass('cp-app-code-fullpage');
|
||||||
|
$previewButton.removeClass('cp-toolbar-button-active');
|
||||||
|
framework._.sfCommon.setPadAttribute('previewMode', false, function (e) {
|
||||||
|
if (e) { return console.log(e); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
framework._.toolbar.$rightside.append($previewButton);
|
||||||
|
|
||||||
$preview.click(function (e) {
|
$preview.click(function (e) {
|
||||||
if (!e.target) { return; }
|
if (!e.target) { return; }
|
||||||
var $t = $(e.target);
|
var $t = $(e.target);
|
||||||
@ -133,7 +121,70 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var setIndentation = APP.setIndentation = function (units, useTabs) {
|
var modeChange = function (mode) {
|
||||||
|
if (mode === "markdown") {
|
||||||
|
$previewButton.show();
|
||||||
|
framework._.sfCommon.getPadAttribute('previewMode', function (e, data) {
|
||||||
|
if (e) { return void console.error(e); }
|
||||||
|
if (data !== false) {
|
||||||
|
$previewContainer.show();
|
||||||
|
$previewButton.addClass('active');
|
||||||
|
$codeMirror.removeClass('cp-app-code-fullpage');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$previewButton.hide();
|
||||||
|
$previewContainer.hide();
|
||||||
|
$previewButton.removeClass('active');
|
||||||
|
$codeMirror.addClass('cp-app-code-fullpage');
|
||||||
|
};
|
||||||
|
|
||||||
|
framework.onReady(function () {
|
||||||
|
// add the splitter
|
||||||
|
if ($('.cp-splitter').length) { return; }
|
||||||
|
var splitter = $('<div>', {
|
||||||
|
'class': 'cp-splitter'
|
||||||
|
}).appendTo($previewContainer);
|
||||||
|
|
||||||
|
$preview.on('scroll', function() {
|
||||||
|
splitter.css('top', $preview.scrollTop() + 'px');
|
||||||
|
});
|
||||||
|
|
||||||
|
var $target = $('.CodeMirror');
|
||||||
|
|
||||||
|
splitter.on('mousedown', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var x = e.pageX;
|
||||||
|
var w = $target.width();
|
||||||
|
|
||||||
|
$(window).on('mouseup mousemove', function handler(evt) {
|
||||||
|
if (evt.type === 'mouseup') {
|
||||||
|
$(window).off('mouseup mousemove', handler);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$target.css('width', (w - x + evt.pageX) + 'px');
|
||||||
|
editor.refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
framework._.sfCommon.getPadAttribute('previewMode', function (e, data) {
|
||||||
|
if (e) { return void console.error(e); }
|
||||||
|
if (data === false && $previewButton) {
|
||||||
|
$previewButton.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
forceDraw: forceDrawPreview,
|
||||||
|
draw: drawPreview,
|
||||||
|
modeChange: modeChange
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var mkIndentSettings = function (editor, metadataMgr) {
|
||||||
|
var setIndentation = function (units, useTabs) {
|
||||||
if (typeof(units) !== 'number') { return; }
|
if (typeof(units) !== 'number') { return; }
|
||||||
editor.setOption('indentUnit', units);
|
editor.setOption('indentUnit', units);
|
||||||
editor.setOption('tabSize', units);
|
editor.setOption('tabSize', units);
|
||||||
@ -152,339 +203,100 @@ define([
|
|||||||
typeof(indentUnit) === 'number'? indentUnit: 2,
|
typeof(indentUnit) === 'number'? indentUnit: 2,
|
||||||
typeof(useTabs) === 'boolean'? useTabs: false);
|
typeof(useTabs) === 'boolean'? useTabs: false);
|
||||||
};
|
};
|
||||||
|
metadataMgr.onChangeLazy(updateIndentSettings);
|
||||||
|
updateIndentSettings();
|
||||||
|
};
|
||||||
|
|
||||||
CommonRealtime.onInfiniteSpinner(function () { setEditable(false); });
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
setEditable(false);
|
var andThen2 = function (editor, CodeMirror, framework) {
|
||||||
var initializing = true;
|
|
||||||
|
|
||||||
var stringifyInner = function (textValue) {
|
var $toolbarContainer = $('#cme_toolbox');
|
||||||
var obj = {
|
var common = framework._.sfCommon;
|
||||||
content: textValue,
|
|
||||||
metadata: metadataMgr.getMetadataLazy()
|
|
||||||
};
|
|
||||||
// set mode too...
|
|
||||||
obj.highlightMode = CodeMirror.highlightMode;
|
|
||||||
|
|
||||||
// stringify the json and send it into chainpad
|
var previewPane = mkPreviewPane(editor, CodeMirror, framework);
|
||||||
return stringify(obj);
|
var evModeChange = Util.mkEvent();
|
||||||
};
|
evModeChange.reg(previewPane.modeChange);
|
||||||
|
|
||||||
var forceDrawPreview = function () {
|
mkIndentSettings(editor, framework._.cpNfInner.metadataMgr);
|
||||||
try {
|
CodeMirror.init(framework.localChange, framework._.title, framework._.toolbar);
|
||||||
DiffMd.apply(DiffMd.render(editor.getValue()), $preview);
|
|
||||||
} catch (e) { console.error(e); }
|
|
||||||
};
|
|
||||||
|
|
||||||
var drawPreview = Cryptpad.throttle(function () {
|
if (!framework.isReadOnly()) {
|
||||||
if (CodeMirror.highlightMode !== 'markdown') { return; }
|
var fileDialogCfg = {
|
||||||
if (!$previewContainer.is(':visible')) { return; }
|
onSelect: function (data) {
|
||||||
forceDrawPreview();
|
if (data.type === 'file') {
|
||||||
}, 150);
|
var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>';
|
||||||
|
editor.replaceSelection(mt);
|
||||||
var onLocal = config.onLocal = function () {
|
return;
|
||||||
if (initializing) { return; }
|
|
||||||
if (isHistoryMode) { return; }
|
|
||||||
if (readOnly) { return; }
|
|
||||||
|
|
||||||
editor.save();
|
|
||||||
|
|
||||||
drawPreview();
|
|
||||||
|
|
||||||
var textValue = canonicalize(CodeMirror.$textarea.val());
|
|
||||||
var shjson = stringifyInner(textValue);
|
|
||||||
|
|
||||||
APP.patchText(shjson);
|
|
||||||
|
|
||||||
if (APP.realtime.getUserDoc() !== shjson) {
|
|
||||||
console.error("realtime.getUserDoc() !== shjson");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var mediaTagModes = [
|
|
||||||
'markdown',
|
|
||||||
'html',
|
|
||||||
'htmlembedded',
|
|
||||||
'htmlmixed',
|
|
||||||
'index.html',
|
|
||||||
'php',
|
|
||||||
'velocity',
|
|
||||||
'xml',
|
|
||||||
];
|
|
||||||
|
|
||||||
var onModeChanged = function (mode) {
|
|
||||||
var $codeMirror = $('.CodeMirror');
|
|
||||||
window.clearTimeout(APP.previewTo);
|
|
||||||
$codeMirror.addClass('transition');
|
|
||||||
APP.previewTo = window.setTimeout(function () {
|
|
||||||
$codeMirror.removeClass('transition');
|
|
||||||
}, 500);
|
|
||||||
if (mediaTagModes.indexOf(mode) !== -1) {
|
|
||||||
$(APP.$mediaTagButton).show();
|
|
||||||
} else { $(APP.$mediaTagButton).hide(); }
|
|
||||||
|
|
||||||
if (mode === "markdown") {
|
|
||||||
APP.$previewButton.show();
|
|
||||||
common.getPadAttribute('previewMode', function (e, data) {
|
|
||||||
if (e) { return void console.error(e); }
|
|
||||||
if (data !== false) {
|
|
||||||
$previewContainer.show();
|
|
||||||
APP.$previewButton.addClass('active');
|
|
||||||
$codeMirror.removeClass('cp-app-code-fullpage');
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
APP.$previewButton.hide();
|
|
||||||
$previewContainer.hide();
|
|
||||||
APP.$previewButton.removeClass('active');
|
|
||||||
$codeMirror.addClass('cp-app-code-fullpage');
|
|
||||||
};
|
|
||||||
|
|
||||||
config.onInit = function (info) {
|
|
||||||
metadataMgr.onChangeLazy(updateIndentSettings);
|
|
||||||
updateIndentSettings();
|
|
||||||
|
|
||||||
readOnly = metadataMgr.getPrivateData().readOnly;
|
|
||||||
|
|
||||||
var titleCfg = { getHeadingText: CodeMirror.getHeadingText };
|
|
||||||
Title = common.createTitle(titleCfg, config.onLocal);
|
|
||||||
|
|
||||||
var configTb = {
|
|
||||||
displayed: ['title', 'useradmin', 'spinner', 'share', 'userlist', 'newpad', 'limit'],
|
|
||||||
title: Title.getTitleConfig(),
|
|
||||||
metadataMgr: metadataMgr,
|
|
||||||
readOnly: readOnly,
|
|
||||||
ifrw: window,
|
|
||||||
realtime: info.realtime,
|
|
||||||
common: Cryptpad,
|
|
||||||
sfCommon: common,
|
|
||||||
$container: $bar,
|
|
||||||
$contentContainer: $contentContainer
|
|
||||||
};
|
|
||||||
toolbar = APP.toolbar = Toolbar.create(configTb);
|
|
||||||
Title.setToolbar(toolbar);
|
|
||||||
CodeMirror.init(config.onLocal, Title, toolbar);
|
|
||||||
|
|
||||||
var $rightside = toolbar.$rightside;
|
|
||||||
var $drawer = toolbar.$drawer;
|
|
||||||
|
|
||||||
/* add a history button */
|
|
||||||
var histConfig = {
|
|
||||||
onLocal: config.onLocal,
|
|
||||||
onRemote: config.onRemote,
|
|
||||||
setHistory: setHistory,
|
|
||||||
applyVal: function (val) {
|
|
||||||
var remoteDoc = JSON.parse(val || '{}').content;
|
|
||||||
editor.setValue(remoteDoc || '');
|
|
||||||
editor.save();
|
|
||||||
},
|
|
||||||
$toolbar: $bar
|
|
||||||
};
|
|
||||||
var $hist = common.createButton('history', true, {histConfig: histConfig});
|
|
||||||
$drawer.append($hist);
|
|
||||||
|
|
||||||
/* save as template */
|
|
||||||
if (!metadataMgr.getPrivateData().isTemplate) {
|
|
||||||
var templateObj = {
|
|
||||||
rt: info.realtime,
|
|
||||||
getTitle: function () { return metadataMgr.getMetadata().title; }
|
|
||||||
};
|
|
||||||
var $templateButton = common.createButton('template', true, templateObj);
|
|
||||||
$rightside.append($templateButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add an export button */
|
|
||||||
var $export = common.createButton('export', true, {}, CodeMirror.exportText);
|
|
||||||
$drawer.append($export);
|
|
||||||
|
|
||||||
if (!readOnly) {
|
|
||||||
/* add an import button */
|
|
||||||
var $import = common.createButton('import', true, {}, CodeMirror.importText);
|
|
||||||
$drawer.append($import);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add a forget button */
|
|
||||||
var forgetCb = function (err) {
|
|
||||||
if (err) { return; }
|
|
||||||
setEditable(false);
|
|
||||||
};
|
|
||||||
var $forgetPad = common.createButton('forget', true, {}, forgetCb);
|
|
||||||
$rightside.append($forgetPad);
|
|
||||||
|
|
||||||
var $previewButton = APP.$previewButton = common.createButton(null, true);
|
|
||||||
$previewButton.removeClass('fa-question').addClass('fa-eye');
|
|
||||||
$previewButton.attr('title', Messages.previewButtonTitle);
|
|
||||||
$previewButton.click(function () {
|
|
||||||
var $codeMirror = $('.CodeMirror');
|
|
||||||
window.clearTimeout(APP.previewTo);
|
|
||||||
$codeMirror.addClass('transition');
|
|
||||||
APP.previewTo = window.setTimeout(function () {
|
|
||||||
$codeMirror.removeClass('transition');
|
|
||||||
}, 500);
|
|
||||||
if (CodeMirror.highlightMode !== 'markdown') {
|
|
||||||
$previewContainer.show();
|
|
||||||
}
|
}
|
||||||
$previewContainer.toggle();
|
};
|
||||||
if ($previewContainer.is(':visible')) {
|
common.initFilePicker(fileDialogCfg);
|
||||||
forceDrawPreview();
|
var $mediaTagButton = $('<button>', {
|
||||||
$codeMirror.removeClass('cp-ap-code-fullpage');
|
title: Messages.filePickerButton,
|
||||||
$previewButton.addClass('cp-toolbar-button-active');
|
'class': 'cp-toolbar-rightside-button fa fa-picture-o',
|
||||||
common.setPadAttribute('previewMode', true, function (e) {
|
style: 'font-size: 17px'
|
||||||
if (e) { return console.log(e); }
|
}).click(function () {
|
||||||
});
|
var pickerCfg = {
|
||||||
|
types: ['file'],
|
||||||
|
where: ['root']
|
||||||
|
};
|
||||||
|
common.openFilePicker(pickerCfg);
|
||||||
|
}).appendTo(framework._.toolbar.$rightside);
|
||||||
|
evModeChange.reg(function (mode) {
|
||||||
|
if (MEDIA_TAG_MODES.indexOf(mode) !== -1) {
|
||||||
|
$($mediaTagButton).show();
|
||||||
} else {
|
} else {
|
||||||
$codeMirror.addClass('cp-app-code-fullpage');
|
$($mediaTagButton).hide();
|
||||||
$previewButton.removeClass('cp-toolbar-button-active');
|
|
||||||
common.setPadAttribute('previewMode', false, function (e) {
|
|
||||||
if (e) { return console.log(e); }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$rightside.append($previewButton);
|
}
|
||||||
|
|
||||||
if (!readOnly) {
|
if (!framework.isReadOnly()) {
|
||||||
CodeMirror.configureTheme(function () {
|
CodeMirror.configureTheme(function () {
|
||||||
CodeMirror.configureLanguage(null, onModeChanged);
|
CodeMirror.configureLanguage(null, evModeChange.fire);
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
CodeMirror.configureTheme();
|
||||||
CodeMirror.configureTheme();
|
}
|
||||||
|
|
||||||
|
////
|
||||||
|
|
||||||
|
framework.onContentUpdate(function (newContent) {
|
||||||
|
var oldDoc = canonicalize(CodeMirror.$textarea.val());
|
||||||
|
var remoteDoc = newContent.content;
|
||||||
|
var highlightMode = newContent.highlightMode;
|
||||||
|
if (highlightMode && highlightMode !== CodeMirror.highlightMode) {
|
||||||
|
CodeMirror.setMode(highlightMode, evModeChange.fire);
|
||||||
}
|
}
|
||||||
|
CodeMirror.setValueAndCursor(oldDoc, remoteDoc, TextPatcher);
|
||||||
|
previewPane.draw();
|
||||||
|
});
|
||||||
|
|
||||||
if (!readOnly) {
|
framework.setContentGetter(function () {
|
||||||
var fileDialogCfg = {
|
editor.save();
|
||||||
onSelect: function (data) {
|
previewPane.draw();
|
||||||
if (data.type === 'file') {
|
return {
|
||||||
var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>';
|
content: canonicalize(CodeMirror.$textarea.val()),
|
||||||
editor.replaceSelection(mt);
|
highlightMode: CodeMirror.highlightMode
|
||||||
return;
|
};
|
||||||
}
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
common.initFilePicker(fileDialogCfg);
|
|
||||||
APP.$mediaTagButton = $('<button>', {
|
|
||||||
title: Messages.filePickerButton,
|
|
||||||
'class': 'cp-toolbar-rightside-button fa fa-picture-o',
|
|
||||||
style: 'font-size: 17px'
|
|
||||||
}).click(function () {
|
|
||||||
var pickerCfg = {
|
|
||||||
types: ['file'],
|
|
||||||
where: ['root']
|
|
||||||
};
|
|
||||||
common.openFilePicker(pickerCfg);
|
|
||||||
}).appendTo($rightside);
|
|
||||||
|
|
||||||
var $tags = common.createButton('hashtag', true);
|
framework.onEditableChange(function () {
|
||||||
$rightside.append($tags);
|
editor.setOption('readOnly', framework.isLocked() || framework.isReadOnly());
|
||||||
}
|
});
|
||||||
};
|
|
||||||
|
|
||||||
config.onReady = function (info) {
|
framework.setTitleRecommender(CodeMirror.getHeadingText);
|
||||||
if (APP.realtime !== info.realtime) {
|
|
||||||
var realtime = APP.realtime = info.realtime;
|
|
||||||
APP.patchText = TextPatcher.create({
|
|
||||||
realtime: realtime,
|
|
||||||
//logging: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var userDoc = APP.realtime.getUserDoc();
|
framework.onReady(function (newPad) {
|
||||||
|
if (newPad && !CodeMirror.highlightMode) {
|
||||||
var isNew = false;
|
CodeMirror.setMode('markdown', evModeChange.fire);
|
||||||
if (userDoc === "" || userDoc === "{}") { isNew = true; }
|
|
||||||
|
|
||||||
var newDoc = "";
|
|
||||||
if (userDoc !== "") {
|
|
||||||
var hjson = JSON.parse(userDoc);
|
|
||||||
|
|
||||||
if (hjson && hjson.metadata) {
|
|
||||||
metadataMgr.updateMetadata(hjson.metadata);
|
|
||||||
}
|
|
||||||
if (typeof (hjson) !== 'object' || Array.isArray(hjson) ||
|
|
||||||
(hjson.metadata && typeof(hjson.metadata.type) !== 'undefined' &&
|
|
||||||
hjson.metadata.type !== 'code')) {
|
|
||||||
var errorText = Messages.typeError;
|
|
||||||
Cryptpad.errorLoadingScreen(errorText);
|
|
||||||
throw new Error(errorText);
|
|
||||||
}
|
|
||||||
|
|
||||||
newDoc = hjson.content;
|
|
||||||
|
|
||||||
if (hjson.highlightMode) {
|
|
||||||
CodeMirror.setMode(hjson.highlightMode, onModeChanged);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Title.updateTitle(Cryptpad.initialName || Title.defaultTitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CodeMirror.highlightMode) {
|
|
||||||
CodeMirror.setMode('markdown', onModeChanged);
|
|
||||||
//console.log("%s => %s", CodeMirror.highlightMode, CodeMirror.$language.val());
|
//console.log("%s => %s", CodeMirror.highlightMode, CodeMirror.$language.val());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newDoc) {
|
|
||||||
editor.setValue(newDoc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Cryptpad.initialName && Title.isDefaultTitle()) {
|
|
||||||
Title.updateTitle(Cryptpad.initialName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
common.getPadAttribute('previewMode', function (e, data) {
|
|
||||||
if (e) { return void console.error(e); }
|
|
||||||
if (data === false && APP.$previewButton) {
|
|
||||||
APP.$previewButton.click();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// add the splitter
|
|
||||||
if (!$('.cp-splitter').length) {
|
|
||||||
var splitter = $('<div>', {
|
|
||||||
'class': 'cp-splitter'
|
|
||||||
}).appendTo($previewContainer);
|
|
||||||
|
|
||||||
$preview.on('scroll', function() {
|
|
||||||
splitter.css('top', $preview.scrollTop() + 'px');
|
|
||||||
});
|
|
||||||
|
|
||||||
var $target = $('.CodeMirror');
|
|
||||||
|
|
||||||
splitter.on('mousedown', function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
var x = e.pageX;
|
|
||||||
var w = $target.width();
|
|
||||||
|
|
||||||
$(window).on('mouseup mousemove', function handler(evt) {
|
|
||||||
if (evt.type === 'mouseup') {
|
|
||||||
$(window).off('mouseup mousemove', handler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$target.css('width', (w - x + evt.pageX) + 'px');
|
|
||||||
editor.refresh();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Cryptpad.removeLoadingScreen();
|
|
||||||
setEditable(!readOnly);
|
|
||||||
initializing = false;
|
|
||||||
|
|
||||||
onLocal(); // push local state to avoid parse errors later.
|
|
||||||
|
|
||||||
if (readOnly) {
|
|
||||||
config.onRemote();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNew) {
|
|
||||||
common.openTemplatePicker();
|
|
||||||
}
|
|
||||||
|
|
||||||
var fmConfig = {
|
var fmConfig = {
|
||||||
dropArea: $('.CodeMirror'),
|
dropArea: $('.CodeMirror'),
|
||||||
body: $('body'),
|
body: $('body'),
|
||||||
@ -499,122 +311,85 @@ define([
|
|||||||
editor.replaceSelection(mt);
|
editor.replaceSelection(mt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
APP.FM = common.createFileManager(fmConfig);
|
common.createFileManager(fmConfig);
|
||||||
};
|
|
||||||
|
|
||||||
config.onRemote = function () {
|
|
||||||
if (initializing) { return; }
|
|
||||||
if (isHistoryMode) { return; }
|
|
||||||
|
|
||||||
var oldDoc = canonicalize(CodeMirror.$textarea.val());
|
|
||||||
var shjson = APP.realtime.getUserDoc();
|
|
||||||
|
|
||||||
// Update the user list (metadata) from the hyperjson
|
|
||||||
//Metadata.update(shjson);
|
|
||||||
|
|
||||||
var hjson = JSON.parse(shjson);
|
|
||||||
var remoteDoc = hjson.content;
|
|
||||||
|
|
||||||
if (hjson.metadata) {
|
|
||||||
metadataMgr.updateMetadata(hjson.metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
var highlightMode = hjson.highlightMode;
|
|
||||||
if (highlightMode && highlightMode !== APP.highlightMode) {
|
|
||||||
CodeMirror.setMode(highlightMode, onModeChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
CodeMirror.setValueAndCursor(oldDoc, remoteDoc, TextPatcher);
|
|
||||||
drawPreview();
|
|
||||||
|
|
||||||
if (!readOnly) {
|
|
||||||
var textValue = canonicalize(CodeMirror.$textarea.val());
|
|
||||||
var shjson2 = stringifyInner(textValue);
|
|
||||||
if (shjson2 !== shjson) {
|
|
||||||
console.error("shjson2 !== shjson");
|
|
||||||
TextPatcher.log(shjson, TextPatcher.diff(shjson, shjson2));
|
|
||||||
APP.patchText(shjson2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldDoc !== remoteDoc) { common.notify(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
config.onAbort = function () {
|
|
||||||
// inform of network disconnect
|
|
||||||
setEditable(false);
|
|
||||||
toolbar.failed();
|
|
||||||
Cryptpad.alert(Messages.common_connectionLost, undefined, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
config.onConnectionChange = function (info) {
|
|
||||||
setEditable(info.state);
|
|
||||||
//toolbar.failed();
|
|
||||||
if (info.state) {
|
|
||||||
initializing = true;
|
|
||||||
//toolbar.reconnecting(info.myId);
|
|
||||||
Cryptpad.findOKButton().click();
|
|
||||||
} else {
|
|
||||||
Cryptpad.alert(Messages.common_connectionLost, undefined, true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
config.onError = onConnectError;
|
|
||||||
|
|
||||||
cpNfInner = common.startRealtime(config);
|
|
||||||
metadataMgr = cpNfInner.metadataMgr;
|
|
||||||
|
|
||||||
cpNfInner.onInfiniteSpinner(function () {
|
|
||||||
setEditable(false);
|
|
||||||
Cryptpad.confirm(Messages.realtime_unrecoverableError, function (yes) {
|
|
||||||
if (!yes) { return; }
|
|
||||||
common.gotoURL();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.on('change', onLocal);
|
framework.onDefaultContentNeeded(function () {
|
||||||
|
editor.setValue(Messages.codeInitialState);
|
||||||
|
});
|
||||||
|
|
||||||
Cryptpad.onLogout(function () { setEditable(false); });
|
framework.setFileExporter(
|
||||||
};
|
function () {
|
||||||
|
return (Modes.extensionOf(CodeMirror.highlightMode) || '.txt').slice(1);
|
||||||
var CMEDITOR_CHECK_INTERVAL = 100;
|
},
|
||||||
var cmEditorAvailable = function (cb) {
|
function () {
|
||||||
var intr;
|
return new Blob([ editor.getValue() ], { type: 'text/plain;charset=utf-8' });
|
||||||
var check = function () {
|
|
||||||
if (window.CodeMirror) {
|
|
||||||
clearTimeout(intr);
|
|
||||||
cb(window.CodeMirror);
|
|
||||||
}
|
}
|
||||||
};
|
);
|
||||||
intr = setInterval(function () {
|
|
||||||
console.log("CodeMirror was not defined. Trying again in %sms", CMEDITOR_CHECK_INTERVAL);
|
framework.setFileImporter({}, function (content, file) {
|
||||||
check();
|
var mime = CodeMirror.findModeByMIME(file.type);
|
||||||
}, CMEDITOR_CHECK_INTERVAL);
|
var mode;
|
||||||
check();
|
if (!mime) {
|
||||||
|
var ext = /.+\.([^.]+)$/.exec(file.name);
|
||||||
|
if (ext[1]) {
|
||||||
|
mode = CMeditor.findModeByExtension(ext[1]);
|
||||||
|
mode = mode && mode.mode || null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mode = mime && mime.mode || null;
|
||||||
|
}
|
||||||
|
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
||||||
|
CodeMirror.setMode(mode);
|
||||||
|
$toolbarContainer.find('#language-mode').val(mode);
|
||||||
|
} else {
|
||||||
|
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
||||||
|
CodeMirror.setMode('text');
|
||||||
|
$toolbarContainer.find('#language-mode').val('text');
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
});
|
||||||
|
|
||||||
|
framework.setNormalizer(function (c) {
|
||||||
|
return {
|
||||||
|
content: c.content,
|
||||||
|
highlightMode: c.highlightMode
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
editor.on('change', framework.localChange);
|
||||||
|
|
||||||
|
framework.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
var main = function () {
|
var main = function () {
|
||||||
var CM;
|
|
||||||
var CodeMirror;
|
var CodeMirror;
|
||||||
var editor;
|
var editor;
|
||||||
var common;
|
var common;
|
||||||
|
var framework;
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
cmEditorAvailable(waitFor(function (cm) {
|
|
||||||
CM = cm;
|
Framework.create({
|
||||||
}));
|
toolbarContainer: '#cme_toolbox',
|
||||||
$(waitFor(function () {
|
contentContainer: '#cp-app-code-editor'
|
||||||
Cryptpad.addLoadingScreen();
|
}, waitFor(function (fw) { framework = fw; }));
|
||||||
}));
|
|
||||||
SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
|
nThen(function (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 () {
|
||||||
|
CodeMirror = common.initCodeMirrorApp(null, CMeditor);
|
||||||
|
$('.CodeMirror').addClass('cp-app-code-fullpage');
|
||||||
|
editor = CodeMirror.editor;
|
||||||
|
}).nThen(waitFor());
|
||||||
|
|
||||||
}).nThen(function (/*waitFor*/) {
|
}).nThen(function (/*waitFor*/) {
|
||||||
CodeMirror = common.initCodeMirrorApp(null, CM);
|
console.log('hi');
|
||||||
$('.CodeMirror').addClass('cp-app-code-fullpage');
|
andThen2(editor, CodeMirror, framework);
|
||||||
editor = CodeMirror.editor;
|
|
||||||
Cryptpad.onError(function (info) {
|
|
||||||
if (info && info.type === "store") {
|
|
||||||
onConnectError();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
andThen(editor, CodeMirror, common);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
main();
|
main();
|
||||||
|
|||||||
@ -1,41 +0,0 @@
|
|||||||
// 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();
|
|
||||||
|
|
||||||
// Loaded in load #2
|
|
||||||
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 + '/code/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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -49,6 +49,7 @@ define([
|
|||||||
var evEditableStateChange = Util.mkEvent();
|
var evEditableStateChange = Util.mkEvent();
|
||||||
var evOnReady = Util.mkEvent();
|
var evOnReady = Util.mkEvent();
|
||||||
var evOnDefaultContentNeeded = Util.mkEvent();
|
var evOnDefaultContentNeeded = Util.mkEvent();
|
||||||
|
var evCreated = Util.mkEvent(true);
|
||||||
|
|
||||||
var evStart = Util.mkEvent(true);
|
var evStart = Util.mkEvent(true);
|
||||||
|
|
||||||
@ -60,6 +61,11 @@ define([
|
|||||||
var toolbar;
|
var toolbar;
|
||||||
var state = STATE.DISCONNECTED;
|
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 titleRecommender = function () { return false; };
|
||||||
var contentGetter = function () { return UNINITIALIZED; };
|
var contentGetter = function () { return UNINITIALIZED; };
|
||||||
@ -247,9 +253,10 @@ define([
|
|||||||
|
|
||||||
var setFileExporter = function (extension, fe) {
|
var setFileExporter = function (extension, fe) {
|
||||||
var $export = common.createButton('export', true, {}, function () {
|
var $export = common.createButton('export', true, {}, function () {
|
||||||
|
var ext = (typeof(extension) === 'function') ? extension() : extension;
|
||||||
var suggestion = title.suggestTitle('cryptpad-document');
|
var suggestion = title.suggestTitle('cryptpad-document');
|
||||||
Cryptpad.prompt(Messages.exportPrompt,
|
Cryptpad.prompt(Messages.exportPrompt,
|
||||||
Cryptpad.fixFileName(suggestion) + '.html', function (filename)
|
Cryptpad.fixFileName(suggestion) + '.' + ext, function (filename)
|
||||||
{
|
{
|
||||||
if (!(typeof(filename) === 'string' && filename)) { return; }
|
if (!(typeof(filename) === 'string' && filename)) { return; }
|
||||||
var blob = fe();
|
var blob = fe();
|
||||||
@ -259,11 +266,11 @@ define([
|
|||||||
toolbar.$drawer.append($export);
|
toolbar.$drawer.append($export);
|
||||||
};
|
};
|
||||||
|
|
||||||
var setFileImporter = function (mimeType, fi) {
|
var setFileImporter = function (options, fi) {
|
||||||
if (readOnly) { return; }
|
if (readOnly) { return; }
|
||||||
toolbar.$drawer.append(
|
toolbar.$drawer.append(
|
||||||
common.createButton('import', true, { accept: mimeType }, function (c) {
|
common.createButton('import', true, options, function (c, f) {
|
||||||
evContentUpdate.fire(fi(c));
|
evContentUpdate.fire(fi(c, f));
|
||||||
onLocal();
|
onLocal();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -275,6 +282,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
|
Cryptpad.addLoadingScreen();
|
||||||
SFCommon.create(waitFor(function (c) { common = c; }));
|
SFCommon.create(waitFor(function (c) { common = c; }));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
cpNfInner = common.startRealtime({
|
cpNfInner = common.startRealtime({
|
||||||
@ -327,13 +335,26 @@ define([
|
|||||||
onConnectError();
|
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 () {
|
}).nThen(function () {
|
||||||
|
|
||||||
var $bar = $('#cke_1_toolbox'); // TODO
|
|
||||||
|
|
||||||
if (!$bar.length) { throw new Error(); }
|
|
||||||
|
|
||||||
title = common.createTitle({ getHeadingText: titleRecommender }, onLocal);
|
title = common.createTitle({ getHeadingText: titleRecommender }, onLocal);
|
||||||
var configTb = {
|
var configTb = {
|
||||||
displayed: ['userlist', 'title', 'useradmin', 'spinner', 'newpad', 'share', 'limit'],
|
displayed: ['userlist', 'title', 'useradmin', 'spinner', 'newpad', 'share', 'limit'],
|
||||||
@ -343,8 +364,8 @@ define([
|
|||||||
realtime: cpNfInner.chainpad,
|
realtime: cpNfInner.chainpad,
|
||||||
common: Cryptpad,
|
common: Cryptpad,
|
||||||
sfCommon: common,
|
sfCommon: common,
|
||||||
$container: $bar,
|
$container: $(toolbarContainer),
|
||||||
$contentContainer: $('#cke_1_contents'), // TODO
|
$contentContainer: $(contentContainer)
|
||||||
};
|
};
|
||||||
toolbar = Toolbar.create(configTb);
|
toolbar = Toolbar.create(configTb);
|
||||||
title.setToolbar(toolbar);
|
title.setToolbar(toolbar);
|
||||||
@ -357,7 +378,7 @@ define([
|
|||||||
applyVal: function (val) {
|
applyVal: function (val) {
|
||||||
evContentUpdate.fire(JSON.parse(val) || ["BODY",{},[]]);
|
evContentUpdate.fire(JSON.parse(val) || ["BODY",{},[]]);
|
||||||
},
|
},
|
||||||
$toolbar: $bar
|
$toolbar: $(toolbarContainer)
|
||||||
};
|
};
|
||||||
var $hist = common.createButton('history', true, {histConfig: histConfig});
|
var $hist = common.createButton('history', true, {histConfig: histConfig});
|
||||||
toolbar.$drawer.append($hist);
|
toolbar.$drawer.append($hist);
|
||||||
@ -447,7 +468,9 @@ define([
|
|||||||
title: title
|
title: title
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
evCreated.fire();
|
||||||
});
|
});
|
||||||
|
return evCreated.reg;
|
||||||
};
|
};
|
||||||
return { create: create };
|
return { create: create };
|
||||||
});
|
});
|
||||||
@ -8,7 +8,6 @@ define([
|
|||||||
], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
|
], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
|
||||||
var requireConfig = RequireConfig();
|
var requireConfig = RequireConfig();
|
||||||
|
|
||||||
// Loaded in load #2
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
$(waitFor());
|
$(waitFor());
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
@ -20,8 +19,8 @@ define([
|
|||||||
window.rc = requireConfig;
|
window.rc = requireConfig;
|
||||||
window.apiconf = ApiConfig;
|
window.apiconf = ApiConfig;
|
||||||
$('#sbox-iframe').attr('src',
|
$('#sbox-iframe').attr('src',
|
||||||
ApiConfig.httpSafeOrigin + '/pad/inner.html?' + requireConfig.urlArgs +
|
ApiConfig.httpSafeOrigin + window.location.pathname + 'inner.html?' +
|
||||||
'#' + encodeURIComponent(JSON.stringify(req)));
|
requireConfig.urlArgs + '#' + encodeURIComponent(JSON.stringify(req)));
|
||||||
|
|
||||||
// This is a cheap trick to avoid loading sframe-channel in parallel with the
|
// This is a cheap trick to avoid loading sframe-channel in parallel with the
|
||||||
// loading screen setup.
|
// loading screen setup.
|
||||||
@ -289,6 +289,15 @@ 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) {
|
||||||
|
setTimeout(function () { cb(window.CryptPad_sframe_common); });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.CryptPad_sframe_common = funcs;
|
||||||
|
|
||||||
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);
|
||||||
// CpNfInner.start() should be here....
|
// CpNfInner.start() should be here....
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="referrer" content="no-referrer" />
|
<meta name="referrer" content="no-referrer" />
|
||||||
<script async data-bootload="main.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
<script async data-bootload="/common/sframe-app-outer.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
|
|||||||
@ -332,7 +332,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var andThen2 = function (editor, Ckeditor, framework) {
|
var andThen2 = function (editor, Ckeditor, framework) {
|
||||||
var mediaTagMap = {}
|
var mediaTagMap = {};
|
||||||
var $bar = $('#cke_1_toolbox');
|
var $bar = $('#cke_1_toolbox');
|
||||||
var $html = $bar.closest('html');
|
var $html = $bar.closest('html');
|
||||||
var $faLink = $html.find('head link[href*="/bower_components/components-font-awesome/css/font-awesome.min.css"]');
|
var $faLink = $html.find('head link[href*="/bower_components/components-font-awesome/css/font-awesome.min.css"]');
|
||||||
@ -472,14 +472,12 @@ define([
|
|||||||
documentBody.innerHTML = Messages.initialState;
|
documentBody.innerHTML = Messages.initialState;
|
||||||
});
|
});
|
||||||
|
|
||||||
framework.setFileImporter('text/html', function (content) {
|
framework.setFileImporter({ accept: 'text/html' }, function (content) {
|
||||||
return Hyperjson.fromDOM(domFromHTML(content).body);
|
return Hyperjson.fromDOM(domFromHTML(content).body);
|
||||||
});
|
});
|
||||||
|
|
||||||
framework.setFileExporter("html", function () {
|
framework.setFileExporter('html', function () {
|
||||||
var html = getHTML(inner);
|
return new Blob([ getHTML(inner) ], { type: "text/html;charset=utf-8" });
|
||||||
var blob = new Blob([html], {type: "text/html;charset=utf-8"});
|
|
||||||
return blob;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
framework.setNormalizer(function (hjson) {
|
framework.setNormalizer(function (hjson) {
|
||||||
@ -538,34 +536,43 @@ define([
|
|||||||
var framework;
|
var framework;
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
ckEditorAvailable(waitFor(function (ck) {
|
Framework.create({
|
||||||
Ckeditor = ck;
|
toolbarContainer: '#cke_1_toolbox',
|
||||||
require(['/pad/wysiwygarea-plugin.js'], waitFor());
|
contentContainer: '#cke_1_contents'
|
||||||
}));
|
}, waitFor(function (fw) { window.APP.framework = framework = fw; }));
|
||||||
$(waitFor());
|
|
||||||
}).nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
Ckeditor.config.toolbarCanCollapse = true;
|
ckEditorAvailable(waitFor(function (ck) {
|
||||||
if (screen.height < 800) {
|
Ckeditor = ck;
|
||||||
Ckeditor.config.toolbarStartupExpanded = false;
|
require(['/pad/wysiwygarea-plugin.js'], waitFor());
|
||||||
$('meta[name=viewport]').attr('content', 'width=device-width, initial-scale=1.0, user-scalable=no');
|
}));
|
||||||
} else {
|
$(waitFor());
|
||||||
$('meta[name=viewport]').attr('content', 'width=device-width, initial-scale=1.0, user-scalable=yes');
|
}).nThen(function (waitFor) {
|
||||||
}
|
Ckeditor.config.toolbarCanCollapse = true;
|
||||||
// Used in ckeditor-config.js
|
if (screen.height < 800) {
|
||||||
Ckeditor.CRYPTPAD_URLARGS = ApiConfig.requireConf.urlArgs;
|
Ckeditor.config.toolbarStartupExpanded = false;
|
||||||
Ckeditor.plugins.addExternal('mediatag','/pad/', 'mediatag-plugin.js');
|
$('meta[name=viewport]').attr('content',
|
||||||
module.ckeditor = editor = Ckeditor.replace('editor1', {
|
'width=device-width, initial-scale=1.0, user-scalable=no');
|
||||||
customConfig: '/customize/ckeditor-config.js',
|
} else {
|
||||||
});
|
$('meta[name=viewport]').attr('content',
|
||||||
editor.on('instanceReady', waitFor());
|
'width=device-width, initial-scale=1.0, user-scalable=yes');
|
||||||
}).nThen(function (waitFor) {
|
}
|
||||||
Framework.create({}, waitFor(function (fw) { window.APP.framework = framework = fw; }));
|
// Used in ckeditor-config.js
|
||||||
editor.plugins.mediatag.translations = {
|
Ckeditor.CRYPTPAD_URLARGS = ApiConfig.requireConf.urlArgs;
|
||||||
title: Messages.pad_mediatagTitle,
|
Ckeditor.plugins.addExternal('mediatag','/pad/', 'mediatag-plugin.js');
|
||||||
width: Messages.pad_mediatagWidth,
|
module.ckeditor = editor = Ckeditor.replace('editor1', {
|
||||||
height: Messages.pad_mediatagHeight
|
customConfig: '/customize/ckeditor-config.js',
|
||||||
};
|
});
|
||||||
Links.addSupportForOpeningLinksInNewTab(Ckeditor)({editor: editor});
|
editor.on('instanceReady', waitFor());
|
||||||
|
}).nThen(function () {
|
||||||
|
editor.plugins.mediatag.translations = {
|
||||||
|
title: Messages.pad_mediatagTitle,
|
||||||
|
width: Messages.pad_mediatagWidth,
|
||||||
|
height: Messages.pad_mediatagHeight
|
||||||
|
};
|
||||||
|
Links.addSupportForOpeningLinksInNewTab(Ckeditor)({editor: editor});
|
||||||
|
}).nThen(waitFor());
|
||||||
|
|
||||||
}).nThen(function (/*waitFor*/) {
|
}).nThen(function (/*waitFor*/) {
|
||||||
andThen2(editor, Ckeditor, framework);
|
andThen2(editor, Ckeditor, framework);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user