2011-05-16 20:26:21 +04:00
|
|
|
$(function() {
|
2013-02-17 04:27:39 +04:00
|
|
|
var currentMode = 'edit';
|
|
|
|
var scrollTops = {
|
|
|
|
'edit' : 0,
|
|
|
|
'preview' : 0
|
|
|
|
};
|
|
|
|
|
|
|
|
var isEdited = false;
|
|
|
|
|
2020-07-17 19:31:22 +03:00
|
|
|
//$('#markdown').val(example);
|
2013-02-17 04:27:39 +04:00
|
|
|
$('#markdown').bind('keyup', function() {
|
|
|
|
isEdited = true;
|
|
|
|
$('#output').html(markdown.toHTML($('#markdown').val()));
|
2019-02-16 17:50:49 +03:00
|
|
|
$('#output a').each(function(index, element) {
|
|
|
|
var href = element.getAttribute('href');
|
|
|
|
if (RegExp('^javascript', 'i').test(href)) {
|
|
|
|
element.setAttribute('href', '#');
|
|
|
|
}
|
|
|
|
});
|
2013-02-17 04:27:39 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
//menu
|
|
|
|
var menuItems = $('#menu a');
|
|
|
|
menuItems.click(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
menuItems.removeClass('active');
|
|
|
|
var sender = $(event.currentTarget);
|
|
|
|
sender.addClass('active');
|
|
|
|
|
|
|
|
$('#content .mode').hide();
|
|
|
|
var menuId = sender.data('menuId');
|
|
|
|
currentMode = menuId;
|
|
|
|
$('#' + menuId).show();
|
|
|
|
$(window).scrollTop(scrollTops[currentMode]);
|
|
|
|
|
2011-05-16 20:26:21 +04:00
|
|
|
});
|
2011-05-18 19:10:58 +04:00
|
|
|
|
|
|
|
//reference
|
|
|
|
$("table#reference tr td:odd").each(function(index, element) {
|
|
|
|
var self = $(element);
|
|
|
|
if (self.html() === "") {
|
|
|
|
self.html(markdown.toHTML(self.siblings().html()));
|
|
|
|
}
|
|
|
|
});
|
2013-02-17 04:27:39 +04:00
|
|
|
|
|
|
|
//clear
|
|
|
|
$('#clearButton').click(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
if (window.confirm('Are you sure you want to delete?')) {
|
|
|
|
$('#markdown').val('');
|
2015-01-13 17:08:17 +03:00
|
|
|
$('#output').html('');
|
2013-02-17 04:27:39 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//autoresize
|
|
|
|
$('textarea').autosize();
|
2013-02-17 09:43:20 +04:00
|
|
|
|
2013-02-17 04:27:39 +04: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
|
|
|
|
|
|
|
$('#output').html(markdown.toHTML($('#markdown').val()));
|
2011-05-16 20:26:21 +04:00
|
|
|
});
|