table.cmds.js 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518
  1. module('plugins.table');
  2. //test('',function(){stop()})
  3. /*trace992,合并单元格后多了一个td*/
  4. test('向右合并--拆分成列', function () {
  5. var editor = te.obj[0];
  6. var range = te.obj[1];
  7. editor.setContent('<p></p>');
  8. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  9. editor.execCommand('inserttable', {numCols:2, numRows:2});
  10. ua.manualDeleteFillData(editor.body);
  11. var tds = editor.body.getElementsByTagName('td');
  12. range.setStart(tds[0], 0).collapse(true).select();
  13. editor.execCommand('mergeright');
  14. range.setStart(tds[1], 0).collapse(true).select();
  15. editor.execCommand('mergeright');
  16. tds = editor.body.getElementsByTagName('td');
  17. equal(tds.length, 2, '2个单元格');
  18. equal(tds[0].getAttribute('colspan'), 2, '第一行的单元格colspan为2');
  19. equal(tds[1].getAttribute('colspan'), 2, '第二行的单元格colspan为2');
  20. ua.manualDeleteFillData(editor.body);
  21. setTimeout(function () {
  22. editor.execCommand('source');
  23. start();
  24. });
  25. stop();
  26. tds = editor.body.getElementsByTagName('td');
  27. equal(tds.length, 2, '2个单元格');
  28. equal(tds[0].getAttribute('colspan'), 2, '切换到源码后第一个的单元格colspan');
  29. equal(tds[1].getAttribute('colspan'), 2, '切换到源码后第二行第一个的单元格colspan');
  30. range.setStart(tds[0], 0).collapse(true).select();
  31. editor.execCommand('splittocols');
  32. equal(tds[0].getAttribute('colspan'), 1, '拆分--[0][0]单元格colspan');
  33. equal(tds[0].rowSpan, 1, '拆分--[0][0]单元格rowspan');
  34. });
  35. test('trace 3985 向右合并--拆分成列:th', function () {
  36. var editor = te.obj[0];
  37. var range = te.obj[1];
  38. editor.setContent('<p></p>');
  39. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  40. editor.execCommand('inserttable', {numCols:2, numRows:2});
  41. var tds = editor.body.getElementsByTagName('td');
  42. range.setStart(tds[0],0).collapse(true).select();
  43. editor.execCommand('inserttitle');
  44. var ths = editor.body.getElementsByTagName('th');
  45. range.setStart(ths[0], 0).collapse(true).select();
  46. editor.execCommand('mergeright');
  47. ths = editor.body.getElementsByTagName('th');
  48. equal(ths.length, 1, '1个th');
  49. range.setStart(ths[0], 0).collapse(true).select();
  50. editor.execCommand('splittocols');
  51. equal(editor.body.getElementsByTagName('th').length, 2, '拆分单元格th');
  52. });
  53. test('trace 3985 向下合并-拆分成行', function () {
  54. var editor = te.obj[0];
  55. var range = te.obj[1];
  56. editor.setContent('<p></p>');
  57. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  58. editor.execCommand('inserttable', {numCols:2, numRows:2});
  59. ua.manualDeleteFillData(editor.body);
  60. var tds = editor.body.getElementsByTagName('td');
  61. range.setStart(tds[0], 0).collapse(true).select();
  62. editor.execCommand('mergedown');
  63. range.setStart(tds[1], 0).collapse(true).select();
  64. editor.execCommand('mergedown');
  65. tds = editor.body.getElementsByTagName('td');
  66. equal(tds.length, 2, '2个单元格');
  67. equal(tds[0].getAttribute('rowspan'), 2, '合并--[0][0]单元格rowspan');
  68. equal(tds[1].getAttribute('rowspan'), 2, '合并--[0][1]单元格rowspan');
  69. range.setStart(tds[0], 0).collapse(true).select();
  70. editor.execCommand('splittorows');
  71. range.setStart(tds[1], 0).collapse(true).select();
  72. editor.execCommand('splittorows');
  73. equal(tds[0].colSpan, 1, '拆分--[0][0]单元格colspan');
  74. equal(tds[0].getAttribute('rowspan'), 1, '拆分--[0][0]单元格rowspan');
  75. });
  76. test('完全拆分单元格', function () {
  77. var editor = te.obj[0];
  78. var range = te.obj[1];
  79. editor.setContent('<p></p>');
  80. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  81. editor.execCommand('inserttable', {numCols:3, numRows:3});
  82. ua.manualDeleteFillData(editor.body);
  83. setTimeout(function () {
  84. var trs = editor.body.firstChild.getElementsByTagName('tr');
  85. var ut = editor.getUETable(editor.body.firstChild);
  86. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  87. ut.setSelected(cellsRange);
  88. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  89. editor.execCommand('mergecells');
  90. ut.clearSelected();
  91. var tds = editor.body.getElementsByTagName('td');
  92. equal(tds.length, 6, '单元格数');
  93. equal(tds[0].getAttribute('colspan'), 2, '合并--[0][0]单元格colspan');
  94. equal(tds[0].getAttribute('rowspan'), 2, '合并--[0][0]单元格rowspan');
  95. editor.execCommand('splittoCells');
  96. equal(tds.length, 9, '单元格数');
  97. equal(tds[0].getAttribute('colspan'), 1, '拆分--[0][0]单元格colspan');
  98. equal(tds[0].getAttribute('rowspan'), 1, '拆分--[0][0]单元格rowspan');
  99. equal(tds[1].colSpan, 1, '拆分--[0][1]单元格colspan');
  100. equal(tds[1].getAttribute('rowspan'), 1, '拆分--[0][1]单元格rowspan');
  101. editor.undoManger.undo();
  102. equal(tds[0].getAttribute('colspan'), 2, '撤销--[0][0]单元格colspan');
  103. equal(tds[0].getAttribute('rowspan'), 2, '撤销--[0][0]单元格rowspan');
  104. start();
  105. }, 50);
  106. stop();
  107. });
  108. test('删除table', function () {
  109. var editor = te.obj[0];
  110. var range = te.obj[1];
  111. editor.setContent('<p></p>');
  112. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  113. editor.execCommand('inserttable');
  114. ua.manualDeleteFillData(editor.body);
  115. equal(editor.queryCommandState('deletetable'), -1, '删除按钮灰色');
  116. var tds = editor.body.getElementsByTagName('td');
  117. range.setStart(tds[0], 0).collapse(true).select();
  118. editor.execCommand('deletetable');
  119. ua.manualDeleteFillData(editor.body);
  120. var table = editor.body.getElementsByTagName('table')[0];
  121. equal(table, undefined, '删除成功');
  122. });
  123. test('平均分配行列', function () {
  124. var editor = te.obj[0];
  125. var range = te.obj[1];
  126. var html = '<table width="267" ><tbody><caption></caption><tr><th></th><th></th><th></th></tr><tr><td width="46" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" height="57" ><br/></td><td width="158" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" height="57" ><br/></td><td width="-1" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" height="57" ><br/></td></tr><tr><td width="46" valign="top" style="word-break: break-all;" height="134" ><br/></td><td width="158" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" height="134" ><br/></td><td width="-1" valign="top" style="word-break: break-all;" height="134" ><br/></td></tr><tr><td width="46" valign="top" style="word-break: break-all;" ><br/></td><td width="158" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" ><br/></td><td width="-1" valign="top" style="word-break: break-all;" ><br/></td></tr></tbody></table>';
  127. editor.setContent(html);
  128. var trs = editor.body.firstChild.getElementsByTagName('tr');
  129. var ut = editor.getUETable(editor.body.firstChild);
  130. var cellsRange = ut.getCellsRange(trs[1].cells[0], trs[1].cells[2]);
  131. ut.setSelected(cellsRange);
  132. range.setStart(trs[1].cells[0], 0).collapse(true).select();
  133. editor.execCommand('averagedistributecol');
  134. ut.clearSelected();
  135. equal(editor.body.firstChild.getElementsByTagName('td')[1].width, editor.body.firstChild.getElementsByTagName('td')[2].width, '平均分配各列');
  136. cellsRange = ut.getCellsRange(trs[1].cells[0], trs[3].cells[0]);
  137. ut.setSelected(cellsRange);
  138. range.setStart(trs[1].cells[0], 0).collapse(true).select();
  139. editor.execCommand('averagedistributerow');
  140. ut.clearSelected();
  141. trs = editor.body.firstChild.getElementsByTagName('tr');
  142. equal(trs[2].cells[0].height, trs[3].cells[0].height, '平均分配各行');
  143. });
  144. test('选部分行时,平均分布行/选部分列时,平均分布列', function () {
  145. var editor = te.obj[0];
  146. var range = te.obj[1];
  147. var html = '<table width="267" ><tbody><tr><td width="46" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" height="57" ><br/></td><td width="158" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" height="57" ><br/></td><td width="-1" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" height="57" ><br/></td></tr><tr><td width="46" valign="top" style="word-break: break-all;" height="134" ><br/></td><td width="158" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" height="134" ><br/></td><td width="-1" valign="top" style="word-break: break-all;" height="134" ><br/></td></tr><tr><td width="46" valign="top" style="word-break: break-all;" ><br/></td><td width="158" valign="top" colspan="1" rowspan="1" style="word-break: break-all;" ><br/></td><td width="-1" valign="top" style="word-break: break-all;" ><br/></td></tr></tbody></table>';
  148. editor.setContent(html);
  149. var trs = editor.body.firstChild.getElementsByTagName('tr');
  150. var ut = editor.getUETable(editor.body.firstChild);
  151. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[2]);
  152. ut.setSelected(cellsRange);
  153. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  154. editor.execCommand('averagedistributerow');
  155. ut.clearSelected();
  156. trs = editor.body.firstChild.getElementsByTagName('tr');
  157. equal(trs[1].cells[0].height, trs[0].cells[0].height, '平均分配各行');
  158. cellsRange = ut.getCellsRange(trs[0].cells[0], trs[2].cells[1]);
  159. ut.setSelected(cellsRange);
  160. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  161. editor.execCommand('averagedistributecol');
  162. ut.clearSelected();
  163. equal(editor.body.firstChild.getElementsByTagName('td')[0].width, editor.body.firstChild.getElementsByTagName('td')[1].width, '平均分配各列');
  164. });
  165. test('表格中设置对齐方式', function () {
  166. var editor = te.obj[0];
  167. var range = te.obj[1];
  168. editor.setContent('<table><caption></caption><tbody><tr><td></td><td><p>hello</p></td></tr></tbody></table>');
  169. stop();
  170. setTimeout(function(){
  171. var caption = editor.body.getElementsByTagName('caption');
  172. range.setStart(caption[0], 0).collapse(true).select();
  173. editor.execCommand('cellalignment', {align:'right', vAlign:'top'});
  174. equal(caption[0].style.textAlign, 'right', 'caption对齐方式为右上对齐');
  175. equal(caption[0].style.verticalAlign, 'top', 'caption对齐方式为右上对齐');
  176. var tds = editor.body.getElementsByTagName('td');
  177. range.setStart(tds[0], 0).collapse(true).select();
  178. editor.execCommand('cellalignment', {align:'right', vAlign:'top'});
  179. equal(tds[0].align, 'right', 'td对齐方式为右上对齐');
  180. equal(tds[0].vAlign, 'top', 'td对齐方式为右上对齐');
  181. //*不闭合设置对齐方式*//*
  182. range.selectNode(tds[1].firstChild, 0).select();
  183. editor.execCommand('cellalignment', {align:'center', vAlign:'middle'});
  184. equal(tds[1].align, 'center', 'p对齐方式为居中对齐');
  185. start();
  186. },50);
  187. });
  188. test('修改table屬性', function () {
  189. var editor = te.obj[0];
  190. var range = te.obj[1];
  191. editor.setContent('<p></p>');
  192. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  193. editor.execCommand('inserttable', {numCols:2, numRows:3});
  194. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  195. editor.execCommand('tablealignment', 'center');
  196. var table = editor.body.getElementsByTagName('table')[0];
  197. equal(table.align, 'center', '对齐方式居中');
  198. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  199. editor.execCommand('edittable', '#ff0000');
  200. ua.manualDeleteFillData(editor.body);
  201. var tds = editor.body.getElementsByTagName('td');
  202. if (ua.browser.ie && ua.browser.ie < 9) {
  203. equal(tds[0].style.borderColor, '#ff0000', '边框颜色:红色');
  204. } else {
  205. equal(tds[0].style.borderColor, 'rgb(255, 0, 0)', '边框颜色:红色');
  206. }
  207. equal(editor.queryCommandState('edittable'), 0, 'state');
  208. });
  209. test('修改单元格', function () {
  210. var editor = te.obj[0];
  211. var range = te.obj[1];
  212. editor.setContent('<p></p>');
  213. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  214. editor.execCommand('inserttable');
  215. var tds = editor.body.getElementsByTagName('td');
  216. range.setStart(tds[2], 0).collapse(true).select();
  217. editor.execCommand('edittd', '#9bbb59');
  218. if (ua.browser.ie && ua.browser.ie < 9) {
  219. equal(tds[2].style.backgroundColor, '#9bbb59', '背景颜色');
  220. } else {
  221. equal(tds[2].style.backgroundColor, 'rgb(155, 187, 89)', '背景颜色');
  222. }
  223. var ut = editor.getUETable(editor.body.firstChild);
  224. var cellsRange = ut.getCellsRange(tds[0], tds[6]);
  225. ut.setSelected(cellsRange);
  226. range.setStart(tds[0], 0).collapse(true).select();
  227. editor.execCommand('edittd', '#9bbb59');
  228. editor.execCommand('cellalignment', {align:'center', vAlign:'bottom'});
  229. ut.clearSelected();
  230. tds = editor.body.firstChild.getElementsByTagName('td');
  231. if (ua.browser.ie && ua.browser.ie < 9) {
  232. equal(tds[5].style.backgroundColor, '#9bbb59', '背景颜色');
  233. } else {
  234. equal(tds[5].style.backgroundColor, 'rgb(155, 187, 89)', '背景颜色');
  235. }
  236. equal(tds[5].align, 'center', '水平居中');
  237. equal(tds[5].vAlign, 'bottom', '下方');
  238. equal(editor.queryCommandState('edittd'), 0, 'state');
  239. equal(editor.queryCommandState('cellalignment'), 0, 'state');
  240. });
  241. test('表格前插行', function () {
  242. var editor = te.obj[0];
  243. var range = te.obj[1];
  244. editor.setContent('<p></p>');
  245. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  246. editor.execCommand('inserttable');
  247. var tds = editor.body.firstChild.getElementsByTagName('td');
  248. range.setStart(tds[1], 0).collapse(true).select();
  249. editor.execCommand('insertparagraphbeforetable');
  250. ua.manualDeleteFillData(editor.body);
  251. var br = ua.browser.ie ? '&nbsp;' : '<br>';
  252. equal(editor.body.firstChild.innerHTML, br, '表格前插行');
  253. });
  254. test('插入行', function () {
  255. var editor = te.obj[0];
  256. var range = te.obj[1];
  257. editor.setContent('<p></p>');
  258. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  259. editor.execCommand('inserttable', {numCols:3, numRows:3});
  260. ua.manualDeleteFillData(editor.body);
  261. var tds = editor.body.getElementsByTagName('td');
  262. range.setStart(tds[0], 0).collapse(true).select();
  263. editor.execCommand('mergedown');
  264. range.setStart(tds[4], 0).collapse(true).select();
  265. editor.execCommand('insertrow');
  266. tds = editor.body.getElementsByTagName('td');
  267. equal(tds[0].getAttribute('rowspan'), 3, '[0][0]单元格rowspan');
  268. editor.undoManger.undo();
  269. equal(tds[0].getAttribute('rowspan'), 2, '[0][0]单元格rowspan');
  270. });
  271. test('选中两行,插入行', function () {
  272. var editor = te.obj[0];
  273. var range = te.obj[1];
  274. editor.setContent('<table width="984"><tbody><tr><td width="307" valign="top">hello</td><td width="307" valign="top"></td><td width="307" valign="top"></td></tr><tr><td width="307" valign="top"></td><td width="307" valign="top"></td><td width="307" valign="top"></td></tr><tr><td width="307" valign="top"></td><td width="307" valign="top"></td><td width="307" valign="top"></td></tr></tbody></table>');
  275. var trs = editor.body.firstChild.getElementsByTagName('tr');
  276. var ut = editor.getUETable(editor.body.firstChild);
  277. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[0]);
  278. ut.setSelected(cellsRange);
  279. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  280. editor.execCommand('insertrow');
  281. ut.clearSelected();
  282. equal(editor.body.getElementsByTagName('tr').length, 5, '选中两行,前插行,3行变5行');
  283. trs = editor.body.firstChild.getElementsByTagName('tr');
  284. ua.manualDeleteFillData(trs[2]);
  285. equal(trs[2].cells[0].innerHTML,'hello','原来的第1行变成第3行');
  286. ut = editor.getUETable(editor.body.firstChild);
  287. cellsRange = ut.getCellsRange(trs[2].cells[0], trs[3].cells[0]);
  288. ut.setSelected(cellsRange);
  289. range.setStart(trs[2].cells[0], 0).collapse(true).select();
  290. editor.execCommand('insertrownext');
  291. ut.clearSelected();
  292. equal(editor.body.getElementsByTagName('tr').length, 7,'选中两行,前插行,5行变7行');
  293. trs = editor.body.firstChild.getElementsByTagName('tr');
  294. ua.manualDeleteFillData(trs[2]);
  295. equal(trs[2].cells[0].innerHTML,'hello','');
  296. });
  297. test('选中两列,插入列', function () {
  298. var editor = te.obj[0];
  299. var range = te.obj[1];
  300. editor.setContent('<table width="984"><tbody><tr><td width="307" valign="top">hello</td><td width="307" valign="top"></td><td width="307" valign="top"></td></tr><tr><td width="307" valign="top"></td><td width="307" valign="top"></td><td width="307" valign="top"></td></tr><tr><td width="307" valign="top"></td><td width="307" valign="top"></td><td width="307" valign="top"></td></tr></tbody></table>');
  301. var trs = editor.body.firstChild.getElementsByTagName('tr');
  302. var ut = editor.getUETable(editor.body.firstChild);
  303. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[1]);
  304. ut.setSelected(cellsRange);
  305. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  306. editor.execCommand('insertcol');
  307. ut.clearSelected();
  308. equal(editor.body.getElementsByTagName('tr')[0].childNodes.length, 5, '选中两列,前插列,3行变5列');
  309. trs = editor.body.firstChild.getElementsByTagName('tr');
  310. ua.manualDeleteFillData(trs[0]);
  311. equal(trs[0].cells[2].innerHTML,'hello','原来的第1列变成第3列');
  312. ut = editor.getUETable(editor.body.firstChild);
  313. cellsRange = ut.getCellsRange(trs[0].cells[2], trs[0].cells[3]);
  314. ut.setSelected(cellsRange);
  315. range.setStart(trs[0].cells[2], 0).collapse(true).select();
  316. editor.execCommand('insertcolnext');
  317. ut.clearSelected();
  318. equal(editor.body.getElementsByTagName('tr')[0].childNodes.length, 7,'选中两列,前插列,5列变7列');
  319. trs = editor.body.firstChild.getElementsByTagName('tr');
  320. ua.manualDeleteFillData(trs[0]);
  321. equal(trs[0].cells[2].innerHTML,'hello','');
  322. });
  323. test('trace 3986 插入列', function () {
  324. var editor = te.obj[0];
  325. var range = te.obj[1];
  326. editor.setContent('<p></p>');
  327. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  328. editor.execCommand('inserttable', {numCols:3, numRows:3});
  329. ua.manualDeleteFillData(editor.body);
  330. var tds = editor.body.getElementsByTagName('td');
  331. range.setStart(tds[0], 0).collapse(true).select();
  332. editor.execCommand('mergeright');
  333. range.setStart(tds[3], 0).collapse(true).select();
  334. editor.execCommand('insertcol');
  335. tds = editor.body.getElementsByTagName('td');
  336. equal(tds[0].getAttribute('colspan'), 3, '[0][0]单元格colspan');
  337. editor.undoManger.undo();
  338. equal(tds[0].getAttribute('colspan'), 2, '[0][0]单元格colspan');
  339. range.setStart(tds[1], 0).setCursor();
  340. editor.execCommand("insertcol");
  341. equal(tds[0].parentNode.cells.length, 3, "插入了一列")
  342. });
  343. test('带th的表格,插入列', function () {
  344. var editor = te.obj[0];
  345. var range = te.obj[1];
  346. editor.setContent('<p></p>');
  347. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  348. editor.execCommand('inserttable', {numCols:2, numRows:3});
  349. var tds = editor.body.getElementsByTagName('td');
  350. range.setStart(tds[0],0).collapse(true).select();
  351. editor.execCommand('inserttitle');
  352. stop();
  353. setTimeout(function(){
  354. var tds = editor.body.getElementsByTagName('td');
  355. range.setStart(tds[0], 0).collapse(true).select();
  356. editor.execCommand('insertcol');
  357. var ths = editor.body.getElementsByTagName('tr')[0].childNodes;
  358. equal(ths.length,3,'第一行有3个单元');
  359. for(var i=0;i<ths.length;i++){
  360. equal(ths[i].tagName.toLowerCase(),'th','第'+i+'个单元tagName是th');
  361. }
  362. start();
  363. },20);
  364. });
  365. test('原表格非第一行带th,插入列', function () {
  366. var editor = te.obj[0];
  367. var range = te.obj[1];
  368. editor.setContent('<table width="984"><tbody><tr><td width="471" valign="top"></td><td width="471" valign="top"></td></tr><tr><th width="471" valign="top"></th><td width="471" valign="top"></td></tr></tbody></table>');
  369. stop();
  370. setTimeout(function(){
  371. var trs = editor.body.getElementsByTagName('tr');
  372. range.setStart(trs[1].cells[0], 0).collapse(true).select();
  373. editor.execCommand('insertcolnext');
  374. trs = editor.body.getElementsByTagName('tr');
  375. equal(trs[1].childNodes.length, 3, '插入一列');
  376. equal(trs[1].cells[1].tagName.toLowerCase(), 'td', '除第一行以外,插入的不能是th');
  377. start();
  378. }, 20);
  379. });
  380. test('删除行', function () {
  381. var editor = te.obj[0];
  382. var range = te.obj[1];
  383. editor.setContent('<table><tbody><tr><td width="483" valign="top">1</td><td width="483" valign="top">2</td></tr><tr><td width="483" valign="top">3</td><td width="483" valign="top">4</td></tr><tr><td width="483" valign="top">5</td><td width="483" valign="top">6</td></tr></tbody></table>');
  384. //
  385. stop();
  386. setTimeout(function () {
  387. var tds = editor.body.getElementsByTagName('td');
  388. range.setStart(tds[0], 0).collapse(1).select();
  389. editor.execCommand('deleterow');
  390. equal(editor.body.getElementsByTagName('tr').length, 2, '删除行');
  391. editor.undoManger.undo();
  392. setTimeout(function () {
  393. equal(editor.body.getElementsByTagName('tr').length, 3, '撤销后的行数');
  394. tds = editor.body.getElementsByTagName('td');
  395. range.setStart(tds[5], 0).collapse(1).select();
  396. editor.execCommand('deleterow');
  397. setTimeout(function () {
  398. equal(editor.body.getElementsByTagName('tr').length, 2, '删除行');
  399. var table = editor.document.getElementsByTagName("table")[0];
  400. var cell = table.rows[0].cells[0];
  401. setTimeout(function () {
  402. range.setStart(cell, 0).setCursor();
  403. editor.execCommand("mergeDown");
  404. equal(cell.rowSpan, 2, "合并了一行");
  405. editor.execCommand("deleterow");
  406. equal(table.rows.length, 1, "在合并的单元格中删除行后,表格变成了一行");
  407. start();
  408. }, 50);
  409. }, 50);
  410. }, 50);
  411. }, 50);
  412. });
  413. test('选中部分单元格,删除行列', function () {
  414. var editor = te.obj[0];
  415. var range = te.obj[1];
  416. editor.setContent('<p></p>');
  417. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  418. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  419. setTimeout(function () {
  420. var trs = editor.body.firstChild.getElementsByTagName('tr');
  421. var ut = editor.getUETable(editor.body.firstChild);
  422. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[1]);
  423. ut.setSelected(cellsRange);
  424. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  425. editor.execCommand('deleterow');
  426. ut.clearSelected();
  427. equal(editor.body.getElementsByTagName('tr').length, 2, '选中部分单元格,删除行');
  428. trs = editor.body.firstChild.getElementsByTagName('tr');
  429. ut = editor.getUETable(editor.body.firstChild);
  430. cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[1]);
  431. ut.setSelected(cellsRange);
  432. range.setStart(trs[0].cells[0], 0).setEnd(trs[0].cells[1], 1).select();
  433. editor.execCommand('deletecol');
  434. ut.clearSelected();
  435. equal(trs[0].childNodes.length, 1, '选中部分单元格,删除列');
  436. trs = editor.body.firstChild.getElementsByTagName('tr');
  437. ut = editor.getUETable(editor.body.firstChild);
  438. cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[0]);
  439. ut.setSelected(cellsRange);
  440. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  441. ut.clearSelected();
  442. editor.execCommand('deletecol');
  443. equal(editor.body.getElementsByTagName('table').length, 0, '删除列至表格删空');
  444. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  445. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  446. trs = editor.body.firstChild.getElementsByTagName('tr');
  447. ut = editor.getUETable(editor.body.firstChild);
  448. cellsRange = ut.getCellsRange(trs[0].cells[0], trs[2].cells[0]);
  449. ut.setSelected(cellsRange);
  450. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  451. editor.execCommand('deleterow');
  452. ut.clearSelected();
  453. equal(editor.body.getElementsByTagName('table').length, 0, '删除列至表格删空');
  454. start();
  455. }, 50);
  456. stop();
  457. });
  458. test('settablebackground', function () {
  459. var editor = te.obj[0];
  460. var range = te.obj[1];
  461. editor.setContent( '<p></p>' );
  462. range.setStart( editor.body.firstChild, 0 ).collapse( true ).select();
  463. editor.execCommand( 'inserttable', {numCols:2,numRows:2} );
  464. var tds = editor.body.firstChild.getElementsByTagName('td');
  465. var ut = editor.getUETable(editor.body.firstChild);
  466. var cellsRange = ut.getCellsRange(tds[0], tds[2]);
  467. ut.setSelected(cellsRange);
  468. range.setStart(tds[0], 0).collapse(true).select();
  469. editor.execCommand("settablebackground",{repeat:true,colorList:["#bbb","#ccc"]});
  470. setTimeout(function(){
  471. var br = ua.browser.ie?'':'<br>';
  472. var tds = editor.body.firstChild.getElementsByTagName('td');
  473. if(ua.browser.ie&&ua.browser.ie<9){
  474. ok( tds[0].style.backgroundColor === '#bbb', '选区隔行变色, 第一列第一行颜色匹配' );
  475. ok( tds[2].style.backgroundColor === '#ccc', '选区隔行变色, 第一列第二行颜色匹配' );
  476. }
  477. else{
  478. ok( tds[0].style.backgroundColor === 'rgb(187, 187, 187)', '选区隔行变色, 第一列第一行颜色匹配' );
  479. ok( tds[2].style.backgroundColor === 'rgb(204, 204, 204)', '选区隔行变色, 第一列第二行颜色匹配' );
  480. }
  481. range.setStart(tds[0], 0).collapse(true).select();
  482. editor.execCommand('cleartablebackground');
  483. setTimeout(function(){
  484. ok( tds[0].style.backgroundColor === '', '取消选区隔行变色, 第一列第一行颜色匹配' );
  485. ok( tds[2].style.backgroundColor === '', '取消选区隔行变色, 第一列第二行颜色匹配' );
  486. start();
  487. },20);
  488. },20);
  489. stop();
  490. });
  491. test('interlacetable', function () {
  492. var editor = te.obj[0];
  493. var range = te.obj[1];
  494. editor.setContent('<p></p>');
  495. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  496. editor.execCommand('inserttable', {numCols:2, numRows:2});
  497. var tds = editor.body.getElementsByTagName('td');
  498. range.setStart(tds[0], 0).collapse(1).select();
  499. editor.execCommand('interlacetable');
  500. stop();
  501. setTimeout(function () {
  502. equal(editor.body.firstChild.attributes['interlaced'].nodeValue, 'enabled', '');
  503. equal(editor.body.getElementsByTagName('tr')[0].className, 'ue-table-interlace-color-single firstRow', '');
  504. equal(editor.body.getElementsByTagName('tr')[1].className, 'ue-table-interlace-color-double', '');
  505. tds = editor.body.getElementsByTagName('td');
  506. range.setStart(tds[0], 0).collapse(1).select();
  507. editor.execCommand('uninterlacetable');
  508. setTimeout(function () {
  509. equal(editor.body.firstChild.attributes['interlaced'].nodeValue, 'disabled', '');
  510. equal(editor.body.getElementsByTagName('tr')[0].className, 'firstRow', '');
  511. start();
  512. }, 20);
  513. }, 20);
  514. });
  515. //
  516. //*trace 750,1308*//*
  517. //test( 'trace1308:前插入行的样式和原先不同', function() {
  518. // var editor = te.obj[0];
  519. // var range = te.obj[1];
  520. // editor.setContent( '<p></p>' );
  521. // range.setStart( editor.body.firstChild, 0 ).collapse( true ).select();
  522. // editor.execCommand( 'inserttable', {numCols:2,numRows:2} );
  523. // ua.manualDeleteFillData( editor.body );
  524. // range.setStartAfter( editor.body.firstChild ).collapse( true ).select();
  525. // //cellborder:2,不支持了
  526. // editor.execCommand( 'inserttable', {border:2,numCols:2,numRows:2} );
  527. // var table2 = editor.body.getElementsByTagName( 'table' )[1];
  528. // range.setStart( table2.getElementsByTagName( 'td' )[0], 0 ).collapse( true ).select();
  529. // editor.execCommand( 'insertrow' );
  530. // var tds = table2.getElementsByTagName( 'td' );
  531. //*//*firefox下用jquery的方式去不到border-width*//*
  532. // for(var index = 0;index<tds.length;index++)
  533. //*//*边框宽度加到table上了*//*
  534. //equal(table2.getAttribute('border'),'2','表格边框为2px');
  535. //// equal( $( tds[index] ).css( 'border-width' ) || tds[index].style.borderWidth, '2px', '表格边框为2px' );
  536. //// for ( var index = 0; index < tds.length; index++ ) {
  537. //// equal( $( tds[index ] ).css( 'border-width' ) || tds[index].style.borderWidth, '2px', '查看第' + (index + 1) + '个单元格的边框' )
  538. //// }
  539. //} );
  540. //*trace 749*//*
  541. test('trace 749:拆分为列后2列都有文本', function () {
  542. var editor = te.obj[0];
  543. var range = te.obj[1];
  544. editor.setContent('<p></p>');
  545. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  546. editor.execCommand('inserttable', {numCols:2, numRows:2});
  547. ua.manualDeleteFillData(editor.body);
  548. var tds = editor.body.getElementsByTagName('td');
  549. tds[1].innerHTML = 'hello';
  550. range.setStart(tds[0], 0).collapse(true).select();
  551. editor.execCommand('mergeright');
  552. var tr = editor.body.getElementsByTagName('tr')[0];
  553. equal($(tr.firstChild).attr('colspan'), '2', '跨度2列');
  554. editor.execCommand('splittocols');
  555. ua.manualDeleteFillData(editor.body);
  556. tds = editor.body.getElementsByTagName('td');
  557. //1.2版本,合并拆分之后hello前多了空的占位符
  558. ok(tds[0].innerHTML, '第一个单元格中有内容');
  559. ok(tds[1].innerHTML == '' || tds[1].innerHTML == '<br>', '第二个单元格中有内容');
  560. });
  561. //*trace 743*//*
  562. test('trace 743:合并单元格后删除列再撤销', function () {
  563. var editor = te.obj[0];
  564. var range = te.obj[1];
  565. editor.setContent('<p></p>');
  566. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  567. editor.execCommand('inserttable', {numCols:4, numRows:4});
  568. ua.manualDeleteFillData(editor.body);
  569. setTimeout(function () {
  570. var trs = editor.body.firstChild.getElementsByTagName('tr');
  571. var ut = editor.getUETable(editor.body.firstChild);
  572. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[3]);
  573. ut.setSelected(cellsRange);
  574. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  575. editor.execCommand('mergecells');
  576. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  577. editor.execCommand('deleterow');
  578. trs = editor.body.getElementsByTagName('tr');
  579. equal(trs.length, 3, '删除后只剩3个tr');
  580. editor.undoManger.undo();
  581. trs = editor.body.getElementsByTagName('tr');
  582. equal(trs.length, 4, '撤销后有4个tr');
  583. equal($(trs[0].cells[0]).attr('colspan'), 4, '第一行的第一个单元格colspan为4');
  584. start();
  585. }, 50);
  586. stop();
  587. });
  588. //*trace 726*//*
  589. test('trace 726:选中合并过的单元格和普通单元格,查看完全拆分单元格菜单是否高亮', function () {
  590. var editor = te.obj[0];
  591. var range = te.obj[1];
  592. editor.setContent('<p></p>');
  593. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  594. editor.execCommand('inserttable', {numCols:4, numRows:4});
  595. ua.manualDeleteFillData(editor.body);
  596. setTimeout(function () {
  597. var trs = editor.body.firstChild.getElementsByTagName('tr');
  598. var ut = editor.getUETable(editor.body.firstChild);
  599. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  600. ut.setSelected(cellsRange);
  601. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  602. editor.execCommand('mergecells');
  603. equal(editor.queryCommandState('splittocells'), 0, '应当可以拆分单元格');
  604. setTimeout(function () {
  605. var trs = editor.body.firstChild.getElementsByTagName('tr');
  606. var ut = editor.getUETable(editor.body.firstChild);
  607. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[3].cells[3]);
  608. ut.setSelected(cellsRange);
  609. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  610. editor.queryCommandState('splittocells');
  611. equal(editor.queryCommandState('splittocells'), -1, '应当不可以拆分单元格');
  612. start();
  613. }, 50);
  614. }, 50);
  615. stop();
  616. });
  617. //*trace 718*//*
  618. test('trace 718:2次撤销删除列', function () {
  619. var editor = te.obj[0];
  620. var range = te.obj[1];
  621. editor.setContent('<p></p>');
  622. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  623. editor.execCommand('inserttable', {numCols:4, numRows:4});
  624. ua.manualDeleteFillData(editor.body);
  625. setTimeout(function () {
  626. var trs = editor.body.firstChild.getElementsByTagName('tr');
  627. var ut = editor.getUETable(editor.body.firstChild);
  628. var cellsRange = ut.getCellsRange(trs[1].cells[1], trs[2].cells[2]);
  629. ut.setSelected(cellsRange);
  630. range.setStart(trs[1].cells[1], 0).collapse(true).select();
  631. editor.execCommand('mergecells');
  632. equal(trs[1].cells[1].rowSpan, 2, 'rowspan 为2');
  633. equal(trs[1].cells[1].colSpan, 2, 'colspan 为2');
  634. editor.execCommand('deletecol');
  635. equal(trs[1].cells.length, 3, '3个td');
  636. editor.undoManger.undo();
  637. trs = editor.body.firstChild.getElementsByTagName('tr');
  638. equal(trs[1].cells.length, 3, '3个td');
  639. equal(trs[1].cells[1].rowSpan, 2, 'rowspan 为2');
  640. equal(trs[1].cells[1].colSpan, 2, 'colspan 为2');
  641. range.setStart(trs[1].cells[1], 0).collapse(1).select();
  642. editor.execCommand('deletecol');
  643. equal(trs[1].cells.length, 3, '3个td');
  644. equal(trs[1].cells[1].rowSpan, 2, 'rowspan 为2');
  645. ok(trs[1].cells[1].colSpan == undefined || trs[1].cells[1].colSpan == 1, 'colspan为1或者undefined');
  646. start();
  647. }, 50);
  648. stop();
  649. });
  650. //*trace 1098 *//*
  651. test('trace 1098:多次合并单元格偶切换到源码再切回来', function () {
  652. var editor = te.obj[0];
  653. var range = te.obj[1];
  654. editor.setContent('<p></p>');
  655. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  656. editor.execCommand('inserttable', {numCols:3, numRows:3});
  657. setTimeout(function () {
  658. var trs = editor.body.firstChild.getElementsByTagName('tr');
  659. var ut = editor.getUETable(editor.body.firstChild);
  660. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[2].cells[0]);
  661. ut.setSelected(cellsRange);
  662. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  663. editor.execCommand('mergecells');
  664. setTimeout(function () {
  665. trs = editor.body.firstChild.getElementsByTagName('tr');
  666. ut = editor.getUETable(editor.body.firstChild);
  667. cellsRange = ut.getCellsRange(trs[0].cells[1], trs[2].cells[0]);
  668. ut.setSelected(cellsRange);
  669. range.setStart(trs[0].cells[1], 0).collapse(true).select();
  670. editor.execCommand('mergecells');
  671. //
  672. setTimeout(function () {
  673. trs = editor.body.firstChild.getElementsByTagName('tr');
  674. ut = editor.getUETable(editor.body.firstChild);
  675. cellsRange = ut.getCellsRange(trs[0].cells[2], trs[1].cells[0]);
  676. ut.setSelected(cellsRange);
  677. range.setStart(trs[0].cells[2], 0).collapse(true).select();
  678. editor.execCommand('mergecells');
  679. editor.execCommand('source');
  680. setTimeout(function () {
  681. editor.execCommand('source');
  682. setTimeout(function () {
  683. trs = editor.body.firstChild.getElementsByTagName('tr');
  684. equal(trs.length, 3, '3个tr');
  685. equal(trs[0].cells[0].rowSpan, 3, '第一个单元格rowspan 3');
  686. equal(trs[0].cells[1].rowSpan, 3, '第二个单元格rowspan 3');
  687. equal(trs[0].cells.length, 3, '3个td');
  688. equal(trs[1].cells.length, 0, '0个td');
  689. equal(trs[2].cells.length, 1, '1个td');
  690. start();
  691. }, 50);
  692. }, 50);
  693. }, 50);
  694. }, 50);
  695. }, 50);
  696. stop();
  697. });
  698. //*trace 1307*//*
  699. test('trace 1307:adjustTable--多次合并单元格切换到源码再切回来--选中单元格浏览器会假死', function () {
  700. var editor = te.obj[0];
  701. var range = te.obj[1];
  702. editor.setContent('<p></p>');
  703. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  704. editor.execCommand('inserttable', {numCols:4, numRows:4});
  705. setTimeout(function () {
  706. var trs = editor.body.firstChild.getElementsByTagName('tr');
  707. var ut = editor.getUETable(editor.body.firstChild);
  708. var cellsRange = ut.getCellsRange(trs[1].cells[0], trs[3].cells[1]);
  709. ut.setSelected(cellsRange);
  710. range.setStart(trs[1].cells[0], 0).collapse(true).select();
  711. editor.execCommand('mergecells');
  712. setTimeout(function () {
  713. var trs = editor.body.firstChild.getElementsByTagName('tr');
  714. var ut = editor.getUETable(editor.body.firstChild);
  715. var cellsRange = ut.getCellsRange(trs[0].cells[2], trs[2].cells[0]);
  716. ut.setSelected(cellsRange);
  717. range.setStart(trs[0].cells[2], 0).collapse(true).select();
  718. editor.execCommand('mergecells');
  719. editor.execCommand('source');
  720. setTimeout(function () {
  721. editor.execCommand('source');
  722. setTimeout(function () {
  723. trs = editor.body.getElementsByTagName('tr');
  724. equal(trs[1].rowIndex, 1, '(1,1)行索引');
  725. equal(trs[1].cells[0].cellIndex, 0, '(1,0)列索引');
  726. equal(trs[1].cells[1].cellIndex, 1, '(1,1)列索引');
  727. equal(trs[2].rowIndex, 2, '(2,2)行索引');
  728. equal(trs[2].cells[0].cellIndex, 0, '(2,0)列索引');
  729. equal(trs[1].cells[0].rowSpan, 3, '第二行第一个单元格rowspan 3');
  730. equal(trs[1].cells[0].colSpan, 2, '第二行第一个单元格colspan 2');
  731. equal(trs[0].cells[2].rowSpan, 3, '第一行第三个单元格rowspan 3');
  732. equal(trs.length, 4, '4个tr');
  733. equal(trs[0].cells.length, 4, '4个td');
  734. equal(trs[1].cells.length, 2, '2个td');
  735. equal(trs[2].cells.length, 1, '1个td');
  736. equal(trs[3].cells.length, 2, '2个td');
  737. start();
  738. }, 50);
  739. }, 50);
  740. }, 50);
  741. }, 50);
  742. stop();
  743. });
  744. //*//*trace 2378*//*
  745. //test('不覆盖原来的class',function(){
  746. // var editor = te.obj[0];
  747. // editor.setContent('<table class="asdf" border="0" cellspacing="1" cellpadding="3" width="332"><tbody><tr><td></td></tr></tbody></table>');
  748. // editor.execCommand('source');
  749. // editor.execCommand('source');
  750. // var table = editor.body.getElementsByTagName('table');
  751. // equal($(table).attr('class'),'asdf noBorderTable','table的class');
  752. //});
  753. //*trace 3121*//*
  754. //*trace 3195*//*
  755. test('单元格对齐方式-align', function () {
  756. var editor = te.obj[0];
  757. var range = te.obj[1];
  758. editor.setContent('<p></p>');
  759. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  760. editor.execCommand('inserttable', {numCols:3, numRows:3});
  761. ua.manualDeleteFillData(editor.body);
  762. var trs = editor.body.firstChild.getElementsByTagName('tr');
  763. var ut = editor.getUETable(editor.body.firstChild);
  764. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[2]);
  765. ut.setSelected(cellsRange);
  766. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  767. editor.execCommand('mergecells');
  768. ut.clearSelected();
  769. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  770. editor.execCommand('cellalign', 'center');
  771. ua.manualDeleteFillData(editor.body);
  772. var tds = editor.body.getElementsByTagName('td');
  773. equal(tds[0].align, 'center', '第一个单元格居中对齐');
  774. range.setStart(tds[0], 0).collapse(true).select();
  775. editor.execCommand('splittocols');
  776. tds = editor.body.getElementsByTagName('td');
  777. equal(tds[0].align, 'center', '第一个单元格居中对齐');
  778. equal(tds[1].align, 'center', '第二个单元格居中对齐');
  779. equal(tds[2].align, 'center', '第二个单元格居中对齐');
  780. });
  781. test('单元格对齐方式-vAlign', function () {
  782. var editor = te.obj[0];
  783. var range = te.obj[1];
  784. editor.setContent('<p></p>');
  785. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  786. editor.execCommand('inserttable', {numCols:2, numRows:2});
  787. ua.manualDeleteFillData(editor.body);
  788. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  789. editor.execCommand('mergedown');
  790. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  791. editor.execCommand('cellvalign', 'middle');
  792. ua.manualDeleteFillData(editor.body);
  793. var tds = editor.body.getElementsByTagName('td');
  794. equal(tds[0].vAlign, 'middle', '第一个单元格居中对齐');
  795. range.setStart(tds[0], 0).collapse(true).select();
  796. editor.execCommand('splittorows');
  797. tds = editor.body.getElementsByTagName('td');
  798. equal(tds[0].vAlign, 'middle', '第一个单元格居中对齐');
  799. equal(tds[2].vAlign, 'middle', '第二个单元格居中对齐');
  800. });
  801. test('adaptbytext,adaptbywindow', function () {
  802. var editor = te.obj[0];
  803. var range = te.obj[1];
  804. editor.setContent('<p></p>');
  805. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  806. editor.execCommand('inserttable', {numCols:2, numRows:2});
  807. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  808. if(ua.browser.ie!=8)
  809. ok( editor.body.offsetWidth === editor.body.getElementsByTagName('table')[0].offsetWidth ,'默认按窗口计算宽度');//数值不具体计算了
  810. editor.execCommand('adaptbytext');//parseInt
  811. stop();
  812. setTimeout(function(){
  813. equal(editor.body.firstChild.width,'','按内容自适应')
  814. editor.execCommand('adaptbywindow');
  815. setTimeout(function(){
  816. ok((parseInt(editor.body.firstChild.width)-editor.body.offsetWidth/2)>0,'默认按窗口计算宽度');
  817. start();
  818. },20);
  819. },20);
  820. });
  821. test('deletetitle', function () {
  822. var editor = te.obj[0];
  823. var range = te.obj[1];
  824. editor.setContent( '<p></p>' );
  825. range.setStart( editor.body.firstChild, 0 ).collapse( true ).select();
  826. editor.execCommand( 'inserttable', {numCols:2, numRows:2});
  827. var tds = editor.body.getElementsByTagName('td');
  828. range.setStart(tds[0],0).collapse(true).select();
  829. editor.execCommand('inserttitle');
  830. stop();
  831. setTimeout(function(){
  832. var trs = editor.body.firstChild.getElementsByTagName('tr');
  833. equal(trs.length,3,'表格增加一行');
  834. for(var i = 0; i< trs[0].childNodes.length;i++){
  835. equal(trs[0].childNodes[i].tagName.toLowerCase(),'th','增加的th');
  836. }
  837. range.setStart(tds[0],0).collapse(true).select();
  838. editor.execCommand('deletetitle');
  839. setTimeout(function(){
  840. equal(editor.body.firstChild.getElementsByTagName('tr').length,2,'表格减少一行');
  841. equal(editor.body.firstChild.getElementsByTagName('tr')[0].firstChild.tagName.toLowerCase(),'td','第一行不是标题');
  842. start();
  843. },20);
  844. },20);
  845. });
  846. /*trace 3222*/
  847. test('trace 3222:在合并后的单元格中按tab键', function () {
  848. var editor = te.obj[0];
  849. var range = te.obj[1];
  850. editor.setContent('<p></p>');
  851. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  852. editor.execCommand('inserttable');
  853. ua.manualDeleteFillData(editor.body);
  854. setTimeout(function () {
  855. var trs = editor.body.firstChild.getElementsByTagName('tr');
  856. var ut = editor.getUETable(editor.body.firstChild);
  857. var cellsRange = ut.getCellsRange(trs[1].cells[1], trs[2].cells[1]);
  858. ut.setSelected(cellsRange);
  859. range.setStart(trs[1].cells[1], 0).collapse(true).select();
  860. editor.execCommand('mergecells');
  861. trs[1].cells[2].innerHTML = 'asd';
  862. range.setStart(trs[1].cells[1], 0).collapse(true).select();
  863. ua.keydown(editor.body, {'keyCode':9});
  864. if (ua.browser.gecko||ua.browser.webkit)
  865. equal(editor.selection.getRange().startContainer.innerHTML, 'asd', '第一次tab键');
  866. else
  867. equal(editor.selection.getRange().startContainer.data, 'asd', '第一次tab键');
  868. range.setStart(trs[1].cells[1], 0).collapse(true).select();
  869. ua.keydown(editor.body, {'keyCode':9});
  870. if (ua.browser.gecko||ua.browser.webkit)
  871. equal(editor.selection.getRange().startContainer.innerHTML, 'asd', '第二次tab键');
  872. else
  873. equal(editor.selection.getRange().startContainer.data, 'asd', '第二次tab键');
  874. start();
  875. }, 50);
  876. stop();
  877. });
  878. /*trace 3191*/
  879. test('trace 3191:删除表格名称', function () {
  880. var editor = te.obj[0];
  881. var range = te.obj[1];
  882. editor.setContent('<p></p>');
  883. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  884. editor.execCommand('inserttable');
  885. setTimeout(function () {
  886. var tds = editor.body.getElementsByTagName('td');
  887. range.setStart(tds[0], 0).collapse(true).select();
  888. editor.execCommand('insertcaption');
  889. range.setStart(editor.body.getElementsByTagName('caption')[0], 0).collapse(true).select();
  890. editor.execCommand('deletecaption');
  891. equal(editor.body.getElementsByTagName('caption').length, '0', '表格名称被删除');
  892. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  893. ua.keydown(editor.body, {keyCode: 90, ctrlKey: true});
  894. equal(editor.body.getElementsByTagName('caption').length, '1', '表格名称被还原');
  895. start();
  896. }, 50);
  897. stop();
  898. });
  899. /*trace 3195*/
  900. test('trace 3195:合并单元格后删除列再撤销', function () {
  901. var editor = te.obj[0];
  902. var range = te.obj[1];
  903. editor.setContent('<p></p>');
  904. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  905. editor.execCommand('inserttable', {numCols:4, numRows:4});
  906. ua.manualDeleteFillData(editor.body);
  907. setTimeout(function () {
  908. var trs = editor.body.firstChild.getElementsByTagName('tr');
  909. var ut = editor.getUETable(editor.body.firstChild);
  910. trs[0].cells[1].innerHTML = 'asd';
  911. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[2].cells[2]);
  912. ut.setSelected(cellsRange);
  913. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  914. editor.execCommand('mergecells');
  915. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  916. editor.execCommand('splittocols');
  917. trs = editor.body.getElementsByTagName('tr');
  918. equal(trs.length, 4, '4个tr');
  919. equal(trs[0].cells.length, 4, '4个td');
  920. equal(trs[1].cells.length, 1, '1个td');
  921. equal(trs[2].cells.length, 1, '1个td');
  922. equal(trs[3].cells.length, 4, '4个td');
  923. equal(trs[0].cells[0].vAlign, 'top', '单元格[0][0]的vAlign');
  924. equal(trs[0].cells[0].align, '', '单元格[0][0]的align');
  925. equal(trs[0].cells[1].vAlign, 'top', '单元格[0][1]的vAlign');
  926. equal(trs[0].cells[2].vAlign, 'top', '单元格[0][2]的vAlign');
  927. if (ua.browser.ie) {
  928. equal(trs[0].cells[1].align, '', '单元格[0][1]的align');
  929. equal(trs[0].cells[2].align, '', '单元格[0][2]的align');
  930. } else {
  931. equal(trs[0].cells[1].align, 'null', '单元格[0][1]的align');
  932. equal(trs[0].cells[2].align, 'null', '单元格[0][2]的align');
  933. }
  934. start();
  935. }, 50);
  936. stop();
  937. });
  938. /*trace 3231*/
  939. test(' trace 3779 trace 3231:向右合并--拆分成列', function () {
  940. if(ua.browser.ie&& ua.browser.ie>8)return;//todo
  941. var editor = te.obj[0];
  942. var range = te.obj[1];
  943. editor.setContent('<p></p>');
  944. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  945. editor.execCommand('inserttable', {numCols:2, numRows:2});
  946. setTimeout(function () {
  947. ua.manualDeleteFillData(editor.body);
  948. var tds = editor.body.getElementsByTagName('td');
  949. tds[1].innerHTML = 'asd';
  950. range.setStart(tds[1], 0).collapse(true).select();
  951. editor.execCommand('insertcolnext');
  952. ua.manualDeleteFillData(editor.body);
  953. equal(editor.body.getElementsByTagName('tr')[0].cells.length, '3', '3列');
  954. equal(editor.body.getElementsByTagName('td')[1].innerHTML, 'asd', '后插入行');
  955. var br = ua.browser.ie ? '' : '<br>';
  956. equal(editor.body.getElementsByTagName('td')[2].innerHTML, br, '后插入行');
  957. range.setStart(editor.body.getElementsByTagName('td')[2], 0).collapse(true).select();
  958. editor.execCommand('insertrownext');
  959. equal(editor.body.getElementsByTagName('tr').length, 3, '3行');
  960. editor.execCommand('deletecol');
  961. equal(editor.body.getElementsByTagName('td')[1].innerHTML, 'asd', '');
  962. equal(editor.body.getElementsByTagName('td').length, '6', '');
  963. start();
  964. }, 50);
  965. stop();
  966. });
  967. //test('标题行中底纹',function(){
  968. // var editor = te.obj[0];
  969. // var range = te.obj[1];
  970. // editor.setContent( '<p></p>' );
  971. // range.setStart( editor.body.firstChild, 0 ).collapse( true ).select();
  972. // editor.execCommand( 'inserttable');
  973. // var tds = editor.body.getElementsByTagName('td');
  974. // range.setStart(tds[0],0).collapse(true).select();
  975. // editor.execCommand('inserttitle');
  976. //
  977. // var ut = editor.getUETable(editor.body.firstChild);
  978. // var ths = editor.body.getElementsByTagName('th');
  979. // var cellsRange = ut.getCellsRange(ths[0],ths[4]);
  980. // ut.setSelected(cellsRange);
  981. // range.setStart( ths[0], 0 ).collapse( true ).select();
  982. // editor.execCommand('interlacetable');
  983. // ut.clearSelected();
  984. // equal(ths[0].style.backgroundColor,'red','红色');
  985. //// equal(editor.queryCommandState('settablebackground'),-1,'命令不可用');
  986. //});
  987. /*trace 713*/
  988. test('trace 713:合并最后一列单元格后再前插入列', function () {
  989. if(ua.browser.ie)//TODO 1.2.6
  990. return;
  991. var editor = te.obj[0];
  992. var range = te.obj[1];
  993. editor.setContent('<p></p>');
  994. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  995. editor.execCommand('inserttable', {numCols:3, numRows:3});
  996. setTimeout(function () {
  997. var trs = editor.body.firstChild.getElementsByTagName('tr');
  998. var ut = editor.getUETable(editor.body.firstChild);
  999. var cellsRange = ut.getCellsRange(trs[0].cells[2], trs[2].cells[2]);
  1000. /*合并最后一列的单元格*/
  1001. ut.setSelected(cellsRange);
  1002. range.setStart(trs[0].cells[2], 0).collapse(true).select();
  1003. editor.execCommand('mergecells');
  1004. setTimeout(function () {
  1005. equal($(trs[0].cells[2]).attr('rowspan'), 3, '跨3行');
  1006. editor.execCommand('insertcol');
  1007. setTimeout(function () {
  1008. /*前插入列*/
  1009. trs = editor.body.getElementsByTagName('tr');
  1010. equal(trs[0].cells.length, 4, '4列');
  1011. equal($(trs[0].cells[3]).attr('rowspan'), 3, '跨3行');
  1012. start();
  1013. }, 50);
  1014. }, 50);
  1015. }, 50);
  1016. stop();
  1017. });
  1018. test('inserttitlecol, deletetitlecol', function () {
  1019. var editor = te.obj[0];
  1020. var range = te.obj[1];
  1021. editor.setContent( '<p></p>' );
  1022. range.setStart( editor.body.firstChild, 0 ).collapse( true ).select();
  1023. editor.execCommand( 'inserttable', {numCols:2, numRows:2});
  1024. var tds = editor.body.getElementsByTagName('td');
  1025. range.setStart(tds[0],0).collapse(true).select();
  1026. editor.execCommand('inserttitlecol');
  1027. stop();
  1028. setTimeout(function(){
  1029. var trs = editor.body.firstChild.getElementsByTagName('tr');
  1030. equal(trs[0].children.length,3,'表格增加一列');
  1031. for(var i = 0; i< trs.length;i++){
  1032. equal(trs[i].childNodes[0].tagName.toLowerCase(),'th','增加的th');
  1033. }
  1034. range.setStart(tds[0],0).collapse(true).select();
  1035. editor.execCommand('deletetitlecol');
  1036. setTimeout(function(){
  1037. equal(trs[0].children.length,2,'表格减少一列');
  1038. equal(editor.body.firstChild.getElementsByTagName('tr')[0].firstChild.tagName.toLowerCase(),'td','第一列不是标题');
  1039. start();
  1040. },20);
  1041. },20);
  1042. });
  1043. /*trace 3216*/
  1044. test('contextMenu trace 3216:前插入行', function () {
  1045. var editor = te.obj[0];
  1046. var range = te.obj[1];
  1047. stop();
  1048. var lang = editor.getLang("contextMenu");
  1049. editor.execCommand('cleardoc');
  1050. editor.execCommand('inserttable');
  1051. var tds = editor.body.getElementsByTagName('td');
  1052. tds[0].innerHTML = 'asd';
  1053. range.setStart(tds[0], 0).collapse(true).select();
  1054. ua.contextmenu(editor.body.firstChild);
  1055. var menutable = document.getElementsByClassName("edui-menu-body")[1];
  1056. var forTable = document.getElementsByClassName('edui-for-table');
  1057. if (ua.browser.ie) {
  1058. ua.mouseenter(forTable[forTable.length - 1]);
  1059. } else {
  1060. ua.mouseover(forTable[forTable.length - 1]);
  1061. }
  1062. setTimeout(function () {
  1063. lang = editor.getLang("contextMenu");
  1064. ua.click(menutable.childNodes[6]);
  1065. equal(editor.body.getElementsByTagName('tr').length, 6, '前插入行后有6行');
  1066. equal(ua.getChildHTML(editor.body.getElementsByTagName('td')[5]), 'asd', '原单元格中文本未改变');
  1067. setTimeout(function () {
  1068. document.getElementById('edui_fixedlayer').parentNode.removeChild(document.getElementById('edui_fixedlayer'));
  1069. te.dom.push(editor.container);
  1070. start();
  1071. }, 200);
  1072. }, 200);
  1073. });
  1074. test('contextMenu 选区背景隔行', function () {
  1075. var editor = te.obj[0];
  1076. var range = te.obj[1];
  1077. stop();
  1078. var lang = editor.getLang("contextMenu");
  1079. editor.execCommand('cleardoc');
  1080. editor.execCommand('inserttable');
  1081. var trs = editor.body.firstChild.getElementsByTagName('tr');
  1082. var ut = editor.getUETable(editor.body.firstChild);
  1083. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  1084. ut.setSelected(cellsRange);
  1085. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  1086. ua.contextmenu(editor.body.firstChild);
  1087. var menutableBody = document.getElementsByClassName("edui-menu-body")[3];
  1088. var forTable = document.getElementsByClassName('edui-for-table');
  1089. if (ua.browser.ie) {
  1090. ua.mouseenter(forTable[forTable.length - 1]);
  1091. } else {
  1092. ua.mouseover(forTable[forTable.length - 1]);
  1093. }
  1094. setTimeout(function () {
  1095. lang = editor.getLang("contextMenu");
  1096. equal(menutableBody.childNodes.length, 4, '4个子项目');
  1097. if (browser.gecko) {
  1098. equal(menutableBody.textContent, '表格隔行变色选区背景隔行红蓝相间三色渐变', '检查menu显示的字符');
  1099. }
  1100. else {
  1101. equal(menutableBody.innerText.replace(/[\r\n\t\u200b\ufeff]/g, ''), '表格隔行变色选区背景隔行红蓝相间三色渐变', '检查menu显示的字符');
  1102. }
  1103. ua.click(menutableBody.childNodes[1]);
  1104. ut.clearSelected();
  1105. trs = editor.body.getElementsByTagName('tr');
  1106. if (ua.browser.ie == 8) {
  1107. equal(trs[0].cells[0].style.backgroundColor, '#bbb', '第一行');
  1108. equal(trs[1].cells[1].style.backgroundColor, '#ccc', '第二行');
  1109. } else {
  1110. equal(trs[0].cells[0].style.backgroundColor, 'rgb(187, 187, 187)', '第一行');
  1111. equal(trs[1].cells[1].style.backgroundColor, 'rgb(204, 204, 204)', '第二行');
  1112. }
  1113. cellsRange = ut.getCellsRange(trs[0].cells[2], trs[1].cells[3]);
  1114. ut.setSelected(cellsRange);
  1115. range.setStart(trs[0].cells[2], 0).collapse(true).select();
  1116. ua.contextmenu(editor.body.firstChild);
  1117. menutableBody = document.getElementsByClassName("edui-menu-body")[3];
  1118. forTable = document.getElementsByClassName('edui-for-table');
  1119. if (ua.browser.ie) {
  1120. ua.mouseenter(forTable[forTable.length - 1]);
  1121. } else {
  1122. ua.mouseover(forTable[forTable.length - 1]);
  1123. }
  1124. setTimeout(function () {
  1125. lang = editor.getLang("contextMenu");
  1126. equal(menutableBody.childNodes.length, 4, '4个子项目');
  1127. ua.click(menutableBody.childNodes[2]);
  1128. ut.clearSelected();
  1129. trs = editor.body.getElementsByTagName('tr');
  1130. equal(trs[0].cells[2].style.backgroundColor, 'red', '第一行');
  1131. equal(trs[1].cells[3].style.backgroundColor, 'blue', '第二行');
  1132. ut = editor.getUETable(editor.body.firstChild);
  1133. cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[3]);
  1134. ut.setSelected(cellsRange);
  1135. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  1136. ua.contextmenu(editor.body.firstChild);
  1137. menutableBody = document.getElementsByClassName("edui-menu-body")[3];
  1138. forTable = document.getElementsByClassName('edui-for-table');
  1139. if (ua.browser.ie) {
  1140. ua.mouseenter(forTable[forTable.length - 1]);
  1141. } else {
  1142. ua.mouseover(forTable[forTable.length - 1]);
  1143. }
  1144. setTimeout(function () {
  1145. lang = editor.getLang("contextMenu");
  1146. ua.click(menutableBody.childNodes[2]);
  1147. trs = editor.body.getElementsByTagName('tr');
  1148. equal(trs[1].cells[2].style.backgroundColor, '', '取消背景隔行');
  1149. setTimeout(function () {
  1150. document.getElementById('edui_fixedlayer').parentNode.removeChild(document.getElementById('edui_fixedlayer'));
  1151. te.dom.push(editor.container);
  1152. start();
  1153. }, 200);
  1154. }, 200);
  1155. }, 200);
  1156. }, 200);
  1157. });
  1158. test('contextMenu 三色渐变', function () {
  1159. var editor = te.obj[0];
  1160. var range = te.obj[1];
  1161. stop();
  1162. editor.execCommand('cleardoc');
  1163. editor.execCommand('inserttable');
  1164. var tds = editor.body.getElementsByTagName('td');
  1165. var ut = editor.getUETable(editor.body.firstChild);
  1166. var cellsRange = ut.getCellsRange(tds[0], tds[16]);
  1167. ut.setSelected(cellsRange);
  1168. range.setStart(tds[0], 0).collapse(true).select();
  1169. ua.contextmenu(editor.body.firstChild);
  1170. var menutable = document.getElementsByClassName("edui-menu-body")[3];
  1171. var forTable = document.getElementsByClassName('edui-for-table');
  1172. if (ua.browser.ie) {
  1173. ua.mouseenter(forTable[forTable.length - 1]);
  1174. } else {
  1175. ua.mouseover(forTable[forTable.length - 1]);
  1176. }
  1177. ua.click(menutable.childNodes[3]);
  1178. ut.clearSelected();
  1179. tds = editor.body.getElementsByTagName('td');
  1180. if (ua.browser.ie == 8) {
  1181. equal(tds[0].style.backgroundColor, '#aaa', '第一行');
  1182. equal(tds[6].style.backgroundColor, '#bbb', '第二行');
  1183. equal(tds[11].style.backgroundColor, '#ccc', '第二行');
  1184. } else {
  1185. equal(tds[0].style.backgroundColor, 'rgb(170, 170, 170)', '第一行');
  1186. equal(tds[6].style.backgroundColor, 'rgb(187, 187, 187)', '第二行');
  1187. equal(tds[11].style.backgroundColor, 'rgb(204, 204, 204)', '第二行');
  1188. }
  1189. setTimeout(function () {
  1190. document.getElementById('edui_fixedlayer').parentNode.removeChild(document.getElementById('edui_fixedlayer'));
  1191. te.dom.push(editor.container);
  1192. start();
  1193. }, 20);
  1194. });
  1195. /*trace 3210*/
  1196. test('contextMenu trace 3210:添加单元格背景色', function () {
  1197. var editor = te.obj[0];
  1198. var range = te.obj[1];
  1199. editor.setContent('<p></p>');
  1200. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  1201. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  1202. var trs = editor.body.firstChild.getElementsByTagName('tr');
  1203. var ut = editor.getUETable(editor.body.firstChild);
  1204. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  1205. ut.setSelected(cellsRange);
  1206. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  1207. editor.execCommand('edittd','#ff0000');
  1208. stop();
  1209. setTimeout(function () {
  1210. var tds = editor.body.firstChild.getElementsByTagName('td');
  1211. equal(tds[2].style.backgroundColor, '', '背景色不变');
  1212. equal(ua.formatColor(tds[0].style.backgroundColor), '#ff0000', '添加单元格背景色');
  1213. equal(ua.formatColor(tds[4].style.backgroundColor), '#ff0000', '添加单元格背景色');
  1214. start();
  1215. }, 50);
  1216. });
  1217. /*trace 3099*/
  1218. test('contextMenu trace 3099: 清除边框颜色', function () {
  1219. var editor = te.obj[0];
  1220. var range = te.obj[1];
  1221. editor.setContent('<p></p>');
  1222. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  1223. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  1224. var trs = editor.body.firstChild.getElementsByTagName('tr');
  1225. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  1226. editor.execCommand('edittable','#ff0000');
  1227. stop();
  1228. setTimeout(function () {
  1229. var tds = editor.body.firstChild.getElementsByTagName('td');
  1230. equal(ua.formatColor(tds[0].style.borderColor), '#ff0000', '添加边框颜色');
  1231. equal(ua.formatColor(tds[2].style.borderColor), '#ff0000', '添加边框颜色');
  1232. editor.execCommand('edittable','');
  1233. setTimeout(function () {
  1234. equal(tds[0].style.borderColor, '', '边框颜色被清除');
  1235. start();
  1236. }, 50);
  1237. }, 50);
  1238. // var div = document.body.appendChild(document.createElement('div'));
  1239. // div.id = 'ue';
  1240. // var editor = UE.getEditor('ue');
  1241. // stop();
  1242. // editor.ready(function () {
  1243. // var range = new baidu.editor.dom.Range(editor.document);
  1244. // var lang = editor.getLang("contextMenu");
  1245. // editor.execCommand('cleardoc');
  1246. // editor.execCommand('inserttable');
  1247. // setTimeout(function () {
  1248. // range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  1249. // ua.contextmenu(editor.body.firstChild);
  1250. // var menutable = document.getElementsByClassName("edui-menu-body")[1];
  1251. // var forTable = document.getElementsByClassName('edui-for-table');
  1252. // if (ua.browser.ie&&ua.browser.ie<9) {
  1253. // ua.mouseenter(forTable[forTable.length - 1]);
  1254. // } else {
  1255. // ua.mouseover(forTable[forTable.length - 1]);
  1256. // }
  1257. // lang = editor.getLang("contextMenu");
  1258. // ua.click(menutable.childNodes[menutable.childNodes.length-1]);//点开表格属性
  1259. // setTimeout(function () {
  1260. // var iframe = document.getElementsByTagName('iframe');
  1261. // var iframe1 ;
  1262. // for (var i = iframe.length-1; i >-1; i--) {
  1263. // if (iframe[i].id && iframe[i].id.indexOf('edui') != -1) {
  1264. // iframe1 = iframe[i];
  1265. // break;
  1266. // }
  1267. // }
  1268. //
  1269. // iframe1.contentDocument.getElementById('J_tone').value = '#ff0000';
  1270. // var buttonBody = document.getElementsByClassName('edui-dialog edui-for-edittable edui-default edui-state-centered')[0].firstChild.firstChild.lastChild.firstChild.firstChild.firstChild.firstChild.firstChild;
  1271. // ua.click(buttonBody);
  1272. // setTimeout(function () {
  1273. // var tds = editor.body.getElementsByTagName('td');
  1274. // if (ua.browser.ie == 8)
  1275. // equal(tds[0].style.borderColor, '#ff0000', '边框颜色设置为红色');
  1276. // else {
  1277. // equal(tds[0].style.borderColor, 'rgb(255, 0, 0)', '边框颜色设置为红色');
  1278. // }
  1279. // range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  1280. // ua.contextmenu(editor.body.firstChild);
  1281. // menutable = document.getElementsByClassName("edui-menu-body")[1];
  1282. // forTable = document.getElementsByClassName('edui-for-table');
  1283. // if (ua.browser.ie&&ua.browser.ie<9) {
  1284. // ua.mouseenter(forTable[forTable.length - 1]);
  1285. // } else {
  1286. // ua.mouseover(forTable[forTable.length - 1]);
  1287. // }
  1288. // lang = editor.getLang("contextMenu");
  1289. // ua.click(menutable.childNodes[menutable.childNodes.length-1]);
  1290. // setTimeout(function () {
  1291. // iframe = document.getElementsByTagName('iframe');
  1292. // iframe1 = null;
  1293. // for (var i = iframe.length-1; i >-1; i--) {
  1294. // if (iframe[i].id.indexOf('edui') != -1) {
  1295. // iframe1 = iframe[i];
  1296. // break;
  1297. // }
  1298. // }
  1299. // ua.click(iframe1.contentDocument.getElementById('J_tone'));
  1300. // setTimeout(function () {
  1301. // var div_nocolor = document.getElementsByClassName('edui-colorpicker-nocolor');
  1302. // ua.click(div_nocolor[0]);
  1303. // var buttonBody = document.getElementsByClassName('edui-dialog edui-for-edittable edui-default edui-state-centered')[1].firstChild.firstChild.lastChild.firstChild.firstChild.firstChild.firstChild.firstChild;
  1304. // ua.click(buttonBody);
  1305. // tds = editor.body.getElementsByTagName('td');
  1306. // equal(tds[0].style.borderColor, '', '边框颜色被清除');
  1307. // setTimeout(function () {
  1308. // UE.delEditor('ue');
  1309. // document.getElementById('edui_fixedlayer').parentNode.removeChild(document.getElementById('edui_fixedlayer'));
  1310. // te.dom.push(document.getElementById('ue'));
  1311. // start();
  1312. // }, 200);
  1313. // }, 200);
  1314. // }, 200);
  1315. // }, 200);
  1316. // }, 1000);
  1317. // }, 200);
  1318. // });
  1319. });
  1320. test('trace 3986 contextMenu 标题行中右插入列', function () {
  1321. var editor = te.obj[0];
  1322. var range = te.obj[1];
  1323. stop();
  1324. var lang = editor.getLang("contextMenu");
  1325. editor.execCommand('cleardoc');
  1326. editor.execCommand('inserttable');
  1327. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  1328. editor.execCommand('inserttitle');
  1329. range.setStart(editor.body.getElementsByTagName('th')[0], 0).collapse(true).select();
  1330. ua.contextmenu(editor.body.firstChild);
  1331. var menutable = document.getElementsByClassName("edui-menu-body")[1];
  1332. var forTable = document.getElementsByClassName('edui-for-table');
  1333. if (ua.browser.ie) {
  1334. ua.mouseenter(forTable[forTable.length - 1]);
  1335. } else {
  1336. ua.mouseover(forTable[forTable.length - 1]);
  1337. }
  1338. setTimeout(function () {
  1339. lang = editor.getLang("contextMenu");
  1340. equal(menutable.childNodes.length, 15, '15个子项目');//当光标在th[0]时,有15个项目
  1341. /*trace 3197:没有后插行选项*/
  1342. var innerText = lang.deletetable + lang.deleterow+ lang.deletecol + lang.insertcolnext + lang.insertcaption + lang.deletetitle +lang.inserttitlecol+ lang.mergeright + lang.edittd + lang.edittable+lang.setbordervisible;
  1343. if (browser.gecko) {
  1344. equal(menutable.textContent, innerText, '检查menu显示的字符');
  1345. } else {
  1346. equal(menutable.innerText.replace(/[\r\n\t\u200b\ufeff]/g, ''), innerText, '检查menu显示的字符');
  1347. }
  1348. ua.click(menutable.childNodes[4]);
  1349. equal(editor.body.getElementsByTagName('tr')[0].cells.length, 6, '左插入列后有6列');
  1350. setTimeout(function () {
  1351. document.getElementById('edui_fixedlayer').parentNode.removeChild(document.getElementById('edui_fixedlayer'));
  1352. te.dom.push(editor.container);
  1353. start();
  1354. }, 200);
  1355. });
  1356. });
  1357. /*trace 3060*/
  1358. test('contextMenu trace 3060:单元格对齐方式', function () {
  1359. var editor = te.obj[0];
  1360. var range = te.obj[1];
  1361. stop();
  1362. var lang = editor.getLang("contextMenu");
  1363. editor.execCommand('cleardoc');
  1364. editor.execCommand('inserttable');
  1365. editor.body.getElementsByTagName('td')[0].innerHTML = 'asd';
  1366. range.setStart(editor.body.firstChild.firstChild.firstChild.firstChild, 0).collapse(true).select();
  1367. ua.contextmenu(editor.body.firstChild);
  1368. var menutableBody = document.getElementsByClassName("edui-for-aligntd")[0];
  1369. setTimeout(function () {
  1370. lang = editor.getLang("contextMenu");
  1371. ua.click(menutableBody.childNodes[0]);
  1372. var div = document.getElementsByClassName('edui-cellalignpicker-body')[0];
  1373. equal(div.childNodes[0].getElementsByTagName('td').length, 9, '9种单元格对齐方式');
  1374. ua.click(div.childNodes[0].childNodes[0].childNodes[1].childNodes[2].firstChild);
  1375. setTimeout(function () {
  1376. var tds = editor.body.getElementsByTagName('td');
  1377. equal(tds[0].align, 'right', '水平居右');
  1378. equal(tds[0].vAlign, 'middle', '垂直居中');
  1379. if(ua.browser.ie>8){
  1380. equal(editor.selection.getRange().startContainer.tagName.toLowerCase(), 'td', '光标位于单元格中');
  1381. }else{
  1382. equal(editor.selection.getRange().startContainer.parentNode.tagName.toLowerCase(), 'td', '光标位于单元格中');
  1383. }
  1384. setTimeout(function () {
  1385. // te.dom.push(editor.container);
  1386. // document.getElementById('edui_fixedlayer').parentNode.removeChild(document.getElementById('edui_fixedlayer'));
  1387. start();
  1388. }, 20);
  1389. }, 200);
  1390. }, 200);
  1391. // });
  1392. });
  1393. /*trace 3315*/
  1394. /*trace 3411*/
  1395. test('contextMenu trace 3315:表格隔行变色', function () {
  1396. var editor = te.obj[0];
  1397. var range = te.obj[1];
  1398. var lang = editor.getLang("contextMenu");
  1399. editor.execCommand('cleardoc');
  1400. editor.execCommand('inserttable');
  1401. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  1402. ua.contextmenu(editor.body.firstChild);
  1403. var menutableBody = document.getElementsByClassName("edui-menu-body")[8];
  1404. var forTable = document.getElementsByClassName('edui-for-table');
  1405. if (ua.browser.ie) {
  1406. ua.mouseenter(forTable[forTable.length - 1]);
  1407. } else {
  1408. ua.mouseover(forTable[forTable.length - 1]);
  1409. }
  1410. setTimeout(function () {
  1411. lang = editor.getLang("contextMenu");
  1412. equal(menutableBody.childNodes.length, 1, '1个子项目');
  1413. if (browser.gecko) {
  1414. equal(menutableBody.textContent, '表格隔行变色', '检查menu显示的字符');
  1415. }
  1416. else {
  1417. equal(menutableBody.innerText.replace(/[\r\n\t\u200b\ufeff]/g, ''), '表格隔行变色', '检查menu显示的字符');
  1418. }
  1419. ua.click(menutableBody.childNodes[0]);
  1420. var trs = editor.body.getElementsByTagName('tr');
  1421. for (var i = 0; i < trs.length; i++) {
  1422. if (i % 2 == 0) {
  1423. ok(trs[i].className.indexOf('ue-table-interlace-color-single')>-1,'第' + i + '行:浅色行');
  1424. } else {
  1425. ok(trs[i].className.indexOf('ue-table-interlace-color-double')>-1,'第' + i + '行:深色行');
  1426. }
  1427. }
  1428. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  1429. ua.contextmenu(editor.body.firstChild);
  1430. menutableBody = document.getElementsByClassName("edui-menu-body")[8];
  1431. forTable = document.getElementsByClassName('edui-for-table');
  1432. if (ua.browser.ie) {
  1433. ua.mouseenter(forTable[forTable.length - 1]);
  1434. } else {
  1435. ua.mouseover(forTable[forTable.length - 1]);
  1436. }
  1437. setTimeout(function () {
  1438. lang = editor.getLang("contextMenu");
  1439. equal(menutableBody.childNodes.length, 1, '2个子项目');
  1440. if (browser.gecko) {
  1441. equal(menutableBody.textContent, '取消表格隔行变色', '检查menu显示的字符');
  1442. }
  1443. else {
  1444. equal(menutableBody.innerText.replace(/[\r\n\t\u200b\ufeff]/g, ''), '取消表格隔行变色', '检查menu显示的字符');
  1445. }
  1446. ua.click(menutableBody.childNodes[0]);
  1447. // equal(editor.body.getElementsByTagName('table')[0].interlaced,'disabled','取消表格隔行变色');
  1448. ok(editor.body.getElementsByTagName('tr')[0].className.indexOf('ue-table-interlace-color')<0, '取消表格隔行变色');
  1449. setTimeout(function () {
  1450. document.getElementById('edui_fixedlayer').parentNode.removeChild(document.getElementById('edui_fixedlayer'));
  1451. te.dom.push(editor.container);
  1452. start();
  1453. }, 200);
  1454. }, 200);
  1455. }, 200);
  1456. stop();
  1457. });