This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
jquery.plugins.js
92 lines (70 loc) · 2.95 KB
/
jquery.plugins.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// This is a jQuery plugins file.
(function($){
// Needs require this lib at the moment:
// CodeMirror
// marked
// codemirror/extend.js
jQuery.fn.extend({
markdown: function(){
return this.each( function(){
if ( this.type !== 'textarea' ){
return false;
}
var $textarea = jQuery(this);
var $wrapper = $textarea.parent();
var $preview = jQuery($textarea.attr('data-markdown-preview'));
if(localStorage.markdown != undefined){
$textarea.val(localStorage.markdown);
}
var editor = CodeMirror.fromTextArea(this, {
mode: 'gfm',
theme: "default",
styleActiveLine: true,
matchBrackets: true,
lineWrapping: true,
autofocus: true,
indentWithTabs: true,
tabSize: 2,
showCursorWhenSelecting: true,
highlightSelectionMatches: true,
extraKeys: {
"Cmd-B" : function(cm) { cm.wrapSymbolTag("**") },
"Ctrl-B" : function(cm) { cm.wrapSymbolTag("**") },
"Cmd-I" : function(cm) { cm.wrapSymbolTag("*") },
"Ctrl-I" : function(cm) { cm.wrapSymbolTag("*") },
"Cmd-U" : function(cm) { cm.wrapSymbolTag("~~") },
"Ctrl-U" : function(cm) { cm.wrapSymbolTag("~~") },
"Cmd-K" : function(cm) { cm.wrapSymbolTag("`") },
"Ctrl-K" : function(cm) { cm.wrapSymbolTag("`") },
"Cmd-1" : function(cm) { cm.insertTitle(1) },
"Ctrl-1" : function(cm) { cm.insertTitle(1) },
"Cmd-2" : function(cm) { cm.insertTitle(2) },
"Ctrl-2" : function(cm) { cm.insertTitle(2) },
"Cmd-3" : function(cm) { cm.insertTitle(3) },
"Ctrl-3" : function(cm) { cm.insertTitle(3) },
"Cmd-4" : function(cm) { cm.insertTitle(4) },
"Ctrl-4" : function(cm) { cm.insertTitle(4) },
"Cmd-5" : function(cm) { cm.insertTitle(5) },
"Ctrl-5" : function(cm) { cm.insertTitle(5) },
"Cmd-6" : function(cm) { cm.insertTitle(6) },
"Ctrl-6" : function(cm) { cm.insertTitle(6) },
"Cmd-S" : function(cm) { cm.saveMarkdownContent() },
"Ctrl-S" : function(cm) { cm.saveMarkdownContent() },
"Tab" : function(cm) { cm.tabFastKey() }
}
});
editor.on("change", function(doc, changeObj) {
$preview.html(marked(doc.getValue()));
$textarea.val(doc.getValue());
localStorage.markdown = doc.getValue();
});
editor.on('scroll', function(instance){
var scrollInfo = instance.getScrollInfo();
$preview.scrollTop( scrollInfo.top / scrollInfo.height * $preview[0].scrollHeight );
});
$preview.html(marked(editor.getValue()));
localStorage.markdown = editor.getValue();
});
}
});
})(jQuery);