indent.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. module( 'plugins.indent' );
  2. /*trace 1030*/
  3. test( '同时加缩进和段前距', function() {
  4. var editor = te.obj[0];
  5. var range = te.obj[1];
  6. editor.setContent('<p>hello1</p><p>hello2</p>');
  7. /*selectNode不能直接选body,否则在ff下回冒到外面去了,一直回冒到外面的html上去了*/
  8. // range.selectNode( editor.body ).select();
  9. setTimeout(function () {
  10. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.lastChild, 1).select();
  11. editor.execCommand('rowspacing', 15, 'top');
  12. editor.execCommand('indent');
  13. // stop()
  14. equal(editor.body.firstChild.style['textIndent'], '2em', '查看缩进量');
  15. equal(editor.queryCommandValue('rowspacing', 'top'), 15, '查询段前距');
  16. start();
  17. }, 50);
  18. stop();
  19. } );
  20. test( 'trace1241--首行缩进的状态反射', function() {
  21. var editor = te.obj[0];
  22. var range = te.obj[1];
  23. editor.setContent( '<h1>hello1</h1>' );
  24. setTimeout(function(){
  25. range.setStart( editor.body.firstChild, 1 ).collapse( 1 ).select();
  26. equal( editor.queryCommandState( 'indent' ), 0, '开始没有缩进' );
  27. editor.execCommand( 'indent' );
  28. equal( editor.queryCommandState( 'indent' ), 1, '有缩进' );
  29. editor.execCommand( 'indent' );
  30. equal( editor.queryCommandState( 'indent' ), 0, '没有缩进' );
  31. start();
  32. },50);
  33. stop();
  34. } );
  35. /*trace 1031*/
  36. test( '缩进后再h1', function() {
  37. var editor = te.obj[0];
  38. var range = te.obj[1];
  39. editor.setContent( '<p>hello1</p><p>hello2</p>' );
  40. setTimeout(function () {
  41. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.lastChild, 1).select();
  42. editor.execCommand('indent');
  43. editor.execCommand('paragraph', 'h1');
  44. equal(editor.queryCommandValue('paragraph'), 'h1', '段落格式为h1');
  45. equal(editor.body.firstChild.style['textIndent'], '2em', '查看缩进量');
  46. start();
  47. }, 50);
  48. stop();
  49. } );
  50. test( '先设h1再缩进', function() {
  51. var editor = te.obj[0];
  52. var range = te.obj[1];
  53. editor.setContent( '<p>hello1</p><p>hello2</p>' );
  54. setTimeout(function () {
  55. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.lastChild, 1).select();
  56. editor.execCommand('paragraph', 'h1');
  57. editor.execCommand('indent');
  58. // equal(editor.queryCommandValue('paragraph'), 'h1', '段落格式为h1');
  59. equal(editor.body.firstChild.style['textIndent'], '2em', '查看缩进量');
  60. start();
  61. }, 50);
  62. stop();
  63. } );
  64. /*trace 1479 首行缩进按钮功能有效*/
  65. test('trace 1479 首行缩进按钮功能有效',function(){
  66. var editor = te.obj[0];
  67. var range = te.obj[1];
  68. editor.setContent('<p>hello</p>');
  69. setTimeout(function () {
  70. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  71. editor.execCommand('indent');
  72. equal(editor.body.firstChild.style['textIndent'], '2em', '选择文字,首行缩进');//text-indent:2em
  73. equal(editor.queryCommandState('indent'), 1, '缩进按钮高亮');
  74. start();
  75. }, 50);
  76. stop();
  77. });
  78. /*trace 1516 选Heading格式的文字首行缩进按钮高亮*/
  79. test('trace 1516 选Heading格式的文字首行缩进按钮高亮',function(){
  80. var editor = te.obj[0];
  81. var range = te.obj[1];
  82. editor.setContent( '<h1>hello</h1>' );
  83. setTimeout(function(){
  84. range.setStart(editor.body.firstChild,0).collapse(true).select();
  85. editor.execCommand( 'indent' );
  86. equal(editor.body.firstChild.style['textIndent'], '2em', '选Heading格式的文字首行缩进');//text-indent:2em
  87. equal(editor.queryCommandState('indent'), 1, '缩进按钮高亮');
  88. start();
  89. },50);
  90. stop();
  91. });
  92. test( '先对齐方式再缩进', function() {
  93. var editor = te.obj[0];
  94. var range = te.obj[1];
  95. editor.setContent( '<p>hello1</p><p>hello2</p>' );
  96. setTimeout(function () {
  97. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.lastChild, 1).select();
  98. editor.execCommand('justify', 'right');
  99. editor.execCommand('indent');
  100. equal(editor.queryCommandValue('justify'), 'right', '段落格式为h1');
  101. equal(editor.body.firstChild.style['textIndent'], '2em', '查看缩进量');
  102. start();
  103. }, 50);
  104. stop();
  105. } );
  106. test( '先缩进再对齐方式', function() {
  107. var editor = te.obj[0];
  108. var range = te.obj[1];
  109. editor.setContent( '<p>hello1</p><p>hello2</p>' );
  110. setTimeout(function () {
  111. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.lastChild, 1).select();
  112. editor.execCommand('indent');
  113. editor.execCommand('justify', 'right');
  114. equal(editor.queryCommandValue('justify'), 'right', '段落格式为h1');
  115. equal(editor.body.firstChild.style['textIndent'], '2em', '查看缩进量');
  116. start();
  117. }, 50);
  118. stop();
  119. } );
  120. /*trace 1033*/
  121. test( '非闭合取消缩进', function() {
  122. var editor = te.obj[0];
  123. var range = te.obj[1];
  124. editor.setContent('<p>hello1</p><p>hello2</p>');
  125. setTimeout(function () {
  126. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.lastChild, 1).select();
  127. editor.execCommand('indent');
  128. equal(editor.body.firstChild.style['textIndent'], '2em', '查看缩进量');
  129. editor.execCommand('indent');
  130. equal(editor.body.firstChild.style['textIndent'], '0em', '查看缩进量');
  131. start();
  132. }, 50);
  133. stop();
  134. } );
  135. test( '闭合取消缩进', function() {
  136. var editor = te.obj[0];
  137. var range = te.obj[1];
  138. editor.setContent( '<p>hello1</p><p>hello2</p>' );
  139. setTimeout(function () {
  140. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.lastChild, 1).select();
  141. editor.execCommand('indent');
  142. equal(editor.body.firstChild.style['textIndent'], '2em', '查看缩进量');
  143. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  144. ua.manualDeleteFillData(editor.body);
  145. editor.execCommand('indent');
  146. equal(editor.body.firstChild.style['textIndent'], '0em', '查看缩进量');
  147. start();
  148. }, 50);
  149. stop();
  150. } );
  151. //test( '表格内闭合缩进和取消缩进', function() {
  152. // var editor = te.obj[0];
  153. // var range = te.obj[1];
  154. // editor.setContent( '<table><tbody><tr><td></td><td></td></tr><tr><td><p>hello</p></td><td></td></tr></tbody></table>' );
  155. // var tds = editor.body.firstChild.getElementsByTagName( 'td' );
  156. // range.setStart( tds[0], 0 ).collapse( true ).select();
  157. // editor.execCommand( 'indent' );
  158. // ua.manualDeleteFillData( editor.body );
  159. // equal( tds[0].firstChild.tagName.toLowerCase(), 'p', '插入一个p标签' );
  160. // equal( tds[0].firstChild.style['textIndent'], '2em', '查看缩进量' );
  161. // range.setStart( tds[0].firstChild, 0 ).collapse( true ).select();
  162. // te.presskey( '', 'h' );
  163. // setTimeout( function() {
  164. // equal( tds[0].firstChild.style['textIndent'], '2em', '插入文本节点后查看缩进量' );
  165. // range.setStart( tds[0].firstChild, 0 ).collapse( true ).select();
  166. // editor.execCommand( 'indent' );
  167. // ua.manualDeleteFillData( editor.body );
  168. // equal( tds[0].firstChild.style['textIndent'], '0em', '取消缩进' );
  169. // /*选中一个单元格设置缩进*/
  170. // range.selectNode( tds[2] ).select();
  171. // editor.execCommand( 'indent' );
  172. // ua.manualDeleteFillData( editor.body );
  173. // equal( tds[2].firstChild.style['textIndent'], '2em', '查看缩进量' );
  174. // start();
  175. // }, 30 );
  176. // stop();
  177. //} );
  178. test( '多个单元格缩进和取消缩进', function() {
  179. var editor = te.obj[0];
  180. var range = te.obj[1];
  181. editor.setContent( '<table><tbody><tr><td>hello1</td><td>hello2<img /></td></tr><tr><td><div>hello3</div></td><td><p>hello4</p></td></tr></tbody></table>' );
  182. setTimeout(function () {
  183. var tds = editor.body.firstChild.getElementsByTagName('td');
  184. range.selectNode(editor.body.firstChild).select();
  185. editor.execCommand('indent');
  186. ua.manualDeleteFillData(editor.body);
  187. /*会自动在非block元素外面套p*/
  188. equal(tds[0].firstChild.tagName.toLowerCase(), 'p', '插入一个p标签');
  189. for (var index = 0; index < tds.length; index++) {
  190. equal(tds[index].firstChild.style['textIndent'], '2em', '查看第' + (index + 1) + '个单元格的缩进量');
  191. }
  192. range.selectNode(editor.body.firstChild).select();
  193. editor.execCommand('indent');
  194. for (index = 0; index < tds.length; index++) {
  195. equal(tds[index].firstChild.style['textIndent'], '0em', '查看第' + (index + 1) + '个单元格的缩进是否被取消');
  196. }
  197. start();
  198. }, 50);
  199. stop();
  200. } );
  201. /*trace 1097*/
  202. test( '列表中缩进', function() {
  203. var editor = te.obj[0];
  204. var range = te.obj[1];
  205. editor.setContent( '<ul><li>nihao</li><li>hello</li></ul>' );
  206. setTimeout(function () {
  207. range.setStart(editor.body.firstChild.firstChild, 0).collapse(true).select();
  208. editor.execCommand('indent');
  209. var p = editor.body.firstChild.firstChild.firstChild;
  210. equal(p.tagName.toLowerCase(), 'p', '自动创建一个p');
  211. equal(p.style['textIndent'], '2em', '设置缩进为2em');
  212. /*在有文本的列表中缩进*/
  213. range.setStart(editor.body.firstChild.lastChild.firstChild, 1).collapse(true).select();
  214. editor.execCommand('indent');
  215. p = editor.body.firstChild.lastChild.firstChild;
  216. equal(p.tagName.toLowerCase(), 'p', '自动创建一个p');
  217. equal(p.style['textIndent'], '2em', '设置缩进为2em');
  218. start();
  219. }, 50);
  220. stop();
  221. } )