2011-05-16 20:26:21 +04:00
|
|
|
$(function() {
|
2020-10-26 18:35:34 +03:00
|
|
|
let isEdited = false;
|
|
|
|
|
|
|
|
let adjustScreen = () => {
|
|
|
|
let screenHeight = $(window).height();
|
|
|
|
let headerHeight = $('#header').outerHeight();
|
|
|
|
let containerHeight = screenHeight - headerHeight;
|
|
|
|
console.log(containerHeight);
|
|
|
|
$('#container').css({ top: `${headerHeight}px` });
|
|
|
|
$('#container').css({ height: `${containerHeight}px`});
|
|
|
|
$('.column').css({ height: `${containerHeight}px`});
|
|
|
|
};
|
|
|
|
|
|
|
|
$(window).resize(() => {
|
|
|
|
adjustScreen();
|
|
|
|
});
|
2013-02-17 04:27:39 +04:00
|
|
|
|
2020-10-23 18:24:28 +03:00
|
|
|
// Setup editor
|
2020-10-26 18:35:34 +03:00
|
|
|
let editor = ace.edit('editor');
|
2020-10-23 18:24:28 +03:00
|
|
|
editor.getSession().setUseWrapMode(true);
|
|
|
|
editor.setOptions({
|
|
|
|
maxLines: Infinity,
|
|
|
|
indentedSoftWrap: false,
|
|
|
|
fontSize: 14,
|
2020-10-26 18:35:34 +03:00
|
|
|
autoScrollEditorIntoView: true,
|
2020-10-23 18:24:28 +03:00
|
|
|
theme: 'ace/theme/github',
|
|
|
|
// TODO consider some options
|
|
|
|
});
|
2020-08-10 16:32:13 +03:00
|
|
|
|
2020-10-23 18:24:28 +03:00
|
|
|
editor.on('change', () => {
|
|
|
|
isEdited = true;
|
|
|
|
convert();
|
2020-10-26 18:35:34 +03:00
|
|
|
adjustScreen();
|
2019-02-16 17:50:49 +03:00
|
|
|
});
|
2013-02-17 04:27:39 +04:00
|
|
|
|
2020-10-23 18:24:28 +03:00
|
|
|
let convert = () => {
|
|
|
|
let html = marked(editor.getValue());
|
|
|
|
let sanitized = DOMPurify.sanitize(html);
|
|
|
|
$('#output').html(sanitized);
|
2013-02-17 04:27:39 +04:00
|
|
|
}
|
2020-10-23 18:24:28 +03:00
|
|
|
|
|
|
|
//leave
|
|
|
|
$(window).bind('beforeunload', function() {
|
|
|
|
if (isEdited) {
|
|
|
|
return 'Are you sure you want to leave? Your changes will be lost.';
|
|
|
|
}
|
|
|
|
});
|
2020-07-17 19:31:22 +03:00
|
|
|
|
2020-10-23 18:24:28 +03:00
|
|
|
convert();
|
2020-10-26 18:35:34 +03:00
|
|
|
adjustScreen();
|
2020-08-14 16:35:54 +03:00
|
|
|
});
|