enterkey.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. module( 'plugins.enterkey' );
  2. ///*
  3. // 闭合选区
  4. // 1.p末尾或中间回车
  5. // 2.列表中回车(关于列表的回车必须加上li这个插件)
  6. // 2.1 列表标号后面有文本
  7. // 2.2列表标号后没有文本
  8. // 3.h1后回车
  9. // 4.带有BIU样式的文本后面回车
  10. //
  11. // 不闭合选区
  12. // 1.选中部分表格后回车
  13. // 2.选中文本后回车
  14. //
  15. // 复合操作
  16. // 1.回车后撤销
  17. // */
  18. //fixed in future
  19. /*trace 3174*/
  20. //test( 'trace 2864:table中回车,br做回车', function () {
  21. // te.dom[0].parentNode.removeChild(te.dom[0]);
  22. // var div2 = document.body.appendChild( document.createElement( 'div' ) );
  23. // $( div2 ).css( 'width', '500px' ).css( 'height', '500px' ).css( 'border', '1px solid #ccc' );
  24. // te.dom.push(div2);
  25. // baidu.editor.plugins.table = function(){};
  26. // var editor = new baidu.editor.Editor({'initialContent':'<p>欢迎使用ueditor</p>','autoFloatEnabled':false,'enterTag':'br'});
  27. // te.obj.push(editor);
  28. // editor.render(div2);
  29. // var range = new baidu.editor.dom.Range( editor.document );
  30. // te.obj.push(range);
  31. // editor.setContent(' <table width="100%" border="1" bordercolor="#000000"><tbody><tr><td >aa</td></tbody></table>' );
  32. // stop();
  33. // setTimeout(function(){
  34. // te.obj[4].selectNode(editor.body.firstChild.firstChild.firstChild.firstChild).select();
  35. // ua.keydown(editor.body,{'keyCode':13});
  36. // setTimeout(function(){
  37. // equal(ua.getChildHTML(te.obj[3].body.firstChild),'<tbody><tr><td><br></td></tr></tbody>','<br>做回车');
  38. // te.dom[1].parentNode.removeChild(te.dom[1]);
  39. // start();
  40. // },50);
  41. // },50);
  42. //} );
  43. //test( 'br做回车,选区非闭合', function () {
  44. // te.dom[0].parentNode.removeChild(te.dom[0]);
  45. // var div2 = document.body.appendChild( document.createElement( 'div' ) );
  46. // $( div2 ).css( 'width', '500px' ).css( 'height', '500px' ).css( 'border', '1px solid #ccc' );
  47. // te.dom.push(div2);
  48. // baidu.editor.plugins.table = function(){};
  49. // var editor = new baidu.editor.Editor({'initialContent':'<p>欢迎使用ueditor</p>','autoFloatEnabled':false,'enterTag':'br'});
  50. // te.obj.push(editor);
  51. // editor.render(div2);
  52. // stop();
  53. // editor.ready(function(){
  54. // var range = new baidu.editor.dom.Range( editor.document );
  55. // te.obj.push(range);
  56. // editor.setContent('<p>hello1</p><p>hello2</p>' );
  57. //
  58. // setTimeout(function(){
  59. // te.obj[4].setStart(editor.body.firstChild,0).setEnd(editor.body.lastChild,1).select();
  60. // ua.keydown(editor.body,{'keyCode':13});
  61. // setTimeout(function(){
  62. // ua.manualDeleteFillData(te.obj[3].body);
  63. // var html = 'h<br>lo';
  64. // equal(ua.getChildHTML(te.obj[3].body.firstChild),html,'<br>做回车');
  65. // te.dom[1].parentNode.removeChild(te.dom[1]);
  66. // start();
  67. // },50);
  68. // },50);
  69. // });
  70. //} );
  71. test( 'br做回车,选区非闭合', function () {
  72. te.dom[0].parentNode.removeChild(te.dom[0]);
  73. var div2 = document.body.appendChild( document.createElement( 'div' ) );
  74. $( div2 ).css( 'width', '500px' ).css( 'height', '500px' ).css( 'border', '1px solid #ccc' );
  75. te.dom.push(div2);
  76. baidu.editor.plugins.table = function(){};
  77. var editor = new baidu.editor.Editor({'initialContent':'<p>欢迎使用ueditor</p>','autoFloatEnabled':false,'enterTag':'br'});
  78. te.obj.push(editor);
  79. editor.render(div2);
  80. stop();
  81. editor.ready(function(){
  82. var range = new baidu.editor.dom.Range( editor.document );
  83. te.obj.push(range);
  84. editor.setContent('<p>hello</p>' );
  85. te.obj[4].setStart(editor.body.firstChild.firstChild,1).setEnd(editor.body.firstChild.firstChild,3).select();
  86. ua.keydown(editor.body,{'keyCode':13});
  87. setTimeout(function(){
  88. ua.manualDeleteFillData(te.obj[3].body);
  89. var html = 'h<br>lo';
  90. equal(ua.getChildHTML(te.obj[3].body.firstChild),html,'<br>做回车');
  91. editor.setContent('<h1>hello<br></h1><p><img src="http://img.baidu.com/hi/jx2/j_0015.gif" /><a href="http://www.baidu.com"></a></p>' );
  92. te.obj[4].setStart( editor.body.lastChild,0 ).setEnd(editor.body.lastChild,1).select();
  93. ua.keydown(editor.body,{'keyCode':13});
  94. setTimeout(function(){
  95. ua.manualDeleteFillData(te.obj[3].body);
  96. var html = 'hello<br>';
  97. equal(ua.getChildHTML(te.obj[3].body.firstChild),html,'<br>做回车');
  98. editor.setContent('<h1>hello<br></h1><p>he<img src="http://img.baidu.com/hi/jx2/j_0015.gif" />oll</p>' );
  99. te.obj[4].setStart( editor.body.lastChild,1 ).setEnd(editor.body.lastChild,2).select();
  100. ua.keydown(editor.body,{'keyCode':13});
  101. setTimeout(function(){
  102. ua.manualDeleteFillData(te.obj[3].body);
  103. var html = 'hello<br>';
  104. equal(ua.getChildHTML(te.obj[3].body.firstChild),html,'<br>做回车');
  105. editor.setContent('<h1>hello<br></h1><p><img src="http://img.baidu.com/hi/jx2/j_0015.gif" /><br></p>' );
  106. te.obj[4].setStart( editor.body.lastChild,0 ).setEnd(editor.body.lastChild,1).select();
  107. ua.keydown(editor.body,{'keyCode':13});
  108. setTimeout(function(){
  109. ua.manualDeleteFillData(te.obj[3].body);
  110. var html = 'hello<br>';
  111. equal(ua.getChildHTML(te.obj[3].body.firstChild),html,'<br>做回车');
  112. editor.setContent('<h1>hello<br></h1><p><img src="http://img.baidu.com/hi/jx2/j_0015.gif" /><a href="http://www.baidu.com">www.baidu.com</a></p>' );
  113. te.obj[4].setStart( editor.body.lastChild,0 ).setEnd(editor.body.lastChild,1).select();
  114. ua.keydown(editor.body,{'keyCode':13});
  115. setTimeout(function(){
  116. ua.manualDeleteFillData(te.obj[3].body);
  117. var html = 'hello<br>';
  118. equal(ua.getChildHTML(te.obj[3].body.firstChild),html,'<br>做回车');
  119. te.dom[1].parentNode.removeChild(te.dom[1]);
  120. start();
  121. },20);
  122. },20);
  123. },20);
  124. },20);
  125. },20);
  126. });
  127. } );
  128. test( 'br做回车,选区闭合', function () {
  129. te.dom[0].parentNode.removeChild(te.dom[0]);
  130. var div2 = document.body.appendChild( document.createElement( 'div' ) );
  131. $( div2 ).css( 'width', '500px' ).css( 'height', '500px' ).css( 'border', '1px solid #ccc' );
  132. te.dom.push(div2);
  133. baidu.editor.plugins.table = function(){};
  134. var editor = new baidu.editor.Editor({'initialContent':'<p>欢迎使用ueditor</p>','autoFloatEnabled':false,'enterTag':'br'});
  135. te.obj.push(editor);
  136. editor.render(div2);
  137. stop();
  138. editor.ready(function () {
  139. var range = new baidu.editor.dom.Range(editor.document);
  140. te.obj.push(range);
  141. editor.setContent('<p>hello</p>');
  142. setTimeout(function () {
  143. te.obj[4].setStart(editor.body.firstChild.firstChild, 1).collapse(true).select();
  144. ua.keydown(editor.body, {'keyCode':13});
  145. setTimeout(function () {
  146. ua.manualDeleteFillData(te.obj[3].body);
  147. var html = 'h<br>ello';
  148. equal(ua.getChildHTML(te.obj[3].body.firstChild), html, '<br>做回车,选区闭合');
  149. te.dom[1].parentNode.removeChild(te.dom[1]);
  150. start();
  151. }, 50);
  152. }, 50);
  153. });
  154. } );
  155. test( 'br做回车,选区闭合,在节点尾部输入回车,要插入2个br', function () {
  156. te.dom[0].parentNode.removeChild(te.dom[0]);
  157. var div2 = document.body.appendChild( document.createElement( 'div' ) );
  158. $(div2).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc');
  159. te.dom.push(div2);
  160. baidu.editor.plugins.table = function () {
  161. };
  162. var editor = new baidu.editor.Editor({'initialContent':'<p>欢迎使用ueditor</p>', 'autoFloatEnabled':false, 'enterTag':'br'});
  163. te.obj.push(editor);
  164. editor.render(div2);
  165. stop();
  166. editor.ready(function () {
  167. var range = new baidu.editor.dom.Range(editor.document);
  168. te.obj.push(range);
  169. editor.setContent('<p>hello</p>');
  170. setTimeout(function () {
  171. te.obj[4].setStart(editor.body.firstChild.firstChild, 5).collapse(true).select();
  172. ua.keydown(editor.body, {'keyCode':13});
  173. setTimeout(function () {
  174. ua.manualDeleteFillData(te.obj[3].body);
  175. var html = 'hello<br><br>';
  176. equal(ua.getChildHTML(te.obj[3].body.firstChild), html, '<br>做回车,选区闭合,在节点尾部输入回车');
  177. te.dom[1].parentNode.removeChild(te.dom[1]);
  178. start();
  179. }, 50);
  180. }, 50);
  181. });
  182. });
  183. test( 'table首行中回车', function () {
  184. var editor = te.obj[0];
  185. if(!ua.browser.ie){
  186. var range = new baidu.editor.dom.Range( editor.document );
  187. editor.setContent(' <table width="100%" border="1" bordercolor="#000000"><tbody><tr><td ><br /></td></tr></tbody></table>' );
  188. range.selectNode(editor.body.firstChild.firstChild.firstChild.firstChild).select();
  189. ua.keydown(editor.body,{'keyCode':13});
  190. stop();
  191. setTimeout(function(){
  192. equal(ua.getChildHTML(te.obj[0].body.firstChild),'<br>','加入p');//opera中,由原生方法实现p标签
  193. start();
  194. },20);
  195. }
  196. } );
  197. test( '去除_moz_dirty', function () {
  198. if(browser.gecko){
  199. var editor = te.obj[0];
  200. var range = te.obj[1];
  201. editor.setContent( '<strong>迎使</strong><em _moz_dirty=""><strong _moz_dirty="">用ued</strong>it</em>' );
  202. range.selectNode(editor.body.firstChild.lastChild.firstChild).select();
  203. ua.keydown(editor.body,{'keyCode':13});
  204. setTimeout( function () {
  205. equal(ua.getChildHTML(editor.body),'<p><strong>迎使</strong><em><strong>用ued</strong>it</em></p>','');
  206. start();
  207. }, 20 );
  208. stop();
  209. }
  210. } );
  211. ///*不作处理chrome会产生div*/
  212. test( 'chrome删除div', function () {
  213. var editor = te.obj[0];
  214. var range = te.obj[1];
  215. var body = editor.body;
  216. if(ua.browser.webkit){
  217. editor.body.innerHTML = '<h1>一级标题</h1><div><br/></div>';
  218. range.setStart( body.firstChild.firstChild, 4 ).collapse( 1 ).select();
  219. ua.keydown(editor.body,{'keyCode':13});
  220. range.selectNode(body.lastChild.firstChild).select();
  221. var index = editor.undoManger.index;
  222. var br = ua.browser.ie ? '' : '<br>';
  223. ua.keyup(editor.body,{'keyCode':13});
  224. equal(editor.undoManger.list.length,2,'保存现场');
  225. setTimeout( function () {
  226. equal( body.childNodes.length, 2, '2个子节点' );
  227. equal(body.lastChild.tagName.toLowerCase(),'p','div转成p');
  228. equal(ua.getChildHTML(body),'<h1>一级标题</h1><p><br></p>','检查内容');
  229. start();
  230. }, 60 );
  231. stop();
  232. }else{
  233. }
  234. } );
  235. test( 'formatBlock', function () {
  236. if(ua.browser.ie)return; //这个处理不针对ie
  237. var editor = te.obj[0];
  238. var range = te.obj[1];
  239. editor.setContent( '<table><tbody><tr><td> hello1</td><td ></td></tr><tr><td >hello2</td><td ></td></tr></tbody></table>' );
  240. setTimeout( function () {
  241. var tds = editor.body.getElementsByTagName('td');
  242. range.setStart(tds[0],1).collapse(true).select();
  243. ua.keydown(editor.body,{'keyCode':13});
  244. setTimeout( function () {
  245. ua.keyup(editor.body,{'keyCode':13});
  246. setTimeout( function () {
  247. var td = editor.body.getElementsByTagName('td')[0];
  248. equal(td.firstChild&&td.firstChild.tagName.toLowerCase(),'p','加上p');
  249. equal(td.firstChild.innerHTML,'hello1','hello1');
  250. start();
  251. }, 60 );
  252. }, 60 );
  253. }, 60 );
  254. stop();
  255. } );
  256. test( '跨td不删', function () {
  257. var editor = te.obj[0];
  258. var range = te.obj[1];
  259. editor.setContent( '<table><tbody><tr><td> hello1</td><td ></td></tr><tr><td >hello2</td><td ></td></tr></tbody></table>' );
  260. editor.addListener("keydown", function (type, evt) {
  261. setTimeout( function () {
  262. ok(evt.defaultPrevented||!evt.returnValue, "keydown");
  263. start();
  264. }, 60 );
  265. });
  266. setTimeout(function () {
  267. var tds = editor.body.getElementsByTagName('td');
  268. range.setStart(tds[0], 0).setEnd(tds[2], 1).select();
  269. ua.keydown(editor.body, {'keyCode': 13});
  270. }, 60);
  271. stop();
  272. } );
  273. ////presskey相关,先不测
  274. //test( '普通文本<strong><span style="color: red">中间</span></strong>回车', function () {
  275. // var editor = te.obj[0];
  276. // var range = te.obj[1];
  277. // var body = editor.body;
  278. // editor.setContent( '<p>你好编辑器</p>' );
  279. // range.setStart( body.firstChild.firstChild, 2 ).collapse( 1 ).select();
  280. // editor.focus();
  281. // setTimeout( function () {
  282. // te.presskey( "enter", "" );
  283. // editor.focus();
  284. // setTimeout( function () {
  285. // var ps = body.childNodes;
  286. // equal( ps.length, 2, '2个p' );
  287. // equal( ps[0].tagName.toLowerCase(), 'p', 'tag名为p' );
  288. // equal( ps[1].tagName.toLowerCase(), 'p', 'tag名为p' );
  289. // equal( ua.getChildHTML( ps[0] ), '你好', '第一个p里是你好' );
  290. // equal( ua.getChildHTML( ps[1] ), '编辑器', '第一个p里是编辑器' );
  291. // start();
  292. // }, 30 );
  293. // }, 100 );
  294. // stop();
  295. //} );
  296. //
  297. //test( '普通文本<strong><span style="color: red">末尾</span></strong>回车', function () {
  298. // var editor = te.obj[0];
  299. // var range = te.obj[1];
  300. // var body = editor.body;
  301. // editor.setContent( '<p>你好编辑器</p>' );
  302. // range.setStart( body.firstChild, 1 ).collapse( 1 ).select();
  303. // editor.focus();
  304. // var br = (ua.browser.ie) ? '' : '<br>';
  305. // setTimeout( function () {
  306. // te.presskey( "enter", "" );
  307. // ua.keydown( body );
  308. // editor.focus();
  309. // setTimeout( function () {
  310. // var ps = body.childNodes;
  311. // equal( ps.length, 2, '2个p' );
  312. // equal( ps[0].tagName.toLowerCase(), 'p', 'tag名为p' );
  313. // equal( ps[1].tagName.toLowerCase(), 'p', 'tag名为p' );
  314. // equal( ua.getChildHTML( ps[0] ), '你好编辑器', '第一个p里是你好编辑器' );
  315. // equal( ua.getChildHTML( ps[1] ), br, '第一个p里是br' );
  316. // start();
  317. // }, 60 );
  318. // }, 100 );
  319. // stop();
  320. //} );
  321. //
  322. // //不好检查
  323. //test( 'table中回车', function () {
  324. // var div2 = document.body.appendChild( document.createElement( 'div' ) );
  325. // $( div2 ).css( 'width', '500px' ).css( 'height', '500px' ).css( 'border', '1px solid #ccc' );
  326. // baidu.editor.plugins.table = function(){};
  327. // var editor = new baidu.editor.Editor({'initialContent':'<p>欢迎使用ueditor</p>','autoFloatEnabled':false});
  328. // editor.render(div2);
  329. // stop();
  330. // setTimeout(function(){
  331. // var range = new baidu.editor.dom.Range( editor.document );
  332. // var body = editor.body;
  333. // editor.setContent(' <table width="100%" border="1" bordercolor="#000000"><tbody><tr><td ><br /></td><td ><br /></td></tr><tr><td ><br /></td><td ><br /></td></tr></tbody></table>' );
  334. // var tds = editor.body.getElementsByTagName( 'td' );
  335. // tds[0].innerHTML = 'hello';
  336. // tds[1].innerHTML = 'hello';
  337. // tds[2].innerHTML = 'hello';
  338. // range.setStart( tds[0].firstChild, 0 ).setEnd(tds[2].lastChild,1).select();
  339. // var re = ua.keydown(editor.body,{'keyCode':13});
  340. // setTimeout(function(){
  341. // start();
  342. // },20);
  343. // },20);
  344. //} );
  345. ///*不作处理chrome会产生div*/
  346. //test( 'trace766 :<strong><span style="color: red">H1</span></strong>回车', function () {
  347. // var editor = te.obj[0];
  348. // var range = te.obj[1];
  349. // var body = editor.body;
  350. // editor.setContent( '<h1><span style="color:red">一级标题</span></h1>' );
  351. //
  352. // range.setStart( body.firstChild, 1 ).collapse( 1 ).select();
  353. // editor.focus();
  354. // var br = ua.browser.ie ? '' : '<br>';
  355. // setTimeout( function () {
  356. // te.presskey( "enter", "" );
  357. // editor.focus();
  358. // setTimeout( function () {
  359. //
  360. // var tagName = body.lastChild.tagName.toLowerCase();
  361. // ok( tagName == 'p' || tagName == 'h1', '回车后不会产生div' );
  362. // equal( body.childNodes.length, 2, '2个子节点' );
  363. // start();
  364. // }, 60 );
  365. // }, 100 );
  366. // stop();
  367. //} );
  368. //
  369. //
  370. //test( 'trace 1382:<strong><span style="color: red">空列表标号后</span></strong>回车', function () {
  371. // var editor = te.obj[0];
  372. // var range = te.obj[1];
  373. // var body = editor.body;
  374. // editor.setContent( '<ol><li></li></ol>' );
  375. // var li = body.getElementsByTagName( 'li' )[0];
  376. // range.setStart( li, 0 ).collapse( 1 ).select();
  377. // editor.focus();
  378. // var br = ua.browser.ie ? '' : '<br>';
  379. // setTimeout( function () {
  380. // te.presskey( "enter", "" );
  381. // editor.focus();
  382. // setTimeout( function () {
  383. // var ol = body.getElementsByTagName( 'ol' );
  384. // equal( ol.length, 0, '列表被删除了' );
  385. // start();
  386. // }, 100 );
  387. // }, 100 );
  388. // stop();
  389. //} );
  390. //
  391. //test( '<strong><span style="color: red">列表有内容处</span></strong>回车', function () {
  392. // var editor = te.obj[0];
  393. // var range = te.obj[1];
  394. // var body = editor.body;
  395. // editor.setContent( '<ol><li>列表1</li><li>列表2</li></ol>' );
  396. // var lis = body.getElementsByTagName( 'li' );
  397. // range.setStart( lis[1].firstChild, 1 ).collapse( 1 ).select();
  398. // editor.focus();
  399. // var br = ua.browser.ie ? '' : '<br>';
  400. // setTimeout( function () {
  401. // te.presskey( "enter", "" );
  402. // editor.focus();
  403. // setTimeout( function () {
  404. // var ol = body.getElementsByTagName( 'ol' )[0];
  405. // lis = ol.childNodes;
  406. // equal( lis.length, 3, '3个li' );
  407. // for ( var index = 0; index < lis.length; index++ )
  408. // equal( lis[index].tagName.toLowerCase(), 'li', 'tag名为li' );
  409. // equal( ua.getChildHTML( lis[1] ), '<p>列表2</p>', '第二个列表自动加了p' );
  410. // equal( ua.getChildHTML( lis[2] ), '<p>' + br + '</p>', '新增了一个列表项' );
  411. // start();
  412. // }, 70 );
  413. // }, 100 );
  414. // stop();
  415. //} );
  416. //
  417. //
  418. //test( 'trace766 :<strong><span style="color: red">BIU文本中间</span></strong>回车', function () {
  419. // var editor = te.obj[0];
  420. // var range = te.obj[1];
  421. // var body = editor.body;
  422. // editor.setContent( '<p><span style="color:red"><em><strong>有样式的文本</strong></em></span></p>' );
  423. //
  424. // var str = body.getElementsByTagName( 'strong' )[0];
  425. // range.setStart( str.firstChild, 2 ).collapse( 1 ).select();
  426. // editor.focus();
  427. // var br = ua.browser.ie ? '' : '<br>';
  428. // setTimeout( function () {
  429. // te.presskey( "enter", "" );
  430. // editor.focus();
  431. // setTimeout( function () {
  432. //// ua.checkHTMLSameStyle( '<span style="color:red"><em><strong>有样​</strong></em></span>', editor.document, body.firstChild, '查看第1个p的内容' );
  433. // //1.2版本中,回车/空格只后有不可见的字符,ua.checkHTMLSameStyle检查的话,<strong>的内容不好检查,即<strong>会多出一个子节点,改成如下:
  434. // baidu.editor.dom.domUtils.removeDirtyAttr( body.lastChild );
  435. // if ( ua.browser.chrome ) {
  436. // equal( body.firstChild.innerHTML.toLowerCase(), '<span style=\"color:red\"><em><strong>有样​</strong></em></span>', '查看第1个p的内容' );
  437. // ua.checkHTMLSameStyle( '<span style="color:red"><em><strong>式的文本</strong></em></span>', editor.document, body.lastChild, '查看第2个p的内容' );
  438. // }
  439. // else if ( ua.browser.gecko ) {
  440. // equal( body.firstChild.innerHTML.toLowerCase(), '<span style=\"color: red;\"><em><strong>有样</strong></em></span>', '查看第1个p的内容' );
  441. // equal( body.lastChild.innerHTML, '<span style=\"color:red\"><em><strong>​式的文本</strong></em></span>', '查看第2个p的内容' );
  442. // }
  443. // else {
  444. // equal( body.firstChild.innerHTML.toLowerCase(), '<span style=\"color: red\"><em><strong>有样​</strong></em></span>', '查看第1个p的内容' );
  445. // ua.checkHTMLSameStyle( '<span style="color:red"><em><strong>式的文本</strong></em></span>', editor.document, body.lastChild, '查看第2个p的内容' );
  446. // }
  447. // start();
  448. // }, 70 );
  449. // }, 100 );
  450. // stop();
  451. //} );
  452. //
  453. //test( 'trace841 :<strong><span style="color: red">BIU文本后面</span></strong>回车', function () {
  454. // var editor = te.obj[0];
  455. // var range = te.obj[1];
  456. // var body = editor.body;
  457. // editor.setContent( '<p><span style="color:red"><em><strong>有样式的文本</strong></em></span></p>' );
  458. // var strong = body.getElementsByTagName( 'strong' )[0];
  459. //// range.setStart( strong.firstChild, 6 ).collapse( 1 ).select();
  460. // range.setStart( strong, 1 ).collapse( 1 ).select();
  461. // editor.focus();
  462. // setTimeout( function () {
  463. // te.presskey( "enter", "" );
  464. // editor.focus();
  465. // setTimeout( function () {
  466. // ua.keydown( body, {keyCode:13} );
  467. // baidu.editor.dom.domUtils.removeDirtyAttr( body.lastChild );
  468. //// ua.checkHTMLSameStyle( '<span style="color:red"><em><strong>有样​</strong></em></span>', editor.document, body.firstChild, '查看第1个p的内容' );
  469. // //1.2版本中,回车/空格只后有不可见的字符,ua.checkHTMLSameStyle检查的话,<strong>的内容不好检查,即<strong>会多出一个子节点,而且每种浏览器的具体结果不同,改成如下:
  470. // if ( ua.browser.chrome )
  471. // equal( body.firstChild.innerHTML.toLowerCase(), '<span style=\"color:red\"><em><strong>有样式的文本​</strong></em></span>', '查看第1个p的内容' );
  472. // else if ( ua.browser.gecko )
  473. // equal( body.firstChild.innerHTML.toLowerCase(), '<span style=\"color: red;\"><em><strong>有样式的文本</strong></em></span>', '查看第1个p的内容' );
  474. // else
  475. // equal( body.firstChild.innerHTML.toLowerCase(), '<span style=\"color: red\"><em><strong>有样式的文本​</strong></em></span>', '查看第1个p的内容' );
  476. // /*ie中有一个已知bug,trace841,暂时不修的*/
  477. // var br = ua.browser.gecko ? '' : '<br>';
  478. // if ( !ua.browser.ie ) {
  479. // /*firefox不知道为什么用程序的方式回车始终不会产生br,可能太快了,浏览器没来得及处理*/
  480. // if ( ua.browser.gecko )
  481. // equal( body.lastChild.innerHTML, '<span style=\"color:red\"><em><strong>​</strong></em></span>', '查看第2个p的内容' );
  482. // else
  483. // ua.checkHTMLSameStyle( '<span style="color:red"><em><strong>' + br + '</strong></em></span>', editor.document, body.lastChild, '查看第2个p的内容' );
  484. // }
  485. // start();
  486. // }, 500 );
  487. // }, 100 );
  488. // stop();
  489. //} );
  490. //
  491. //
  492. //test( '<strong><span style="color: red">不闭合选择</span></strong>普通文本回车', function () {
  493. // var editor = te.obj[0];
  494. // var range = te.obj[1];
  495. // var body = editor.body;
  496. // editor.setContent( '<p>普通文本回车</p>' );
  497. // range.setStart( body.firstChild.firstChild, 2 ).setEnd( body.firstChild.firstChild, 4 ).select();
  498. // editor.focus();
  499. // setTimeout( function () {
  500. // te.presskey( "enter", "" );
  501. // editor.focus();
  502. // setTimeout( function () {
  503. // var ps = body.childNodes;
  504. // equal( ps.length, 2, '2个p' );
  505. // equal( ps[0].tagName.toLowerCase(), 'p', 'tag名为p' );
  506. // equal( ps[1].tagName.toLowerCase(), 'p', 'tag名为p' );
  507. // equal( ua.getChildHTML( ps[0] ), '普通', '第一个p里是你好编辑器' );
  508. // equal( ua.getChildHTML( ps[1] ), '回车', '第2个p里是br' );
  509. // start();
  510. // }, 60 );
  511. // }, 100 );
  512. // stop();
  513. //} );
  514. //
  515. //test( '<strong><span style="color: red">不闭合选择</span></strong>段落回车', function () {
  516. // var editor = te.obj[0];
  517. // var range = te.obj[1];
  518. // var body = editor.body;
  519. // editor.setContent( '<p>不闭合选择两个段落1</p><p>不闭合选择两个段落2</p>' );
  520. // range.setStart( body.firstChild.firstChild, 3 ).setEnd( body.lastChild.firstChild, 5 ).select();
  521. // editor.focus();
  522. // var br = ua.browser.ie ? '' : '<br>';
  523. // setTimeout( function () {
  524. // te.presskey( "enter", "" );
  525. // editor.focus();
  526. // setTimeout( function () {
  527. // var ps = body.childNodes;
  528. // equal( ps.length, 2, '2个p' );
  529. // equal( ps[0].tagName.toLowerCase(), 'p', 'tag名为p' );
  530. // equal( ps[1].tagName.toLowerCase(), 'p', 'tag名为p' );
  531. // equal( ua.getChildHTML( ps[0] ), '不闭合', '第一个p里是你好编辑器' );
  532. // equal( ua.getChildHTML( ps[1] ), '两个段落2', '第一个p里是br' );
  533. // start();
  534. // }, 60 );
  535. // }, 100 );
  536. // stop();
  537. //} );
  538. //
  539. //
  540. //test( '撤销<strong><span style="color: red">回车不闭合删除</span></strong>段落', function () {
  541. // var editor = te.obj[0];
  542. // var range = te.obj[1];
  543. // var body = editor.body;
  544. // editor.setContent( '<p>不闭合选择两个段落1</p><p>不闭合选择两个段落2</p>' );
  545. // range.setStart( body.firstChild.firstChild, 3 ).setEnd( body.lastChild.firstChild, 5 ).select();
  546. // editor.focus();
  547. // var br = ua.browser.ie ? '' : '<br>';
  548. // setTimeout( function () {
  549. // te.presskey( "enter", "" );
  550. // editor.focus();
  551. // setTimeout( function () {
  552. // var ps = body.childNodes;
  553. // equal( ps.length, 2, '2个p' );
  554. // equal( ps[0].tagName.toLowerCase(), 'p', 'tag名为p' );
  555. // equal( ps[1].tagName.toLowerCase(), 'p', 'tag名为p' );
  556. // equal( ua.getChildHTML( ps[0] ), '不闭合', '第一个p里是你好编辑器' );
  557. // equal( ua.getChildHTML( ps[1] ), '两个段落2', '第一个p里是br' );
  558. // editor.undoManger.undo();
  559. // equal( ps.length, 2, '2个p' );
  560. // equal( ps[0].tagName.toLowerCase(), 'p', 'tag名为p' );
  561. // equal( ps[1].tagName.toLowerCase(), 'p', 'tag名为p' );
  562. // equal( ua.getChildHTML( ps[0] ), '不闭合选择两个段落1', '第一个p里是你好编辑器' );
  563. // equal( ua.getChildHTML( ps[1] ), '不闭合选择两个段落2', '第一个p里是br' );
  564. // start();
  565. // }, 60 );
  566. // }, 100 );
  567. // stop();
  568. //} );
  569. //
  570. ///*1723 ie 在源码中写<ol><li></li></ol>,自动变成<ol><li><p><br></p></li></ol>,在ie中<br>会导致undo操作多记了一步*/
  571. //test( '撤销<strong><span style="color: red">回车删除空列表</span></strong>', function () {
  572. // var editor = te.obj[0];
  573. // var range = te.obj[1];
  574. // var body = editor.body;
  575. // editor.setContent( '<ol><li></li></ol>' );
  576. // var li = body.getElementsByTagName( 'li' )[0];
  577. // range.setStart( li.firstChild, 0 ).collapse( 1 ).select();
  578. // editor.focus();
  579. //
  580. // setTimeout( function () {
  581. // te.presskey( "enter", "" );
  582. // /*好像用程序控制按回车的速度会比程序捕获的速度快,
  583. // 所以程序还没反应过来时keydown已经触发完了,
  584. // 而keydown中用于进行场景保存的,这样就会导致undo操作失效*/
  585. // ua.keydown( body );
  586. // editor.focus();
  587. // setTimeout( function () {
  588. // var ol = body.getElementsByTagName( 'ol' );
  589. // equal( ol.length, 0, '列表被删除了' );
  590. // setTimeout( function () {
  591. // editor.undoManger.undo();
  592. // equal( ua.getChildHTML( body ), '<ol><li><p><br></p></li></ol>', '撤销删除列表' );
  593. // start();
  594. // }, 50 );
  595. //
  596. // }, 150 );
  597. // }, 100 );
  598. // stop();
  599. //} );
  600. //
  601. //test( '撤销<strong><span style="color: red">列表中的</span></strong>回车', function () {
  602. // var editor = te.obj[0];
  603. // var range = te.obj[1];
  604. // var body = editor.body;
  605. // editor.setContent( '<ol><li>列表</li></ol>' );
  606. // var li = body.getElementsByTagName( 'li' )[0];
  607. // range.setStart( li.firstChild, 1 ).collapse( 1 ).select();
  608. // editor.focus();
  609. // var br = ua.browser.ie ? '' : '<br>';
  610. //
  611. // setTimeout( function () {
  612. // te.presskey( "enter", "" );
  613. // ua.keydown( body );
  614. // editor.focus();
  615. // setTimeout( function () {
  616. // var li = body.getElementsByTagName( 'li' );
  617. // equal( li.length, 2, '2个列表子项' );
  618. // equal( ua.getChildHTML( li[0] ), '<p>列表</p>' );
  619. // equal( ua.getChildHTML( li[1] ), '<p>' + br + '</p>' );
  620. // editor.undoManger.undo();
  621. // equal( ua.getChildHTML( body ), '<ol><li><p>列表</p></li></ol>', '撤销后列表恢复原状' );
  622. // start();
  623. // }, 250 );
  624. // }, 100 );
  625. // stop();
  626. //} );