cryptpad/www/pad/main.js

41 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-10-31 16:42:58 +01:00
define([
2015-01-29 17:55:18 +01:00
'/api/config?cb=' + Math.random().toString(16).substring(2),
'/pad/realtime-wysiwyg.js',
'/common/messages.js',
'/common/crypto.js',
2015-01-29 17:55:18 +01:00
'/bower_components/jquery/dist/jquery.min.js',
'/bower_components/ckeditor/ckeditor.js',
], function (Config, RTWysiwyg, Messages, Crypto) {
2014-10-31 16:42:58 +01:00
var Ckeditor = window.CKEDITOR;
var $ = window.jQuery;
2014-10-31 16:42:58 +01:00
$(function () {
$(window).on('hashchange', function() {
window.location.reload();
});
2015-01-28 17:58:55 +01:00
if (window.location.href.indexOf('#') === -1) {
window.location.href = window.location.href + '#' + Crypto.genKey();
2015-01-28 17:58:55 +01:00
return;
}
var key = Crypto.parseKey(window.location.hash.substring(1));
2014-10-31 16:42:58 +01:00
var editor = Ckeditor.replace('editor1', {
removeButtons: 'Source,Maximize',
// This plugin inserts html crap into the document which is not part of the document
// itself and causes problems when it's sent across the wire and reflected back.
2014-11-04 10:53:49 +01:00
removePlugins: 'magicline'
2014-10-31 16:42:58 +01:00
});
editor.on('instanceReady', function () {
2014-10-31 17:05:09 +01:00
editor.execCommand('maximize');
2014-10-31 16:42:58 +01:00
var ifr = window.ifr = $('iframe')[0];
ifr.contentDocument.body.innerHTML = Messages.initialState;
2014-10-31 16:42:58 +01:00
var rtw =
RTWysiwyg.start(Config.websocketURL,
Crypto.rand64(8),
key.channel,
2014-10-31 16:42:58 +01:00
key.cryptKey);
editor.on('change', function () { rtw.onEvent(); });
});
});
});