You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.2 KiB
JavaScript
79 lines
2.2 KiB
JavaScript
9 years ago
|
define([
|
||
|
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
||
9 years ago
|
'/bower_components/chainpad-netflux/chainpad-netflux.js',
|
||
|
'/bower_components/chainpad-crypto/crypto.js',
|
||
9 years ago
|
'/bower_components/textpatcher/TextPatcher.amd.js',
|
||
9 years ago
|
'/common/cryptpad-common.js',
|
||
9 years ago
|
'/bower_components/jquery/dist/jquery.min.js',
|
||
9 years ago
|
], function (Config, Realtime, Crypto, TextPatcher, Cryptpad) {
|
||
9 years ago
|
// TODO consider adding support for less.js
|
||
9 years ago
|
var $ = window.jQuery;
|
||
9 years ago
|
|
||
9 years ago
|
var $style = $('style').first(),
|
||
|
$edit = $('#edit');
|
||
|
|
||
9 years ago
|
var module = window.APP = {};
|
||
9 years ago
|
|
||
9 years ago
|
var secret = Cryptpad.getSecrets();
|
||
9 years ago
|
var config = {
|
||
|
websocketURL: Config.websocketURL,
|
||
9 years ago
|
channel: secret.channel,
|
||
|
crypto: Crypto.createEncryptor(secret.key),
|
||
9 years ago
|
};
|
||
9 years ago
|
|
||
9 years ago
|
var userName = module.userName = config.userName = Crypto.rand64(8);
|
||
9 years ago
|
|
||
|
var lazyDraw = (function () {
|
||
|
var to,
|
||
|
delay = 500;
|
||
|
return function (content) {
|
||
9 years ago
|
if (to) { clearTimeout(to); }
|
||
9 years ago
|
to = setTimeout(function () {
|
||
|
$style.text(content);
|
||
|
},delay);
|
||
|
};
|
||
|
}());
|
||
|
|
||
9 years ago
|
var draw = function (content) { lazyDraw(content); };
|
||
|
|
||
|
var initializing = true;
|
||
|
|
||
|
var onInit = config.onInit = function (info) {
|
||
9 years ago
|
window.location.hash = info.channel + secret.key;
|
||
9 years ago
|
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;
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
var onRemote = config.onRemote = function () {
|
||
|
draw(module.realtime.getUserDoc());
|
||
|
};
|
||
9 years ago
|
|
||
9 years ago
|
var onAbort = config.onAbort = function (info) {
|
||
|
// notify the user of the abort
|
||
|
window.alert("Network Connection Lost");
|
||
|
};
|
||
9 years ago
|
|
||
9 years ago
|
var onLocal = config.onLocal = function () {
|
||
|
// nope
|
||
|
};
|
||
9 years ago
|
|
||
9 years ago
|
|
||
8 years ago
|
$edit.attr('href', '/examples/text/'+ window.location.hash);
|
||
9 years ago
|
|
||
9 years ago
|
var rt = Realtime.start(config);
|
||
9 years ago
|
});
|