justify.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. module( "plugins.justify" );
  2. test( '闭合在段落中设置对齐方式', function() {
  3. var editor = te.obj[0];
  4. var range = te.obj[1];
  5. var body = editor.body;
  6. editor.setContent( '<p><em>hello1</em></p>' );
  7. setTimeout(function(){
  8. range.setStart( body.firstChild.firstChild.firstChild, 3 ).collapse( true ).select();
  9. editor.execCommand( 'justify', 'center' );
  10. equal( body.firstChild.style['textAlign'], 'center', 'p对齐方式为居中对齐' );
  11. start();
  12. },50);
  13. stop();
  14. } );
  15. test( '不闭合在段落中设置对齐方式', function() {
  16. var editor = te.obj[0];
  17. var range = te.obj[1];
  18. var body = editor.body;
  19. editor.setContent( '<p><em>hello1</em></p><p><span style="color:red">hello2</span>hello3</p>' );
  20. setTimeout(function(){
  21. range.selectNode( body.firstChild.firstChild.firstChild ).select();
  22. editor.execCommand( 'justify', 'center' );
  23. equal( body.firstChild.style['textAlign'], 'center', 'p对齐方式为居中对齐' );
  24. range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select();
  25. editor.execCommand( 'justify', 'right' );
  26. equal( body.firstChild.style['textAlign'], 'right', 'p对齐方式为居中对齐' );
  27. equal( body.lastChild.style['textAlign'], 'right', 'p对齐方式为居中对齐' );
  28. range.setStart( body.firstChild.firstChild.firstChild, 3 ).collapse( true ).select();
  29. editor.execCommand( 'justify', 'center' );
  30. equal( body.firstChild.style['textAlign'], 'center', 'p对齐方式为居中对齐' );
  31. start();
  32. },50);
  33. stop();
  34. } );
  35. //test( '对齐方式-参数为json', function() {
  36. // var editor = te.obj[0];
  37. // var range = te.obj[1];
  38. // editor.setContent( '<table><tbody><tr><td></td><td><p>hello</p></td></tr></tbody></table>' );
  39. // setTimeout(function(){
  40. // var tds = editor.body.getElementsByTagName( 'td' );
  41. // range.setStart( tds[1].firstChild, 0 ).collapse( true ).select();
  42. // editor.execCommand( 'justify', 'right' );
  43. // equal( tds[1].firstChild.style['textAlign'], 'right', 'p对齐方式为右对齐' );
  44. // equal( editor.queryCommandValue( 'justify' ), 'right', 'querycommand value' );
  45. // start();
  46. // },50);
  47. // stop();
  48. //} );
  49. test( 'startContainer是body', function() {
  50. var editor = te.obj[0];
  51. var range = te.obj[1];
  52. editor.setContent( '<p><em>tell</em></p>' );
  53. setTimeout(function(){
  54. range.setStart( editor.body, 0 ).collapse( true ).select();
  55. editor.execCommand( 'justify', 'right' );
  56. equal( editor.queryCommandValue( 'justify' ), 'right', 'startContainer 是body' );
  57. equal( editor.queryCommandValue( 'justify' ), 'right', 'querycommand value' );
  58. /*json格式的参数*/
  59. range.setStart( editor.body, 0 ).collapse( true ).select();
  60. editor.execCommand( 'justify', {'text-align':'left'} );
  61. equal( editor.queryCommandValue( 'justify' ), 'left', 'startContainer 是body--json格式的参数' );
  62. start();
  63. },50);
  64. stop();
  65. } );
  66. test( '连续2次设置对齐方式', function() {
  67. var editor = te.obj[0];
  68. var range = te.obj[1];
  69. editor.setContent( '<p ><em>tell</em></p>' );
  70. setTimeout(function(){
  71. range.setStart( editor.body.firstChild.firstChild, 0 ).collapse( 1 ).select();
  72. editor.execCommand( 'justify', 'right' );
  73. equal( editor.queryCommandValue( 'justify' ), 'right', 'querycommand value' );
  74. range.setStart( editor.body.firstChild.firstChild, 0 ).collapse( 1 ).select();
  75. editor.execCommand( 'justify', 'center' );
  76. equal( editor.queryCommandValue( 'justify' ), 'center', 'querycommand value' );
  77. start();
  78. },50);
  79. stop();
  80. } );