markdown-live-preview/public/js/main.js
Hideaki Tanabe 0ddec7c937 Fix #16
2020-08-10 22:32:13 +09:00

38 lines
764 B
JavaScript

$(function() {
var currentMode = 'edit';
var scrollTops = {
'edit' : 0,
'preview' : 0
};
var isEdited = false;
let convert = () => {
let html = marked($('#markdown').val());
$('#output').html(html);
}
$('#markdown').bind('keyup', function() {
isEdited = true;
convert();
$('#output a').each(function(index, element) {
var href = element.getAttribute('href');
if (RegExp('^javascript', 'i').test(href)) {
element.setAttribute('href', '#');
}
});
});
//autoresize
$('textarea').autosize();
//leave
$(window).bind('beforeunload', function() {
if (isEdited) {
return 'Are you sure you want to leave? Your changes will be lost.';
}
});
convert();
});