autotypeset.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. module('plugins.autotypeset');
  2. test('全角半角转换',function(){
  3. window.localStorage.clear();
  4. var editor = te.obj[0];
  5. editor.setContent('<p>Mayday123,.Mayday123,.</p>');
  6. var text = editor.getContent();
  7. equal(text,'<p>Mayday123,.Mayday123,.</p>','半角全角内容输入正确');
  8. editor.execCommand('autotypeset');
  9. var text2 = editor.body.firstChild.innerHTML;
  10. equal(text2,'Mayday123,.Mayday123,.','半角全角内容输入正确2');
  11. editor.options.autotypeset.tobdc=true;
  12. editor.execCommand('autotypeset');
  13. equal(editor.body.firstChild.innerHTML,'Mayday123,.Mayday123,.','内容转为全角:正确');
  14. editor.options.autotypeset.tobdc=false;
  15. editor.setContent('<p>Mayday123,.Mayday123,.</p>');
  16. editor.options.autotypeset.bdc2sb=true;
  17. editor.execCommand('autotypeset');
  18. equal(editor.body.firstChild.innerHTML,'Mayday123,.Mayday123,.','内容转为半角:正确');
  19. editor.options.autotypeset.bdc2sb=false;
  20. });
  21. //todo
  22. test('文本居中',function(){
  23. var editor = te.obj[0];
  24. editor.setContent('<p>p文本<br></p>');
  25. setTimeout(function(){
  26. editor.options.autotypeset.textAlign = 'center';
  27. editor.execCommand('autotypeset');
  28. equal($(editor.body.firstChild).css('text-align'),'center','文本居中');
  29. start();
  30. }, 100 );
  31. stop();
  32. });
  33. test('trace:2183 h1标题居中',function(){
  34. var editor = te.obj[0];
  35. editor.setContent('<h1>h1标题<br /></h1>');
  36. setTimeout(function(){
  37. editor.options.autotypeset.textAlign = 'center';
  38. editor.execCommand('autotypeset');
  39. equal($(editor.body.firstChild).css('text-align'),'center','h1标题居中');
  40. start();
  41. }, 50 );
  42. stop();
  43. });
  44. test('合并空行',function(){
  45. var editor = te.obj[0];
  46. editor.setContent('<p>欢迎使用</p><p><br /></p><p><br /></p><p>ueditor!</p>');
  47. setTimeout(function(){
  48. editor.options.autotypeset.mergeEmptyline = true;
  49. delete editor.options.autotypeset.textAlign;
  50. editor.execCommand('autotypeset');
  51. ua.manualDeleteFillData(editor.body);
  52. var html =editor.body.innerHTML.toLowerCase().replace(/\r\n/ig,'');
  53. equal(html,'<p>欢迎使用</p><p><br></p><p>ueditor!</p>','合并空行');
  54. start();
  55. }, 50 );
  56. stop();
  57. });
  58. test('带有图片表情',function(){
  59. var editor = te.obj[0];
  60. editor.setContent('<p>欢迎使用ueditor!<img src="http://img.baidu.com/hi/jx2/j_0015.gif" /></p>');
  61. editor.execCommand('autotypeset');
  62. equal($(editor.body.lastChild).css('text-align'),'center','图片居中');
  63. editor.options.autotypeset.imageBlockLine = 'left';
  64. editor.execCommand('autotypeset');
  65. equal($(editor.body.lastChild).css('text-align'),'left','图片居左');
  66. });
  67. test('删除空行',function(){
  68. var editor = te.obj[0];
  69. editor.setContent('<p>欢迎使用</p><p><br /></p><p><br /></p><p>ueditor!</p>');
  70. setTimeout(function(){
  71. editor.options.autotypeset.mergeEmptyline = false;//removeEmptyline
  72. editor.options.autotypeset.removeEmptyline = true;
  73. delete editor.options.autotypeset.textAlign;
  74. editor.execCommand('autotypeset');
  75. ua.manualDeleteFillData(editor.body);
  76. equal(editor.body.innerHTML.toLowerCase().replace(/\r\n/ig,''),'<p>欢迎使用</p><p>ueditor!</p>','删除空行');
  77. start();
  78. }, 50 );
  79. stop();
  80. });
  81. test('首行缩进',function(){
  82. var editor = te.obj[0];
  83. editor.setContent('<p>欢迎使用ueditor!</p>');
  84. setTimeout(function(){
  85. editor.options.autotypeset.indent = true;
  86. editor.options.autotypeset.textAlign= "left";
  87. editor.execCommand('autotypeset');
  88. ua.manualDeleteFillData(editor.body);
  89. var html = '<p style=\"text-indent: 2em; text-align: left; \">欢迎使用ueditor!</p>';
  90. ua.checkHTMLSameStyle(html ,editor.document,editor.body,'首行缩进');
  91. start();
  92. }, 50 );
  93. stop();
  94. });
  95. /*trace 2650*/
  96. test( 'trace 3277:图像对齐', function () {
  97. var editor = te.obj[0];
  98. editor.setContent( '<p><img src="http://img.baidu.com/hi/jx2/j_0001.gif" width="50" height="51" _src="http://img.baidu.com/hi/jx2/j_0001.gif"></p>' );
  99. setTimeout(function(){
  100. editor.options.autotypeset.imageBlockLine = 'center';
  101. delete editor.options.autotypeset.textAlign;//imageBlockLine
  102. var html= '<p style="text-align:center"><img src="http://img.baidu.com/hi/jx2/j_0001.gif" width="50" height="51" _src="http://img.baidu.com/hi/jx2/j_0001.gif"/></p>';
  103. editor.execCommand('autotypeset');
  104. ua.checkHTMLSameStyle(html ,editor.document,editor.body,'图像对齐');
  105. start();
  106. }, 50 );
  107. stop();
  108. } );
  109. //ie下
  110. test('trace 2651:字体样式',function(){
  111. var editor = te.obj[0];
  112. editor.setContent('<p><span style="font-size:24px;font-family:黑体, simhei;">欢迎使用ue</span>ditor!</p>');
  113. setTimeout(function(){
  114. editor.options.autotypeset.clearFontSize = editor.options.autotypeset.clearFontFamily = true;
  115. delete editor.options.autotypeset.textAlign;
  116. editor.execCommand('autotypeset');
  117. equal(ua.getChildHTML(editor.body),'<p>欢迎使用ueditor!</p>','恢复字体默认样式');
  118. start();
  119. }, 50 );
  120. stop();
  121. });
  122. test('去掉class,去掉多余节点',function(){
  123. var editor = te.obj[0];
  124. editor.setContent('<p class="noBorder">欢迎使用ueditor!</p>');
  125. editor.options.autotypeset.removeClass = true;
  126. delete editor.options.autotypeset.textAlign;
  127. editor.execCommand('autotypeset');
  128. equal(ua.getChildHTML(editor.body),'<p>欢迎使用ueditor!</p>','去掉class');
  129. });
  130. test('粘贴过滤',function(){
  131. var div = document.body.appendChild(document.createElement('div'));
  132. var editor = te.obj[0];
  133. editor.setContent('');
  134. editor.options.autotypeset.pasteFilter = true;
  135. editor.options.autotypeset.removeEmptyline = true;
  136. delete editor.options.autotypeset.textAlign;
  137. editor.execCommand('autotypeset');
  138. var html ={html:'<img src="http://img.baidu.com/hi/jx2/j_0015.gif" />hello1'};
  139. editor.fireEvent('beforepaste',html);
  140. editor.execCommand( 'insertHtml',html.html,true);
  141. editor.fireEvent("afterpaste");
  142. var txt='<p style="text-align:center;"><img src="http://img.baidu.com/hi/jx2/j_0015.gif"></p>hello1';
  143. ua.checkHTMLSameStyle(txt, editor.document, editor.body, '文字左对齐,表情居中');
  144. editor.setContent('');
  145. editor.options.autotypeset.imageBlockLine = 'none';
  146. editor.options.autotypeset.textAlign = 'center';
  147. editor.options.autotypeset.removeEmptyline = true;
  148. editor.options.autotypeset.pasteFilter = true;
  149. editor.execCommand('autotypeset');
  150. html ={html:'<p>hello1</p><p style="text-align:center;"><img src="http://img.baidu.com/hi/jx2/j_0001.gif"/></p><p>hello2</p>'};
  151. editor.fireEvent('beforepaste',html);
  152. editor.execCommand( 'insertHtml',html.html,true);
  153. editor.fireEvent("afterpaste");
  154. txt='<p style="text-align:center;">hello1<img src="http://img.baidu.com/hi/jx2/j_0001.gif" style="float: none;">hello2</p>';
  155. ua.checkHTMLSameStyle(txt, editor.document, editor.body, '文字居中,表情居左');
  156. });
  157. test('trace:4018,4012',function(){
  158. var div = document.body.appendChild(document.createElement('div'));
  159. div.id = 'ue2';
  160. var editor2 = UE.getEditor('ue2');
  161. editor2.ready(function(){
  162. editor2.setContent('Mayday123,.Mayday123,.');
  163. var c = $('#edui18_state div');
  164. ua.click(c[4]);
  165. ua.click($("input")[19]);
  166. var d = $(".edui-autotypesetpicker-body tr");
  167. var e = d[7].getElementsByTagName('input');
  168. ua.click(e[0]);
  169. var button = $(".edui-autotypesetpicker-body button");
  170. ua.click(button[0]);
  171. if(ua.browser.ie&&ua.browser.ie==8){
  172. equal(editor2.getContent(),"<p style=\"TEXT-ALIGN: left\">Mayday123,.Mayday123,.</p>","未执行半角转全角");
  173. }else{
  174. equal(editor2.getContent(),'<p style="text-align: left;">Mayday123,.Mayday123,.</p>',"未执行半角转全角");
  175. }
  176. setTimeout(function () {
  177. UE.delEditor('ue2');
  178. window.localStorage.clear();
  179. start();
  180. }, 100);
  181. });
  182. stop();
  183. });
  184. test('trace:3991',function(){
  185. var editor3 = te.obj[0];
  186. setTimeout(function(){
  187. editor3.setContent('');
  188. editor3.execCommand('inserttable', {numCols: 3, numRows: 3});
  189. var text =editor3.body.getElementsByTagName('td')[0];
  190. var range = new baidu.editor.dom.Range(editor3.document);
  191. range.setStart(text,0).collapse(1).select();
  192. editor3.execCommand("inserttitlecol");
  193. equal(editor3.queryCommandState("inserttitlecol"),-1,'标题列不能向右合并');
  194. var f = $("#edui538_state")[0];
  195. start();
  196. }, 100);
  197. stop();
  198. });
  199. test('trace:3967',function(){
  200. var editor = te.obj[0];
  201. editor.setContent('123<br/>');
  202. editor.execCommand('insertorderedlist','decimal');
  203. editor.execCommand('source');
  204. setTimeout(function(){
  205. editor.execCommand('source');
  206. setTimeout(function(){
  207. editor.execCommand('source');
  208. var x = editor.getContent();
  209. ok(x.indexOf('br')== x.lastIndexOf('br'),'只有一个<br/>');
  210. start();
  211. },50)
  212. },50)
  213. stop();
  214. });