From e26246178f2cdfdad255f277a3e9d7377839935d Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 25 Mar 2016 18:01:23 +0100 Subject: [PATCH] start to clean up and give things more sensible names. get rid of the textarea entirely --- www/_socket/index.html | 13 +------------ www/_socket/main.js | 14 +++++++------- www/_socket/realtime-input.js | 7 +++---- ..._textarea-transport-only.js => text-patcher.js} | 7 ++----- 4 files changed, 13 insertions(+), 28 deletions(-) rename www/_socket/{sharejs_textarea-transport-only.js => text-patcher.js} (96%) diff --git a/www/_socket/index.html b/www/_socket/index.html index 6ee2a8596..830d56125 100644 --- a/www/_socket/index.html +++ b/www/_socket/index.html @@ -14,28 +14,17 @@ left:0px; bottom:0px; right:0px; - width:70%; + width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; } - #feedback { - position: fixed; - top: 0px; - right: 0px; - border: 0px; - height: 100vh; - width: 30vw; - background-color: #222; - color: #ccc; - } - diff --git a/www/_socket/main.js b/www/_socket/main.js index 86ccdc4a1..43dd1d824 100644 --- a/www/_socket/main.js +++ b/www/_socket/main.js @@ -90,7 +90,7 @@ define([ var $textarea = $('#feedback'); var setEditable = function (bool) { - // inner.style.backgroundColor = bool? 'unset': 'grey'; + inner.style.backgroundColor = bool? 'unset': 'grey'; inner.setAttribute('contenteditable', bool); }; @@ -197,7 +197,7 @@ define([ var shjson2 = JSON.stringify(Convert.core.hyperjson.fromDOM(inner)); if (shjson2 !== shjson) { - rti.propogate(shjson2); + rti.patchText(shjson2); } }; @@ -220,8 +220,8 @@ define([ var onAbort = function (info) { console.log("Aborting the session!"); // stop the user from continuing to edit + // by setting the editable to false setEditable(false); - // TODO inform them that the session was torn down toolbar.failed(); }; @@ -246,7 +246,6 @@ define([ // reject patch if it results in invalid JSON transformFunction : JsonOT.validate, - // websocketURL, ofc websocketURL: Config.websocketURL, // username @@ -259,15 +258,16 @@ define([ cryptKey: key.cryptKey }; - var rti = module.realtimeInput = window.rti = realtimeInput.start(realtimeOptions); + var rti = module.realtimeInput = realtimeInput.start(realtimeOptions); + // FIXME Spaghetti code. realtime-input needs access to this variable.. var propogate = window.cryptpad_propogate = function () { var shjson = JSON.stringify(Convert.core.hyperjson.fromDOM(inner, isNotMagicLine)); - if (!rti.propogate(shjson)) { return; } + if (!rti.patchText(shjson)) { return; } rti.onEvent(shjson); }; - var testInput = window.testInput = function (el, offset) { + var testInput = function (el, offset) { var i = 0, j = offset, input = "The quick red fox jumps over the lazy brown dog. ", diff --git a/www/_socket/realtime-input.js b/www/_socket/realtime-input.js index 289f3d348..926fc2e1d 100644 --- a/www/_socket/realtime-input.js +++ b/www/_socket/realtime-input.js @@ -19,10 +19,10 @@ define([ '/bower_components/reconnectingWebsocket/reconnecting-websocket.js', '/common/crypto.js', '/_socket/toolbar.js', - '/_socket/sharejs_textarea-transport-only.js', + '/_socket/text-patcher.js', '/common/chainpad.js', '/bower_components/jquery/dist/jquery.min.js', -], function (Messages,/*FIXME*/ ReconnectingWebSocket, Crypto, Toolbar, sharejs) { +], function (Messages,/*FIXME*/ ReconnectingWebSocket, Crypto, Toolbar, TextPatcher) { var $ = window.jQuery; var ChainPad = window.ChainPad; var PARANOIA = true; @@ -326,8 +326,7 @@ define([ // TODO maybe push this out to the application layer. //bindAllEvents(null, doc, onEvent, false); - // TODO rename 'sharejs.attach' to imply what we want to do - var genOp = toReturn.propogate = sharejs.attach({ + toReturn.patchText = TextPatcher.create({ realtime: realtime }); diff --git a/www/_socket/sharejs_textarea-transport-only.js b/www/_socket/text-patcher.js similarity index 96% rename from www/_socket/sharejs_textarea-transport-only.js rename to www/_socket/text-patcher.js index 3e2ba7fc8..bcbadb2e9 100644 --- a/www/_socket/sharejs_textarea-transport-only.js +++ b/www/_socket/text-patcher.js @@ -7,9 +7,6 @@ define(function () { it performs a diff on the two values, and generates patches which are then passed into `ctx.remove` and `ctx.insert` - - - */ var applyChange = function(ctx, oldval, newval) { // Strings are immutable and have reference equality. I think this test is O(1), so its worth doing. @@ -39,7 +36,7 @@ var applyChange = function(ctx, oldval, newval) { } }; -var attachTextarea = function(config) { +var create = function(config) { var ctx = config.realtime; // initial state will always fail the !== check in genop. @@ -70,5 +67,5 @@ var attachTextarea = function(config) { }; }; -return { attach: attachTextarea }; +return { create: create }; });