Implement a new pad framework and make it work (seemingly) with /pad/
This commit is contained in:
559
www/pad/inner.js
559
www/pad/inner.js
@@ -19,22 +19,15 @@ require(['/api/config'], function (ApiConfig) {
|
||||
});
|
||||
define([
|
||||
'jquery',
|
||||
'/bower_components/chainpad-crypto/crypto.js',
|
||||
'/bower_components/hyperjson/hyperjson.js',
|
||||
'/common/toolbar3.js',
|
||||
'/common/sframe-app-framework.js',
|
||||
'/common/cursor.js',
|
||||
'/bower_components/chainpad-json-validator/json-ot.js',
|
||||
'/common/TypingTests.js',
|
||||
'json.sortify',
|
||||
'/bower_components/textpatcher/TextPatcher.js',
|
||||
'/common/cryptpad-common.js',
|
||||
'/common/cryptget.js',
|
||||
'/customize/messages.js',
|
||||
'/pad/links.js',
|
||||
'/bower_components/nthen/index.js',
|
||||
'/common/sframe-common.js',
|
||||
'/api/config',
|
||||
|
||||
'/bower_components/file-saver/FileSaver.min.js',
|
||||
'/bower_components/diff-dom/diffDOM.js',
|
||||
|
||||
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
|
||||
@@ -42,30 +35,17 @@ define([
|
||||
'less!/customize/src/less2/main.less',
|
||||
], function (
|
||||
$,
|
||||
Crypto,
|
||||
Hyperjson,
|
||||
Toolbar,
|
||||
Framework,
|
||||
Cursor,
|
||||
JsonOT,
|
||||
TypingTest,
|
||||
JSONSortify,
|
||||
TextPatcher,
|
||||
Cryptpad,
|
||||
Cryptget,
|
||||
Messages,
|
||||
Links,
|
||||
nThen,
|
||||
SFCommon,
|
||||
ApiConfig)
|
||||
{
|
||||
var saveAs = window.saveAs;
|
||||
var Messages = Cryptpad.Messages;
|
||||
var DiffDom = window.diffDOM;
|
||||
|
||||
var stringify = function (obj) { return JSONSortify(obj); };
|
||||
|
||||
window.Toolbar = Toolbar;
|
||||
window.Hyperjson = Hyperjson;
|
||||
|
||||
var slice = function (coll) {
|
||||
return Array.prototype.slice.call(coll);
|
||||
};
|
||||
@@ -87,21 +67,11 @@ define([
|
||||
|
||||
var module = window.REALTIME_MODULE = window.APP = {
|
||||
Hyperjson: Hyperjson,
|
||||
TextPatcher: TextPatcher,
|
||||
logFights: true,
|
||||
fights: [],
|
||||
Cryptpad: Cryptpad,
|
||||
Cursor: Cursor,
|
||||
};
|
||||
|
||||
var emitResize = module.emitResize = function () {
|
||||
var evt = window.document.createEvent('UIEvents');
|
||||
evt.initUIEvent('resize', true, false, window, 0);
|
||||
window.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
var toolbar;
|
||||
|
||||
var isNotMagicLine = function (el) {
|
||||
return !(el && typeof(el.getAttribute) === 'function' &&
|
||||
el.getAttribute('class') &&
|
||||
@@ -114,10 +84,6 @@ define([
|
||||
return hj;
|
||||
};
|
||||
|
||||
var onConnectError = function () {
|
||||
Cryptpad.errorLoadingScreen(Messages.websocketError);
|
||||
};
|
||||
|
||||
var domFromHTML = function (html) {
|
||||
return new DOMParser().parseFromString(html, 'text/html');
|
||||
};
|
||||
@@ -272,38 +238,53 @@ define([
|
||||
};
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var andThen = function (editor, Ckeditor, common) {
|
||||
//var $iframe = $('#pad-iframe').contents();
|
||||
//var secret = Cryptpad.getSecrets();
|
||||
//var readOnly = secret.keys && !secret.keys.editKeyStr;
|
||||
//if (!secret.keys) {
|
||||
// secret.keys = secret.key;
|
||||
//}
|
||||
var readOnly = false; // TODO
|
||||
var cpNfInner;
|
||||
var metadataMgr;
|
||||
var onLocal;
|
||||
var addToolbarHideBtn = function (framework, $bar) {
|
||||
// Expand / collapse the toolbar
|
||||
var $collapse = framework._.sfCommon.createButton(null, true);
|
||||
$collapse.removeClass('fa-question');
|
||||
var updateIcon = function (isVisible) {
|
||||
$collapse.removeClass('fa-caret-down').removeClass('fa-caret-up');
|
||||
if (!isVisible) {
|
||||
framework.feedback('HIDETOOLBAR_PAD');
|
||||
$collapse.addClass('fa-caret-down');
|
||||
}
|
||||
else {
|
||||
framework.feedback('SHOWTOOLBAR_PAD');
|
||||
$collapse.addClass('fa-caret-up');
|
||||
}
|
||||
};
|
||||
updateIcon();
|
||||
$collapse.click(function () {
|
||||
$(window).trigger('resize');
|
||||
$('.cke_toolbox_main').toggle();
|
||||
$(window).trigger('cryptpad-ck-toolbar');
|
||||
var isVisible = $bar.find('.cke_toolbox_main').is(':visible');
|
||||
framework._.sfCommon.setAttribute(['pad', 'showToolbar'], isVisible);
|
||||
updateIcon(isVisible);
|
||||
});
|
||||
framework._.sfCommon.getAttribute(['pad', 'showToolbar'], function (err, data) {
|
||||
if (typeof(data) === "undefined" || data) {
|
||||
$('.cke_toolbox_main').show();
|
||||
updateIcon(true);
|
||||
return;
|
||||
}
|
||||
$('.cke_toolbox_main').hide();
|
||||
updateIcon(false);
|
||||
});
|
||||
framework._.toolbar.$rightside.append($collapse);
|
||||
};
|
||||
|
||||
var andThen2 = function (editor, Ckeditor, framework) {
|
||||
var $bar = $('#cke_1_toolbox');
|
||||
|
||||
var $html = $bar.closest('html');
|
||||
var $faLink = $html.find('head link[href*="/bower_components/components-font-awesome/css/font-awesome.min.css"]');
|
||||
if ($faLink.length) {
|
||||
$html.find('iframe').contents().find('head').append($faLink.clone());
|
||||
}
|
||||
var isHistoryMode = false;
|
||||
|
||||
if (readOnly) {
|
||||
$('#cke_1_toolbox > .cke_toolbox_main').hide();
|
||||
}
|
||||
|
||||
/* add a class to the magicline plugin so we can pick it out more easily */
|
||||
|
||||
var ml = Ckeditor.instances.editor1.plugins.magicline.backdoor.that.line.$;
|
||||
[ml, ml.parentElement].forEach(function (el) {
|
||||
@@ -326,27 +307,15 @@ define([
|
||||
if (href) { ifrWindow.open(bounceHref, '_blank'); }
|
||||
};
|
||||
|
||||
var setEditable = module.setEditable = function (bool) {
|
||||
if (bool) {
|
||||
$(inner).css({
|
||||
color: '#333',
|
||||
});
|
||||
}
|
||||
if (!readOnly || !bool) {
|
||||
inner.setAttribute('contenteditable', bool);
|
||||
}
|
||||
};
|
||||
if (!framework.isReadOnly()) {
|
||||
framework.onEditableChange(function () {
|
||||
var locked = framework.isLocked();
|
||||
$(inner).css({ 'background-color': ((locked) ? '#aaa' : '') });
|
||||
inner.setAttribute('contenteditable', !locked);
|
||||
});
|
||||
}
|
||||
|
||||
// don't let the user edit until the pad is ready
|
||||
setEditable(false);
|
||||
|
||||
var initializing = true;
|
||||
|
||||
var Title;
|
||||
//var UserList;
|
||||
//var Metadata;
|
||||
|
||||
var getHeadingText = function () {
|
||||
framework.setTitleRecommender(function () {
|
||||
var text;
|
||||
if (['h1', 'h2', 'h3'].some(function (t) {
|
||||
var $header = $(inner).find(t + ':first-of-type');
|
||||
@@ -355,273 +324,38 @@ define([
|
||||
return true;
|
||||
}
|
||||
})) { return text; }
|
||||
};
|
||||
});
|
||||
|
||||
var DD = new DiffDom(mkDiffOptions(cursor, readOnly));
|
||||
var DD = new DiffDom(mkDiffOptions(cursor, framework.isReadOnly()));
|
||||
|
||||
// apply patches, and try not to lose the cursor in the process!
|
||||
var applyHjson = function (shjson) {
|
||||
var userDocStateDom = hjsonToDom(JSON.parse(shjson));
|
||||
framework.onContentUpdate(function (hjson) {
|
||||
var userDocStateDom = hjsonToDom(hjson);
|
||||
|
||||
userDocStateDom.setAttribute("contenteditable",
|
||||
inner.getAttribute('contenteditable'));
|
||||
|
||||
if (!readOnly && !initializing) {
|
||||
userDocStateDom.setAttribute("contenteditable", "true"); // lol wtf
|
||||
} else if (readOnly) {
|
||||
userDocStateDom.removeAttribute("contenteditable");
|
||||
}
|
||||
var patch = (DD).diff(inner, userDocStateDom);
|
||||
(DD).apply(inner, patch);
|
||||
if (readOnly) {
|
||||
if (framework.isReadOnly()) {
|
||||
var $links = $(inner).find('a');
|
||||
// off so that we don't end up with multiple identical handlers
|
||||
$links.off('click', openLink).on('click', openLink);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var stringifyDOM = module.stringifyDOM = function (dom) {
|
||||
var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter);
|
||||
hjson[3] = {
|
||||
metadata: metadataMgr.getMetadataLazy()
|
||||
};
|
||||
/*hjson[3] = { TODO
|
||||
users: UserList.userData,
|
||||
defaultTitle: Title.defaultTitle,
|
||||
type: 'pad'
|
||||
}
|
||||
};
|
||||
if (!initializing) {
|
||||
hjson[3].metadata.title = Title.title;
|
||||
} else if (Cryptpad.initialName && !hjson[3].metadata.title) {
|
||||
hjson[3].metadata.title = Cryptpad.initialName;
|
||||
}*/
|
||||
return stringify(hjson);
|
||||
};
|
||||
framework.setContentGetter(function () {
|
||||
return Hyperjson.fromDOM(inner, isNotMagicLine, brFilter);
|
||||
});
|
||||
|
||||
var realtimeOptions = {
|
||||
readOnly: readOnly,
|
||||
// really basic operational transform
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
$bar.find('#cke_1_toolbar_collapser').hide();
|
||||
if (!framework.isReadOnly()) {
|
||||
addToolbarHideBtn(framework, $bar);
|
||||
} else {
|
||||
$('.cke_toolbox_main').hide();
|
||||
}
|
||||
|
||||
var setHistory = function (bool, update) {
|
||||
isHistoryMode = bool;
|
||||
setEditable(!bool);
|
||||
if (!bool && update) {
|
||||
realtimeOptions.onRemote();
|
||||
}
|
||||
};
|
||||
|
||||
realtimeOptions.onRemote = function () {
|
||||
if (initializing) { return; }
|
||||
if (isHistoryMode) { return; }
|
||||
|
||||
var oldShjson = stringifyDOM(inner);
|
||||
|
||||
var shjson = module.realtime.getUserDoc();
|
||||
|
||||
// remember where the cursor is
|
||||
cursor.update();
|
||||
|
||||
// Update the user list (metadata) from the hyperjson
|
||||
// TODO Metadata.update(shjson);
|
||||
|
||||
var newInner = JSON.parse(shjson);
|
||||
var newSInner;
|
||||
if (newInner.length > 2) {
|
||||
newSInner = stringify(newInner[2]);
|
||||
}
|
||||
|
||||
if (newInner[3]) {
|
||||
metadataMgr.updateMetadata(newInner[3].metadata);
|
||||
}
|
||||
|
||||
// build a dom from HJSON, diff, and patch the editor
|
||||
applyHjson(shjson);
|
||||
|
||||
if (!readOnly) {
|
||||
var shjson2 = stringifyDOM(inner);
|
||||
|
||||
// TODO
|
||||
//shjson = JSON.stringify(JSON.parse(shjson).slice(0,3));
|
||||
|
||||
if (shjson2 !== shjson) {
|
||||
console.error("shjson2 !== shjson");
|
||||
module.patchText(shjson2);
|
||||
|
||||
/* pushing back over the wire is necessary, but it can
|
||||
result in a feedback loop, which we call a browser
|
||||
fight */
|
||||
if (module.logFights) {
|
||||
// what changed?
|
||||
var op = TextPatcher.diff(shjson, shjson2);
|
||||
// log the changes
|
||||
TextPatcher.log(shjson, op);
|
||||
var sop = JSON.stringify(TextPatcher.format(shjson, op));
|
||||
|
||||
var index = module.fights.indexOf(sop);
|
||||
if (index === -1) {
|
||||
module.fights.push(sop);
|
||||
console.log("Found a new type of browser disagreement");
|
||||
console.log("You can inspect the list in your " +
|
||||
"console at `REALTIME_MODULE.fights`");
|
||||
console.log(module.fights);
|
||||
} else {
|
||||
console.log("Encountered a known browser disagreement: " +
|
||||
"available at `REALTIME_MODULE.fights[%s]`", index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Notify only when the content has changed, not when someone has joined/left
|
||||
var oldSInner = stringify(JSON.parse(oldShjson)[2]);
|
||||
if (newSInner && newSInner !== oldSInner) {
|
||||
common.notify();
|
||||
}
|
||||
};
|
||||
|
||||
var exportFile = function () {
|
||||
var html = getHTML(inner);
|
||||
var suggestion = Title.suggestTitle('cryptpad-document');
|
||||
Cryptpad.prompt(Messages.exportPrompt,
|
||||
Cryptpad.fixFileName(suggestion) + '.html', function (filename) {
|
||||
if (!(typeof(filename) === 'string' && filename)) { return; }
|
||||
var blob = new Blob([html], {type: "text/html;charset=utf-8"});
|
||||
saveAs(blob, filename);
|
||||
});
|
||||
};
|
||||
var importFile = function (content) {
|
||||
var shjson = stringify(Hyperjson.fromDOM(domFromHTML(content).body));
|
||||
applyHjson(shjson);
|
||||
realtimeOptions.onLocal();
|
||||
};
|
||||
|
||||
realtimeOptions.onInit = function (info) {
|
||||
readOnly = metadataMgr.getPrivateData().readOnly;
|
||||
console.log('onInit');
|
||||
var titleCfg = { getHeadingText: getHeadingText };
|
||||
Title = common.createTitle(titleCfg, realtimeOptions.onLocal);
|
||||
var configTb = {
|
||||
displayed: ['userlist', 'title', 'useradmin', 'spinner', 'newpad', 'share', 'limit'],
|
||||
title: Title.getTitleConfig(),
|
||||
metadataMgr: metadataMgr,
|
||||
readOnly: readOnly,
|
||||
ifrw: window,
|
||||
realtime: info.realtime,
|
||||
common: Cryptpad,
|
||||
sfCommon: common,
|
||||
$container: $bar,
|
||||
$contentContainer: $('#cke_1_contents'),
|
||||
};
|
||||
toolbar = info.realtime.toolbar = Toolbar.create(configTb);
|
||||
Title.setToolbar(toolbar);
|
||||
|
||||
var $rightside = toolbar.$rightside;
|
||||
var $drawer = toolbar.$drawer;
|
||||
|
||||
var src = 'less!/customize/src/less/toolbar.less';
|
||||
require([
|
||||
src
|
||||
], function () {
|
||||
var $html = $bar.closest('html');
|
||||
$html
|
||||
.find('head style[data-original-src="' + src.replace(/less!/, '') + '"]')
|
||||
.appendTo($html.find('head'));
|
||||
});
|
||||
|
||||
$bar.find('#cke_1_toolbar_collapser').hide();
|
||||
if (!readOnly) {
|
||||
// Expand / collapse the toolbar
|
||||
var $collapse = common.createButton(null, true);
|
||||
$collapse.removeClass('fa-question');
|
||||
var updateIcon = function (isVisible) {
|
||||
$collapse.removeClass('fa-caret-down').removeClass('fa-caret-up');
|
||||
if (!isVisible) {
|
||||
if (!initializing) { common.feedback('HIDETOOLBAR_PAD'); }
|
||||
$collapse.addClass('fa-caret-down');
|
||||
}
|
||||
else {
|
||||
if (!initializing) { common.feedback('SHOWTOOLBAR_PAD'); }
|
||||
$collapse.addClass('fa-caret-up');
|
||||
}
|
||||
};
|
||||
updateIcon();
|
||||
$collapse.click(function () {
|
||||
$(window).trigger('resize');
|
||||
$('.cke_toolbox_main').toggle();
|
||||
$(window).trigger('cryptpad-ck-toolbar');
|
||||
var isVisible = $bar.find('.cke_toolbox_main').is(':visible');
|
||||
common.setAttribute(['pad', 'showToolbar'], isVisible);
|
||||
updateIcon(isVisible);
|
||||
});
|
||||
common.getAttribute(['pad', 'showToolbar'], function (err, data) {
|
||||
if (typeof(data) === "undefined" || data) {
|
||||
$('.cke_toolbox_main').show();
|
||||
updateIcon(true);
|
||||
return;
|
||||
}
|
||||
$('.cke_toolbox_main').hide();
|
||||
updateIcon(false);
|
||||
});
|
||||
$rightside.append($collapse);
|
||||
} else {
|
||||
$('.cke_toolbox_main').hide();
|
||||
}
|
||||
|
||||
/* add a history button */
|
||||
var histConfig = {
|
||||
onLocal: realtimeOptions.onLocal,
|
||||
onRemote: realtimeOptions.onRemote,
|
||||
setHistory: setHistory,
|
||||
applyVal: function (val) { applyHjson(val || '["BODY",{},[]]'); },
|
||||
$toolbar: $bar
|
||||
};
|
||||
var $hist = common.createButton('history', true, {histConfig: histConfig});
|
||||
$drawer.append($hist);
|
||||
|
||||
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, {}, exportFile);
|
||||
$drawer.append($export);
|
||||
|
||||
if (!readOnly) {
|
||||
/* add an import button */
|
||||
var $import = common.createButton('import', true, {
|
||||
accept: 'text/html'
|
||||
}, importFile);
|
||||
$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);
|
||||
};
|
||||
|
||||
// this should only ever get called once, when the chain syncs
|
||||
realtimeOptions.onReady = function (info) {
|
||||
console.log('onReady');
|
||||
framework.onReady(function (newPad) {
|
||||
if (!module.isMaximized) {
|
||||
module.isMaximized = true;
|
||||
$('iframe.cke_wysiwyg_frame').css('width', '');
|
||||
@@ -629,110 +363,40 @@ define([
|
||||
}
|
||||
$('body').addClass('app-pad');
|
||||
|
||||
if (module.realtime !== info.realtime) {
|
||||
module.patchText = TextPatcher.create({
|
||||
realtime: info.realtime,
|
||||
//logging: true,
|
||||
});
|
||||
}
|
||||
|
||||
module.realtime = info.realtime;
|
||||
|
||||
var shjson = module.realtime.getUserDoc();
|
||||
|
||||
var newPad = false;
|
||||
if (shjson === '') { newPad = true; }
|
||||
|
||||
if (!newPad) {
|
||||
applyHjson(shjson);
|
||||
|
||||
// Update the user list (metadata) from the hyperjson
|
||||
// XXX Metadata.update(shjson);
|
||||
var parsed = JSON.parse(shjson);
|
||||
if (parsed[3] && parsed[3].metadata) {
|
||||
metadataMgr.updateMetadata(parsed[3].metadata);
|
||||
}
|
||||
|
||||
if (!readOnly) {
|
||||
var shjson2 = stringifyDOM(inner);
|
||||
var hjson2 = JSON.parse(shjson2).slice(0,3);
|
||||
var hjson = JSON.parse(shjson).slice(0,3);
|
||||
if (stringify(hjson2) !== stringify(hjson)) {
|
||||
console.log('err');
|
||||
console.error("shjson2 !== shjson");
|
||||
console.log(stringify(hjson2));
|
||||
console.log(stringify(hjson));
|
||||
Cryptpad.errorLoadingScreen(Messages.wrongApp);
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Title.updateTitle(Cryptpad.initialName || Title.defaultTitle);
|
||||
documentBody.innerHTML = Messages.initialState;
|
||||
}
|
||||
|
||||
Cryptpad.removeLoadingScreen(emitResize);
|
||||
setEditable(!readOnly);
|
||||
initializing = false;
|
||||
|
||||
if (readOnly) { return; }
|
||||
|
||||
|
||||
if (newPad) {
|
||||
common.openTemplatePicker();
|
||||
}
|
||||
|
||||
onLocal();
|
||||
editor.focus();
|
||||
if (newPad) {
|
||||
documentBody.innerHTML = Messages.initialState;
|
||||
cursor.setToEnd();
|
||||
} else {
|
||||
} else if (framework.isReadOnly()) {
|
||||
cursor.setToStart();
|
||||
}
|
||||
};
|
||||
|
||||
realtimeOptions.onConnectionChange = function (info) {
|
||||
setEditable(info.state);
|
||||
//toolbar.failed(); TODO
|
||||
if (info.state) {
|
||||
initializing = true;
|
||||
//toolbar.reconnecting(info.myId); // TODO
|
||||
Cryptpad.findOKButton().click();
|
||||
} else {
|
||||
Cryptpad.alert(Messages.common_connectionLost, undefined, true);
|
||||
}
|
||||
};
|
||||
|
||||
realtimeOptions.onError = onConnectError;
|
||||
|
||||
onLocal = realtimeOptions.onLocal = function () {
|
||||
console.log('onlocal');
|
||||
if (initializing) { return; }
|
||||
if (isHistoryMode) { return; }
|
||||
if (readOnly) { return; }
|
||||
|
||||
// stringify the json and send it into chainpad
|
||||
var shjson = stringifyDOM(inner);
|
||||
|
||||
module.patchText(shjson);
|
||||
if (module.realtime.getUserDoc() !== shjson) {
|
||||
console.error("realtime.getUserDoc() !== shjson");
|
||||
}
|
||||
};
|
||||
|
||||
cpNfInner = common.startRealtime(realtimeOptions);
|
||||
metadataMgr = cpNfInner.metadataMgr;
|
||||
|
||||
cpNfInner.onInfiniteSpinner(function () {
|
||||
setEditable(false);
|
||||
Cryptpad.confirm(Messages.realtime_unrecoverableError, function (yes) {
|
||||
if (!yes) { return; }
|
||||
common.gotoURL();
|
||||
//window.parent.location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
Cryptpad.onLogout(function () { setEditable(false); });
|
||||
framework.onDefaultContentNeeded(function () {
|
||||
documentBody.innerHTML = Messages.initialState;
|
||||
});
|
||||
|
||||
framework.setFileImporter('text/html', function (content) {
|
||||
return Hyperjson.fromDOM(domFromHTML(content).body);
|
||||
});
|
||||
|
||||
framework.setFileExporter("html", function () {
|
||||
var html = getHTML(inner);
|
||||
var blob = new Blob([html], {type: "text/html;charset=utf-8"});
|
||||
return blob;
|
||||
});
|
||||
|
||||
framework.setNormalizer(function (hjson) {
|
||||
return [
|
||||
'BODY',
|
||||
{
|
||||
"class": "cke_editable cke_editable_themed cke_contents_ltr cke_show_borders",
|
||||
"contenteditable": "true",
|
||||
"spellcheck":"false"
|
||||
},
|
||||
hjson[2]
|
||||
];
|
||||
});
|
||||
|
||||
/* hitting enter makes a new line, but places the cursor inside
|
||||
of the <br> instead of the <p>. This makes it such that you
|
||||
@@ -743,7 +407,7 @@ define([
|
||||
the first such keypress will not be inserted into the P. */
|
||||
inner.addEventListener('keydown', cursor.brFix);
|
||||
|
||||
editor.on('change', onLocal);
|
||||
editor.on('change', framework.localChange);
|
||||
|
||||
// export the typing tests to the window.
|
||||
// call like `test = easyTest()`
|
||||
@@ -751,8 +415,8 @@ define([
|
||||
window.easyTest = function () {
|
||||
cursor.update();
|
||||
var start = cursor.Range.start;
|
||||
var test = TypingTest.testInput(inner, start.el, start.offset, onLocal);
|
||||
onLocal();
|
||||
var test = TypingTest.testInput(inner, start.el, start.offset, framework.localChange);
|
||||
framework.localChange();
|
||||
return test;
|
||||
};
|
||||
|
||||
@@ -765,25 +429,24 @@ define([
|
||||
|
||||
var id = classes[0];
|
||||
if (typeof(id) === 'string') {
|
||||
common.feedback(id.toUpperCase());
|
||||
framework.feedback(id.toUpperCase());
|
||||
}
|
||||
});
|
||||
|
||||
framework.start();
|
||||
};
|
||||
|
||||
var main = function () {
|
||||
var Ckeditor;
|
||||
var editor;
|
||||
var common;
|
||||
var framework;
|
||||
|
||||
nThen(function (waitFor) {
|
||||
ckEditorAvailable(waitFor(function (ck) {
|
||||
Ckeditor = ck;
|
||||
require(['/pad/wysiwygarea-plugin.js'], waitFor());
|
||||
}));
|
||||
$(waitFor(function () {
|
||||
Cryptpad.addLoadingScreen();
|
||||
}));
|
||||
SFCommon.create(waitFor(function (c) { module.common = common = c; }));
|
||||
$(waitFor());
|
||||
}).nThen(function (waitFor) {
|
||||
Ckeditor.config.toolbarCanCollapse = true;
|
||||
if (screen.height < 800) {
|
||||
@@ -798,21 +461,11 @@ define([
|
||||
customConfig: '/customize/ckeditor-config.js',
|
||||
});
|
||||
editor.on('instanceReady', waitFor());
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
/*if (Ckeditor.env.safari) {
|
||||
var fixIframe = function () {
|
||||
$('iframe.cke_wysiwyg_frame').height($('#cke_1_contents').height());
|
||||
};
|
||||
$(window).resize(fixIframe);
|
||||
fixIframe();
|
||||
}*/
|
||||
}).nThen(function (waitFor) {
|
||||
Framework.create({}, waitFor(function (fw) { window.APP.framework = framework = fw; }));
|
||||
Links.addSupportForOpeningLinksInNewTab(Ckeditor)({editor: editor});
|
||||
Cryptpad.onError(function (info) {
|
||||
if (info && info.type === "store") {
|
||||
onConnectError();
|
||||
}
|
||||
});
|
||||
andThen(editor, Ckeditor, common);
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
andThen2(editor, Ckeditor, framework);
|
||||
});
|
||||
};
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user