horizontal.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. module( "plugins.horizontal" );
  2. //normal
  3. test( 'horizontal', function() {
  4. var editor = te.obj[0];
  5. var d = editor.document;
  6. var range = te.obj[1];
  7. var db = editor.body;
  8. editor.setContent( '<b><i>top</i></b><p>bottom</p>' );
  9. setTimeout(function(){
  10. range.setStart( d.getElementsByTagName( 'em' )[0].firstChild, 0 ).setEnd( db.lastChild.firstChild, 5 ).select();
  11. equal( editor.queryCommandState( "horizontal" ), 0, "边界不在table里" );
  12. editor.execCommand( 'horizontal' );
  13. var spase = ua.browser.ie?'':'<br>';
  14. equal( ua.getChildHTML( db ), "<p><strong><em></em></strong></p><hr><p>m"+spase+"</p>", "边界不在table里" );
  15. start();
  16. },50);
  17. stop();
  18. } );
  19. test( 'horizontal_br', function() {//trace 3854
  20. var div = document.body.appendChild(document.createElement('div'));
  21. $(div).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc');
  22. var editor = new baidu.editor.Editor({'initialContent':'<p>欢迎使用ueditor</p>', 'autoFloatEnabled':false,enterTag:'br'});
  23. editor.render(div);
  24. editor.ready(function () {
  25. var range = new baidu.editor.dom.Range(editor.document);
  26. editor.setContent( '<ol><li><p>top</p></li></ol>' );
  27. range.setStart( editor.body.firstChild.firstChild, 1 ).collapse( true ).select();
  28. editor.execCommand( 'horizontal' );
  29. range = editor.selection.getRange();
  30. var containger = (ua.browser.ie&&ua.browser.ie<9)?editor.body.getElementsByTagName('li')[0]:editor.body.getElementsByTagName('hr')[0].nextSibling;
  31. var offset = (ua.browser.webkit||ua.browser.ie==11)?1:((ua.browser.ie&&ua.browser.ie<9)?3:0);
  32. if(!ua.browser.opera){
  33. ua.checkResult( range,containger,containger, offset, offset, true, 'check range' );
  34. }
  35. ua.manualDeleteFillData(editor.body);
  36. equal( ua.getChildHTML( editor.body.firstChild ), "<li><p>top</p><hr><br></li>", "在列表中插入分隔线,在分隔线后面添加p用于定位" );
  37. setTimeout(function(){
  38. te.dom.push(div);
  39. start();
  40. },50);
  41. });
  42. stop();
  43. } );
  44. test( 'horizontal-delkeydown', function() {
  45. var editor = te.obj[0];
  46. var d = editor.document;
  47. var range = te.obj[1];
  48. var db = editor.body;
  49. editor.setContent( '<b><i>top</i></b><p>bottom</p>' );
  50. setTimeout(function(){
  51. range.setStart( d.getElementsByTagName( 'em' )[0].firstChild, 0 ).setEnd( db.lastChild.firstChild, 5 ).select();
  52. editor.execCommand( 'horizontal' );
  53. setTimeout(function(){
  54. range.setStart( editor.body.lastChild, 0 ).collapse(true).select();
  55. editor.fireEvent('delkeydown',{});
  56. var spase = ua.browser.ie?'':'<br>';
  57. equal( ua.getChildHTML( db ), "<p><strong><em></em></strong></p><p>m"+spase+"</p>", "删除分隔符" );
  58. start();
  59. },50);
  60. },50);
  61. stop();
  62. } );
  63. test( '在列表中插入分隔线,回车符为p', function() {
  64. var editor = te.obj[0];
  65. var range = te.obj[1];
  66. var body = editor.body;
  67. editor.setContent( '<ol><li><p>top</p></li></ol>' );
  68. range.setStart( body.firstChild.firstChild, 1 ).collapse( true ).select();
  69. editor.execCommand( 'horizontal' );
  70. range = editor.selection.getRange();
  71. var p = body.firstChild.firstChild.lastChild;
  72. var offset = ((ua.browser.ie&&ua.browser.ie>8&&ua.browser.ie<11)||ua.browser.gecko)?0:1;
  73. if(!ua.browser.opera){
  74. ua.checkResult( range, p.firstChild, p.firstChild, offset, offset, true, 'check range' );
  75. }
  76. ua.manualDeleteFillData(editor.body);
  77. equal( ua.getChildHTML( body.firstChild ), "<li><p>top</p><hr><p></p></li>", "在列表中插入分隔线,在分隔线后面添加p用于定位" );
  78. } );
  79. //test( '在列表中插入分隔线,回车符为br', function() {
  80. //
  81. // var editor = new baidu.editor.Editor({'enterTag':'br'});
  82. // var div = document.body.appendChild(document.createElement('div'));
  83. // editor.render(div);
  84. // var range = new baidu.editor.dom.Range(editor.document);
  85. // var body = editor.body;
  86. // editor.setContent( '<ol><li>top</li></ol>' );
  87. // range.setStart( body.firstChild.firstChild, 1 ).collapse( true ).select();
  88. //
  89. // editor.execCommand( 'horizontal' );
  90. //
  91. // var li = body.firstChild.firstChild;
  92. // if ( !baidu.editor.browser.gecko ) {
  93. // equal( ua.getChildHTML( body ), "<ol><li><p>top</p><hr><br></li></ol>", "在列表中插入分隔线,在分隔线后面添加p用于定位" );
  94. // } else {
  95. // equal( ua.getChildHTML( body ), "<ol><li><p>top</p><hr></li></ol>", "ff在列表中插入分隔线" );
  96. // }
  97. // te.dom.push(div);
  98. //} );
  99. //table
  100. test( 'horizontal in table', function() {
  101. var editor = te.obj[0];
  102. var d = editor.document;
  103. var range = te.obj[1];
  104. editor.setContent( '<table><tr><td>1</td></tr><tr><td>2</td></tr></table>' );
  105. stop();
  106. setTimeout(function () {
  107. range.setStart(d.getElementsByTagName('tr')[0].firstChild, 0).setEnd(d.getElementsByTagName('tr')[1].firstChild, 0).select();
  108. equal(editor.queryCommandState("horizontal"), -1, "边界在table里");
  109. start();
  110. }, 50);
  111. } );
  112. //collapsed=true
  113. test( 'horizontal&&collapsed', function() {
  114. var editor = te.obj[0];
  115. var range = te.obj[1];
  116. var db = editor.body;
  117. editor.setContent( '<b><i>top</i></b><p>bottom</p>' );
  118. range.setStart( db.lastChild.firstChild, 0 ).collapse( true ).select();
  119. equal( editor.queryCommandState( "horizontal" ), 0, "边界不在table里" );
  120. editor.execCommand( 'horizontal' );
  121. var spase = ua.browser.ie?'':'<br>';
  122. equal( ua.getChildHTML( db ), "<p><strong><em>top</em></strong></p><hr><p>bottom"+spase+"</p>", "边界不在table里" );
  123. } );
  124. //TODO 1.2.6
  125. //test( 'trace 3338:horizontal&&enterTag', function() {
  126. // var editor = te.obj[0];
  127. // var range = te.obj[1];
  128. // editor.options.enterTag ='br';
  129. // editor.setContent( '<ol><li>top</li></ol>' );
  130. // range.setStartAfter(editor.body.firstChild.firstChild.firstChild).collapse( true ).select();
  131. // editor.execCommand('horizontal');
  132. // ua.manualDeleteFillData(editor.body);
  133. // var br = (ua.browser.ie && ua.browser.ie<9) || ua.browser.webkit?"<br>":"";
  134. // equal(ua.getChildHTML(editor.body), '<ol><li><p>top</p><hr>'+br+'</li></ol>', 'enterTag=br');
  135. //} );