|
|
@ -11,15 +11,18 @@ define([
|
|
|
|
'/common/json-ot.js',
|
|
|
|
'/common/json-ot.js',
|
|
|
|
'/common/TypingTests.js',
|
|
|
|
'/common/TypingTests.js',
|
|
|
|
'json.sortify',
|
|
|
|
'json.sortify',
|
|
|
|
|
|
|
|
'/common/TextPatcher.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, Hyperjson, Hyperscript, Toolbar, Cursor, JsonOT, TypingTest, JSONSortify) {
|
|
|
|
], function (Config, Messages, Crypto, realtimeInput, Hyperjson, Hyperscript,
|
|
|
|
|
|
|
|
Toolbar, Cursor, JsonOT, TypingTest, JSONSortify, TextPatcher) {
|
|
|
|
|
|
|
|
|
|
|
|
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...
|
|
|
|
var DiffDom = window.diffDOM;
|
|
|
|
var DiffDom = window.diffDOM;
|
|
|
|
|
|
|
|
|
|
|
|
var stringify = function (obj) {
|
|
|
|
var stringify = function (obj) {
|
|
|
|
return JSONSortify(obj);
|
|
|
|
return JSONSortify(obj);
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -288,7 +291,7 @@ define([
|
|
|
|
var shjson2 = stringifyDOM(inner);
|
|
|
|
var shjson2 = stringifyDOM(inner);
|
|
|
|
if (shjson2 !== shjson) {
|
|
|
|
if (shjson2 !== shjson) {
|
|
|
|
console.error("shjson2 !== shjson");
|
|
|
|
console.error("shjson2 !== shjson");
|
|
|
|
module.realtimeInput.patchText(shjson2);
|
|
|
|
module.patchText(shjson2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -304,12 +307,21 @@ define([
|
|
|
|
/* TODO handle disconnects and such*/
|
|
|
|
/* TODO handle disconnects and such*/
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this should only ever get called once, when the chain syncs
|
|
|
|
var onReady = realtimeOptions.onReady = function (info) {
|
|
|
|
var onReady = realtimeOptions.onReady = function (info) {
|
|
|
|
console.log("Unlocking editor");
|
|
|
|
module.patchText = TextPatcher.create({
|
|
|
|
initializing = false;
|
|
|
|
realtime: info.realtime,
|
|
|
|
setEditable(true);
|
|
|
|
logging: false,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.realtime = info.realtime;
|
|
|
|
|
|
|
|
|
|
|
|
var shjson = info.realtime.getUserDoc();
|
|
|
|
var shjson = info.realtime.getUserDoc();
|
|
|
|
applyHjson(shjson);
|
|
|
|
applyHjson(shjson);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Unlocking editor");
|
|
|
|
|
|
|
|
setEditable(true);
|
|
|
|
|
|
|
|
initializing = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onAbort = realtimeOptions.onAbort = function (info) {
|
|
|
|
var onAbort = realtimeOptions.onAbort = function (info) {
|
|
|
@ -320,21 +332,9 @@ define([
|
|
|
|
toolbar.failed();
|
|
|
|
toolbar.failed();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var onLocal = realtimeOptions.onLocal = function () {
|
|
|
|
|
|
|
|
if (initializing) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rti = module.realtimeInput = realtimeInput.start(realtimeOptions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* It's incredibly important that you assign 'rti.onLocal'
|
|
|
|
|
|
|
|
It's used inside of realtimeInput to make sure that all changes
|
|
|
|
|
|
|
|
make it into chainpad.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It's being assigned this way because it can't be passed in, and
|
|
|
|
|
|
|
|
and can't be easily returned from realtime input without making
|
|
|
|
|
|
|
|
the code less extensible.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var propogate = rti.onLocal = function () {
|
|
|
|
|
|
|
|
// serialize your DOM into an object
|
|
|
|
// serialize your DOM into an object
|
|
|
|
var hjson = Hyperjson.fromDOM(inner, isNotMagicLine, brFilter);
|
|
|
|
var hjson = Hyperjson.fromDOM(inner, isNotMagicLine, brFilter);
|
|
|
|
|
|
|
|
|
|
|
@ -344,12 +344,15 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// stringify the json and send it into chainpad
|
|
|
|
// stringify the json and send it into chainpad
|
|
|
|
var shjson = stringify(hjson);
|
|
|
|
var shjson = stringify(hjson);
|
|
|
|
if (!rti.patchText(shjson)) {
|
|
|
|
module.patchText(shjson);
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (module.realtime.getUserDoc() !== shjson) {
|
|
|
|
|
|
|
|
console.error("realtime.getUserDoc() !== shjson");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rti.onEvent(shjson);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rti = module.realtimeInput = realtimeInput.start(realtimeOptions);
|
|
|
|
|
|
|
|
|
|
|
|
/* hitting enter makes a new line, but places the cursor inside
|
|
|
|
/* hitting enter makes a new line, but places the cursor inside
|
|
|
|
of the <br> instead of the <p>. This makes it such that you
|
|
|
|
of the <br> instead of the <p>. This makes it such that you
|
|
|
|
cannot type until you click, which is rather unnacceptable.
|
|
|
|
cannot type until you click, which is rather unnacceptable.
|
|
|
@ -359,7 +362,7 @@ define([
|
|
|
|
the first such keypress will not be inserted into the P. */
|
|
|
|
the first such keypress will not be inserted into the P. */
|
|
|
|
inner.addEventListener('keydown', cursor.brFix);
|
|
|
|
inner.addEventListener('keydown', cursor.brFix);
|
|
|
|
|
|
|
|
|
|
|
|
editor.on('change', propogate);
|
|
|
|
editor.on('change', onLocal);
|
|
|
|
|
|
|
|
|
|
|
|
// export the typing tests to the window.
|
|
|
|
// export the typing tests to the window.
|
|
|
|
// call like `test = easyTest()`
|
|
|
|
// call like `test = easyTest()`
|
|
|
@ -367,8 +370,8 @@ define([
|
|
|
|
var easyTest = window.easyTest = function () {
|
|
|
|
var easyTest = window.easyTest = function () {
|
|
|
|
cursor.update();
|
|
|
|
cursor.update();
|
|
|
|
var start = cursor.Range.start;
|
|
|
|
var start = cursor.Range.start;
|
|
|
|
var test = TypingTest.testInput(inner, start.el, start.offset, propogate);
|
|
|
|
var test = TypingTest.testInput(inner, start.el, start.offset, onLocal);
|
|
|
|
propogate();
|
|
|
|
onLocal();
|
|
|
|
return test;
|
|
|
|
return test;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|