From 1c54af69a1f189951edd85068ea5fcb12e9ffca8 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 7 Mar 2016 11:52:18 +0100 Subject: [PATCH] update minor editors to use new realtime-input api --- www/hack/main.js | 15 ++++++++------- www/input/main.js | 17 ++++++++++------- www/multitest/main.js | 14 +++++++++----- www/render/main.js | 37 ++++++++++++++++++++----------------- www/style/main.js | 24 ++++++++++++++---------- www/text/main.js | 14 +++++++------- 6 files changed, 68 insertions(+), 53 deletions(-) diff --git a/www/hack/main.js b/www/hack/main.js index dcb80b3b5..ab38f8402 100644 --- a/www/hack/main.js +++ b/www/hack/main.js @@ -28,7 +28,13 @@ define([ transformFunction */ - var config = {}; + var config = { + textarea: $textarea[0], + websocketURL: Config.websocketURL, + userName: Crypto.rand64(8), + channel: key.channel, + cryptKey: key.cryptKey, + }; var initializing = true; $textarea.attr('disabled', true); @@ -51,12 +57,7 @@ define([ window.alert("Server Connection Lost"); }; - var rt = Realtime.start($textarea[0], // window - Config.websocketURL, // websocketUrl - Crypto.rand64(8), // userName - key.channel, // channel - key.cryptKey, - config); // cryptKey + var rt = Realtime.start(config); $run.click(function (e) { e.preventDefault(); diff --git a/www/input/main.js b/www/input/main.js index a50a657ed..9be43e973 100644 --- a/www/input/main.js +++ b/www/input/main.js @@ -11,7 +11,7 @@ define([ Crypto) { var $ = window.jQuery; - + var $textarea = $('input'); $(window).on('hashchange', function() { @@ -28,10 +28,13 @@ define([ var key = Crypto.parseKey(window.location.hash.substring(1)); - var rttext = - RTText.start( $textarea[0], // window - Config.websocketURL, // websocketUrl - Crypto.rand64(8), // userName - key.channel, // channel - key.cryptKey); // cryptKey + var config = { + textarea: $textarea[0], + websocketURL: Config.websocketURL, + userName: Crypto.rand64(8), + channel: key.channel, + key.cryptKey + }; + + var rttext = RTText.start(config); }); diff --git a/www/multitest/main.js b/www/multitest/main.js index d6fa8075d..30d36508c 100644 --- a/www/multitest/main.js +++ b/www/multitest/main.js @@ -18,11 +18,15 @@ define([ var key = Crypto.parseKey(window.location.hash.substring(1)); var rts = $('textarea').toArray().map(function (e, i) { - var rt = Realtime.start(e, // window - Config.websocketURL, // websocketUrl - Crypto.rand64(8), // userName - key.channel, // channel - key.cryptKey); // cryptKey + var config = { + textarea: e, + websocketURL: Config.websocketURL, + userName: Crypto.rand64(8), + channel: key.channel, + cryptKey: key.cryptKey + }; + + var rt = Realtime.start(config); return rt; }); }); diff --git a/www/render/main.js b/www/render/main.js index 1237b05db..a3eaaa45c 100644 --- a/www/render/main.js +++ b/www/render/main.js @@ -83,23 +83,26 @@ define([ }, 450); }; - var rts = Realtime.start($textarea[0], // window - Config.websocketURL, // websocketUrl - Crypto.rand64(8), // userName - key.channel, // channel - key.cryptKey, // cryptkey - { - // when remote editors do things... - onRemote: function () { - lazyDraw($textarea.val()); - }, - // when your editor is ready - onReady: function (info) { - if (info.userList) { console.log("Userlist: [%s]", info.userList.join(',')); } - console.log("Realtime is ready!"); - $textarea.trigger('keyup'); - } - }); + var config = { + textarea: $textarea[0], + websocketURL: Config.websocketURL, + userName: Crypto.rand64(8), + channel: key.channel, + cryptKey: key.cryptKey, + + // when remote editors do things... + onRemote: function () { + lazyDraw($textarea.val()); + }, + // when your editor is ready + onReady: function (info) { + if (info.userList) { console.log("Userlist: [%s]", info.userList.join(',')); } + console.log("Realtime is ready!"); + $textarea.trigger('keyup'); + } + }; + + var rts = Realtime.start(config); $textarea.on('change keyup keydown', function () { if (redrawTimeout) { clearTimeout(redrawTimeout); } diff --git a/www/style/main.js b/www/style/main.js index 6bc6e95f3..b230bbb3f 100644 --- a/www/style/main.js +++ b/www/style/main.js @@ -47,16 +47,20 @@ define([ .on('change', draw); var rts = $('textarea').toArray().map(function (e, i) { - var rt = Realtime.start(e, // window - Config.websocketURL, // websocketUrl - userName, // userName - key.channel, // channel - key.cryptKey, // cryptKey - { - onRemote: draw, - onInit: draw, - onReady: draw - }); + + var config = { + onRemote: draw, + onInit: draw, + onReady: draw, + + textarea: e, + websocketURL: Config.websocketURL, + userName: userName, + channel: key.channel, + cryptKey: key.cryptKey + }; + + var rt = Realtime.start(config); return rt; }); }); diff --git a/www/text/main.js b/www/text/main.js index 9b8886e86..4c84064c7 100644 --- a/www/text/main.js +++ b/www/text/main.js @@ -19,7 +19,12 @@ define([ var initializing = true; var $textarea = $('textarea'); - var config = {}; + var config = { + websocketURL: Config.websocketURL, + userName: Crypto.rand64(8), + channel: key.channel, + cryptKey: key.cryptKey + }; var onInit = config.onInit = function (info) { }; @@ -38,10 +43,5 @@ define([ window.alert("Server Connection Lost"); }; - var rt = Realtime.start($textarea[0], // window - Config.websocketURL, // websocketUrl - Crypto.rand64(8), // userName - key.channel, // channel - key.cryptKey, - config); // cryptKey + var rt = Realtime.start(config); });