From 938df2b92ff260bea6fbd9b409b0b636c3eba4f1 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 3 Mar 2016 18:05:05 +0100 Subject: [PATCH] lock the editor until the chain has synced add 'onAbort' hook. lock the editor if the connection fails. --- www/vdom/main.js | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/www/vdom/main.js b/www/vdom/main.js index e6c1c03db..a1abef7ed 100644 --- a/www/vdom/main.js +++ b/www/vdom/main.js @@ -133,36 +133,51 @@ define([ }; var onRemote = function (shjson) { - if (!initializing) { - // remember where the cursor is - cursor.update(); + if (!initializing) { return; } - // build a dom from HJSON, diff, and patch the editor - applyHjson(shjson); - } + // remember where the cursor is + cursor.update(); + + // build a dom from HJSON, diff, and patch the editor + applyHjson(shjson); }; var onInit = function (info) { 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*/ }; + 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 = { // configuration :D doc: inner, // first thing called onInit: onInit, - onReady: function (info) { - console.log("Unlocking editor"); - initializing = false; - setEditable(true); - applyHjson($textarea.val()); - $textarea.trigger('keyup'); - }, + onReady: onReady, + // when remote changes occur onRemote: onRemote, + + // handle aborts + onAbort: onAbort, + // really basic operational transform transformFunction : JsonOT.validate // pass in websocket/netflux object TODO