|
|
@ -1,31 +1,34 @@
|
|
|
|
define([
|
|
|
|
define([
|
|
|
|
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
|
|
|
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
|
|
|
'/common/realtime-input.js',
|
|
|
|
'/common/realtime-input.js',
|
|
|
|
'/common/messages.js',
|
|
|
|
|
|
|
|
'/common/crypto.js',
|
|
|
|
'/common/crypto.js',
|
|
|
|
|
|
|
|
'/common/TextPatcher.js',
|
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
|
|
|
'/customize/pad.js'
|
|
|
|
'/customize/pad.js'
|
|
|
|
], function (Config, Realtime, Messages, Crypto) {
|
|
|
|
], function (Config, Realtime, Crypto, TextPatcher) {
|
|
|
|
// TODO consider adding support for less.js
|
|
|
|
// TODO consider adding support for less.js
|
|
|
|
var $ = window.jQuery;
|
|
|
|
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) {
|
|
|
|
var key;
|
|
|
|
window.location.href = window.location.href + '#' + Crypto.genKey();
|
|
|
|
var channel = '';
|
|
|
|
return;
|
|
|
|
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 config = {
|
|
|
|
|
|
|
|
websocketURL: Config.websocketURL,
|
|
|
|
var $style = $('style').first(),
|
|
|
|
channel: channel,
|
|
|
|
$css = $('#css'),
|
|
|
|
cryptKey: key,
|
|
|
|
$edit = $('#edit');
|
|
|
|
crypto: Crypto,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$edit.attr('href', '/text/'+ window.location.hash);
|
|
|
|
var userName = module.userName = config.userName = Crypto.rand64(8);
|
|
|
|
|
|
|
|
|
|
|
|
var lazyDraw = (function () {
|
|
|
|
var lazyDraw = (function () {
|
|
|
|
var to,
|
|
|
|
var to,
|
|
|
@ -38,29 +41,47 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
|
|
var draw = function () {
|
|
|
|
var draw = function (content) { lazyDraw(content); };
|
|
|
|
lazyDraw($css.val());
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
var onRemote = config.onRemote = function () {
|
|
|
|
.val($style.text())
|
|
|
|
draw(module.realtime.getUserDoc());
|
|
|
|
.on('change', draw);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
var onLocal = config.onLocal = function () {
|
|
|
|
onRemote: draw,
|
|
|
|
// nope
|
|
|
|
onInit: draw,
|
|
|
|
};
|
|
|
|
onReady: draw,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textarea: e,
|
|
|
|
var $style = $('style').first(),
|
|
|
|
websocketURL: Config.websocketURL,
|
|
|
|
$edit = $('#edit');
|
|
|
|
userName: userName,
|
|
|
|
|
|
|
|
channel: key.channel,
|
|
|
|
$edit.attr('href', '/text/'+ window.location.hash);
|
|
|
|
cryptKey: key.cryptKey
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rt = Realtime.start(config);
|
|
|
|
var rt = Realtime.start(config);
|
|
|
|
return rt;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|