|
|
@ -6,17 +6,16 @@ define([
|
|
|
|
'/common/convert.js',
|
|
|
|
'/common/convert.js',
|
|
|
|
'/common/toolbar.js',
|
|
|
|
'/common/toolbar.js',
|
|
|
|
'/common/cursor.js',
|
|
|
|
'/common/cursor.js',
|
|
|
|
|
|
|
|
'/common/json-ot.js',
|
|
|
|
'/bower_components/diff-dom/diffDOM.js',
|
|
|
|
'/bower_components/diff-dom/diffDOM.js',
|
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
|
|
|
'/customize/pad.js'
|
|
|
|
'/customize/pad.js'
|
|
|
|
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
|
|
|
|
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor, JsonOT) {
|
|
|
|
var $ = window.jQuery;
|
|
|
|
var $ = window.jQuery;
|
|
|
|
var ifrw = $('#pad-iframe')[0].contentWindow;
|
|
|
|
var ifrw = $('#pad-iframe')[0].contentWindow;
|
|
|
|
var Ckeditor; // to be initialized later...
|
|
|
|
var Ckeditor; // to be initialized later...
|
|
|
|
//window.Ckeditor = ifrw.CKEDITOR;
|
|
|
|
//window.Ckeditor = ifrw.CKEDITOR;
|
|
|
|
var DiffDom = window.diffDOM;
|
|
|
|
var DiffDom = window.diffDOM;
|
|
|
|
var ChainPad = window.ChainPad;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var userName = Crypto.rand64(8),
|
|
|
|
var userName = Crypto.rand64(8),
|
|
|
|
toolbar;
|
|
|
|
toolbar;
|
|
|
|
|
|
|
|
|
|
|
@ -41,8 +40,6 @@ define([
|
|
|
|
removePlugins: 'magicline,resize'
|
|
|
|
removePlugins: 'magicline,resize'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var CKE = Ckeditor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editor.on('instanceReady', function (Ckeditor) {
|
|
|
|
editor.on('instanceReady', function (Ckeditor) {
|
|
|
|
editor.execCommand('maximize');
|
|
|
|
editor.execCommand('maximize');
|
|
|
|
var documentBody = ifrw.$('iframe')[0].contentDocument.body;
|
|
|
|
var documentBody = ifrw.$('iframe')[0].contentDocument.body;
|
|
|
@ -51,7 +48,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var inner = documentBody;
|
|
|
|
var inner = documentBody;
|
|
|
|
window.inner = inner;
|
|
|
|
window.inner = inner;
|
|
|
|
var cursor = window.cursor = Cursor(CKE, editor, inner);
|
|
|
|
var cursor = window.cursor = Cursor(inner);
|
|
|
|
|
|
|
|
|
|
|
|
var $textarea = $('#feedback');
|
|
|
|
var $textarea = $('#feedback');
|
|
|
|
|
|
|
|
|
|
|
@ -79,27 +76,7 @@ define([
|
|
|
|
//cursor.replace();
|
|
|
|
//cursor.replace();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onInit = function (info) {
|
|
|
|
var onInit = function (info) { /* TODO initialize the toolbar */ };
|
|
|
|
// TODO initialize the toolbar
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rejectIfNotValidJson = function (text, toTransform, transformBy) {
|
|
|
|
|
|
|
|
var resultOp = ChainPad.Operation.transform0(text, toTransform, transformBy);
|
|
|
|
|
|
|
|
var text2 = ChainPad.Operation.apply(transformBy, text);
|
|
|
|
|
|
|
|
var text3 = ChainPad.Operation.apply(resultOp, text2);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
JSON.parse(text3);
|
|
|
|
|
|
|
|
return resultOp;
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returning **null** breaks out of the loop
|
|
|
|
|
|
|
|
// which transforms conflicting operations
|
|
|
|
|
|
|
|
// in theory this should prevent us from producing bad JSON
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rti = realtimeInput.start($textarea[0], // synced element
|
|
|
|
var rti = realtimeInput.start($textarea[0], // synced element
|
|
|
|
Config.websocketURL, // websocketURL, ofc
|
|
|
|
Config.websocketURL, // websocketURL, ofc
|
|
|
@ -108,7 +85,6 @@ define([
|
|
|
|
key.cryptKey, // key
|
|
|
|
key.cryptKey, // key
|
|
|
|
{ // configuration :D
|
|
|
|
{ // configuration :D
|
|
|
|
doc: inner,
|
|
|
|
doc: inner,
|
|
|
|
|
|
|
|
|
|
|
|
// first thing called
|
|
|
|
// first thing called
|
|
|
|
onInit: onInit,
|
|
|
|
onInit: onInit,
|
|
|
|
|
|
|
|
|
|
|
@ -116,13 +92,11 @@ define([
|
|
|
|
applyHjson($textarea.val());
|
|
|
|
applyHjson($textarea.val());
|
|
|
|
$textarea.trigger('keyup');
|
|
|
|
$textarea.trigger('keyup');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// when remote changes occur
|
|
|
|
// when remote changes occur
|
|
|
|
onRemote: onRemote,
|
|
|
|
onRemote: onRemote,
|
|
|
|
|
|
|
|
// really basic operational transform
|
|
|
|
transformFunction : rejectIfNotValidJson,
|
|
|
|
transformFunction : JsonOT.validate
|
|
|
|
|
|
|
|
// pass in websocket/netflux object TODO
|
|
|
|
// pass in websocket/netflux object
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$textarea.val(JSON.stringify(Convert.dom.to.hjson(inner)));
|
|
|
|
$textarea.val(JSON.stringify(Convert.dom.to.hjson(inner)));
|
|
|
@ -132,11 +106,15 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
$textarea.val(JSON.stringify(hjson));
|
|
|
|
$textarea.val(JSON.stringify(hjson));
|
|
|
|
rti.bumpSharejs();
|
|
|
|
rti.bumpSharejs();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// update the cursor on changes to the editor
|
|
|
|
cursor.update();
|
|
|
|
cursor.update();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// a mouseup or keyup might change the cursor but not the contents
|
|
|
|
['mouseup', 'keyup'].forEach(function (type) {
|
|
|
|
['mouseup', 'keyup'].forEach(function (type) {
|
|
|
|
editor.document.on(type, function (e) {
|
|
|
|
editor.document.on(type, function (e) {
|
|
|
|
|
|
|
|
// when this is the case, update the cursor
|
|
|
|
cursor.update();
|
|
|
|
cursor.update();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|