forked from AlexP11223/JavaSpringMvcBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditpost.js
More file actions
70 lines (61 loc) · 2.29 KB
/
Copy patheditpost.js
File metadata and controls
70 lines (61 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$(document).ready(function() {
var converter = Markdown.getSanitizingConverter();
converter.hooks.chain("preConversion", function (text) {
return text.replace(/===cut===/g, '');
});
var editor = new Markdown.Editor(converter);
editor.run();
$("#wmd-button-row").append(
'<li class="wmd-button" style="left: 400px; top: -10px;"><a id="insertSeparator" class="btn btn-default btn-sm">short/full text separator</a> </li>');
jQuery.fn.extend({
insertAtCaret: function(myValue){
return this.each(function(i) {
if (document.selection) {
this.focus();
var sel = document.selection.createRange();
sel.text = myValue;
this.focus();
}
else if (this.selectionStart || this.selectionStart == '0') {
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
this.focus();
this.selectionStart = startPos + myValue.length;
this.selectionEnd = startPos + myValue.length;
this.scrollTop = scrollTop;
} else {
this.value += myValue;
this.focus();
}
});
}
});
$('#insertSeparator').click(function(){
var $textarea = $('#wmd-input');
$textarea.insertAtCaret('===cut===');
});
$("#postForm").validate({
rules: {
title: {
required: true,
minlength: 3
},
tags: {
required: true
},
text: {
required: true,
minlength: 50
}
}
});
$(window).bind('beforeunload', function(){
if ($.trim($('#wmd-input').val()) != '')
return 'You have not submitted your post.';
});
$(document).on("submit", "form", function(event){
$(window).off('beforeunload');
});
});