pagebreak.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. module( 'plugins.pagebreak' );
  2. /*trace 1179*/
  3. //TODO bug没有修复,暂时注释
  4. test( '对合并过单元格的表格分页', function () {
  5. stop();
  6. var editor = te.obj[0];
  7. var range = te.obj[1];
  8. editor.setContent( '<p></p>' );
  9. range.setStart( editor.body.firstChild, 0 ).collapse( true ).select();
  10. editor.execCommand( 'inserttable', {numCols:5, numRows:5} );
  11. var trs = editor.body.getElementsByTagName( 'tr' );
  12. range.setStart( trs[0].firstChild, 0 ).collapse( 1 ).select();
  13. editor.currentSelectedArr = [trs[0].firstChild, trs[1].firstChild, trs[2].firstChild, trs[3].firstChild];
  14. editor.execCommand( 'mergecells' );
  15. editor.currentSelectedArr = [trs[1].childNodes[2], trs[1].childNodes[3], trs[2].childNodes[2], trs[2].childNodes[3]];
  16. editor.execCommand( 'mergecells' );
  17. range.setStart( trs[1].childNodes[1], 0 ).collapse( 1 ).select();
  18. editor.execCommand( 'pagebreak' );
  19. var tables = editor.body.getElementsByTagName( 'table' );
  20. var tr1 = tables[0].getElementsByTagName( 'tr' );
  21. equal( tables.length, 2, '应当拆为2个table' );
  22. equal( tr1.length, 1, '第一个table只有一行' );
  23. // equal( $( tr1 ).attr( 'rowspan' ), 1, 'rowspan为1' );
  24. //
  25. // tr1 = tables[1].getElementsByTagName( 'tr' );
  26. // equal( tr1.length, 3, '第2个table有3行' );
  27. // equal( $( tr1[0] ).attr( 'rowspan' ), 2, 'rowspan为2' );
  28. setTimeout( function () {
  29. /*src中有延时操作*/
  30. start();
  31. }, 200 );
  32. } );
  33. test( '对第一行的单元格进行分页', function () {
  34. stop();
  35. var editor = te.obj[0];
  36. var range = te.obj[1];
  37. editor.setContent( '<p></p>' );
  38. range.setStart( editor.body.firstChild, 0 ).collapse( true ).select();
  39. editor.execCommand( 'inserttable', {numCols:5, numRows:5} );
  40. var tds = editor.body.getElementsByTagName( 'td' );
  41. range.setStart( tds[1], 0 ).collapse( 1 ).select();
  42. var table = editor.body.getElementsByTagName( 'table' )[0];
  43. var tablehtml = ua.getChildHTML( table );
  44. editor.execCommand( 'pagebreak' );
  45. var hr = editor.body.firstChild;
  46. equal( ua.getChildHTML( editor.body.getElementsByTagName( 'table' )[0] ), tablehtml, '表格没发生变化' );
  47. equal( $( hr ).attr( 'class' ), 'pagebreak', '插入一个分页符' );
  48. equal( hr.tagName.toLowerCase(), 'hr', 'hr' );
  49. setTimeout( function () {
  50. /*trace 2383*/
  51. // range.setStart( tds[1], 0 ).collapse( 1 ).select();
  52. // editor.execCommand( 'pagebreak' );
  53. // range.setStart( tds[1], 0 ).collapse( 1 ).select();
  54. // editor.execCommand( 'pagebreak' );
  55. // editor.execCommand('source');
  56. // editor.execCommand('source');
  57. // var hr = editor.body.getElementsByTagName( 'hr' );
  58. // equal( ua.getChildHTML( editor.body.getElementsByTagName( 'table' )[0] ), tablehtml, '表格没发生变化' );
  59. // equal( $( hr[0] ).attr( 'class' ), 'pagebreak', '插入一个分页符' );
  60. // equal( hr.length, 3, 'hr' );
  61. start();
  62. }, 200 );
  63. } );
  64. test( '对最后一行的单元格进行分页', function () {
  65. stop();
  66. var editor = te.obj[0];
  67. var range = te.obj[1];
  68. editor.setContent( '<p></p>' );
  69. range.setStart( editor.body.firstChild, 0 ).collapse( true ).select();
  70. editor.execCommand( 'inserttable', {numCols:5, numRows:5} );
  71. var tds = editor.body.getElementsByTagName( 'td' );
  72. /*最后一行的单元格*/
  73. range.setStart( tds[24], 0 ).collapse( 1 ).select();
  74. editor.execCommand( 'pagebreak' );
  75. var ts = editor.body.getElementsByTagName( 'table' );
  76. var hr = editor.body.childNodes[1];
  77. equal( ts[0].getElementsByTagName( 'tr' ).length, 4, '第一个table 4行' );
  78. equal( ts[1].getElementsByTagName( 'tr' ).length, 1, '第2个table 1行' );
  79. equal( $( hr ).attr( 'class' ), 'pagebreak', '插入一个分页符' );
  80. equal( hr.tagName.toLowerCase(), 'hr', '插入的分页符是hr' );
  81. setTimeout( function () {
  82. start();
  83. }, 200 );
  84. } );
  85. test( '在段落中间闭合插入分页符', function () {
  86. stop();
  87. var editor = te.obj[0];
  88. var range = te.obj[1];
  89. var body = editor.body;
  90. editor.setContent( '<p>你好Ueditor</p>' );
  91. range.setStart( editor.body.firstChild.firstChild, 2 ).collapse( true ).select();
  92. editor.execCommand( 'pagebreak' );
  93. ua.manualDeleteFillData( editor.body );
  94. equal( body.childNodes.length, 3, '3个孩子' );
  95. equal( ua.getChildHTML( body.firstChild ), '你好' );
  96. equal( body.firstChild.tagName.toLowerCase(), 'p', '第一个孩子是p' );
  97. equal( $( body.firstChild.nextSibling ).attr( 'class' ), 'pagebreak' );
  98. equal( ua.getChildHTML( body.lastChild ), 'ueditor' );
  99. equal( body.lastChild.tagName.toLowerCase(), 'p', '第二个孩子是p' );
  100. setTimeout( function () {
  101. start();
  102. }, 100 );
  103. } );
  104. test( '选中部分段落再插入分页符', function () {
  105. stop();
  106. var editor = te.obj[0];
  107. var range = te.obj[1];
  108. var body = editor.body;
  109. editor.setContent( '<p>你好Ueditor</p><p>hello编辑器</p>' );
  110. range.setStart( body.firstChild.firstChild, 2 ).setEnd( body.lastChild.firstChild, 5 ).select();
  111. editor.execCommand( 'pagebreak' );
  112. ua.manualDeleteFillData( editor.body );
  113. equal( body.childNodes.length, 3, '3个孩子' );
  114. equal( ua.getChildHTML( body.firstChild ), '你好' );
  115. equal( $( body.firstChild.nextSibling ).attr( 'class' ), 'pagebreak' );
  116. equal( ua.getChildHTML( body.lastChild ), '编辑器' );
  117. equal( body.firstChild.tagName.toLowerCase(), 'p', '第一个孩子是p' );
  118. equal( body.lastChild.tagName.toLowerCase(), 'p', '第二个孩子是p' );
  119. setTimeout( function () {
  120. start();
  121. }, 200 );
  122. } );
  123. test( 'trace 1887:连续插入2次分页符,每次插入都在文本后面', function () {
  124. stop();
  125. var editor = te.obj[0];
  126. var range = te.obj[1];
  127. var body = editor.body;
  128. editor.setContent( '<p>你好</p>' );
  129. range.setStart( body.firstChild, 1 ).collapse( 1 ).select();
  130. editor.execCommand('pagebreak');
  131. range.setStart( body.firstChild, 1 ).collapse( 1 ).select();
  132. editor.execCommand('pagebreak');
  133. equal(body.childNodes.length,3,'3个孩子');
  134. //trace 1187,chrome和firefox下都会有br,目前的做法是第二次插入就把前一个删除
  135. equal(body.childNodes[1].childNodes.length,0,'hr没有孩子节点');
  136. setTimeout( function () {
  137. start();
  138. }, 200 );
  139. } );