1
0

lineheight.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. module( 'plugins.lineheight' );
  2. //test( '', function() {
  3. // equal('','','');
  4. //} );
  5. /*
  6. *
  7. *利用pict工具生成的用例设计结果,有微调。3to1表示先设置行距为3再设置为1,选区“singlePara”表示选中一个段落,
  8. * “multiPara”表示选中多个段落,“字号统一”表示所有的字号都是一样大,“16to36To16”表示先设置大小为16px,再设置为36,再设置为16
  9. 设置行距顺序 选区 选区内字号顺序
  10. <li>3to1 collapse 字号统一</li>
  11. <li>1 multiPara 36To16To36</li>
  12. <li>1to3to1 singlePara 字号统一</li>
  13. <li>1 collapse 16to36To16</li>
  14. <li>1to3to1 multiPara 16to36To16</li>
  15. <li>3to1 singlePara 36To16To16</li>
  16. <li>3 multiPara 字号统一</li>
  17. <li>1to3to1 collapse 36To16To16</li>
  18. <li>3to1 multiPara 16to36To16</li>
  19. <li>3 singlePara 16to36To16</li>
  20. * */
  21. //
  22. //var compareLineHeight = function ( node, value,fontSize, descript ) {
  23. // var currLineHeight = $(node).css('lineHeight').replace(/px/,'');
  24. // var spans = node.getElementsByTagName('')
  25. // value = value.replace( /px/, '' );
  26. // var baseLineHeight = (ua.browser.ie ? domUtils.getComputedStyle( node, 'font-size' ).replace( /px/, '' ) : node.offsetHeight);
  27. // var fontSize = $( node ).css( 'font-size' ).replace( /px/, '' );
  28. // if ( value >= fontSize && value >= baseLineHeight ) {
  29. // ok( true, descript );
  30. // } else {
  31. // ok( false, descript + '--- "lineHeight应取fontSize和baseLineHeight*倍数的最大值":lineHeight=' + value + ' ;font-sze=' + fontSize + ';baseLineHeight=' + baseLineHeight );
  32. // }
  33. //
  34. //}
  35. //
  36. ///*<li>3to1 collapse 字号统一</li>*/
  37. test( '闭合情况,字号统一', function () {
  38. var editor = te.obj[0];
  39. var range = te.obj[1];
  40. var body = editor.body;
  41. editor.setContent( '<p style="font-size: 36px">hello</p>' );
  42. range.setStart(body.firstChild, 1).collapse(1).select();
  43. editor.execCommand('lineheight', 3);
  44. setTimeout( function () {
  45. var p = body.firstChild;
  46. equal( editor.queryCommandValue('lineheight'), "3", '行间距为3');
  47. editor.execCommand('lineheight', 1);
  48. p = body.firstChild;
  49. equal( editor.queryCommandValue('lineheight'), "1", '行间距为1');
  50. equal( p.style['lineHeight'], 'normal', '检查行高' );
  51. equal( $( p ).css('font-size'), '36px', '检查字体');
  52. start();
  53. }, 20 );
  54. stop();
  55. } );
  56. /*<li>1 multiPara 36To16To36</li>*/
  57. //test( '多个段落设置多倍行距,段落中字体大小各不相同', function () {
  58. // var editor = te.obj[0];
  59. // var range = te.obj[1];
  60. // var body = editor.body;
  61. // editor.setContent( '<p style="font-size: 36px">hello</p><p style="font-size: 16px">hello</p><p style="font-size: 36px">hello</p>' );
  62. // range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select();
  63. // editor.execCommand( 'lineheight', 1 );
  64. // setTimeout( function () {
  65. // var ps = body.childNodes;
  66. // equal( $( ps[0] ).css( 'line-height' ), '36px', '第1个p行高为36px' );
  67. // equal( $( ps[1] ).css( 'line-height' ), '16px', '第2个p行高为36px' );
  68. // equal( $( ps[2] ).css( 'line-height' ), '36px', '第3个p行高为36px' );
  69. // range.selectNode( ps[0] ).select();
  70. // equal( editor.queryCommandValue( 'lineheight' ), "1", '第1个p行间距为1' );
  71. // range.selectNode( ps[0] ).select();
  72. // equal( editor.queryCommandValue( 'lineheight' ), "1", '第2个p行间距为1' );
  73. // range.selectNode( ps[0] ).select();
  74. // equal( editor.queryCommandValue( 'lineheight' ), "1", '第3个p行间距为1' );
  75. // start();
  76. // }, 20 );
  77. // stop();
  78. //} );
  79. //
  80. ///*<li>1 collapse 16to36To16</li>*/
  81. //test( '多个段落设置多倍行距,段落中字体大小各不相同', function () {
  82. // var editor = te.obj[0];
  83. // var range = te.obj[1];
  84. // var body = editor.body;
  85. // editor.setContent( '<p style="font-size: 16px">hello</p><p style="font-size: 36px">hello</p><p style="font-size: 16px">hello</p>' );
  86. // range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select();
  87. // editor.execCommand( 'lineheight', 1 );
  88. // setTimeout( function () {
  89. // var ps = body.childNodes;
  90. // compareLineHeight( ps[0], $( ps[0] ).css( 'line-height' ), '行距为1,第1个p行高' );
  91. // compareLineHeight( ps[1], $( ps[1] ).css( 'line-height' ), '行距为1,第2个p行高' );
  92. // compareLineHeight( ps[2], $( ps[2] ).css( 'line-height' ), '行距为1,第3个p行高' );
  93. // range.selectNode( ps[0] ).select();
  94. // equal( editor.queryCommandValue( 'lineheight' ), "1", '第1个p行间距为1' );
  95. // range.selectNode( ps[0] ).select();
  96. // equal( editor.queryCommandValue( 'lineheight' ), "1", '第2个p行间距为1' );
  97. // range.selectNode( ps[0] ).select();
  98. // equal( editor.queryCommandValue( 'lineheight' ), "1", '第3个p行间距为1' );
  99. // start();
  100. // }, 20 );
  101. // stop();
  102. //} );
  103. //
  104. ///*<li>1to3to1 singlePara 字号统一</li>*/
  105. //test( '1个段落设置多倍行距,字号相同', function () {
  106. // var editor = te.obj[0];
  107. // var range = te.obj[1];
  108. // var body = editor.body;
  109. // editor.setContent( '<p style="font-size: 36px">hello</p>' );
  110. // range.selectNode( body.firstChild ).select();
  111. // editor.execCommand( 'lineheight', 1 );
  112. // setTimeout( function () {
  113. // var p = body.firstChild;
  114. // equal( $( p ).css( 'line-height' ), '36px', '第1个p行高为36px' );
  115. // editor.execCommand( 'lineheight', 3 );
  116. // p = body.firstChild;
  117. // compareLineHeight( p, $( p ).css( 'line-height' ), '行距为1,第1个p行高' );
  118. // editor.execCommand( 'lineheight', 1 );
  119. // var p = body.firstChild;
  120. // equal( $( p ).css( 'line-height' ), '36px', '第1个p行高为36px' );
  121. // start();
  122. // }, 20 );
  123. // stop();
  124. //} );
  125. //
  126. ///* <li>1to3to1 multiPara 16to36To16</li>*/
  127. //test( '多个段落设置多倍行距,字号不同', function () {
  128. // var editor = te.obj[0];
  129. // var range = te.obj[1];
  130. // var body = editor.body;
  131. // editor.setContent( '<p style="font-size: 16px">hello</p><p style="font-size: 36px">hello</p><p style="font-size: 16px">hello</p>' );
  132. // range.setStart( body.firstChild.firstChild, 1 ).setEnd( body.lastChild.firstChild, 2 ).select();
  133. // editor.execCommand( 'lineheight', 1 );
  134. // setTimeout( function () {
  135. // var ps = body.childNodes;
  136. // compareLineHeight( ps[0], $( ps[0] ).css( 'line-height' ), '行距为1,第1个p行高' );
  137. // compareLineHeight( ps[1], $( ps[1] ).css( 'line-height' ), '行距为1,第2个p行高' );
  138. // compareLineHeight( ps[2], $( ps[2] ).css( 'line-height' ), '行距为1,第3个p行高' );
  139. // range.selectNode( ps[0] ).select();
  140. // equal( editor.queryCommandValue( 'lineheight' ), "1", '第3个p行间距为1' );
  141. //
  142. // range.setStart( body.firstChild.firstChild, 1 ).setEnd( body.lastChild.firstChild, 2 ).select();
  143. // editor.execCommand( 'lineheight', 3 );
  144. // ps = body.childNodes;
  145. // compareLineHeight( ps[0], $( ps[0] ).css( 'line-height' ), '行距为3,第1个p行高' );
  146. // compareLineHeight( ps[1], $( ps[1] ).css( 'line-height' ), '行距为3,第2个p行高' );
  147. // compareLineHeight( ps[2], $( ps[2] ).css( 'line-height' ), '行距为3,第3个p行高' );
  148. // range.selectNode( ps[0] ).select();
  149. // equal( editor.queryCommandValue( 'lineheight' ), "3", '第1个p行间距为1' );
  150. //
  151. // range.setStart( body.firstChild.firstChild, 1 ).setEnd( body.lastChild.firstChild, 2 ).select();
  152. // editor.execCommand( 'lineheight', 1 );
  153. // ps = body.childNodes;
  154. // compareLineHeight( ps[0], $( ps[0] ).css( 'line-height' ), '行距为1,第1个p行高' );
  155. // compareLineHeight( ps[1], $( ps[1] ).css( 'line-height' ), '行距为1,第2个p行高' );
  156. // compareLineHeight( ps[2], $( ps[2] ).css( 'line-height' ), '行距为1,第3个p行高' );
  157. // range.selectNode( ps[0] ).select();
  158. // equal( editor.queryCommandValue( 'lineheight' ), "1", '第1个p行间距为1' );
  159. // start();
  160. // }, 20 );
  161. // stop();
  162. //
  163. //} );