diff --git a/www/canvas/main.js b/www/canvas/main.js
index 1a52213ff..212f12bfe 100644
--- a/www/canvas/main.js
+++ b/www/canvas/main.js
@@ -67,6 +67,7 @@ define([
userName: Crypto.rand64(8),
channel: channel,
cryptKey: key,
+ crypto: Crypto,
};
var onInit = config.onInit = function (info) {
diff --git a/www/hack/main.js b/www/hack/main.js
index 8830b9007..fe71ac64d 100644
--- a/www/hack/main.js
+++ b/www/hack/main.js
@@ -6,10 +6,6 @@ define([
'/bower_components/jquery/dist/jquery.min.js'
], function (Config, Realtime, Crypto, TextPatcher) {
var $ = window.jQuery;
- /*
- $(window).on('hashchange', function() {
- window.location.reload();
- });*/
var key;
var channel = '';
@@ -44,6 +40,7 @@ define([
userName: userName,
channel: channel,
cryptKey: key,
+ crypto: Crypto,
};
var initializing = true;
@@ -54,6 +51,7 @@ define([
var onInit = config.onInit = function (info) {
window.location.hash = info.channel + key;
+ $(window).on('hashchange', function() { window.location.reload(); });
};
var onRemote = config.onRemote = function (info) {
diff --git a/www/p/main.js b/www/p/main.js
index 023f9b9f1..64eda9f70 100644
--- a/www/p/main.js
+++ b/www/p/main.js
@@ -194,9 +194,6 @@ define([
var now = function () { return new Date().getTime(); };
var realtimeOptions = {
- // configuration :D
- doc: inner,
-
// provide initialstate...
initialState: stringifyDOM(inner) || '{}',
@@ -213,7 +210,9 @@ define([
channel: key.channel,
// encryption key
- cryptKey: key.cryptKey
+ cryptKey: key.cryptKey,
+
+ crypto: Crypto,
};
var DD = new DiffDom(diffOptions);
diff --git a/www/padrtc/main.js b/www/padrtc/main.js
index ba983e799..233241a86 100644
--- a/www/padrtc/main.js
+++ b/www/padrtc/main.js
@@ -206,14 +206,12 @@ define([
// our encryption key
cryptKey: key,
- // configuration :D
- doc: inner,
-
setMyID: setMyID,
// really basic operational transform
- transformFunction : JsonOT.validate
- // pass in websocket/netflux object TODO
+ transformFunction : JsonOT.validate,
+
+ crypto: Crypto,
};
var onRemote = realtimeOptions.onRemote = function (info) {
diff --git a/www/style/index.html b/www/style/index.html
index e9fdf2855..4ede5c688 100644
--- a/www/style/index.html
+++ b/www/style/index.html
@@ -8,7 +8,6 @@
Edit this document's style
-
HTML Ipsum Presents
diff --git a/www/style/main.js b/www/style/main.js
index b230bbb3f..7fe78cc34 100644
--- a/www/style/main.js
+++ b/www/style/main.js
@@ -1,31 +1,34 @@
define([
'/api/config?cb=' + Math.random().toString(16).substring(2),
'/common/realtime-input.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) {
+], function (Config, Realtime, Crypto, TextPatcher) {
// TODO consider adding support for less.js
var $ = window.jQuery;
- $(window).on('hashchange', function() {
- window.location.reload();
- });
- var userName = Crypto.rand64(8);
+ var module = window.APP = {};
- if (window.location.href.indexOf('#') === -1) {
- window.location.href = window.location.href + '#' + Crypto.genKey();
- return;
+ var key;
+ var channel = '';
+ if (!/#/.test(window.location.href)) {
+ key = Crypto.genKey();
+ } else {
+ var hash = window.location.hash.slice(1);
+ channel = hash.slice(0, 32);
+ key = hash.slice(32);
}
- var key = Crypto.parseKey(window.location.hash.slice(1));
-
- var $style = $('style').first(),
- $css = $('#css'),
- $edit = $('#edit');
+ var config = {
+ websocketURL: Config.websocketURL,
+ channel: channel,
+ cryptKey: key,
+ crypto: Crypto,
+ };
- $edit.attr('href', '/text/'+ window.location.hash);
+ var userName = module.userName = config.userName = Crypto.rand64(8);
var lazyDraw = (function () {
var to,
@@ -38,29 +41,47 @@ define([
};
}());
- var draw = function () {
- lazyDraw($css.val());
+ var draw = function (content) { lazyDraw(content); };
+
+ var initializing = true;
+
+ var onInit = config.onInit = function (info) {
+ window.location.hash = info.channel + key;
+ var realtime = module.realtime = info.realtime;
+ module.patchText = TextPatcher.create({
+ realtime: realtime,
+ logging: true,
+ });
+
+ $(window).on('hashchange', function() {
+ window.location.reload();
+ });
+ };
+
+ var onReady = config.onReady = function (info) {
+ var userDoc = module.realtime.getUserDoc();
+ draw(userDoc);
+ console.log("Ready");
+ initializing = false;
};
- $css // set the initial value
- .val($style.text())
- .on('change', draw);
+ var onRemote = config.onRemote = function () {
+ draw(module.realtime.getUserDoc());
+ };
- var rts = $('textarea').toArray().map(function (e, i) {
+ var onAbort = config.onAbort = function (info) {
+ // notify the user of the abort
+ window.alert("Network Connection Lost");
+ };
- var config = {
- onRemote: draw,
- onInit: draw,
- onReady: draw,
+ var onLocal = config.onLocal = function () {
+ // nope
+ };
- textarea: e,
- websocketURL: Config.websocketURL,
- userName: userName,
- channel: key.channel,
- cryptKey: key.cryptKey
- };
+ var $style = $('style').first(),
+ $edit = $('#edit');
+
+ $edit.attr('href', '/text/'+ window.location.hash);
- var rt = Realtime.start(config);
- return rt;
- });
+ var rt = Realtime.start(config);
});
diff --git a/www/text/main.js b/www/text/main.js
index 644fa86f6..2b91c446d 100644
--- a/www/text/main.js
+++ b/www/text/main.js
@@ -1,22 +1,12 @@
define([
'/api/config?cb=' + Math.random().toString(16).substring(2),
'/common/realtime-input.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) {
+], function (Config, Realtime, 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 key;
var channel = '';
@@ -42,6 +32,7 @@ define([
userName: userName,
channel: channel,
cryptKey: key,
+ crypto: Crypto,
};
var setEditable = function (bool) { $textarea.attr('disabled', !bool); };
@@ -51,6 +42,9 @@ define([
var onInit = config.onInit = function (info) {
window.location.hash = info.channel + key;
+ $(window).on('hashchange', function() {
+ window.location.reload();
+ });
};
var onRemote = config.onRemote = function (info) {