forked from miws/wangEditorExt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wangEditorExt.js
68 lines (67 loc) · 2.43 KB
/
wangEditorExt.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
/**
* wangEditor扩展,增加全屏 查看源码功能
* 传入均为 editor实例,非css选择器
* 依赖jquery 如果是layui之类的需要在layui.use方法中使用
* 全屏功能需要引入 wangEditor-fullscreen.css
* @author [email protected]
* @date 2018.8.30 am 10:00
* 2018.9.18 pm 16:00 增加同页多编辑器支持
* 使用方法:
* E.fullscreen.init(editor);
* E.viewSource.init(editor);
*/
window.wangEditor.fullscreen = {
init: function(editor) {
id = editor.id;
if(!this.pluginsEditors){
this.pluginsEditors = {}
}
if(this.pluginsEditors[id]){
editor = this.pluginsEditors[id];
} else {
this.pluginsEditors[id]=editor;
}
editor.isFullScreen = false;
toolbar = editor.$toolbarElem[0];
$(toolbar).append('<div class="w-e-menu btn_fullscreen" onclick="window.wangEditor.fullscreen.run(\''+id+'\')">全屏</div>');
},
run: function(id) {
editor = this.pluginsEditors[id];
editor.isFullScreen = editor.isFullScreen;
container = $(editor.toolbarSelector);
container.toggleClass('fullscreen-editor');
container.find('.btn_fullscreen').text(this.isFullScreen ? '退出全屏': '全屏');
}
};
window.wangEditor.viewSource = {
init: function(editor) {
id = editor.id;
if(!this.pluginsEditors){
this.pluginsEditors = {}
}
if(this.pluginsEditors[id]){
editor = this.pluginsEditors[id];
} else {
this.pluginsEditors[id]=editor;
}
editor.isHTML = false;
toolbar = editor.$toolbarElem[0];
$(toolbar).append("<div class='w-e-menu btn_viewSource' title='查看源码' onclick='window.wangEditor.viewSource.run(\""+id+"\")'>源</div>");
},
run: function(id) {
editor = this.pluginsEditors[id];
editor.isHTML = !editor.isHTML;
_source = editor.txt.html();
toolbar = editor.$toolbarElem[0];
if (editor.isHTML) {
_source = _source.replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " ");
$(toolbar).find('.w-e-menu').css({ "display": "none" });
$(toolbar).find('.btn_viewSource').css({ "display": "" });
} else {
_source = editor.txt.text().replace(/</ig, "<").replace(/>/ig, ">").replace(/ /ig, " ");
$(toolbar).find('.w-e-menu').css({ "display": "" });
editor.change && editor.change();
}
editor.txt.html(_source);
}
};