|
|
|
@ -1,6 +1,3 @@
|
|
|
|
|
/*
|
|
|
|
|
globals define console
|
|
|
|
|
*/
|
|
|
|
|
define([
|
|
|
|
|
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
|
|
|
|
'/common/messages.js',
|
|
|
|
@ -10,7 +7,6 @@ define([
|
|
|
|
|
'/common/toolbar.js',
|
|
|
|
|
'/common/cursor.js',
|
|
|
|
|
'/bower_components/diff-dom/diffDOM.js',
|
|
|
|
|
|
|
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
|
|
|
|
'/customize/pad.js'
|
|
|
|
|
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
|
|
|
|
@ -24,12 +20,7 @@ define([
|
|
|
|
|
var userName = Crypto.rand64(8),
|
|
|
|
|
toolbar;
|
|
|
|
|
|
|
|
|
|
var Vdom = Convert.core.vdom,
|
|
|
|
|
Hyperjson = Convert.core.hyperjson;
|
|
|
|
|
|
|
|
|
|
window.Hyperjson = Hyperjson;
|
|
|
|
|
|
|
|
|
|
var andThen = function () {
|
|
|
|
|
var andThen = function (Ckeditor) {
|
|
|
|
|
$(window).on('hashchange', function() {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
});
|
|
|
|
@ -50,6 +41,8 @@ define([
|
|
|
|
|
removePlugins: 'magicline,resize'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var CKE = Ckeditor;
|
|
|
|
|
|
|
|
|
|
editor.on('instanceReady', function (Ckeditor) {
|
|
|
|
|
editor.execCommand('maximize');
|
|
|
|
|
var documentBody = ifrw.$('iframe')[0].contentDocument.body;
|
|
|
|
@ -58,7 +51,7 @@ define([
|
|
|
|
|
|
|
|
|
|
var inner = documentBody;
|
|
|
|
|
window.inner = inner;
|
|
|
|
|
var cursor = window.cursor = Cursor(Ckeditor, editor, inner);
|
|
|
|
|
var cursor = window.cursor = Cursor(CKE, editor, inner);
|
|
|
|
|
|
|
|
|
|
var $textarea = $('#feedback');
|
|
|
|
|
|
|
|
|
@ -67,7 +60,6 @@ define([
|
|
|
|
|
var applyHjson = function (shjson) {
|
|
|
|
|
console.log("Applying HJSON");
|
|
|
|
|
var userDocStateDom = Convert.hjson.to.dom(JSON.parse(shjson));
|
|
|
|
|
//var userDocStateDom = Vdom.create(Convert.hjson.to.vdom(JSON.parse(shjson)));
|
|
|
|
|
|
|
|
|
|
userDocStateDom.setAttribute("contentEditable", "true"); // lol wtf
|
|
|
|
|
var patch = (new DiffDom()).diff(inner, userDocStateDom);
|
|
|
|
@ -80,7 +72,7 @@ define([
|
|
|
|
|
|
|
|
|
|
applyHjson(shjson);
|
|
|
|
|
|
|
|
|
|
cursor.find();
|
|
|
|
|
//cursor.find();
|
|
|
|
|
|
|
|
|
|
// put the cursor back where you left it
|
|
|
|
|
// FIXME put this back in
|
|
|
|
@ -91,6 +83,24 @@ define([
|
|
|
|
|
// 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
|
|
|
|
|
Config.websocketURL, // websocketURL, ofc
|
|
|
|
|
userName, // userName
|
|
|
|
@ -99,49 +109,26 @@ define([
|
|
|
|
|
{ // configuration :D
|
|
|
|
|
doc: inner,
|
|
|
|
|
|
|
|
|
|
// first thing called
|
|
|
|
|
onInit: onInit,
|
|
|
|
|
|
|
|
|
|
onReady: function (info) {
|
|
|
|
|
applyHjson($textarea.val());
|
|
|
|
|
$textarea.trigger('keyup');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// when remote changes occur
|
|
|
|
|
onRemote: onRemote,
|
|
|
|
|
onInit: onInit,
|
|
|
|
|
|
|
|
|
|
transformFunction : function (text, toTransform, transformBy) {
|
|
|
|
|
/* FIXME
|
|
|
|
|
operational transform on json shouldn't be in all editors
|
|
|
|
|
just those transmitting/expecting JSON
|
|
|
|
|
console.log({
|
|
|
|
|
text: text,
|
|
|
|
|
toTransform: toTransform,
|
|
|
|
|
transformBy: 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;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
FIXME NOT A REAL FUNCTION WONT WORK
|
|
|
|
|
transformFunction: function (state0str, toTransform, transformBy) {
|
|
|
|
|
var state1A = JSON.parse(Operation.apply(state0str, transformBy));
|
|
|
|
|
var state1B = JSON.parse(Operation.apply(state0str, toTransform));
|
|
|
|
|
var state0 = JSON.parse(state0str);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
transformFunction : rejectIfNotValidJson,
|
|
|
|
|
|
|
|
|
|
// pass in websocket/netflux object
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$textarea.val(JSON.stringify(Convert.dom.to.hjson(inner)));
|
|
|
|
|
|
|
|
|
|
editor.on('change', function () {
|
|
|
|
|
var hjson = Hyperjson.fromDOM(inner);
|
|
|
|
|
var hjson = Convert.core.hyperjson.fromDOM(inner);
|
|
|
|
|
|
|
|
|
|
$textarea.val(JSON.stringify(hjson));
|
|
|
|
|
rti.bumpSharejs();
|
|
|
|
|