Add markdown preview; fix bug with deleted editor

This commit is contained in:
jomo
2014-05-11 06:43:56 +02:00
parent df030f4d2d
commit 19eb868a50
19 changed files with 135 additions and 39 deletions
+1
View File
@@ -40,6 +40,7 @@ $(function(){
$(this).parent().attr("lang", "(language unknown)");
}
});
updateTimestamps();
setInterval(updateTimestamps, 1000*10);
});
+2 -1
View File
@@ -12,5 +12,6 @@
//= require jquery
//= require jquery_ujs
//= require app
//= require editor
//= require ago
//= require highlight
//= require highlight
+55
View File
@@ -0,0 +1,55 @@
$(function() {
$('.md_editor .field_container .preview-button').click(function() {
if ($(this).data('preview') == 'true') {
edit($(this));
} else {
preview($(this));
}
});
function edit(target) {
target.data('preview', 'false');
target.text('Preview');
target.parent().find('.preview').hide();
target.parent().find('.editor_field').show();
}
function preview(target) {
target.data('preview', 'true');
target.text('Edit');
var prev = target.parent().find('.preview');
var editor = target.parent().find('.editor_field')
prev.html("<i>(Loading ...)</i>");
prev.show();
editor.hide()
if (target.parent().parent().hasClass('mini')) {
var url = '/tools/render_mini_markdown';
} else {
var url = '/tools/render_markdown';
}
$.ajax(url, {
type: 'post',
data: {text: editor.val()},
dataType: 'html',
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
success: function(data) {
prev.html(data);
prev.find('pre code').each(function(i, e) {
if ($(this).attr("class")) {
$(this).parent().attr("lang", $(this).attr("class").replace("hljs", "").trim());
} else {
$(this).parent().attr("lang", "(language unknown)");
}
hljs.highlightBlock(e);
});
},
error: function(xhr, status, err) {
prev.html('<i>(Error: ' + status + ')</i><br>' + err);
}
});
}
});
+27 -10
View File
@@ -216,7 +216,7 @@ span.no-about {
display: block;
}
.post, .thread, .thread-reply {
.post, .thread, .thread-reply, .preview {
margin-bottom: 50px;
.post-content, .thread-content {
@@ -224,11 +224,8 @@ span.no-about {
clear: both;
word-wrap: break-word;
overflow: hidden;
img {
max-width: 100%;
}
}
.post-title, .thread-title {
margin-bottom: 10px;
word-wrap: break-word;
@@ -297,7 +294,9 @@ pre {
// code blocks
code {
padding: 0;
display: block;
padding: 0.5em;
color: #C5C8C6; //hljs
box-shadow: 0 0 16px #222 inset;
background: #3f3f3f !important;
border: none;
@@ -388,6 +387,28 @@ blockquote p {
}
}
.md_editor {
.field_container {
position: relative;
.preview-button {
position: absolute;
top: 1em;
left: 1em;
z-index: 10;
}
.editor_field {
padding-top: 4em;
min-height: 5em;
}
.preview {
display: none;
padding: 4em 1em 1em;
}
}
}
#comments {
margin: 50px 0 0 40px;
}
@@ -457,10 +478,6 @@ textarea {
padding: 1em;
min-height: 3.5em;
resize: vertical;
&.comment {
height: 75px;
}
}
tr.spacer {