forked from leeyoshinari/WinHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.html
More file actions
184 lines (171 loc) · 6.87 KB
/
document.html
File metadata and controls
184 lines (171 loc) · 6.87 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>wangEditor catalog</title>
<link href="document/normalize.min.css" rel="stylesheet">
<link href="document/style.css" rel="stylesheet">
<script src="../js/jq.min.js"></script>
<script src="../js/md5.min.js"></script>
<style>
#header-container {
list-style-type: none;
padding-left: 20px;
}
#header-container li {
color: #333;
margin: 10px 0;
cursor: pointer;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
#header-container li:hover {
text-decoration: underline;
}
#header-container li[type="header1"] {
font-size: 20px;
font-weight: bold;
}
#header-container li[type="header2"] {
font-size: 16px;
padding-left: 15px;
font-weight: bold;
}
#header-container li[type="header3"] {
font-size: 14px;
padding-left: 30px;
}
#header-container li[type="header4"] {
font-size: 12px;
padding-left: 45px;
}
#header-container li[type="header5"] {
font-size: 12px;
padding-left: 60px;
}
</style>
</head>
<body>
<div class="page-container">
<input type="text" id="content_length" name="" value="0" style="display:none;"/>
<div class="page-right" style="display: flex;">
<div id="content-doc" style="border: 1px solid #ccc; flex: 1; width: calc(100vw - 370px);">
<div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
<div id="editor-text-area"></div>
</div>
<div id="catalog" style="width: 20%; background-color: #ffffff; overflow-y: scroll;">
<ul id="header-container"></ul>
</div>
</div>
</div>
<script src="document/index.js"></script>
<script>
let params = window.location.href.split('&');
let servers = params[0].split('=')[1];
let file_id = params[1].split('=')[1];
let is_share = file_id.length > 10;
let url = servers + '/content/get/' + file_id;
if (!is_share) {
url = servers + '/share/get/' + file_id;
}
let content = '';
let filename = '';
let old_md5 = '';
$.ajax({
type: "GET",
async: false,
url: url,
success: function (data) {
if (data['code'] === 0) {
if (is_share) {
window.parent.document.querySelectorAll('.window.docu>.titbar>span>.title')[0].innerText = data['msg'];
old_md5 = md5(data['data']);
}
document.title = data['msg'];
filename = data['msg'];
content = data['data'];
}
}
});
const E = window.wangEditor
const LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
E.i18nChangeLanguage(LANG)
const headerContainer = document.getElementById('header-container')
headerContainer.addEventListener('mousedown', event => {
if (event.target.tagName !== 'LI') return
event.preventDefault()
const id = event.target.id
editor.scrollToElem(id)
})
window.editor = E.createEditor({
selector: '#editor-text-area',
html: content,
config: {
placeholder: '请在这里输入内容...',
MENU_CONF: {
uploadImage: {
fieldName: filename,
base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
}
},
onChange(editor) {
const headers = editor.getElemsByTypePrefix('header')
headerContainer.innerHTML = headers.map(header => {
const text = E.SlateNode.string(header)
const { id, type } = header
return `<li id="${id}" type="${type}">${text}</li>`
}).join('')
}
}
})
window.toolbar = E.createToolbar({
editor,
selector: '#editor-toolbar',
config: {}
})
if (is_share) {
document.getElementById("content-doc").style.height = window.parent.document.getElementById("iframe_docu").clientHeight - 20 + 'px';
document.getElementById("catalog").style.height = window.parent.document.getElementById("iframe_docu").clientHeight - 20 + 'px';
// document.getElementById("editor-text-area").style.height = window.parent.document.getElementById("iframe_docu").contentRect.height - document.getElementById("editor-toolbar").clientHeight - 20 + 'px';
let resizeDoc = new ResizeObserver(event => {
document.getElementById("content-doc").style.height = event[0].contentRect.height - 20 + 'px';
document.getElementById("catalog").style.height = event[0].contentRect.height - 20 + 'px';
document.getElementById("editor-text-area").style.height = event[0].contentRect.height - document.getElementById("editor-toolbar").clientHeight - 20 + 'px';
})
setTimeout(() => {
resizeDoc.observe(window.parent.document.getElementById("iframe_docu"));
}, 200);
let editor_interval = window.setInterval(() => {
let text_data = editor.getHtml();
let new_md5 = md5(text_data);
if (new_md5 !== old_md5) {
window.parent.document.querySelectorAll('.window.docu>.titbar>span>.save-status')[0].innerText = "正在保存...";
window.parent.save_text_file(file_id, text_data);
old_md5 = new_md5;
window.parent.document.querySelectorAll('.window.docu>.titbar>span>.save-status')[0].innerText = window.parent.get_current_time() + " 已保存";
}
}, 10000);
function close_document_editor(file_id) {
clearInterval(editor_interval);
resizeDoc.disconnect();
window.parent.document.querySelectorAll('.window.docu>.titbar>span>.save-status')[0].innerText = "正在保存...";
let content = editor.getHtml();
if (old_md5 !== md5(content)) {
window.parent.save_text_file(file_id, content);
}
window.parent.document.querySelectorAll('.window.docu>.titbar>span>.save-status')[0].innerText = "";
window.parent.document.getElementById("iframe_docu").src = 'about:blank';
}
} else {
setTimeout(() => {
document.getElementById("content-doc").style.height = window.innerHeight - 20 + 'px';
document.getElementById("catalog").style.height = window.innerHeight - 20 + 'px';
document.getElementById("editor-text-area").style.height = window.innerHeight - document.getElementById("editor-toolbar").clientHeight - 20 + 'px';
}, 100);
}
</script>
</body>
</html>