|
|
@ -6,12 +6,9 @@ define([
|
|
|
|
'/common/convert.js',
|
|
|
|
'/common/convert.js',
|
|
|
|
'/common/toolbar.js',
|
|
|
|
'/common/toolbar.js',
|
|
|
|
'/common/cursor.js',
|
|
|
|
'/common/cursor.js',
|
|
|
|
'/common/Operation.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, Operation) {
|
|
|
|
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
|
|
|
|
window.Operation = Operation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $ = window.jQuery;
|
|
|
|
var $ = window.jQuery;
|
|
|
|
var ifrw = $('#pad-iframe')[0].contentWindow;
|
|
|
|
var ifrw = $('#pad-iframe')[0].contentWindow;
|
|
|
|
window.Ckeditor = ifrw.CKEDITOR;
|
|
|
|
window.Ckeditor = ifrw.CKEDITOR;
|
|
|
@ -107,53 +104,29 @@ define([
|
|
|
|
onInit: onInit,
|
|
|
|
onInit: onInit,
|
|
|
|
|
|
|
|
|
|
|
|
transformFunction : function (text, toTransform, transformBy) {
|
|
|
|
transformFunction : function (text, toTransform, transformBy) {
|
|
|
|
|
|
|
|
/* FIXME
|
|
|
|
|
|
|
|
operational transform on json shouldn't be in all editors
|
|
|
|
|
|
|
|
just those transmitting/expecting JSON
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
false && console.log({
|
|
|
|
|
|
|
|
text: text,
|
|
|
|
|
|
|
|
toTransform: toTransform,
|
|
|
|
|
|
|
|
transformBy: transformBy
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// returning **null** breaks out of the loop
|
|
|
|
// returning **null** breaks out of the loop
|
|
|
|
// which transforms conflicting operations
|
|
|
|
// which transforms conflicting operations
|
|
|
|
// in theory this should prevent us from producing bad JSON
|
|
|
|
// in theory this should prevent us from producing bad JSON
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// OT
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
transformFunction: function (text, toTransform, transformBy) {
|
|
|
|
FIXME NOT A REAL FUNCTION WONT WORK
|
|
|
|
if (toTransform.offset > transformBy.offset) {
|
|
|
|
transformFunction: function (state0str, toTransform, transformBy) {
|
|
|
|
if (toTransform.offset > transformBy.offset + transformBy.toRemove) {
|
|
|
|
var state1A = JSON.parse(Operation.apply(state0str, transformBy));
|
|
|
|
// simple rebase
|
|
|
|
var state1B = JSON.parse(Operation.apply(state0str, toTransform));
|
|
|
|
toTransform.offset -= transformBy.toRemove;
|
|
|
|
var state0 = JSON.parse(state0str);
|
|
|
|
toTransform.offset += transformBy.toInsert.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO check that this is using the correct parameters
|
|
|
|
|
|
|
|
// TODO get the actual library
|
|
|
|
|
|
|
|
// TODO functionize this because it's repeated
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var temp = Operation.apply(text, toTransform)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
JSON.parse(temp);
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error(err.stack);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return toTransform;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// goto the end, anything you deleted that they also deleted should be skipped.
|
|
|
|
|
|
|
|
var newOffset = transformBy.offset + transformBy.toInsert.length;
|
|
|
|
|
|
|
|
toTransform.toRemove = 0; //-= (newOffset - toTransform.offset);
|
|
|
|
|
|
|
|
if (toTransform.toRemove < 0) { toTransform.toRemove = 0; }
|
|
|
|
|
|
|
|
toTransform.offset = newOffset;
|
|
|
|
|
|
|
|
if (toTransform.toInsert.length === 0 && toTransform.toRemove === 0) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return toTransform;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toTransform.offset + toTransform.toRemove < transformBy.offset) {
|
|
|
|
|
|
|
|
return toTransform;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
toTransform.toRemove = transformBy.offset - toTransform.offset;
|
|
|
|
|
|
|
|
if (toTransform.toInsert.length === 0 && toTransform.toRemove === 0) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toTransform;
|
|
|
|
*/
|
|
|
|
} */
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$textarea.val(JSON.stringify(Convert.dom.to.hjson(inner)));
|
|
|
|
$textarea.val(JSON.stringify(Convert.dom.to.hjson(inner)));
|
|
|
|