From a527024a8c4efe4e32d42c85d97cbc8ad786a287 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 21 Apr 2016 15:51:04 +0200 Subject: [PATCH] start on realtime form prototype --- www/form/index.html | 46 ++++++++++++++++++++++++++ www/form/main.js | 80 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 www/form/index.html create mode 100644 www/form/main.js diff --git a/www/form/index.html b/www/form/index.html new file mode 100644 index 000000000..aa5a39fc6 --- /dev/null +++ b/www/form/index.html @@ -0,0 +1,46 @@ + + + + + + + + + + +
+
+
+ + One
+ Two
+ Three
+ + Checkbox One
+ Checkbox Two
+ + Number
+ + Ranges
+ + Dropdowns
+ +
+ +
+ + + + diff --git a/www/form/main.js b/www/form/main.js new file mode 100644 index 000000000..ce756275e --- /dev/null +++ b/www/form/main.js @@ -0,0 +1,80 @@ +define([ + '/api/config?cb=' + Math.random().toString(16).substring(2), + '/common/RealtimeTextarea.js', + '/common/messages.js', + '/common/crypto.js', + '/common/TextPatcher.js', + '/bower_components/jquery/dist/jquery.min.js', + '/customize/pad.js' +], function (Config, Realtime, Messages, Crypto, TextPatcher) { + var $ = window.jQuery; + $(window).on('hashchange', function() { + window.location.reload(); + }); + if (window.location.href.indexOf('#') === -1) { + window.location.href = window.location.href + '#' + Crypto.genKey(); + return; + } + + var module = window.APP = {}; + var key = Crypto.parseKey(window.location.hash.substring(1)); + var initializing = true; + + /* elements that we need to listen to */ + /* + * text + * password + * radio + * checkbox + * number + * range + * select + * textarea + */ + + var $textarea = $('textarea'); + + var config = module.config = { + websocketURL: Config.websocketURL + '_old', + userName: Crypto.rand64(8), + channel: key.channel, + cryptKey: key.cryptKey + }; + + var setEditable = function (bool) {/* allow editing */}; + var canonicalize = function (text) {/* canonicalize all the things */}; + + setEditable(false); + + var onInit = config.onInit = function (info) { }; + + var onRemote = config.onRemote = function (info) { + if (initializing) { return; } + /* integrate remote changes */ + }; + + var onLocal = config.onLocal = function () { + if (initializing) { return; } + /* serialize local changes */ + }; + + var onReady = config.onReady = function (info) { + var realtime = module.realtime = info.realtime; + + // create your patcher + module.patchText = TextPatcher.create({ + realtime: realtime + }); + + // get ready + + setEditable(true); + initializing = false; + }; + + var onAbort = config.onAbort = function (info) {}; + + var rt = Realtime.start(config); + + // bind to events... +});