Repository navigation
Expand file tree
/
Copy patheditor.js
More file actions
117 lines (110 loc) · 2.63 KB
/
Copy patheditor.js
File metadata and controls
117 lines (110 loc) · 2.63 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* 创建一个 EpicEditor
*
* @param {Element} textarea
* @return {EpicEditor}
*/
function createEpicEditor (textarea) {
var $node = $(textarea);
var id = $node.attr('id');
var h = $node.height();
$node.before('<div id="editor_' + id + '" style="height:' + h + 'px; border: 1px solid #DDD; border-radius: 4px;"></div>');
$node.hide();
var opts = {
container: 'editor_' + id,
textarea: id,
basePath: '/public/libs/epiceditor',
clientSideStorage: false,
useNativeFullscreen: true,
parser: marked,
theme: {
base: '/themes/base/epiceditor.css',
preview: '/themes/preview/github.css',
editor: '/themes/editor/epic-light.css'
},
button: {
preview: true,
fullscreen: true,
bar: true
},
focusOnLoad: false,
shortcut: {
modifier: 18,
fullscreen: 70,
preview: 80
},
string: {
togglePreview: '预览',
toggleEdit: '编辑',
toggleFullscreen: '全屏'
},
autogrow: {
minHeight: 200
}
};
var editor = new EpicEditor(opts);
// 进入全屏模式时,给编辑器增加一些额外的样式
function _fullscreenenter ($e) {
var d = {
margin: '90px 8px 8px 8px',
padding: '8px',
border: '1px solid #aaa',
width: $e.width() - 34,
height: $e.height() - 114
};
setTimeout(function () {
$e.css(d);
}, 100);
}
function _fullscreenexit ($e) {
$e.css({
margin: '0',
padding: '0',
border: 'none'
});
}
function fullscreenenter () {
_fullscreenenter($(editor.editorIframe));
_fullscreenenter($(editor.previewerIframe));
window.e = editor;
}
function fullscreenexit () {
_fullscreenexit($(editor.editorIframe));
_fullscreenexit($(editor.previewerIframe));
}
editor.on('fullscreenenter', fullscreenenter);
editor.on('fullscreenexit', fullscreenexit);
$(window).resize(function () {
if (editor.is('fullscreen')) {
fullscreenenter();
}
});
return editor;
}
/**
* 向EpicEditor末尾增加内容
*
* @param {EpicEditor} editor
* @param {String} text
* @return {String}
*/
function epicEditorAppend (editor, text) {
return editor.getElement('editor').body.innerHTML += text;
}
/**
* 向EpicEditor前面增加内容
*
* @param {EpicEditor} editor
* @param {String} text
* @return {String}
*/
function epicEditorPrepend (editor, text) {
return editor.getElement('editor').body.innerHTML = text + editor.getElement('editor').body.innerHTML;
}
// 自动创建编辑框
$(function () {
var $node = $('#wmd-input');
if ($node.length > 0) {
createEpicEditor($node).load();
}
});