cryptpad/www/pad/main.js

44 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-10-31 15:42:58 +00:00
define([
2015-01-29 16:55:18 +00:00
'/api/config?cb=' + Math.random().toString(16).substring(2),
'/pad/realtime-wysiwyg.js',
'/common/messages.js',
'/common/crypto.js',
2015-01-29 16:55:18 +00:00
'/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js'
], function (Config, RTWysiwyg, Messages, Crypto) {
var $ = window.jQuery;
var ifrw = $('#pad-iframe')[0].contentWindow;
var Ckeditor = ifrw.CKEDITOR;
2014-10-31 15:42:58 +00:00
$(function () {
$(window).on('hashchange', function() {
window.location.reload();
});
2015-01-28 16:58:55 +00:00
if (window.location.href.indexOf('#') === -1) {
window.location.href = window.location.href + '#' + Crypto.genKey();
2015-01-28 16:58:55 +00:00
return;
}
var key = Crypto.parseKey(window.location.hash.substring(1));
2014-10-31 15:42:58 +00:00
var editor = Ckeditor.replace('editor1', {
removeButtons: 'Source,Maximize',
// magicline 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
removePlugins: 'magicline,resize'
2014-10-31 15:42:58 +00:00
});
editor.on('instanceReady', function () {
2014-10-31 16:05:09 +00:00
editor.execCommand('maximize');
// (contenteditable) iframe in an iframe
ifrw.$('iframe')[0].contentDocument.body.innerHTML = Messages.initialState;
2014-10-31 15:42:58 +00:00
var rtw =
RTWysiwyg.start(ifrw,
Config.websocketURL,
Crypto.rand64(8),
key.channel,
2014-10-31 15:42:58 +00:00
key.cryptKey);
editor.on('change', function () { rtw.onEvent(); });
});
});
});