forked from fex-team/ueditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertcode.js
More file actions
283 lines (263 loc) · 14.8 KB
/
Copy pathinsertcode.js
File metadata and controls
283 lines (263 loc) · 14.8 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
module('plugins.insertcode');
//test('',function(){stop();})
test('trace 3343:插入代码中有空行', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent('hello');
ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
editor.execCommand('insertcode', 'Java');
range.setStart(editor.body.firstChild, 0).collapse(true).select();
ua.keydown(editor.body, {'keyCode':13});
range.setStart(editor.body.firstChild, 0).collapse(true).select();
ua.keydown(editor.body, {'keyCode':13});
range.setStart(editor.body.firstChild, 0).collapse(true).select();
range.insertNode(editor.document.createTextNode('hello'));
var br = ua.browser.ie ? '' : '<br>';
if (ua.browser.ie)
ua.checkSameHtml(editor.body.innerHTML, '<PRE class=brush:Java;toolbar:false><BR>hello<BR>hello</PRE><P></P>', '插入代码');
else if (ua.browser.gecko||ua.browser.webkit)
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:Java;toolbar:false">hello<br><br>hello</pre>', '插入代码');
else
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:Java;toolbar:false">hello<br><br>hello</pre><p>' + br + '</p>', '插入代码');
setTimeout(function () {
editor.execCommand('source');
setTimeout(function () {
editor.execCommand('source');
var br = ua.browser.ie ? '' : '<br>';
if (ua.browser.ie&&ua.browser.ie<9)
ua.checkSameHtml(editor.body.innerHTML, "<PRE class=brush:Java;toolbar:false>hello<BR>hello<BR></PRE><P> </P>", '样式不变');
else if (ua.browser.gecko||ua.browser.webkit)
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:Java;toolbar:false">hello<br><br>hello<br></pre>', '样式不变');
start();
}, 20);
}, 20);
stop();
});
test('trace 3355:不闭合选区插入代码', function () {
var editor = te.obj[0];
var code = '<div id="upload" style="display: none" ><img id="uploadBtn"></div>';
editor.setContent(code);
setTimeout(function () {
ua.keydown(editor.body, {'keyCode': 65, 'ctrlKey': true});
editor.execCommand('insertcode', 'html');
var br = ua.browser.ie ? '' : '<br>';
if (ua.browser.gecko || ua.browser.opera ||ua.browser.webkit)
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false"><div id=\"upload\" style=\"display: none\" ><img id=\"uploadBtn\"></div></pre>', '检查插入了html');
else
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false"><div id=\"upload\" style=\"display: none\" ><img id=\"uploadBtn\"></div></pre><p>' + br + '</p>', '检查插入了html');
start();
}, 50);
stop();
});
test('trace 3395:插入代码为空时,清空编辑器', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent('');
editor.execCommand('insertcode', 'html');
var br = ua.browser.ie ? ' ' : '<br>';
if (ua.browser.gecko||ua.browser.ie > 10)
ua.checkSameHtml(editor.body.firstChild.outerHTML, '<pre class="brush:html;toolbar:false"><br></pre>', '检查插入了html');
else if (ua.browser.ie > 8)
ua.checkSameHtml(editor.body.firstChild.outerHTML, '<pre class="brush:html;toolbar:false"></pre>', '检查插入了html');
else
ua.checkSameHtml(editor.body.firstChild.outerHTML, '<pre class="brush:html;toolbar:false">' + br + '</pre>', '检查插入了html');
range.setStart(editor.body.firstChild, 0).collapse(true).select();
range.insertNode(editor.document.createTextNode('hello'));//TODO bug修复把此行删除
ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
ua.keydown(editor.body, {'keyCode':8});
br = ua.browser.ie ? '' : '<br>';
ua.checkSameHtml(editor.body.innerHTML, '<p>' + br + '</p>', '检查编辑器清空');
});
test('trace 3396:多次切换源码,不会产生空行', function () {
var editor = te.obj[0];
editor.setContent('<p><body></p><p></body></p>');
ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
editor.execCommand('insertcode', 'html');
var br = (ua.browser.ie==9||ua.browser.ie==10) ? '\n' : '<br>';
var p = editor.body.firstChild.outerHTML.toLowerCase();
var x ='\"';
if(ua.browser.ie<9&&ua.browser.ie)x='';
equal(p, '<pre class='+x+'brush:html;toolbar:false'+x+'><body>'+br+'</body></pre>', '检查插入了html')
ua.checkSameHtml(editor.body.firstChild.outerHTML, '<pre class="brush:html;toolbar:false"><body>'+br+'</body></pre>', '检查插入了html');
//todo 1.3.6 3853
setTimeout(function () {
editor.execCommand('source');
setTimeout(function () {
editor.execCommand('source');
var end = (ua.browser.ie==9||ua.browser.ie==10) ?'':'<br>';
br =(ua.browser.ie==9||ua.browser.ie==10) ?'\n':'<br>';
var Bbr =( ua.browser.ie&&ua.browser.ie<9)?'\n':'';
ua.checkSameHtml(editor.body.firstChild.innerHTML, '<body>'+Bbr+br+'</body>'+end, '切回源码无影响');
// setTimeout(function() {//TODO bug修复后去掉注释
// editor.execCommand('source');
// setTimeout(function() {
// editor.execCommand('source');
// ua.checkSameHtml(editor.body.firstChild.innerHTML,'<body><br></body><br>','切回源码无影响');
// setTimeout(function () {
// UE.delEditor('ue');
// document.getElementById('ue')&&te.dom.push(document.getElementById('ue'));
start();
}, 20);
}, 20);
stop();
});
test('trace 3407:表格中插入代码', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent('');
editor.execCommand('inserttable');
stop();
setTimeout(function () {
var tds = editor.body.getElementsByTagName('td');
tds[1].innerHTML = 'asd';
range.setStart(tds[1], 0).setEnd(tds[1], 1).select();
editor.execCommand('insertcode', 'Javascript');
var br = ua.browser.ie ? ' ' : '<br>';
ua.checkSameHtml(tds[1].innerHTML, '<pre class="brush:Javascript;toolbar:false">asd</pre>', '检查插入了html');
// stop();
// setTimeout(function() {//TODO bug
// editor.execCommand('source');
// setTimeout(function() {
// editor.execCommand('source');
// ua.checkSameHtml(tds[1].innerHTML,'<pre class="brush:Javascript;toolbar:false">asd</pre><br>','切回源码无影响');
// start();
// },20);
// },20);
start();
}, 50);
});
test('test-beforeInsertHTML', function(){
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent('<pre class="brush:html;toolbar:false"><br/></pre>');
//闭合
range.setStart(editor.body.firstChild,0).collapse(true).select();
var insert = 'text';
editor.execCommand('inserthtml', insert);
if(ua.browser.ie==9||ua.browser.ie==10)
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">'+insert+'</pre>', '插入IE');
else
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">'+insert+'<br></pre>', '插入chrome/ff/ie11+');
ua.manualDeleteFillData(editor.body);
//插入非br element
range.setStart(editor.body.firstChild.firstChild,0).collapse(true).select();
insert='<p>I</p>';
editor.execCommand('inserthtml', insert);
if(ua.browser.ie==9||ua.browser.ie==10)
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">Itext</pre>', '插入IE');
else
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">Itext<br></pre>', '插入chrome/ff/ie11+');
ua.manualDeleteFillData(editor.body);
//插入br element
range.setStart(editor.body.firstChild.firstChild,1).collapse(true).select();
insert='<br>br';
editor.execCommand('inserthtml', insert);
if(ua.browser.ie==9||ua.browser.ie==10){
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">\nbrItext</pre>', '插入IE');
}
else if(ua.browser.ie>10){
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">I\nbrtext<br></pre>', '插入IE11+');
}
else{
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">I<br>brtext<br></pre>', '插入chrome/ff');}
ua.manualDeleteFillData(editor.body);
//混合标签
range.setStart(editor.body.firstChild,0).collapse(true).select();
insert='<p>PPP<p>222</p><span>SSS</span><br>BBB</p>';
editor.execCommand('inserthtml', insert);
if(ua.browser.ie==9||ua.browser.ie==10){
// if(ua.browser.ie<11){
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">PPP222SSS\nBBB\nbrItext</pre>', '插入IE');
// }else{
// ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">PPP222SSS\nBBBI\nbrtext</pre>', '插入IE');
// }
}
else if(ua.browser.ie>10){
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">PPP222SSS\nBBBI\nbrtext<br></pre>', '插入IE11+');
}
else{
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">PPP222SSS<br>BBBI<br>brtext<br></pre>', '插入chrome/ff/ie11+');
}
ua.manualDeleteFillData(editor.body);
//非闭合
//插入非element
range.setStart(editor.body.firstChild, 0).setEnd(editor.body.firstChild, 4).select();
insert = 'replace';
editor.execCommand('inserthtml', insert);
if(ua.browser.ie==9||ua.browser.ie==10)
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">replace</pre>', '插入IE');
else if(ua.browser.ie>10){
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">replace<br></pre>', '插入IE11+');
}
else
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">replaceBBBI<br>brtext<br></pre>', '插入chrome/ff/ie11+');
ua.manualDeleteFillData(editor.body);
//插入element
range.setStart(editor.body.firstChild, 0).setEnd(editor.body.firstChild, 0).select();
insert = '<p>PPP</p>';
editor.execCommand('inserthtml', insert);
if(ua.browser.ie==9||ua.browser.ie==10)
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">PPPreplace</pre>', '插入IE');
else if(ua.browser.ie>10){
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">PPPreplace<br></pre>', '插入IE11+');
}
else
ua.checkSameHtml(editor.body.innerHTML, '<pre class="brush:html;toolbar:false">PPPreplaceBBBI<br>brtext<br></pre>', '插入chrome/ff/ie11+');
ua.manualDeleteFillData(editor.body);
});
test('关于pre中的tabKey',function(){
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent('<pre class="brush:Javascript;toolbar:false">function a(){var a = true;}</pre>');
var text = editor.body.firstChild.firstChild;
range.setStart(text,13).setEnd(text,16).select();
ua.keydown(editor.body,{'shiftKey':false,'keyCode':9});
ua.keyup(editor.body,{'shiftKey':false,'keyCode':9});
if(ua.browser.ie==8||ua.browser.ie==9){
equal(editor.getContent(),'<pre class=\"brush:Javascript;toolbar:false\"> function a(){var a = true;}</pre>');
}else if(ua.browser.ie>9){
equal(editor.getContent(),'<pre class=\"brush:Javascript;toolbar:false\"> function a(){var a = true;}</pre>','验证pre下tabKey1');
}else{
equal(editor.getContent(),'<pre class="brush:Javascript;toolbar:false"> function a(){var a = true;}</pre>','验证pre下tabKey1');
}
editor.setContent('<pre class="brush:Javascript;toolbar:false"><br>function a(){var a = true;}</pre>');
var text = editor.body.firstChild.firstChild;
range.setStart(text,13).setEnd(text,16).select();
ua.keydown(editor.body,{'shiftKey':false,'keyCode':9});
ua.keyup(editor.body,{'shiftKey':false,'keyCode':9});
if(ua.browser.ie==8||ua.browser.ie==9){
var x = '\n';
if(ua.browser.ie==9){
x = '';
}
equal(editor.getContent(),'<pre class=\"brush:Javascript;toolbar:false\"> '+x+'function a(){var a = true;}</pre>','验证pre下tabKey2');
}else if(ua.browser.ie>9){
var x2 = '';
var x3 = ' ';
if(ua.browser.ie==11){
x2 = ' ';
x3='\n';
}
equal(editor.getContent(),'<pre class=\"brush:Javascript;toolbar:false\">'+x3+'function a(){var a = true;}</pre>'+x2,'验证pre下tabKey2');
}else{
equal(editor.getContent(),'<pre class="brush:Javascript;toolbar:false">\n function a(){var a = true;}</pre>','验证pre下tabKey2');
}
editor.setContent('<pre class="brush:Javascript;toolbar:false">function a(){<br>var a = true;}</pre>');
var text = editor.body.firstChild.firstChild;
range.setStart(text,13).setEnd(text,16).select();
ua.keydown(editor.body,{'shiftKey':false,'keyCode':9});
ua.keyup(editor.body,{'shiftKey':false,'keyCode':9});
if(ua.browser.ie==8){
equal(editor.getContent(),'<pre class=\"brush:Javascript;toolbar:false\">function a(){ \nvar a = true;}</pre>','验证pre下tabKey3');
}else if(ua.browser.ie>8){
var xx = ' ';
var xx2 = '';
if(ua.browser.ie==11){
xx = '';
xx2 = ' ';
}
equal(editor.getContent(),'<pre class=\"brush:Javascript;toolbar:false\">'+xx+'function a(){'+xx2+'\nvar a = true;}</pre>','验证pre下tabKey3');
}else{
equal(editor.getContent(),'<pre class="brush:Javascript;toolbar:false">function a(){ \nvar a = true;}</pre>','验证pre下tabKey3');
}
});