-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditorV1.3.html
268 lines (240 loc) · 8.23 KB
/
editorV1.3.html
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>editorV1.3_Icon版</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<style>
body {
min-width: 480px;
margin: 0;
padding: 0;
position: relative;
}
i{
color: #333;
}
.container {
width: 80%;
margin: 10px auto;
position: relative;
}
#main {
position: relative;
top: -14px;
left: 0;
display: block;
width: 80%;
min-height: 280px;
margin: 0 auto;
padding: 10px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 3px;
outline: none;
/* overflow: scroll; */
}
p {
margin: 0;
padding: 0;
}
input{
width: 40px;
height: 18px;
position: relative;
top: 0;
left: 0;
border: 1px solid #777;
background-color: #eeeeee;
border-radius: 8%;
overflow: hidden;
}
button{
position: relative;
top: -7px;
left: 0;
margin-top: 4px;
}
select{
position: relative;
top: -7px;
left: 0;
margin-top: 4px;
}
</style>
<body>
<div class="container">
<form action="#">
<button value="大标题" id="maintitle"><i class="icon-file-alt" aria-hidden="true"></i></button>
<button value="正文" id="content"><i class="icon-file-text-alt"></i></button>
<button value="加粗" id="bold"><i class="icon-bold"></i></button>
<button value="倾斜" id="italic"><i class="icon-italic"></i></button>
<button value="格式化" id="removeFormat"><i class="icon-eraser"></i></button>
<button value="有序" id="InsertOrderedList"><i class="icon-list-ol"></i></button>
<button value="无序" id="InsertUnorderedList"><i class="icon-list-ul"></i></button>
<button value="left" id="JustifyLeft"><i class="icon-align-left"></i></button>
<button value="center" id="JustifyCenter"><i class="icon-align-center"></i></button>
<button value="right" id="JustifyRight"><i class="icon-align-right"></i></button>
<select name="" id="fontList">
<option value="宋体">宋体</option>
<option value="微软雅黑">微软雅黑</option>
<option value="黑体">黑体</option>
<option value="Arial">Arial</option>
<option value="Courier">Courier</option>
<option value="Sans-serif">Sans-serif</option>
<option value="Verdana">Verdana</option>
<option value="Times New Roman">Times New Roman</option>
</select>
<select name="" id="fontsize">
<option value="1">12px</option>
<option value="4">18px</option>
<option selected="selected" value="3">14px</option>
<option value="5">24px</option>
<option value="6">32px</option>
<option value="7">48px</option>
</select>
<input type="color" value="颜色" id="color">
<button value="添加链接" id="createLink"><i class="icon-link"></i></button>
<button value="取消链接" id="unlink"><i class="icon-unlink"></i></button>
<button value="webimg" id="img"><i class="icon-picture"></i></button>
</form>
</div>
<div id="main" contenteditable="true" onfocus="true">请输入文字...</div>
</body>
<script>
window.onload = function() {
/*页面载入确认*/
if (document.readyState == "complete") {
document.getElementById("main").focus();
}
function getSelectionText() {
//流行浏览器支持
if (window.getSelection) {
return window.getSelection().toString();
//getseletion返回是一个getselection的对象 需要转化字符串
//判断IE支持
} else if (document.selection && document.selection.createRange) {
return document.selection.createRange().text;
}
return '';
//当按下按钮一 将选中的文字变颜色
selection ? alert("选中有数值") : alert("没选中内容");
}
document.execCommand("2D-Position", "false", "true");
/*将光标所在段落修改为一级标题*/
$('#maintitle').click(function() {
// document.execCommand('formatBlock', true, 'h1');
document.execCommand('bold')
document.execCommand('Fontsize', false, '6')
// if($('#main b').css(fontsize))
return false;
});
/*将光标所在块修改为段落*/
$('#content').click(function() {
// document.execCommand('formatBlock', true, 'p');
document.execCommand('Fontsize', false, '1')
});
/*加粗*/
$('#bold').click(function() {
document.execCommand('bold');
});
/*倾斜所选*/
$('#italic').click(function() {
document.execCommand('italic');
});
/*下划线所选*/
$('#italic').click(function() {
document.execCommand('underline');
});
/*为所选文字加链接*/
$('#createLink').click(function() {
addLink();
/*document.execCommand('createLink', true, sLinkURL);*/
});
/*取消链接*/
$('#unlink').click(function() {
document.execCommand('unlink');
});
/*对当前字体样式格式化*/
$('#removeFormat').click(function() {
document.execCommand('removeFormat', true);
});
/*有序列表*/
$('#InsertOrderedList').click(function() {
document.execCommand('InsertOrderedList');
});
/*无序列表*/
$('#InsertUnorderedList').click(function() {
document.execCommand('InsertUnorderedList');
});
/*居左显示*/
$('#JustifyLeft').click(function() {
document.execCommand('JustifyLeft');
});
/*居中显示*/
$('#JustifyCenter').click(function() {
document.execCommand('JustifyCenter');
});
/*居右显示*/
$('#JustifyRight').click(function() {
document.execCommand('JustifyRight');
});
/*插入固定图片*/
$('#insertImage').click(function() {
document.execCommand('insertImage', false,"http://misc.360buyimg.com/lib/img/e/logo-201305.png");
});
/*插入本地文件*/
/* $('#insertImage').click(function() {
document.execCommand('insertFile', false, this.value);
});*/
/*弹出图片地址框*/
$('#img').click(function() {
addimg();
});
/*字体字号设置*/
$('#fontsize').click(function() {
$('#fontsize').change(function() {
document.execCommand('Fontsize', false, this.value)
});
});
/*字体颜色设置*/
$('#color').click(function() {
document.getElementById('color').onchange = function() {
document.execCommand('ForeColor', true, this.value);
$("#main li").css({color: this.value});
};
});
/*字体样式设置*/
$('#fontList').change(function() {
document.execCommand('FontName', true, this.value)
});
/*需要定义属性的js*/
function addLink() {
var linkURL = prompt('请输入跳转链接:', 'http://');
var sText = document.getSelection();
if (linkURL!=null && linkURL!=""&&linkURL!="http://"){
document.execCommand('insertHTML', false, '<a href="' + linkURL + '" target="_blank">' + sText + '</a>');
}
else{
console.log('您未定义任何链接')
}
}
function addimg() {
var imgURL = prompt('请输入图片链接:', 'http://');
var sIMG = document.getSelection();
if (imgURL!=null && imgURL!=""){
document.execCommand('insertHTML', true, '<img src="' + imgURL + '" target="_blank">' + sIMG);
}
else{
console.log('您未插入任何图片')
}
// document.execCommand('insertHTML', true, '<img src="' + imgURL + '" target="_blank">' + sIMG);
// console.log()
/*http://www.baidu.com/img/baidu_jgylogo3.gif*/
}
}
</script>
</html>