cryptpad/www/examples/board/main.js

94 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-09-01 14:23:40 +00:00
define([
'jquery',
'/api/config',
2016-09-01 14:23:40 +00:00
'/customize/messages.js',
'board.js',
2016-09-01 14:23:40 +00:00
'/bower_components/textpatcher/TextPatcher.js',
'/bower_components/chainpad-listmap/chainpad-listmap.js',
'/bower_components/chainpad-crypto/crypto.js',
'/common/cryptpad-common.js',
2017-05-04 14:16:09 +00:00
//'/common/visible.js',
//'/common/notify.js',
'/bower_components/file-saver/FileSaver.min.js'
2017-05-04 14:16:09 +00:00
], function ($, Config, Messages, Board, TextPatcher, Listmap, Crypto, Cryptpad /*, Visible, Notify*/) {
2017-05-04 14:16:09 +00:00
// var saveAs = window.saveAs;
2016-09-01 14:23:40 +00:00
Cryptpad.styleAlerts();
console.log("Initializing your realtime session...");
var secret = Cryptpad.getSecrets();
var module = window.APP = {
Board: Board,
};
2017-05-04 14:16:09 +00:00
/*
2016-09-01 14:23:40 +00:00
var unnotify = function () {
if (!(module.tabNotification &&
typeof(module.tabNotification.cancel) === 'function')) { return; }
module.tabNotification.cancel();
};
var notify = function () {
if (!(Visible.isSupported() && !Visible.currently())) { return; }
unnotify();
module.tabNotification = Notify.tab(1000, 10);
2016-09-01 14:23:40 +00:00
};
2017-05-04 14:16:09 +00:00
*/
2016-09-01 14:23:40 +00:00
var setEditable = function (bool) {
2017-05-04 14:16:09 +00:00
bool = bool;
2016-09-01 14:23:40 +00:00
};
setEditable(false);
var $lists = $('#lists');
2017-05-04 14:16:09 +00:00
$('#create-list').click(function () {
2016-09-01 14:23:40 +00:00
Board.List.draw($lists);
});
var firstUser = function () {
Cryptpad.log("You are the first user to visit this board");
};
2017-05-04 14:16:09 +00:00
var whenReady = function () {
2016-09-01 14:23:40 +00:00
var rt = module.rt;
var proxy = rt.proxy;
var first = Board.initialize(proxy);
//var board = module.board = Board.create(proxy);
Board.Draw($lists);
if (first) { firstUser(); }
};
var config = {
websocketURL: Config.websocketURL,
channel: secret.channel,
data: {},
crypto: Crypto.createEncryptor(secret.key),
};
Cryptpad.ready(function () {
var rt = module.rt = Listmap.create(config);
var proxy = rt.proxy;
proxy
.on('create', function (info) {
2017-05-04 14:16:09 +00:00
module.realtime = info.realtime;
2016-09-01 14:23:40 +00:00
window.location.hash = info.channel + secret.key;
})
2017-05-04 14:16:09 +00:00
.on('ready', function () {
2016-09-01 14:23:40 +00:00
Cryptpad.log("Ready!");
whenReady({
});
})
.on('disconnect', function () {
Cryptpad.warn("Disconnected!");
});
});
});