list.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. module("plugins.list");
  2. /*
  3. * <li>有序列表切换到无序
  4. * <li>无序列表切换到有序
  5. * <li>有序之间相互切换
  6. * <li>无序之间相互切换
  7. * <li>先引用后列表
  8. * <li>表格中插入列表
  9. * <li>h1套列表
  10. * <li>去除链接
  11. *
  12. * */
  13. //test('',function(){stop();})
  14. test('trace 3859 回车将p转成列表', function () {
  15. if(ua.browser.ie==9||ua.browser.ie==10)return;
  16. var editor = te.obj[0];
  17. var range = te.obj[1];
  18. var br = ua.browser.ie ? '' : '<br>';
  19. editor.setContent('<p>1. 2</p>');
  20. stop();
  21. setTimeout(function () {
  22. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  23. ua.keydown(editor.body, {keyCode:13});
  24. setTimeout(function () {
  25. ua.checkSameHtml(ua.getChildHTML(editor.body), '<ol style=\"list-style-type: decimal;\" class=\" list-paddingleft-2\"><li><p> 2</p></li><li><p>' + br + '</p></li></ol>', '回车将p转成列表');
  26. start()
  27. }, 50);
  28. }, 100);
  29. });
  30. //todo bug3418
  31. test('ol标签嵌套', function () {
  32. var editor = te.obj[0];
  33. editor.setContent('<ol class="custom_num list-paddingleft-1"><li class="list-num-1-1 list-num-paddingleft-1"><p>a</p></li><ol class="custom_num list-paddingleft-1"><li class="list-num-1-1 list-num-paddingleft-1"><p>b</p></li></ol></ol>');
  34. ua.checkSameHtml(editor.body.innerHTML, '<ol class=\"custom_num list-paddingleft-1\"><li class=\"list-num-1-1 list-num-paddingleft-1\"><p>a</p></li><ol class=\"custom_num1 list-paddingleft-2\"><li class=\"list-num-2-1 list-num1-paddingleft-1\"><p>b</p></li></ol></ol>');
  35. });
  36. test('li内添加p标签', function () {
  37. var editor = te.obj[0];
  38. editor.setContent('<ol><li>asd<p>asd</p></li></ol>');
  39. ua.manualDeleteFillData(editor.body);
  40. ua.checkSameHtml(editor.body.innerHTML, '<ol class=\" list-paddingleft-2\"><li><p>asd</p><p>asd</p></li></ol>', '添加p标签');
  41. });
  42. //todo 1.2.6.1
  43. test('p转成列表', function () {
  44. var div = document.body.appendChild(document.createElement('div'));
  45. div.id = 'ue';
  46. var editor = UE.getEditor('ue',{autoTransWordToList:true});
  47. // var br = ua.browser.ie ? '&nbsp;' : '';
  48. var br = '';
  49. editor.ready(function () {
  50. setTimeout(function(){
  51. editor.setContent('<p class="MsoListParagraph">1.a</p><ol><li>b</li></ol>');
  52. ua.manualDeleteFillData(editor.body);
  53. //todo 1.2.6.1
  54. // ua.checkSameHtml(editor.body.innerHTML,'<ol style=\"list-style-type: decimal;\" class=\" list-paddingleft-2\"><li><p>a</p></li><li><p>b</p></li></ol>','p转成有序列表');
  55. editor.setContent('<p class="MsoListParagraph"><span style="font-family: Symbol;">abc</span></p>');
  56. ua.manualDeleteFillData(editor.body);
  57. ua.checkSameHtml(editor.body.innerHTML, '<ul style=\"list-style-type: disc;\" class=\" list-paddingleft-2\"><li><p>' + br + '</p></li></ul>', 'p转成无序列表');
  58. //todo bug3417
  59. // editor.setContent('<p class="MsoListParagraph"><span style="font-family: Symbol;">n</span></p>');
  60. // ua.manualDeleteFillData(editor.body);
  61. // ua.checkSameHtml(editor.body.innerHTML,'<ul style=\"list-style-type: disc;\" class=\" list-paddingleft-2\"><li><p><br></p></li></ul>','p转成无序列表');
  62. UE.delEditor('ue');
  63. te.dom.push(document.getElementById('ue'));
  64. start();
  65. },200);
  66. });
  67. stop();
  68. });
  69. test('列表复制粘贴', function () {
  70. var editor = te.obj[0];
  71. editor.setContent('<ol class="custom_num2 list-paddingleft-1"><li class="list-num-3-1 list-num2-paddingleft-1">a</li><li>b</li></ol><ul><li>a</li><li>b</li></ul>');
  72. ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
  73. ua.keydown(editor.body, {'keyCode':67, 'ctrlKey':true});
  74. /*ctrl+c*/
  75. setTimeout(function () {
  76. var html = {html:editor.body.innerHTML};
  77. editor.fireEvent('beforepaste', html);
  78. /*粘贴*/
  79. // range.setStart(editor.body,1).collapse(true).select();
  80. // editor.fireEvent("paste");
  81. // ua.manualDeleteFillData(editor.body);
  82. // equal(editor.body.innerHTML,'<p><br></p>','编辑器清空');
  83. editor.setContent('<ol><li>a</li><li>b</li></ol><ul><li>a</li><li>b</li></ul>');
  84. ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
  85. ua.keydown(editor.body, {'keyCode':67, 'ctrlKey':true});
  86. /*ctrl+c*/
  87. html = {html:editor.body.innerHTML};
  88. editor.fireEvent('beforepaste', html);
  89. /*粘贴*/
  90. editor.setContent('<ol><ol><li>a</li><li>b</li></ol><ul><li>a</li><li>b</li></ul></ol>');
  91. ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
  92. ua.keydown(editor.body, {'keyCode':67, 'ctrlKey':true});
  93. /*ctrl+c*/
  94. html = {html:editor.body.innerHTML};
  95. editor.fireEvent('beforepaste', html);
  96. /*粘贴*/
  97. editor.setContent('<ol class="custom_cn1 list-paddingleft-1"><ol><li>a</li><li>b</li></ol><ul><li>a</li><li>b</li></ul></ol>');
  98. ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
  99. ua.keydown(editor.body, {'keyCode':67, 'ctrlKey':true});
  100. /*ctrl+c*/
  101. html = {html:editor.body.innerHTML};
  102. setTimeout(function () {
  103. editor.fireEvent('beforepaste', html);
  104. /*粘贴*/
  105. start()
  106. }, 50);
  107. }, 50);
  108. stop();
  109. });
  110. //TODO trace-3416 此处只为提高覆盖率
  111. //test('剪切列表',function(){
  112. // var editor = te.obj[0];
  113. // var range = te.obj[1];
  114. // editor.setContent('<ol><li><p><img src="http://img.baidu.com/hi/jx2/j_0015.gif"/><br/></p></li><li></li></ol>');
  115. // range.setStart(editor.body.firstChild.lastChild,0).collapse(true).select();
  116. // ua.cut(editor.body);
  117. // stop();
  118. // setTimeout(function(){
  119. // ua.manualDeleteFillData(editor.body);
  120. // var br = ua.browser.ie?'':'<br>';
  121. // equal(editor.body.innerHTML,'<p>'+br+'</p>','编辑器清空');
  122. // editor.setContent('<ol><li><p><img src="http://img.baidu.com/hi/jx2/j_0015.gif"/><br/></p></li><li></li></ol><p>asdf</p>');
  123. // range.setStart(editor.body.firstChild.lastChild,0).collapse(true).select();
  124. // ua.cut(editor.body);
  125. // setTimeout(function(){
  126. // ua.manualDeleteFillData(editor.body);
  127. // equal(editor.body.innerHTML,'<p>asdf</p>','列表删除');
  128. // editor.setContent('<a href="http://www.baidu.com">www.baidu.com</a><ol><li><p><img src="http://img.baidu.com/hi/jx2/j_0015.gif"/><br/></p></li><li></li></ol>');
  129. // range.setStart(editor.body.firstChild.nextSibling.lastChild,0).collapse(true).select();
  130. // ua.cut(editor.body);
  131. // setTimeout(function(){
  132. // ua.manualDeleteFillData(editor.body);
  133. // ua.checkSameHtml(editor.body.innerHTML,'<p><a href=\"http://www.baidu.com\" _href=\"http://www.baidu.com\">www.baidu.com</a></p>','列表删除');
  134. // start();
  135. // },20);
  136. // },20);
  137. // },20);
  138. //});
  139. test('修改列表再删除列表', function () {
  140. if ((ua.browser.safari && !ua.browser.chrome))return 0;
  141. var editor = te.obj[0];
  142. var range = te.obj[1];
  143. var br = baidu.editor.browser.ie ? "" : "<br>";
  144. editor.setContent('<ol>hello1</ol>');
  145. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  146. editor.execCommand('insertorderedlist', 'cn2');
  147. ua.manualDeleteFillData(editor.body);
  148. equal(editor.body.firstChild.tagName.toLowerCase(), 'ol', '查询列表的类型');
  149. equal(ua.getChildHTML(editor.body.firstChild), '<li class=\"list-cn-3-1 list-cn2-paddingleft-1\"><p>hello1</p></li>');
  150. range.setStart(editor.body.lastChild, 0).setEnd(editor.body.lastChild, 1).select();
  151. editor.execCommand('insertorderedlist', 'cn2');
  152. ua.manualDeleteFillData(editor.body);
  153. ua.checkSameHtml(editor.body.innerHTML, '<p>hello1</p>');
  154. });
  155. test('列表内没有列表标号的项后退', function () {
  156. if ((ua.browser.safari && !ua.browser.chrome))return 0;
  157. var editor = te.obj[0];
  158. var range = te.obj[1];
  159. var lis;
  160. var br = ua.browser.ie ? '<br>' : '<br>';
  161. editor.setContent('<ol><li><p>hello</p><p><a href="http://www.baidu.com">www.baidu.com</a></p></li></ol>');
  162. range.setStart(editor.body.firstChild.firstChild.lastChild.lastChild, 0).collapse(true).select();
  163. ua.manualDeleteFillData(editor.body);
  164. ua.keydown(editor.body, {keyCode:8});
  165. setTimeout(function () {
  166. lis = editor.body.getElementsByTagName('li');
  167. equal(lis.length, '1', '列表长度不变');
  168. ua.checkSameHtml(ua.getChildHTML(editor.body), '<ol class=" list-paddingleft-2"><li><p>hello</p></li></ol><p><a href="http://www.baidu.com" _href="http://www.baidu.com">www.baidu.com</a></p>', 'p在列表外');
  169. start()
  170. }, 50);
  171. stop();
  172. });
  173. test('多个p,选中其中几个变为列表', function () {
  174. var editor = te.obj[0];
  175. var range = te.obj[1];
  176. var body = editor.body;
  177. editor.setContent('<p>hello1</p><p>hello2</p><p>hello3</p><p>hello4</p>');
  178. setTimeout(function () {
  179. range.setStart(body.firstChild, 0).setEnd(body.firstChild.nextSibling, 1).select();
  180. editor.execCommand('insertorderedlist');
  181. equal(ua.getChildHTML(body.firstChild), '<li><p>hello1</p></li><li><p>hello2</p></li>', '检查列表的内容');
  182. equal(body.firstChild.tagName.toLowerCase(), 'ol', '检查列表的类型');
  183. equal(body.childNodes.length, 3, '3个孩子');
  184. equal(body.lastChild.tagName.toLowerCase(), 'p', '后面的p没有变为列表');
  185. equal(body.lastChild.innerHTML.toLowerCase(), 'hello4', 'p里的文本');
  186. start();
  187. }, 50);
  188. stop();
  189. });
  190. //trace 988,有序123切到abc再切到123
  191. test('有序列表的切换', function () {
  192. var editor = te.obj[0];
  193. var range = te.obj[1];
  194. var body = editor.body;
  195. editor.setContent('<p>你好</p><p>是的</p>');
  196. setTimeout(function () {
  197. range.setStart(body, 0).setEnd(body, 2).select();
  198. editor.execCommand('insertorderedlist', 'decimal');
  199. equal(editor.queryCommandValue('insertorderedlist'), 'decimal', '查询插入数字列表的结果1');
  200. editor.execCommand('insertorderedlist', 'lower-alpha');
  201. equal(editor.queryCommandValue('insertorderedlist'), 'lower-alpha', '查询插入字母列表的结果');
  202. editor.execCommand('insertorderedlist', 'decimal');
  203. equal(editor.queryCommandValue('insertorderedlist'), 'decimal', '查询插入数字列表的结果2');
  204. start();
  205. }, 50);
  206. stop();
  207. });
  208. //trace 988,无序圆圈切到方块再切到圆圈
  209. test('无序列表之间的切换', function () {
  210. var editor = te.obj[0];
  211. var range = te.obj[1];
  212. var body = editor.body;
  213. editor.setContent('<p>你好</p><p>是的</p>');
  214. range.setStart(body, 0).setEnd(body, 2).select();
  215. editor.execCommand('insertunorderedlist', 'circle');
  216. equal(editor.queryCommandValue('insertunorderedlist'), 'circle', '查询插入圆圈列表的结果1');
  217. editor.execCommand('insertunorderedlist', 'square');
  218. equal(editor.queryCommandValue('insertunorderedlist'), 'square', '查询插入正方形列表的结果');
  219. editor.execCommand('insertunorderedlist', 'circle');
  220. equal(editor.queryCommandValue('insertunorderedlist'), 'circle', '查询插入圆圈列表的结果1');
  221. });
  222. test('引用中插入列表', function () {
  223. var editor = te.obj[0];
  224. var range = te.obj[1];
  225. var body = editor.body;
  226. editor.setContent('<p></p>');
  227. range.setStart(body.firstChild, 0).collapse(1).select();
  228. editor.execCommand('blockquote');
  229. editor.execCommand('insertorderedlist');
  230. equal(body.firstChild.tagName.toLowerCase(), 'blockquote', 'firstChild of body is blockquote');
  231. equal(body.childNodes.length, 1, '只有一个孩子');
  232. equal(body.firstChild.firstChild.tagName.toLowerCase(), 'ol', 'insert an ordered list');
  233. equal(body.firstChild.childNodes.length, 1, 'blockquote只有一个孩子');
  234. equal($(body.firstChild.firstChild).css('list-style-type'), 'decimal', '数字列表');
  235. equal(editor.queryCommandValue('insertorderedlist'), 'decimal', 'queryCommand value is decimal');
  236. });
  237. /*trace 1118*/
  238. test('去除无序列表', function () {
  239. var editor = te.obj[0];
  240. var range = te.obj[1];
  241. var body = editor.body;
  242. editor.setContent('<p></p>');
  243. range.setStart(body.firstChild, 0).collapse(1).select();
  244. editor.execCommand('insertunorderedlist');
  245. equal(body.firstChild.tagName.toLowerCase(), 'ul', 'insert an unordered list');
  246. equal(body.childNodes.length, 1, 'body只有一个孩子');
  247. equal(editor.queryCommandValue('insertunorderedlist'), 'disc', 'queryCommand value is disc');
  248. ok(editor.queryCommandState('insertunorderedlist'), 'state是1');
  249. /*去除列表*/
  250. editor.execCommand('insertunorderedlist');
  251. ua.manualDeleteFillData(editor.body);
  252. equal(body.firstChild.tagName.toLowerCase(), 'p', '去除列表');
  253. equal(body.childNodes.length, 1, 'body只有一个孩子');
  254. ok(!editor.queryCommandState('insertunorderedlist'), 'state是0');
  255. });
  256. test('闭合方式有序和无序列表之间的切换', function () {
  257. var editor = te.obj[0];
  258. var range = te.obj[1];
  259. var body = editor.body;
  260. editor.setContent('<p></p>');
  261. range.setStart(body.firstChild, 0).collapse(1).select();
  262. editor.execCommand('insertunorderedlist');
  263. equal(body.firstChild.tagName.toLowerCase(), 'ul', 'insert an unordered list');
  264. equal(body.childNodes.length, 1, 'body只有一个孩子');
  265. equal(editor.queryCommandValue('insertunorderedlist'), 'disc', 'queryCommand value is disc');
  266. equal(editor.queryCommandValue('insertorderedlist'), null, '有序列表查询结果为null');
  267. /*切换为有序列表*/
  268. editor.execCommand('insertorderedlist');
  269. ua.manualDeleteFillData(editor.body);
  270. equal(body.firstChild.tagName.toLowerCase(), 'ol', '变为有序列表');
  271. equal(body.childNodes.length, 1, 'body只有一个孩子');
  272. equal(editor.queryCommandValue('insertorderedlist'), 'decimal', 'queryCommand value is decimal');
  273. equal(editor.queryCommandValue('insertunorderedlist'), null, '无序列表查询结果为null');
  274. /*切换为圆圈无序列表*/
  275. editor.execCommand('insertunorderedlist', 'circle');
  276. ua.manualDeleteFillData(editor.body);
  277. equal(body.firstChild.tagName.toLowerCase(), 'ul', '变为无序列表');
  278. equal(body.childNodes.length, 1, 'body只有一个孩子');
  279. equal(editor.queryCommandValue('insertunorderedlist'), 'circle', '无序列表是圆圈');
  280. equal(editor.queryCommandValue('insertorderedlist'), null, '有序列表查询结果为null');
  281. });
  282. test('非闭合方式切换有序和无序列表', function () {
  283. var editor = te.obj[0];
  284. var range = te.obj[1];
  285. var body = editor.body;
  286. /*如果只选中hello然后切换有序无序的话,不同浏览器下表现不一样*/
  287. editor.setContent('<ol><li>hello</li><li>hello3</li></ol><p>hello2</p>');
  288. range.selectNode(body.firstChild).select();
  289. editor.execCommand('insertunorderedlist', 'square');
  290. equal(body.firstChild.tagName.toLowerCase(), 'ul', '有序列表变为无序列表');
  291. equal(editor.queryCommandValue('insertunorderedlist'), 'square', '无序列表是方块');
  292. equal(ua.getChildHTML(body.firstChild), '<li><p>hello</p></li><li><p>hello3</p></li>', 'innerHTML 不变');
  293. /*切换为有序列表*/
  294. editor.execCommand('insertorderedlist', 'upper-alpha');
  295. equal(body.firstChild.tagName.toLowerCase(), 'ol', '无序列表变为有序列表');
  296. equal(editor.queryCommandValue('insertorderedlist'), 'upper-alpha', '有序列表是A');
  297. equal(ua.getChildHTML(body.firstChild), '<li><p>hello</p></li><li><p>hello3</p></li>', '变为有序列表后innerHTML 不变');
  298. });
  299. test('将列表下的文本合并到列表中', function () {
  300. var editor = te.obj[0];
  301. var range = te.obj[1];
  302. var body = editor.body;
  303. editor.setContent('<ul><li>hello1</li></ul><p>是的</p>');
  304. setTimeout(function () {
  305. range.setStart(body.firstChild, 0).setEnd(body.lastChild, 1).select();
  306. /*将无序的变为有序,文本也相应变成无序列表的一部分*/
  307. editor.execCommand('insertorderedlist');
  308. ua.manualDeleteFillData(editor.body);
  309. equal(body.firstChild.tagName.toLowerCase(), 'ol', 'ul变为了ol');
  310. equal(ua.getChildHTML(body.firstChild), '<li><p>hello1</p></li><li><p>是的</p></li>');
  311. equal(body.childNodes.length, 1, '只有一个孩子是ol');
  312. start();
  313. }, 50);
  314. stop();
  315. });
  316. test('多个列表', function () {
  317. var editor = te.obj[0];
  318. var range = te.obj[1];
  319. var body = editor.body;
  320. editor.setContent('<ol><li>hello1</li></ol><ul><li>hello2</li></ul>');
  321. range.selectNode(body.lastChild).select();
  322. /*将无序的变为有序*/
  323. editor.execCommand('insertorderedlist');
  324. equal(body.firstChild.tagName.toLowerCase(), 'ol', '仍然是ol');
  325. equal(body.childNodes.length, 1, 'body只有1个孩子ol');
  326. equal(body.firstChild.childNodes.length, 2, '下面的列表合并到上面');
  327. equal(ua.getChildHTML(body.lastChild), '<li><p>hello1</p></li><li><p>hello2</p></li>', '2个li子节点');
  328. });
  329. test('修改列表中间某一段列表为另一种列表', function () {
  330. var editor = te.obj[0];
  331. var range = te.obj[1];
  332. var body = editor.body;
  333. editor.setContent('<ol><li>hello</li><li>hello2</li><li>hello3</li><li>hello4</li></ol>');
  334. var lis = body.firstChild.getElementsByTagName('li');
  335. range.setStart(lis[1], 0).setEnd(lis[2], 1).select();
  336. editor.execCommand('insertunorderedlist');
  337. equal(body.childNodes.length, 3, '3个列表');
  338. equal(ua.getChildHTML(body.firstChild), '<li><p>hello</p></li>', '第一个列表只有一个li');
  339. equal(ua.getChildHTML(body.lastChild), '<li><p>hello4</p></li>', '最后一个列表只有一个li');
  340. equal(body.childNodes[1].tagName.toLowerCase(), 'ul', '第二个孩子是无序列表');
  341. equal(ua.getChildHTML(body.childNodes[1]), '<li><p>hello2</p></li><li><p>hello3</p></li>', '检查第二个列表的内容');
  342. });
  343. test('两个列表,将下面的合并上去', function () {
  344. var editor = te.obj[0];
  345. var range = te.obj[1];
  346. var body = editor.body;
  347. editor.setContent('<ol><li>hello3</li></ol><ol><li>hello1</li></ol><ul><li>hello2</li></ul>');
  348. range.selectNode(body.lastChild).select();
  349. /*将无序的变为有序,有序上面的有序不会合并在一起了*/
  350. editor.execCommand('insertorderedlist');
  351. equal(body.firstChild.tagName.toLowerCase(), 'ol', '仍然是ol');
  352. equal(body.childNodes.length, 2, 'body有两个孩子ol');
  353. equal(body.lastChild.childNodes.length, 2, '下面和上面的列表合并到上面去了');
  354. //TODO 1.2.6不严重bug注释 空style未删除
  355. // equal( ua.getChildHTML( editor.body ), '<ol class=" list-paddingleft-2" ><li><p>hello3</p></li></ol><ol class=" list-paddingleft-2" ><li><p>hello1</p></li><li><p>hello2</p></li></ol>', '3个li子节点' );
  356. });
  357. test('trace 3293:列表下的文本合并到列表中', function () {
  358. var editor = te.obj[0];
  359. var range = te.obj[1];
  360. var body = editor.body;
  361. editor.setContent('<ol><li>hello3</li><li>hello1</li></ol><p>文本1</p><p>文本2</p>');
  362. range.setStart(body, 1).setEnd(body, 3).select();
  363. /*选中文本变为有序列表,和上面的列表合并了*/
  364. editor.execCommand('insertorderedlist');
  365. var ol = body.firstChild;
  366. equal(body.childNodes.length, 1, '所有合并为一个列表');
  367. equal(ol.tagName.toLowerCase(), 'ol', '仍然是ol');
  368. equal(ol.childNodes.length, 4, '下面和上面的列表合并到上面去了');
  369. equal(ua.getChildHTML(body.firstChild), '<li><p>hello3</p></li><li><p>hello1</p></li><li><p>文本1</p></li><li><p>文本2</p></li>', '4个li子节点');
  370. });
  371. test('2个相同类型的列表合并', function () {
  372. var editor = te.obj[0];
  373. var range = te.obj[1];
  374. var body = editor.body;
  375. editor.setContent('<ol><li>hello3</li><li>hello1</li></ol><ol style="list-style-type: lower-alpha"><li><p>文本1</p></li><li><p>文本2</p></li></ol>');
  376. range.selectNode(body.lastChild).select();
  377. editor.execCommand('insertorderedlist');
  378. var ol = body.firstChild;
  379. equal(body.childNodes.length, 1, '所有合并为一个列表');
  380. equal(ol.tagName.toLowerCase(), 'ol', '仍然是ol');
  381. equal(ol.childNodes.length, 4, '下面和上面的列表合并到上面去了');
  382. equal(ua.getChildHTML(body.firstChild), '<li><p>hello3</p></li><li><p>hello1</p></li><li><p>文本1</p></li><li><p>文本2</p></li>', '4个li子节点');
  383. });
  384. test('不闭合情况h1套列表', function () {
  385. var editor = te.obj[0];
  386. var range = te.obj[1];
  387. var body = editor.body;
  388. editor.setContent('<h1>hello1</h1><h2>hello2</h2>');
  389. range.setStart(body.firstChild, 0).setEnd(body.lastChild, 1).select();
  390. /*对h1添加列表*/
  391. editor.execCommand('insertorderedlist');
  392. equal(body.firstChild.tagName.toLowerCase(), 'ol', '仍然是ol');
  393. equal(ua.getChildHTML(body.firstChild), '<li><h1>hello1</h1></li><li><h2>hello2</h2></li>', '查看插入列表后的结果');
  394. equal(body.childNodes.length, 1, 'body只有一个孩子ol');
  395. equal(body.firstChild.childNodes.length, 2, '2个li');
  396. });
  397. test('闭合情况h1套列表', function () {
  398. var editor = te.obj[0];
  399. var range = te.obj[1];
  400. var body = editor.body;
  401. editor.setContent('<h2>hello1</h2>');
  402. range.setStart(body.firstChild, 0).collapse(1).select();
  403. /*对h1添加列表*/
  404. editor.execCommand('insertorderedlist');
  405. equal(body.firstChild.tagName.toLowerCase(), 'ol', '仍然是ol');
  406. equal(ua.getChildHTML(body.firstChild), '<li><h2>hello1</h2></li>', '查看插入列表后的结果');
  407. equal(body.childNodes.length, 1, 'body只有一个孩子ol');
  408. equal(body.firstChild.childNodes.length, 1, '1个li');
  409. });
  410. test('列表内后退', function () {
  411. /*实际操作没问题,取range时会在将文本节点分为两个节点,后退操作无法实现*/
  412. if ((ua.browser.safari && !ua.browser.chrome))
  413. return 0;
  414. var editor = te.obj[0];
  415. var range = te.obj[1];
  416. var lis;
  417. var br = ua.browser.ie ? '<br>' : '<br>';
  418. //////标签空格的处理
  419. editor.setContent('<ol><li><br></li><li><p>hello2</p></li><li><br></li><li><sss>hello3</sss></li><li><p>hello4</p></li><li><p>hello5</p></li></ol>');
  420. // editor.setContent('<ol><li><br></li><li><p>hello2</p></li><li></li><li><sss>hello3</sss></li><li><p>hello4</p></li><li><p>hello5</p></li></ol>');
  421. range.setStart(editor.body.firstChild.lastChild.firstChild.firstChild, 0).collapse(1).select();
  422. ua.manualDeleteFillData(editor.body);
  423. ua.keydown(editor.body, {keyCode:8});
  424. var ol = editor.body.getElementsByTagName('ol');
  425. lis = editor.body.getElementsByTagName('li');
  426. equal(lis.length, '5', '变成5个列表项');
  427. equal(ua.getChildHTML(editor.body.firstChild), '<li><p>' + br + '</p></li><li><p>hello2</p></li><li><p>' + br + '</p></li><li><sss>hello3</sss></li><li><p>hello4</p><p>hello5</p></li>', '最后一个列表项');
  428. range.setStart(lis[0].firstChild, 0).collapse(1).select();
  429. ua.keydown(editor.body, {keyCode:8});
  430. lis = editor.body.getElementsByTagName('li');
  431. equal(lis.length, '4', '变成4个列表项');
  432. equal(ua.getChildHTML(editor.body.lastChild), '<li><p>hello2</p></li><li><p>' + br + '</p></li><li><sss>hello3</sss></li><li><p>hello4</p><p>hello5</p></li>', '第一个列表项且为空行');
  433. range.setStart(lis[1].firstChild, 0).collapse(1).select();
  434. ua.keydown(editor.body, {keyCode:8});
  435. lis = editor.body.getElementsByTagName('li');
  436. equal(lis.length, '3', '变成3个列表项');
  437. equal(ua.getChildHTML(editor.body.lastChild), '<li><p>hello2</p><p>' + br + '</p></li><li><sss>hello3</sss></li><li><p>hello4</p><p>hello5</p></li>', '中间列表项且为空行');
  438. if (!ua.browser.ie) {
  439. range.setStart(lis[1].firstChild.firstChild, 0).collapse(1).select();
  440. ua.manualDeleteFillData(editor.body);
  441. ua.keydown(editor.body, {keyCode:8});
  442. //TODO 1.2.6不严重bug注释 空style未删除
  443. // equal(ua.getChildHTML(editor.body),'<p><br></p><ol class=\" list-paddingleft-2\"><li><p>hello2</p><p><br></p><sss>hello3</sss></li><li><p>hello4</p><p>hello5</p></li></ol>','自定义标签后退');
  444. }
  445. });
  446. test('列表内回车', function () {
  447. var editor = te.obj[0];
  448. var range = te.obj[1];
  449. var lis;
  450. var br = ua.browser.ie ? '' : '<br>';
  451. editor.setContent('<ol><li><sss></sss><sss></sss></li></ol>');
  452. lis = editor.body.getElementsByTagName('li');
  453. range.setStart(lis[0], 0).collapse(1).select();
  454. ua.keydown(editor.body, {keyCode:13});
  455. var spa = ua.browser.opera ? '<br>' : '';
  456. equal(ua.getChildHTML(editor.body), spa + '<p><sss></sss><sss></sss></p>', '空列表项回车--无列表');
  457. editor.setContent('<ol><li><sss>hello1</sss><p>hello2</p></li></ol>');
  458. lis = editor.body.getElementsByTagName('li');
  459. range.setStart(lis[0].lastChild, 0).collapse(1).select();
  460. ua.keydown(editor.body, {keyCode:13});
  461. equal(ua.getChildHTML(editor.body.firstChild), '<li><p><sss>hello1</sss><p></p></p></li><li><p><p>hello2</p></p></li>', '单个列表项内回车');
  462. //////标签空格的处理
  463. // editor.setContent('<ol><li><br></li><li><p>hello5</p></li><li><p><br></p><p><br></p></li></ol>');
  464. editor.setContent('<ol><li><br></li><li><p>hello5</p></li><li><p><br></p><p><br></p></li></ol>');
  465. lis = editor.body.getElementsByTagName('li');
  466. range.setStart(lis[2].firstChild.firstChild, 0).setEnd(lis[2].lastChild.firstChild, 0).select();
  467. ua.keydown(editor.body, {keyCode:13});
  468. //TODO 1.2.6不严重bug注释 空style未删除
  469. // equal(ua.getChildHTML(editor.body),'<ol class=\" list-paddingleft-2\"><li><p>'+br+'</p></li><li><p>hello5</p></li></ol><p>'+br+'</p>','最后一个列表项为空行回车');
  470. /*trace 2652*/
  471. range.setStart(editor.body.firstChild.firstChild.firstChild, 0).collapse(1).select();
  472. ua.keydown(editor.body, {keyCode:13});
  473. //TODO 1.2.6不严重bug注释 空style未删除
  474. // equal(ua.getChildHTML(editor.body),'<p>'+br+'</p><ol class=\" list-paddingleft-2\"><li><p>hello5</p></li></ol><p>'+br+'</p>','第一个列表项为空行下回车');
  475. /*trace 2653*/
  476. editor.setContent('<ol><li><p>hello2</p></li><li><p>hello3</p></li><li><p><br /></p><p>hello5</p></li></ol>');
  477. lis = editor.body.getElementsByTagName('li');
  478. range.setStart(lis[0].firstChild.firstChild, 2).setEnd(lis[1].firstChild.firstChild, 4).select();
  479. ua.keydown(editor.body, {keyCode:13});
  480. equal(ua.getChildHTML(editor.body.firstChild), '<li><p>he</p></li><li><p>o3</p></li><li><p><br></p><p>hello5</p></li>', '非闭合回车');
  481. editor.setContent('<ol><li><sss>hello</sss><p>hello4</p></li><li><p>hello5</p></li></ol>');
  482. lis = editor.body.getElementsByTagName('li');
  483. range.setStart(lis[0].lastChild.firstChild, 1).setEnd(lis[0].lastChild.firstChild, 2).select();
  484. ua.keydown(editor.body, {keyCode:13});
  485. equal(ua.getChildHTML(editor.body.firstChild), '<li><p><sss>hello</sss><p>h</p></p></li><li><p><p>llo4</p></p></li><li><p>hello5</p></li>', '一个列表项内两行');
  486. });
  487. test('tab键', function () {
  488. var editor = te.obj[0];
  489. var range = te.obj[1];
  490. var lis;
  491. editor.setContent('<ol><li><p>hello1</p></li><li><p>hello2</p></li></ol>');
  492. lis = editor.body.getElementsByTagName('li');
  493. range.setStart(lis[1], 0).collapse(1).select();
  494. ua.keydown(editor.body, {keyCode:9});
  495. ua.keydown(editor.body, {keyCode:9});
  496. var str = '<li><p>hello1</p></li><ol style="list-style-type: lower-alpha;" class=" list-paddingleft-2" ><ol style="list-style-type: lower-roman;" class=" list-paddingleft-2" ><li><p>hello2</p></li></ol></ol>';
  497. ua.checkSameHtml(str, editor.body.firstChild.innerHTML.toLowerCase(), '有序列表---tab键');
  498. });
  499. test('回车后产生新的li-选区闭合', function () {
  500. var editor = te.obj[0];
  501. var range = te.obj[1];
  502. var body = editor.body;
  503. editor.setContent('<p>hello1</p><p>hello2</p>');
  504. setTimeout(function () {
  505. range.setStart(body.firstChild, 0).setEnd(body.firstChild.nextSibling, 1).select();
  506. editor.execCommand('insertorderedlist');
  507. var lastLi = body.firstChild.lastChild.firstChild.firstChild;
  508. range.setStart(lastLi, lastLi.length).collapse(1).select();
  509. setTimeout(function () {
  510. ua.keydown(editor.body, {'keyCode':13});
  511. equal(body.firstChild.childNodes.length, 3, '回车后产生新的li');
  512. equal(body.firstChild.lastChild.tagName.toLowerCase(), 'li', '回车后产生新的li');
  513. var br = ua.browser.ie ? '' : '<br>';
  514. equal(ua.getChildHTML(body.firstChild), '<li><p>hello1</p></li><li><p>hello2</p></li><li><p>' + br + '</p></li>', '检查内容');
  515. var lastLi = body.firstChild.lastChild.firstChild.firstChild;
  516. range.setStart(lastLi, lastLi.length).collapse(1).select();
  517. setTimeout(function () {
  518. ua.keydown(editor.body, {'keyCode':13});
  519. equal(body.firstChild.childNodes.length, 2, '空li后回车,删除此行li');
  520. equal(body.lastChild.tagName.toLowerCase(), 'p', '产生p');
  521. br = ua.browser.ie ? '' : '<br>';
  522. ua.manualDeleteFillData(body.lastChild);
  523. equal(body.lastChild.innerHTML.toLowerCase().replace(/\r\n/ig, ''), br, '检查内容');
  524. start()
  525. }, 20);
  526. }, 20);
  527. }, 50);
  528. stop();
  529. });
  530. /*trace 3074*/
  531. test('trace 1622:表格中插入列表', function () {
  532. var editor = te.obj[0];
  533. var range = te.obj[1];
  534. var body = editor.body;
  535. editor.setContent('<table><tbody><tr><td><br></td><td>你好</td></tr><tr><td>hello2</td><td>你好2</td></tr></tbody></table>');
  536. /*必须加br,否则没办法占位*/
  537. stop()
  538. setTimeout(function () {
  539. var tds = body.getElementsByTagName('td');
  540. range.setStart(tds[0], 0).collapse(1).select();
  541. /*选中一个单元格*/
  542. editor.execCommand('insertorderedlist');
  543. /*插入有序列表*/
  544. equal(tds[0].firstChild.tagName.toLowerCase(), 'ol', '查询列表的类型');
  545. equal(tds[0].firstChild.style['listStyleType'], 'decimal', '查询有序列表的类型');
  546. var br = baidu.editor.browser.ie ? "<br>" : "<br>";
  547. equal(ua.getChildHTML(tds[0].firstChild), '<li>' + '<p>' + br + '</p>' + '</li>');
  548. setTimeout(function () {
  549. var trs = editor.body.firstChild.getElementsByTagName('tr');
  550. /*选中多个单元格*/
  551. var ut = editor.getUETable(editor.body.firstChild);
  552. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  553. ut.setSelected(cellsRange);
  554. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  555. tds = body.getElementsByTagName('td');
  556. editor.execCommand('insertunorderedlist', 'circle');
  557. /*插入无序列表*/
  558. equal(tds[1].firstChild.tagName.toLowerCase(), 'ul', '查询无序列表');
  559. equal(tds[1].firstChild.style['listStyleType'], 'circle', '查询无序列表的类型');
  560. equal(ua.getChildHTML(tds[1].firstChild), '<li>你好</li>');
  561. equal(ua.getChildHTML(tds[3].firstChild), '<li>你好2</li>');
  562. start();
  563. }, 50);
  564. }, 50);
  565. });
  566. ///*presskey*/
  567. //test( ' trace 1536:删除部分列表', function () {
  568. // var editor = te.obj[0];
  569. // editor.setContent( '<ol><li>hello1</li><li>你好</li><li>hello3</li></ol>' );
  570. // var body = editor.body;
  571. // var range = te.obj[1];
  572. // stop();
  573. // expect( 2 );
  574. // range.setStart( body.firstChild, 1 ).setEnd( body.firstChild, 2 ).select();
  575. // editor.focus();
  576. // te.presskey( 'del', '' );
  577. // editor.focus();
  578. // setTimeout( function () {
  579. // equal( body.childNodes.length, 1, '删除后只剩一个ol元素' );
  580. // var br = (baidu.editor.browser.ie || baidu.editor.browser.gecko) ? "" : "<br>";
  581. // //todo 不同浏览器原生选区的差别导致
  582. //// equal( ua.getChildHTML( body ), '<ol><li><p>hello1</p></li><li><p>hello3' + br + '</p></li></ol>', '第二个li被删除' );
  583. // start();
  584. // }, 30 );
  585. //} );
  586. ///*presskey*/
  587. //test( ' trace 1544,1624 :列表中回车后再回退,会产生一个空行', function () {
  588. // var editor = te.obj[0];
  589. // editor.setContent( '<ol><li><p>hello1</p></li><li><p>你好</p></li></ol>' );
  590. // var body = editor.body;
  591. // var ol = body.firstChild;
  592. // var range = te.obj[1];
  593. //
  594. // range.setStart( ol.firstChild.firstChild, 1 ).collapse( 1 ).select();
  595. // editor.focus();
  596. // te.presskey( 'enter', '' );
  597. // equal(editor.selection.getRange().startContainer.parentNode.innerHTML,'');
  598. //
  599. // setTimeout( function () {
  600. // range.setStart( ol.childNodes[1], 0 ).collapse( 1 ).select();
  601. // equal(editor.selection.getRange().startContainer.parentNode.innerHTML,'');
  602. // editor.focus();
  603. // te.presskey( 'back', '' );
  604. // setTimeout( function () {
  605. // editor.focus();
  606. // var br = ua.browser.ie ? "" : "<br>";
  607. // equal( ua.getChildHTML( body ), '<ol><li><p>hello1</p><p>' + br + '</p></li><li><p>你好</p></li></ol>', '第二个li被删除' );
  608. // range.setStart( body, 0 ).setEnd( body, 1 ).select();
  609. // editor.execCommand( 'insertorderedlist' );
  610. // equal( ua.getChildHTML( body ), '<p>hello1</p><p>' + br + '</p><p>你好</p>', '应当变为纯文本' );
  611. // start();
  612. // }, 70 );
  613. // }, 50 );
  614. // stop();
  615. //} );
  616. test('trace1620:修改上面的列表与下面的列表一致', function () {
  617. var editor = te.obj[0];
  618. var range = te.obj[1];
  619. editor.setContent('<p>你好</p><ol><li><p>数字列表1</p></li><li><p>数字列表2</p></li></ol><ol style="list-style-type:lower-alpha; "><li><p>字母列表2</p></li><li><p>字母列表2</p></li></ol>');
  620. range.selectNode(editor.body.firstChild.nextSibling).select();
  621. editor.execCommand('insertorderedlist', 'lower-alpha');
  622. var html = '<p>你好</p><ol style="list-style-type: lower-alpha;" class=" list-paddingleft-2" ><li><p>数字列表1</p></li><li><p>数字列表2</p></li><li><p>字母列表2</p></li><li><p>字母列表2</p></li></ol>'
  623. ua.checkSameHtml(html, editor.body.innerHTML.toLowerCase(), '检查列表结果');
  624. });
  625. test('trace 1621:选中多重列表,设置为相同类型的列表', function () {
  626. var editor = te.obj[0];
  627. var range = te.obj[1];
  628. var body = editor.body;
  629. editor.setContent('<ol style="list-style-type:decimal; "><li><p>数字列表1</p></li><li><p>数字列表2</p></li></ol><ol style="list-style-type:lower-alpha; "><li><p>字母列表1</p></li><li><p>字母列表2</p></li></ol><ol style="list-style-type: upper-alpha; "><li><p>​大写字母1<br></p></li><li><p>大写字母2</p></li><li><p>大写字母3</p></li></ol>');
  630. range.setStart(body, 1).setEnd(body.lastChild.firstChild.nextSibling, 1).select();
  631. var html = '<ol style="list-style-type: decimal;" class=" list-paddingleft-2" ><li><p>数字列表1</p></li><li><p>数字列表2</p></li></ol><ol style="list-style-type: upper-alpha;" class=" list-paddingleft-2" ><li><p>字母列表1</p></li><li><p>字母列表2</p></li><li><p>大写字母1<br/></p></li><li><p>大写字母2</p></li><li><p>大写字母3</p></li></ol>';
  632. editor.execCommand('insertorderedlist', 'upper-alpha');
  633. ua.checkSameHtml(html, editor.body.innerHTML.toLowerCase(), 'trace 1621');
  634. });
  635. //TODO 1.2.6不严重bug注释 空style未删除
  636. //test( 'trace 3049:列表内有引用', function () {
  637. // var editor = te.obj[0];
  638. // editor.setContent( '<blockquote><ol class="custom_cn1 list-paddingleft-1" ><li class="list-cn-2-1 list-cn1-paddingleft-1" ><p>a</p></li><li class="list-cn-2-2 list-cn1-paddingleft-1" ><p>b</p></li></ol></blockquote>' );
  639. // editor.execCommand( 'selectall');
  640. // editor.execCommand( 'blockquote' );
  641. // var html = '<ol class="custom_cn1 list-paddingleft-1" ><li class="list-cn-2-1 list-cn1-paddingleft-1"><p>a</p></li><li class="list-cn-2-2 list-cn1-paddingleft-1"><p>b</p></li></ol>';
  642. // equal(ua.getChildHTML(editor.body),html,'检查列表结果');
  643. //});
  644. /*trace 3056:模拟不完全,还需手动测试*/
  645. test('trace 3056:列表内表格后回车', function () {
  646. var editor = te.obj[0];
  647. var range = te.obj[1];
  648. var body = editor.body;
  649. editor.setContent('<ol class="custom_cn2 list-paddingleft-1" ><li class="list-cn-3-1 list-cn2-paddingleft-1" ><p>a</p></li><li class="list-cn-3-2 list-cn2-paddingleft-1" ><p><br></p></li><li class="list-cn-3-3 list-cn2-paddingleft-1" ><p>c</p></li></ol>');
  650. var lis = editor.body.getElementsByTagName('li');
  651. range.setStart(lis[1].firstChild, 0).collapse(true).select();
  652. setTimeout(function () {
  653. editor.execCommand('inserttable');
  654. var tds = body.getElementsByTagName('td');
  655. tds[0].innerHTML = 'asd<br>';
  656. range.setStart(tds[0].firstChild, 3).collapse(true).select();
  657. setTimeout(function () {
  658. ua.keydown(body, {'keyCode':13});
  659. equal(body.childNodes.length, 1, 'body只有一个孩子');
  660. equal(editor.body.getElementsByTagName('li').length, 3, 'ol有3个孩子');
  661. equal(editor.body.getElementsByTagName('table').length, 1, '只有1个table');
  662. start()
  663. }, 20);
  664. }, 50);
  665. stop();
  666. });
  667. /*trace 3075:fix in future*/
  668. //test( 'trace 3075:表格标题行中插入有序列表', function () {
  669. // var editor = te.obj[0];
  670. // var range = te.obj[1];
  671. // var body = editor.body;
  672. // editor.setContent( '<table><tbody><tr><th><br></th><th><br></th><th><br></th></tr><tr><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td></tr></tbody></table>' ); /*必须加br,否则没办法占位*/
  673. // var ths = body.getElementsByTagName( 'th' );
  674. // range.setStart( ths[1], 0 ).collapse( 1 ).select(); /*选中一个单元格*/
  675. // editor.execCommand( 'insertorderedlist' ); /*插入有序列表*/
  676. // equal( ths[1].firstChild.tagName.toLowerCase(), 'ol', '查询列表的类型' );
  677. // equal( ths[1].firstChild.style['listStyleType'], 'decimal', '查询有序列表的类型' );
  678. // var br = baidu.editor.browser.ie ? "" : "<br>";
  679. // equal( ua.getChildHTML( ths[0].firstChild ), '<li>' + '<p>' + br + '</p>' + '</li>' );
  680. // stop();
  681. // setTimeout(function() {
  682. // editor.execCommand('source');
  683. // setTimeout(function() {
  684. // editor.execCommand('source');
  685. // equal( body.getElementsByTagName('table').length, 1, '只有1个table' );
  686. // start();
  687. // },20);
  688. // },20);
  689. //} );
  690. //test( 'trace 3075:表格标题行中插入无序列表', function () {
  691. // var editor = te.obj[0];
  692. // var range = te.obj[1];
  693. // var body = editor.body;
  694. // editor.setContent( '<table><tbody><tr><th><br></th><th><br></th><th><br></th></tr><tr><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td></tr></tbody></table>' ); /*必须加br,否则没办法占位*/
  695. // var trs = editor.body.firstChild.getElementsByTagName( 'tr' ); /*选中多个单元格*/
  696. // var ut = editor.getUETable(editor.body.firstChild);
  697. // var cellsRange = ut.getCellsRange(trs[0].cells[1],trs[0].cells[2]);
  698. // ut.setSelected(cellsRange);
  699. // range.setStart( trs[0].cells[1], 0 ).collapse( true ).select();
  700. // var ths = body.getElementsByTagName( 'th' );
  701. // editor.execCommand( 'insertunorderedlist', 'circle' ); /*插入无序列表*/
  702. // equal( ths[1].firstChild.tagName.toLowerCase(), 'ul', '查询无序列表' );
  703. // equal( ths[1].firstChild.style['listStyleType'], 'circle', '查询无序列表的类型' );
  704. // stop();
  705. // setTimeout(function() {
  706. // editor.execCommand('source');
  707. // setTimeout(function() {
  708. // editor.execCommand('source');
  709. // equal( body.getElementsByTagName('table').length, 1, '只有1个table' );
  710. // start();
  711. // },20);
  712. // },20);
  713. //} );
  714. test('trace 3117:列表内后退两次', function () {
  715. /*实际操作没问题,取range时会在将文本节点分为两个节点,后退操作无法实现*/
  716. if ((ua.browser.safari && !ua.browser.chrome))return 0;
  717. var editor = te.obj[0];
  718. var range = te.obj[1];
  719. var br = ua.browser.ie ? '<br>' : '<br>';
  720. editor.setContent('<ol><li>hello</li><li><p><br></p></li></ol>');
  721. range.setStart(editor.body.firstChild.lastChild.firstChild, 0).collapse(1).select();
  722. ua.manualDeleteFillData(editor.body);
  723. ua.keydown(editor.body, {keyCode:8});
  724. var ol = editor.body.getElementsByTagName('ol');
  725. var lis = editor.body.getElementsByTagName('li');
  726. equal(lis.length, '1', '变成1个列表项');
  727. equal(ua.getChildHTML(editor.body.firstChild), '<li><p>hello</p><p>' + br + '</p></li>', '检查列表内容');
  728. //TODO 1.2.6不严重bug注释 空style未删除
  729. // range.setStart(lis[0].lastChild,0).collapse(1).select();
  730. // ua.keydown(editor.body,{keyCode:8});
  731. // equal(ua.getChildHTML(editor.body),'<ol class=\" list-paddingleft-2\"><li><p>hello</p></li></ol><p>'+br+'</p>','检查body内容');
  732. /*模拟不到光标跳到上一行?*/
  733. // range.setStart(editor.body.lastChild,0).collapse(1).select();
  734. // ua.keydown(editor.body,{keyCode:8});
  735. // equal(ua.getChildHTML(editor.body),'<ol class=\" list-paddingleft-2\"><li><p>hello</p></li></ol>','检查body内容');
  736. });
  737. /*trace 3136*/
  738. test('trace 3118:全选后backspace', function () {
  739. /*实际操作没问题,取range时会在将文本节点分为两个节点,后退操作无法实现*/
  740. if ((ua.browser.safari && !ua.browser.chrome))return 0;
  741. var editor = te.obj[0];
  742. var range = te.obj[1];
  743. var br = ua.browser.ie ? '' : '<br>';
  744. editor.setContent('<ol><li>hello</li><li><p><br></p></li></ol>');
  745. ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
  746. ua.keydown(editor.body, {keyCode:8});
  747. equal(ua.getChildHTML(editor.body), '<p>' + br + '</p>', '');
  748. ok(!editor.queryCommandState('insertorderedlist'), 'state是0');
  749. });
  750. test('trace 3126:1.2.5+列表重构新增标签,tab键', function () {
  751. var editor = te.obj[0];
  752. var range = te.obj[1];
  753. var body = editor.body;
  754. editor.setContent('<p>hello1</p><p>hello2</p><p>hello3</p><p>hello4</p>');
  755. editor.execCommand('selectAll');
  756. editor.execCommand('insertorderedlist', 'cn2');
  757. var lis = body.getElementsByTagName('li');
  758. range.setStart(lis[1].firstChild, 0).setEnd(lis[2].firstChild, 1).select();
  759. ua.keydown(editor.body, {keyCode:9});
  760. var str = '<li class="list-cn-3-1 list-cn2-paddingleft-1" ><p>hello1</p></li><ol style="list-style-type: decimal;" class=" list-paddingleft-3" ><li><p>hello2</p></li><li><p>hello3</p></li></ol><li class="list-cn-3-2 list-cn2-paddingleft-1" ><p>hello4</p></li>';
  761. ua.checkSameHtml(str, editor.body.firstChild.innerHTML.toLowerCase(), '有序列表---tab键');
  762. });
  763. test('trace 3132:单行列表backspace', function () {
  764. /*实际操作没问题,取range时会在将文本节点分为两个节点,后退操作无法实现*/
  765. if ((ua.browser.safari && !ua.browser.chrome))return 0;
  766. var editor = te.obj[0];
  767. var range = te.obj[1];
  768. editor.setContent('<ol><li><br></li></ol>');
  769. range.selectNode(editor.body.firstChild.firstChild.firstChild.firstChild).select();
  770. ua.keydown(editor.body, {keyCode:8});
  771. var space ='<br>';
  772. equal(ua.getChildHTML(editor.body), '<p>'+space+'</p>', '');
  773. });
  774. test('trace 3133:表格中插入列表再取消列表', function () {
  775. /*实际操作没问题,取range时会在将文本节点分为两个节点,后退操作无法实现*/
  776. if ((ua.browser.safari && !ua.browser.chrome))return 0;
  777. var editor = te.obj[0];
  778. var range = te.obj[1];
  779. var body = editor.body;
  780. var br = baidu.editor.browser.ie ? "" : "<br>";
  781. editor.setContent('<table><tbody><tr><td><br></td></tr></tbody></table>');
  782. /*插入一行一列的表格*/
  783. var tds = body.getElementsByTagName('td');
  784. range.setStart(tds[0], 0).collapse(1).select();
  785. editor.execCommand('insertorderedlist', 'num2');
  786. /*插入列表*/
  787. equal(tds[0].firstChild.tagName.toLowerCase(), 'ol', '查询列表的类型');
  788. equal(ua.getChildHTML(tds[0].firstChild), '<li class="list-num-3-1 list-num2-paddingleft-1"><p><br></p></li>');
  789. editor.execCommand('insertorderedlist', 'num2');
  790. /*取消列表*/
  791. equal(ua.getChildHTML(tds[0]), '<p><br></p>');
  792. ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
  793. /*ctrl+a*/
  794. ua.keydown(editor.body, {keyCode:8});
  795. /*backspace*/
  796. equal(ua.getChildHTML(editor.body), '<p>' + br + '</p>', '');
  797. });
  798. test('trace 3164:添加列表,取消列表', function () {
  799. var editor = te.obj[0];
  800. var body = editor.body;
  801. editor.setContent('<p>hello1</p><p>hello2</p><p>hello3</p><p>hello4</p>');
  802. editor.execCommand('selectAll');
  803. editor.execCommand('insertunorderedlist', 'dash');
  804. equal(body.firstChild.tagName.toLowerCase(), 'ul', '检查无序列表');
  805. equal(body.firstChild.className, 'custom_dash list-paddingleft-1', '查询有序列表的类型');
  806. equal(editor.queryCommandValue('insertunorderedlist'), 'dash', '查询插入无序列表的结果');
  807. ok(editor.queryCommandState('insertunorderedlist'), 'state是1');
  808. editor.execCommand('selectAll');
  809. editor.execCommand('insertunorderedlist', 'dash');
  810. ua.checkHTMLSameStyle('<p>hello1</p><p>hello2</p><p>hello3</p><p>hello4</p>', editor.document, editor.body, '取消列表');
  811. equal(editor.queryCommandValue('insertunorderedlist'), null, '查询取消无序列表的结果');
  812. ok(!editor.queryCommandState('insertunorderedlist'), 'state是0');
  813. });
  814. test('trace 3165:检查表格中列表tab键', function () {
  815. var editor = te.obj[0];
  816. var range = te.obj[1];
  817. var body = editor.body;
  818. setTimeout(function () {
  819. editor.execCommand('inserttable');
  820. var tds = body.getElementsByTagName('td');
  821. range.setStart(tds[6], 0).collapse(1).select();
  822. editor.execCommand('insertorderedlist');
  823. equal(tds[6].firstChild.style['listStyleType'], 'decimal', '查询有序列表的类型');
  824. tds = body.getElementsByTagName('td');
  825. range.setStart(tds[5], 0).collapse(1).select();
  826. range = editor.selection.getRange();
  827. if(ua.browser.ie==9||ua.browser.ie==10)
  828. equal(range.startContainer.tagName.toLowerCase(), 'td', 'tab键前光标位于td中');
  829. else
  830. equal(range.startContainer.parentNode.tagName.toLowerCase(), 'td', 'tab键前光标位于td中');
  831. ua.keydown(editor.body, {keyCode:9});
  832. setTimeout(function () {
  833. range = editor.selection.getRange();
  834. if (!ua.browser.gecko && !ua.browser.ie && !ua.browser.webkit)//TODO 1.2.6
  835. equal(range.startContainer.parentNode.tagName.toLowerCase(), 'li', 'tab键后光标跳到有列表的单元格中');
  836. equal(tds[6].firstChild.style['listStyleType'], 'decimal', '检查有序列表的类型不应该被改变');
  837. start();
  838. }, 100);
  839. }, 100);
  840. stop();
  841. });
  842. test('trace 3168:表格中列表更改样式', function () {
  843. var editor = te.obj[0];
  844. var range = te.obj[1];
  845. var body = editor.body;
  846. editor.execCommand('inserttable');
  847. var tds = body.getElementsByTagName('td');
  848. tds[0].innerHTML = 'asdf';
  849. tds[1].innerHTML = '<ol class="custom_num1 list-paddingleft-1"><li class="list-num-2-1 list-num1-paddingleft-1"><p>asd</p></li></ol>';
  850. setTimeout(function () {
  851. var trs = editor.body.firstChild.getElementsByTagName('tr');
  852. var ut = editor.getUETable(editor.body.firstChild);
  853. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[1]);
  854. ut.setSelected(cellsRange);
  855. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  856. editor.execCommand('insertorderedlist', 'cn1');
  857. equal(tds[0].firstChild.className, 'custom_cn1 list-paddingleft-1', '查询有序列表的类型');
  858. equal(tds[1].firstChild.className, 'custom_cn1 list-paddingleft-1', '查询有序列表的类型');
  859. equal(editor.queryCommandValue('insertorderedlist'), 'cn1', '查询插入有序列表的结果');
  860. editor.execCommand('insertunorderedlist', 'dot');
  861. equal(tds[0].firstChild.className, 'custom_dot list-paddingleft-1', '查询无序列表的类型');
  862. equal(tds[1].firstChild.className, 'custom_dot list-paddingleft-1', '查询无序列表的类型');
  863. equal(editor.queryCommandValue('insertunorderedlist'), 'dot', '查询插入无序列表的结果');
  864. start();
  865. }, 50);
  866. stop();
  867. });
  868. //todo 1.2.6.1
  869. //test('trace 3213 3499:tab键后更改列表样式', function () {
  870. // var div = document.body.appendChild(document.createElement('div'));
  871. // div.id = 'ue';
  872. // var editor = UE.getEditor('ue');
  873. // editor.ready(function () {
  874. // var range = new baidu.editor.dom.Range(editor.document);
  875. // editor.setContent('<ol><li><p>hello1</p></li><li><p>hello2</p></li><li><p>hello1</p></li><li><p>hello1</p></li></ol>');
  876. // var lis = editor.body.getElementsByTagName('li');
  877. // range.setStart(lis[2], 0).setEnd(lis[3], 1).select();
  878. // ua.keydown(editor.body, {keyCode:9});
  879. // ua.keydown(editor.body, {'keyCode':65, 'ctrlKey':true});
  880. // editor.execCommand('insertorderedlist', 'lower-alpha');
  881. // var str = '<ol style="list-style-type: lower-alpha;" class=" list-paddingleft-2"><li><p>hello1</p></li><li><p>hello2</p></li><li><p>hello1</p></li><li><p>hello1</p></li></ol>';
  882. // ua.checkSameHtml(str, editor.body.innerHTML.toLowerCase(), '');
  883. // UE.delEditor('ue');
  884. // start();
  885. // });
  886. // stop();
  887. //});