lock the editor until the chain has synced
add 'onAbort' hook. lock the editor if the connection fails.
This commit is contained in:
@@ -133,36 +133,51 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var onRemote = function (shjson) {
|
var onRemote = function (shjson) {
|
||||||
if (!initializing) {
|
if (!initializing) { return; }
|
||||||
// remember where the cursor is
|
|
||||||
cursor.update();
|
|
||||||
|
|
||||||
// build a dom from HJSON, diff, and patch the editor
|
// remember where the cursor is
|
||||||
applyHjson(shjson);
|
cursor.update();
|
||||||
}
|
|
||||||
|
// build a dom from HJSON, diff, and patch the editor
|
||||||
|
applyHjson(shjson);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onInit = function (info) {
|
var onInit = function (info) {
|
||||||
var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox');
|
var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox');
|
||||||
toolbar = Toolbar.create($bar, userName, info.realtime);
|
toolbar = info.realtime.toolbar = Toolbar.create($bar, userName, info.realtime);
|
||||||
/* TODO handle disconnects and such*/
|
/* TODO handle disconnects and such*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var onReady = function (info) {
|
||||||
|
console.log("Unlocking editor");
|
||||||
|
initializing = false;
|
||||||
|
setEditable(true);
|
||||||
|
applyHjson($textarea.val());
|
||||||
|
$textarea.trigger('keyup');
|
||||||
|
};
|
||||||
|
|
||||||
|
var onAbort = function (info) {
|
||||||
|
console.log("Aborting the session!");
|
||||||
|
// stop the user from continuing to edit
|
||||||
|
setEditable(false);
|
||||||
|
|
||||||
|
// TODO inform them that the session was torn down
|
||||||
|
};
|
||||||
|
|
||||||
var realtimeOptions = {
|
var realtimeOptions = {
|
||||||
// configuration :D
|
// configuration :D
|
||||||
doc: inner,
|
doc: inner,
|
||||||
// first thing called
|
// first thing called
|
||||||
onInit: onInit,
|
onInit: onInit,
|
||||||
|
|
||||||
onReady: function (info) {
|
onReady: onReady,
|
||||||
console.log("Unlocking editor");
|
|
||||||
initializing = false;
|
|
||||||
setEditable(true);
|
|
||||||
applyHjson($textarea.val());
|
|
||||||
$textarea.trigger('keyup');
|
|
||||||
},
|
|
||||||
// when remote changes occur
|
// when remote changes occur
|
||||||
onRemote: onRemote,
|
onRemote: onRemote,
|
||||||
|
|
||||||
|
// handle aborts
|
||||||
|
onAbort: onAbort,
|
||||||
|
|
||||||
// really basic operational transform
|
// really basic operational transform
|
||||||
transformFunction : JsonOT.validate
|
transformFunction : JsonOT.validate
|
||||||
// pass in websocket/netflux object TODO
|
// pass in websocket/netflux object TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user