1
0

font.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. module("plugins.font");
  2. //test('stop',function(){stop();});
  3. test('trace1583:applyInlineStyle--MergeToParent', function () {
  4. var editor = te.obj[0];
  5. var range = te.obj[1];
  6. stop();
  7. setTimeout(function () {
  8. editor.setContent('<p>1<span style="font-size: 24px; ">23456<span style="font-size: 16px; ">7</span></span><span style="font-size: 16px; ">89</span>10</p>');
  9. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.firstChild, 4).select();
  10. editor.execCommand('fontsize', '24px');
  11. var html = '<span style=\"font-size: 24px;\">12345678910</span>';
  12. ua.checkSameHtml(editor.body.firstChild.innerHTML.toLowerCase(), html, '');
  13. start();
  14. }, 50);
  15. });
  16. test('trace 3337:字符边框', function () {
  17. if (ua.browser.opera)return;
  18. var editor = te.obj[0];
  19. var range = te.obj[1];
  20. editor.setContent('<p></p>');
  21. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  22. editor.execCommand('fontborder');
  23. range = editor.selection.getRange();
  24. range.insertNode(editor.document.createTextNode('hello'));
  25. ua.manualDeleteFillData(editor.body);
  26. var br = baidu.editor.browser.ie ? '&nbsp;' : '<br>';
  27. if (ua.browser.ie && ua.browser.ie < 9) {
  28. equal(editor.queryCommandValue('fontborder'), '#000 1px solid', '检查反射值');
  29. equal(ua.getChildHTML(editor.body.firstChild), "<span style=\"border-bottom: #000 1px solid; border-left: #000 1px solid; border-top: #000 1px solid; border-right: #000 1px solid\">hello</span>&nbsp;", '查看添加了字符边框后的样式');
  30. }
  31. else {
  32. equal(editor.queryCommandValue('fontborder'), '1px solid rgb(0, 0, 0)', '检查反射值');
  33. ua.checkHTMLSameStyle('<span style="border: 1px solid rgb(0, 0, 0);">hello</span>' + br, editor.document, editor.body.firstChild, '查看添加了字符边框后的样式');
  34. }
  35. range.setStart(editor.body.firstChild.firstChild.firstChild, 5).collapse(true).select();
  36. editor.execCommand('fontborder');
  37. equal(editor.queryCommandState('fontborder'), '0');
  38. equal(editor.queryCommandValue('fontborder'), '', '无反射值');
  39. editor.setContent('<p><span style="color: red">欢</span>迎光临</p>');
  40. range.setStart(editor.body.firstChild.firstChild, 0).setEnd(editor.body.firstChild.lastChild, 3).select();
  41. editor.execCommand('fontborder');
  42. var p1 = '<span style="border: 1px solid rgb(0, 0, 0);"><span style="color: red;">欢</span>迎光临</span>';
  43. var p2 = '<span style=\"border-bottom: #000 1px solid; border-left: #000 1px solid; border-top: #000 1px solid; border-right: #000 1px solid\"><span style="color: red;">欢</span>迎光临</span>';
  44. if (ua.browser.ie && ua.browser.ie < 9)
  45. ua.checkSameHtml(editor.body.firstChild.innerHTML, p2, '查看添加了字符边框后的样式');
  46. else
  47. ua.checkHTMLSameStyle(p1, editor.document, editor.body.firstChild, '查看添加了字符边框后的样式');
  48. });
  49. test('设置超链接前景色再清除颜色', function () {
  50. if (ua.browser.ie < 9)return;//TODO 1.2.6
  51. var editor = te.obj[0];
  52. var range = te.obj[1];
  53. editor.setContent('<p>hello<a href="www.baidu.com">baidu</a></p>');
  54. range.selectNode(editor.body.firstChild).select();
  55. editor.execCommand('forecolor', 'rgb(255,0,0)');
  56. editor.execCommand('backcolor', 'rgb(0,255,0)');
  57. editor.execCommand('forecolor', 'default');
  58. // var html = '<span style="background-color: rgb(0, 255, 0);">hello</span><a href="www.baidu.com" _href=\"www.baidu.com\" style="text-decoration: underline;"><span style="background-color: rgb(0, 255, 0);">baidu</span></a>';todo 1.2.6.1 样式复制了一次
  59. var html = '<span style="background-color: rgb(0, 255, 0);">hello</span><a href="www.baidu.com" _href=\"www.baidu.com\" style="background-color: rgb(0, 255, 0);text-decoration: underline;"><span style="background-color: rgb(0, 255, 0);">baidu</span></a>';
  60. ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '清除前景色');
  61. });
  62. test('font转span', function () {
  63. var editor = te.obj[0];
  64. editor.setContent('<font size="12" color="red" lang="en" face="arial"><b><i>hello</i>hello</b>');
  65. var html = '<span style="font-size:12px;color:red;font-family:arial"><strong><em>hello</em>hello</strong></span>';
  66. ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '转换font标签');
  67. /*size的值在sizeMap中有对应的值*/
  68. editor.setContent('<b><font size="10" color="#ff0000" lang="en" face="楷体">hello');
  69. html = '<strong><span style="font-size:10px;color:#ff0000;font-family:楷体">hello</span></strong>';
  70. ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '转换font标签');
  71. });
  72. test('beforegetContent', function () {
  73. var editor = te.obj[0];
  74. var range = te.obj[1];
  75. editor.body.innerHTML = '<p>hello<span></span></p>';
  76. range.selectNode(editor.body.firstChild).select();
  77. editor.execCommand('forecolor', 'rgb(255,0,0)');
  78. var div = document.createElement('div');
  79. var div1 = document.createElement('div');
  80. stop();
  81. setTimeout(function () {
  82. /*getContent会触发beforegetcontent事件*/
  83. div1.innerHTML = editor.getContent();
  84. div.innerHTML = '<p><span style="color: rgb(255, 0, 0);" >hello</span></p>';
  85. // ok( ua.haveSameAllChildAttribs( div, div1 ), '查看空span是否被删除' );
  86. // equal(ua.getChildHTML(div), ua.getChildHTML(div1));
  87. start();
  88. }, 50);
  89. });
  90. /*为超链接添加删除线,超链接仍然有删除线,trace946*/
  91. test('underline and linethrough', function () {
  92. var editor = te.obj[0];
  93. var range = te.obj[1];
  94. stop();
  95. editor.setContent('hello<a href="http://www.baidu.com/">baidu</a>test');
  96. setTimeout(function () {
  97. if (!ua.browser.opera) {
  98. editor.focus();
  99. }
  100. var body = editor.body;
  101. ua.manualDeleteFillData(editor.body);
  102. range.selectNode(body.firstChild.firstChild.nextSibling).select();
  103. ok(/underline/.test(editor.queryCommandValue('underline')), 'query command value is underline');
  104. ok(/underline/.test(editor.queryCommandValue('strikethrough')), 'query command value is underline');
  105. ok(editor.queryCommandState('underline'), 'query underline state');
  106. editor.execCommand('strikethrough');
  107. var html = 'hello<a href="http://www.baidu.com/" _href=\"http://www.baidu.com/\" style="text-decoration: line-through" >baidu</a>test';
  108. ua.checkHTMLSameStyle(html, editor.document, body.firstChild, 'check results');
  109. start();
  110. }, 50);
  111. });
  112. /*为不同字号的文本加背景色,trace981*/
  113. test('background--不同字号', function () {
  114. if (!ua.browser.opera) {
  115. var editor = te.obj[0];
  116. var range = te.obj[1];
  117. editor.setContent('你好');
  118. editor.focus();
  119. var body = editor.document.body;
  120. ua.manualDeleteFillData(editor.body);
  121. range.selectNode(body.firstChild.firstChild).select();
  122. editor.execCommand('backcolor', 'rgb(255,0,0)');
  123. range.setStart(body.firstChild.firstChild, 1).collapse(1).select();
  124. editor.execCommand('fontsize', '30px');
  125. range = editor.selection.getRange();
  126. range.insertNode(editor.document.createTextNode('hello'));
  127. stop();
  128. setTimeout(function () {
  129. ua.manualDeleteFillData(editor.body);
  130. /*去掉空白字符*/
  131. var color = ua.browser.ie && ua.browser.ie < 9 ? '' : ';background-color: rgb(255, 0, 0); ';
  132. var html = '<span style="background-color: rgb(255, 0, 0)">你好<span style="font-size: 30px ' + color + '">hello</span></span>';
  133. ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '检查不同字号的文本背景色是否一致');
  134. start();
  135. }, 50);
  136. }
  137. });
  138. /*trace 937,chrome,safari,maxthon有问题*/
  139. test('trace 937:为第一个有样式的字加删除线', function () {
  140. var editor = te.obj[0];
  141. var range = te.obj[1];
  142. editor.setContent('<p><span style="color: red">欢</span>迎光临</p>');
  143. range.selectNode(editor.body.firstChild).select();
  144. editor.execCommand('strikethrough');
  145. var p1 = editor.document.createElement('p');
  146. p1.innerHTML = '<span style="text-decoration: line-through;"><span style="text-decoration: line-through; color: red;">欢</span>迎光临</span>';
  147. ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '查看添加了下划线后的样式');
  148. });
  149. /*trace 918*/
  150. test('trace 918:字体的状态反射', function () {
  151. var editor = te.obj[0];
  152. var range = te.obj[1];
  153. editor.setContent('<p>欢迎你回来</p>');
  154. var p = editor.body.firstChild;
  155. range.selectNode(p).select();
  156. editor.execCommand('underline');
  157. var p1 = document.createElement('p');
  158. p1.innerHTML = '<span style="text-decoration: underline;">欢迎你回来</span>';
  159. if (!ua.browser.opera) {
  160. ok(ua.haveSameAllChildAttribs(p, p1), '检查是否添加了下划线');
  161. }
  162. range.setStart(p.firstChild.firstChild, 3).setEnd(p.firstChild.firstChild, 4).select();
  163. editor.execCommand('fontfamily', '楷体');
  164. var txt = '楷体';
  165. if (ua.browser.opera)
  166. txt = '\"楷体\"';
  167. equal(editor.queryCommandValue('fontfamily'), txt, '检查字体的状态反射');
  168. });
  169. test(' 选中文本设置前景色为默认', function () {
  170. var editor = te.obj[0];
  171. var range = te.obj[1];
  172. editor.setContent('hello');
  173. range.selectNode(editor.body.firstChild).select();
  174. editor.execCommand('forecolor', 'rgb(255,0,0)');
  175. ua.checkHTMLSameStyle('<span style="color:rgb(255, 0, 0)">hello</span>', editor.document, editor.body.firstChild, '文本的前景色设为红色');
  176. editor.execCommand('forecolor', 'default');
  177. equal(ua.getChildHTML(editor.body), '<p>hello</p>', '设置字体颜色为默认颜色');
  178. });
  179. /*trace 869*/
  180. //插件相关!!!!!!!!!!
  181. //test( 'trace 869:设置前景色后清除前景色,再输入文本', function() {
  182. // var editor = te.obj[0];
  183. // var range = te.obj[1];
  184. // editor.setContent( '' );
  185. // stop()
  186. //// alert(navigator.userAgent)
  187. // setTimeout( function() {
  188. // range.setStart( editor.body.firstChild, 0 ).select();
  189. // editor.execCommand( 'forecolor', 'red' );
  190. // editor.execCommand( 'forecolor', 'default' );
  191. // range = editor.selection.getRange();
  192. // editor.focus();
  193. // setTimeout( function() {
  194. // //TODO maxthon有2种模式,句柄分为IE的和maxthon两种,需要根据userAgent区别对待,但是貌似还是有问题的
  195. // te.presskey( '', 'e' );
  196. // editor.focus();
  197. // setTimeout( function() {
  198. // var br = baidu.editor.browser.ie ? '' : '<br />';
  199. // ua.manualDeleteFillData( editor.body );
  200. // equal( editor.getContent(), '<p>e' + br + '</p>' );
  201. // start();
  202. // }, 250 );
  203. // }, 100 );
  204. //// range.insertNode( document.createTextNode( 'hello' ) );
  205. // }, 150 );
  206. //} );
  207. /*trace 823*/
  208. //TODO 涉及文本输入和光标位置移动的结合
  209. // 不好测,采取workaround,不用输入的方式
  210. test('trace 823:设置前景色后设置删除线', function () {
  211. var editor = te.obj[0];
  212. var range = te.obj[1];
  213. editor.setContent('<p><span style="color: rgb(153, 230, 0); ">你好<span style="color: rgb(255, 0, 0); ">​hello</span></span></p>');
  214. range.selectNode(editor.body.firstChild.firstChild, 0).select();
  215. editor.execCommand('strikethrough');
  216. var p1 = editor.document.createElement('p');
  217. p1.innerHTML = '<span style="color: rgb(153, 230, 0); text-decoration: line-through;">你好<span style="color: rgb(255, 0, 0); text-decoration: line-through;">hello</span></span>';
  218. ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '检查加入删除线后的样式');
  219. });
  220. /*trace 819, 765*/
  221. test('trace 819, 765:删除线和下划线互斥', function () {
  222. var editor = te.obj[0];
  223. var range = te.obj[1];
  224. var p1 = editor.document.createElement('p');
  225. editor.setContent('<p>你好</p>');
  226. range.selectNode(editor.body.firstChild).select();
  227. editor.execCommand('underline');
  228. p1.innerHTML = '<span style="text-decoration: underline">你好</span>';
  229. ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '下划线');
  230. range.selectNode(editor.body.firstChild).select();
  231. editor.execCommand('strikethrough');
  232. p1.innerHTML = '<span style="text-decoration: line-through">你好</span>';
  233. ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '删除线,和下划线互斥');
  234. range.selectNode(editor.body.firstChild).select();
  235. editor.execCommand('underline');
  236. p1.innerHTML = '<span style="text-decoration: underline">你好</span>';
  237. ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '下划线,和删除线互斥');
  238. });
  239. ///*trace 810*/
  240. //TODO 1.2.6
  241. //test( 'trace 810:闭合时设置删除线会改变文本前景色', function() {
  242. // if(!ua.browser.opera){
  243. // var editor = te.obj[2];
  244. // var div = document.body.appendChild( document.createElement( 'div' ) );
  245. // $( div ).css( 'width', '500px' ).css( 'height', '500px' ).css( 'border', '1px solid #ccc' );
  246. // editor.render(div);
  247. // var range = new baidu.editor.dom.Range( editor.document );
  248. // stop();
  249. // setTimeout(function(){
  250. // editor.setContent( '<p><span style="color: rgb(153, 230, 0); ">你好<span style="color: rgb(255, 0, 0); ">​hello</span></span></p>' );
  251. // range.setStart( editor.body.firstChild.firstChild.lastChild, 1 ).collapse( true ).select();
  252. // editor.execCommand( 'strikethrough' );
  253. // range = editor.selection.getRange();
  254. // range.insertNode( editor.document.createTextNode( 'hey' ) );
  255. // /*ff下会自动加一个空的设置了style的span,比较时不作考虑*/
  256. // if ( baidu.editor.dom.domUtils.isEmptyNode( editor.body.firstChild.lastChild ) && baidu.editor.browser.gecko )
  257. // editor.body.firstChild.removeChild( editor.body.firstChild.lastChild );
  258. // var html = '<span style="color: rgb(153, 230, 0)">你好<span style="color: rgb(255, 0, 0)">hello<span style="color: rgb(255, 0, 0); text-decoration: line-through;">hey</span></span></span>';
  259. // ua.checkHTMLSameStyle( html, editor.document, editor.body.firstChild, '检查插入的删除线前景色是否正确' );
  260. // equal(editor.body.firstChild.innerHTML,html);
  261. // div.parentNode.removeChild(div);
  262. // start();
  263. // },50);
  264. // }
  265. //} );
  266. /*trace 809*/
  267. test('trace 809:闭合时改变前景色和删除线,再输入文本', function () {
  268. if (!ua.browser.opera) {
  269. var editor = te.obj[0];
  270. var range = te.obj[1];
  271. editor.setContent('<p><span style="color: rgb(255, 0, 0); text-decoration: line-through; ">你好</span></p>');
  272. var p = editor.body.firstChild;
  273. range.setStart(p.firstChild, 1).collapse(true).select();
  274. editor.execCommand('forecolor', 'rgb(0,255,0)');
  275. range = editor.selection.getRange();
  276. editor.execCommand('underline');
  277. range = editor.selection.getRange();
  278. range.insertNode(editor.document.createTextNode('hey'));
  279. var p1 = editor.document.createElement('p');
  280. p1.innerHTML = '<span style="color: rgb(255, 0, 0); text-decoration: line-through; ">你好</span><span style="color: rgb(255, 0, 0); "><span style="color: rgb(0, 255, 0); text-decoration: underline; ">​hey</span></span>';
  281. ua.manualDeleteFillData(editor.body);
  282. /*ff下会自动加一个空的设置了style的span,比较时不作考虑*/
  283. if (baidu.editor.dom.domUtils.isEmptyNode(editor.body.firstChild.lastChild) && baidu.editor.browser.gecko)
  284. editor.body.firstChild.removeChild(editor.body.firstChild.lastChild);
  285. ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '检查新输入的文本下划线和颜色是否正确');
  286. }
  287. });
  288. /*trace 805*/
  289. test('trace 805:切换删除线和下划线,前景色没了', function () {
  290. var editor = te.obj[0];
  291. var range = te.obj[1];
  292. editor.setContent('<p><strong>你好早安</strong></p>');
  293. var text = editor.body.firstChild.firstChild.firstChild;
  294. range.selectNode(text).select();
  295. editor.execCommand('forecolor', 'rgb(255,0,0)');
  296. range.setStart(text, 0).setEnd(text, 2).select();
  297. editor.execCommand('underline');
  298. range.setStart(text, 0).setEnd(text, 2).select();
  299. editor.execCommand('strikethrough');
  300. var p1 = editor.document.createElement('p');
  301. p1.innerHTML = '<span style="color: rgb(255, 0, 0); text-decoration: line-through;"><strong>你好</strong></span><span style="color: rgb(255, 0, 0);"><strong>早安</strong></span>';
  302. ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '查看前景色是不是还在');
  303. });
  304. /*trace 802*/
  305. test('trace 802:为设置了字体的文本添加删除线', function () {
  306. var editor = te.obj[0];
  307. var range = te.obj[1];
  308. editor.setContent('<p><strong>你好早安</strong></p>');
  309. var text = editor.body.firstChild.firstChild.firstChild;
  310. range.setStart(text, 0).setEnd(text, 2).select();
  311. editor.execCommand('strikethrough');
  312. var p1 = editor.document.createElement('p');
  313. p1.innerHTML = '<span style="text-decoration: line-through;"><strong>你好</strong></span><strong>早安</strong>';
  314. ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '检查删除线是否正确');
  315. editor.execCommand('fontfamily', '隶书');
  316. editor.execCommand('source');
  317. var txt = '隶书';
  318. if (ua.browser.opera)
  319. txt = '\"隶书\"';
  320. if(!ua.browser.gecko)//todo 1.4.0
  321. equal(editor.queryCommandValue('fontfamily'), txt);
  322. });
  323. /*trace 744*/
  324. test('trace 744:设置超链接背景色后切换到源码再切回来', function () {
  325. var editor = te.obj[0];
  326. var range = te.obj[1];
  327. stop();
  328. editor.setContent('<p>hello<a href="www.baidu.com">baidu</a></p>');
  329. range.selectNode(editor.body.firstChild).select();
  330. editor.execCommand('backcolor', 'rgb(255,0,0)');
  331. var html = editor.body.firstChild.innerHTML;
  332. editor.execCommand('source');
  333. setTimeout(function () {
  334. editor.execCommand('source');
  335. setTimeout(function () {
  336. ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '切换后html代码不变');
  337. /*切换源码前后代码应当相同*/
  338. start();
  339. }, 50);
  340. }, 50);
  341. });
  342. test('对表格中的文本添加颜色和下划线', function () {
  343. var editor = te.obj[0];
  344. var range = te.obj[1];
  345. stop();
  346. editor.setContent('<table><tbody><tr><td>hello1</td><td>hello2</td></tr><tr><td colspan="2">hello3</td></tr></tbody></table>');
  347. setTimeout(function () {
  348. var trs = editor.body.firstChild.getElementsByTagName('tr');
  349. var ut = editor.getUETable(editor.body.firstChild);
  350. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[0]);
  351. ut.setSelected(cellsRange);
  352. if (ua.browser.ie && ua.browser.ie < 9) {
  353. range.setStart(editor.body.firstChild.firstChild.firstChild.firstChild, 0).setEnd(editor.body.firstChild.firstChild.lastChild.firstChild, 6).select();
  354. }
  355. else {
  356. range.setStart(trs[0].cells[0].firstChild, 0).setEnd(trs[1].cells[0].firstChild, 6).select();
  357. }
  358. editor.execCommand('forecolor', 'rgb(255,100,100)');
  359. setTimeout(function () {
  360. ut.clearSelected();
  361. trs = editor.body.firstChild.getElementsByTagName('tr');
  362. ut = editor.getUETable(editor.body.firstChild);
  363. range.selectNode(trs[0].firstChild).select();
  364. ut.setSelected(range);
  365. setTimeout(function () {
  366. editor.execCommand('underline');
  367. setTimeout(function () {
  368. var tds = editor.body.firstChild.getElementsByTagName('td');
  369. trs = editor.body.firstChild.getElementsByTagName('tr');
  370. ua.checkSameHtml('<span style="color: rgb(255, 100, 100); text-decoration: underline; ">hello1</span>', tds[0].innerHTML, '第一个单元格有下划线和前景色');
  371. // equal('<span style="color: rgb(255, 100, 100); text-decoration: underline; ">hello1</span>', tds[0].innerHTML, '第一个单元格有下划线和前景色');
  372. ua.checkSameHtml('<span style="color: rgb(255, 100, 100); ">hello2</span>', tds[1].innerHTML, '第2个单元格有前景色');
  373. ua.checkSameHtml('<span style="color: rgb(255, 100, 100); ">hello3</span>', tds[2].innerHTML, '第3个单元格有前景色');
  374. equal(trs[1].firstChild.getAttribute('colspan'), 2, 'colspan为2');
  375. equal(editor.queryCommandState('underline'), true, '状态是underline');
  376. equal(editor.queryCommandState('forecolor'), 0, '非underline和line-through返回0');
  377. setTimeout(function () {
  378. start();
  379. }, 100);
  380. }, 100);
  381. }, 100);
  382. }, 100);
  383. }, 50);
  384. });
  385. /*trace 740*/
  386. test('trace 740:设置左右字为红色,修改部分字颜色为蓝色,再修改所有字体', function () {
  387. var editor = te.obj[0];
  388. var range = te.obj[1];
  389. stop();
  390. editor.setContent('<p>你好早安</p>');
  391. range.selectNode(editor.body.firstChild).select();
  392. editor.execCommand('forecolor', 'rgb(255,0,0)');
  393. var text = editor.body.firstChild.firstChild.firstChild;
  394. range.setStart(text, 2).setEnd(text, 4).select();
  395. editor.execCommand('forecolor', 'rgb(0,255,0)');
  396. range.setStart(editor.body.firstChild, 0).setEnd(editor.body.firstChild, 1).select();
  397. editor.execCommand('fontfamily', ' 楷体, 楷体_GB2312, SimKai; ');
  398. setTimeout(function () {
  399. var html = '<span style="color: rgb(255, 0, 0); font-family: 楷体, 楷体_GB2312, SimKai;">你好<span style="color: rgb(0, 255, 0);">早安</span></span>';
  400. ua.checkSameHtml(html, editor.body.firstChild.innerHTML, '查看字体和颜色是否正确');
  401. start();
  402. }, 50);
  403. });
  404. /*trace 721*/
  405. test('trace 721:预先设置下划线和字体颜色,再输入文本,查看下划线颜色', function () {
  406. if (!ua.browser.opera) {
  407. var editor = te.obj[0];
  408. var range = te.obj[1];
  409. editor.setContent('<p><br></p>');
  410. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  411. editor.execCommand('underline');
  412. editor.execCommand('forecolor', 'rgb(255,0,0)');
  413. range = editor.selection.getRange();
  414. range.insertNode(editor.document.createTextNode('hello'));
  415. ua.manualDeleteFillData(editor.body);
  416. var html = '<span style="text-decoration:underline;color:rgb(255,0,0)">hello</span><br>';
  417. ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '查看下划线颜色是否与字体颜色一致');
  418. }
  419. });
  420. test('trace 3342:字符ab, 给a 加边框再给b加边框,边框效果错误', function () {
  421. var editor = te.obj[0];
  422. var range = te.obj[1];
  423. editor.setContent('<p>hello</p>');
  424. range.setStart(editor.body.firstChild.firstChild, 0).setEnd(editor.body.firstChild.firstChild, 2).select();
  425. editor.execCommand('fontborder');
  426. range.setStart(editor.body.firstChild.lastChild, 0).setEnd(editor.body.firstChild.lastChild, 2).select();
  427. editor.execCommand('fontborder');
  428. // var br = baidu.editor.browser.ie ? '&nbsp;' : '<br>';
  429. if (ua.browser.ie && ua.browser.ie < 9) {
  430. equal(ua.getChildHTML(editor.body.firstChild), "<span style=\"border-bottom: #000 1px solid; border-left: #000 1px solid; border-top: #000 1px solid; border-right: #000 1px solid\">hell</span>o", '查看添加了字符边框后的样式');
  431. }else if(ua.browser.ie && ua.browser.ie == 11){
  432. equal(ua.getChildHTML(editor.body.firstChild), '<span style="border: 1px solid rgb(0, 0, 0); border-image: none;">hell</span>o', '查看添加了字符边框后的样式');
  433. }
  434. else {
  435. equal(ua.getChildHTML(editor.body.firstChild), '<span style="border: 1px solid rgb(0, 0, 0);">hell</span>o', '查看添加了字符边框后的样式');
  436. }
  437. });
  438. test('trace 3096:单元格中改变字号', function () {
  439. var editor = te.obj[0];
  440. var range = te.obj[1];
  441. editor.setContent('<p></p>');
  442. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  443. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  444. var trs = editor.body.firstChild.getElementsByTagName('tr');
  445. trs[0].cells[0].innerHTML = 'asd';
  446. setTimeout(function () {
  447. range.setStart(editor.body.firstChild.firstChild.firstChild.firstChild.firstChild, 0).setEnd(editor.body.firstChild.firstChild.firstChild.firstChild.firstChild, 3).select();
  448. editor.execCommand('fontsize', '32px');
  449. equal(editor.body.firstChild.getElementsByTagName('td')[0].style.height, '', '不固定高度');
  450. start();
  451. }, 50);
  452. stop();
  453. });
  454. test('转换font标签', function () {
  455. var editor = te.obj[0];
  456. editor.setContent('<font size="16" color="red"><b><i>x</i></b></font>');
  457. var html = '<p><span style="font-size:16px;color:red" ><strong><em>x</em></strong></span></p>';
  458. ua.checkHTMLSameStyle(html, editor.document, editor.body, '转换font标签');
  459. editor.setContent('<font style="color:red"><u>x</u></font>');
  460. html = '<span style="color:red"><span style="text-decoration:underline;">x</span></span>';
  461. ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '转换font标签');
  462. });