blockquote.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. module( "plugins.blockquote" );
  2. /*trace 967*/
  3. //这个用例暂不测ie,因为ie中输入回车无效
  4. //test( '切换到源码模式再切换回来点引用', function () {
  5. // if(!ua.browser.ie){
  6. // var editor = te.obj[0];
  7. // var body = editor.body;
  8. // editor.setContent( 'hello' );
  9. // editor.execCommand( 'source' );
  10. // var tas = editor.iframe.parentNode.getElementsByTagName( 'textarea' );
  11. // tas[tas.length - 1].value = '';
  12. // stop();
  13. // setTimeout( function () { //source.js中有延时操作
  14. // editor.execCommand( 'source' );
  15. // editor.execCommand( 'blockquote' );
  16. // setTimeout( function () { //模拟回车,在引用后回车两段都是引用
  17. // //firefox竟然要多触发一次。。什么乱七八糟的bug啊
  18. // //if ( ua.getBrowser() == "firefox" )
  19. // //te.presskey( "enter", "" );
  20. // editor.focus();
  21. // te.presskey( "enter", "" );
  22. // setTimeout( function () {
  23. // editor.focus();
  24. // setTimeout( function () {
  25. // var bq = body.firstChild;
  26. // equal( body.childNodes.length, 1, 'body有1个孩子' );
  27. // equal( bq.childNodes.length, 2, 'blockquote有2个孩子' );
  28. // ok( bq.childNodes[0]&&bq.childNodes[0].tagName.toLowerCase()=='p', '第一个孩子是p' );
  29. // ok( bq.childNodes[1]&&bq.childNodes[1].tagName.toLowerCase()=='p', '第二个孩子是p' );
  30. // start();
  31. // }, 50 );
  32. // }, 30 );
  33. // }, 60 );
  34. // }, 50 );
  35. // }
  36. // else
  37. // ok(ua.browser.ie,'这个用例暂不测,因为ie中输入回车无效');
  38. //} );
  39. test( '在表格中添加和去除引用', function () {
  40. var editor = te.obj[0];
  41. var range = te.obj[1];
  42. editor.setContent( 'hello<table><tbody><tr><td>hello</td></tr></tbody></table>' );
  43. var body = editor.body;
  44. var tds = body.lastChild.getElementsByTagName( 'td' );
  45. range.setStart( tds[0].firstChild, 2 ).collapse( true ).select(); /*闭合选取*/
  46. editor.execCommand( 'blockquote' );
  47. equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '引用加到表格外面去了' );
  48. equal( tds[0].firstChild.nodeType, 3, 'td里仍然是文本' );
  49. equal( tds[0].firstChild.data, 'he', 'td里仍然是文本he' );
  50. range.setStart( tds[0].firstChild, 2 ).collapse( true ).select();
  51. editor.execCommand( 'blockquote' ); /*再执行一次引用,会去掉引用*/
  52. ok( body.lastChild.tagName.toLowerCase() != 'blockquote', '引用去掉了' ); //1.2版本table外加了div
  53. stop();
  54. setTimeout(function(){
  55. tds = body.lastChild.getElementsByTagName( 'td' );
  56. range.selectNode( tds[0] ).select(); /*不闭合选中表格,添加引用*/
  57. editor.execCommand( 'blockquote' );
  58. equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '非闭合方式选中添加引用' );
  59. start();
  60. },50);
  61. } );
  62. test( '在列表中添加引用', function () {
  63. var editor = te.obj[0];
  64. var range = te.obj[1];
  65. editor.setContent( 'hello<ol><li><p>hello1</p></li><li><p>hello2</p></li></ol>' );
  66. var body = editor.body;
  67. var lis = body.lastChild.getElementsByTagName( 'li' );
  68. range.setStart( lis[0].firstChild, 1 ).collapse( 1 ).select(); /*闭合选取*/
  69. editor.execCommand( 'blockquote' );
  70. equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '引用加到列表外面去了' );
  71. equal( lis[0].firstChild.nodeType, 1, '列表里套着p' );
  72. equal( lis[0].firstChild.firstChild.data, 'hello1', '列表里仍然是文本hello1' );
  73. } );
  74. /*trace 1183*/
  75. test( 'trace1183:选中列表中添加引用,再去掉引用', function () {
  76. var editor = te.obj[0];
  77. var range = te.obj[1];
  78. editor.setContent( '<p>hello1</p><p>hello2</p>' );
  79. var body = editor.body;
  80. range.setStart( body, 0 ).setEnd( body, 2 ).select();
  81. editor.execCommand( 'insertorderedlist' ); /*添加列表*/
  82. ua.manualDeleteFillData( editor.body );
  83. var ol = body.getElementsByTagName( 'ol' )[0];
  84. var html = ua.getChildHTML( ol );
  85. editor.execCommand( 'blockquote' );
  86. editor.execCommand( 'blockquote' );
  87. ua.manualDeleteFillData( editor.body );
  88. equal( ua.getChildHTML( body.getElementsByTagName( 'ol' )[0] ), html, '引用前后列表没有发生变化' );
  89. equal( body.getElementsByTagName( 'ol' ).length, 1, '只有一个有序列表' );
  90. } );
  91. test( 'trace 3298:对段落添加引用和去除引用', function () {
  92. var editor = te.obj[0];
  93. var range = te.obj[1];
  94. editor.setContent( '<p><strong><em>hello1</em></strong></p><p>hello2 world</p>' );
  95. var body = editor.body;
  96. range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select(); /*不闭合添加引用*/
  97. editor.execCommand( 'blockquote' );
  98. equal( ua.getChildHTML( body ), '<blockquote><p><strong><em>hello1</em></strong></p><p>hello2 &nbsp;world</p></blockquote>', '不闭合添加引用' );
  99. equal( editor.queryCommandState( 'blockquote' ), 1, '引用高亮' );
  100. range.setStart( body.firstChild.lastChild, 0 ).collapse( true ).select(); /*闭合去除引用*/
  101. editor.execCommand( 'blockquote' );
  102. equal( ua.getChildHTML( body ), '<blockquote><p><strong><em>hello1</em></strong></p></blockquote><p>hello2 &nbsp;world</p>', '闭合去除引用' );
  103. equal( editor.queryCommandState( 'blockquote' ), 0, '引用不高亮' );
  104. range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select(); /*非闭合去除引用*/
  105. editor.execCommand( 'blockquote' );
  106. equal( ua.getChildHTML( body ), '<p><strong><em>hello1</em></strong></p><p>hello2 &nbsp;world</p>' );
  107. equal( editor.queryCommandState( 'blockquote' ), 0, '非闭合去除引用后,引用不高亮' );
  108. range.setStart( body.lastChild, 0 ).collapse( true ).select(); /*闭合添加引用*/
  109. editor.execCommand( 'blockquote' );
  110. equal( ua.getChildHTML( body ), '<p><strong><em>hello1</em></strong></p><blockquote><p>hello2 &nbsp;world</p></blockquote>', '闭合添加引用 ' );
  111. } );
  112. /*trace 3285*/
  113. test( 'trace 3285:startContainer为body添加引用', function () {
  114. var editor = te.obj[0];
  115. var range = te.obj[1];
  116. editor.setContent( 'hello<ol><li>hello1</li><li>hello2</li></ol>' );
  117. var body = editor.body;
  118. range.setStart( body, 0 ).setEnd( body, 2 ).select(); /*不闭合选取*/
  119. editor.execCommand( 'blockquote' );
  120. // var padding = ua.browser.ie&&ua.browser.ie<9?' style=\" list-paddingleft-2\"':(ua.browser.webkit?' class=\" list-paddingleft-2\"':' style=\" list-paddingleft-2\"');
  121. var padding = ' class=\" list-paddingleft-2\"';
  122. equal( ua.getChildHTML( body ), '<blockquote><p>hello</p><ol'+padding+'><li><p>hello1</p></li><li><p>hello2</p></li></ol></blockquote>', '选中body加引用' );
  123. equal( editor.queryCommandState( 'blockquote' ), 1, '引用高亮' );
  124. editor.undoManger.undo();
  125. range.setStart( body, 1 ).collapse( true ).select(); /*闭合选取*/
  126. equal( editor.queryCommandState( 'blockquote' ), 0, '引用不高亮' );
  127. } );
  128. //ie 不通过
  129. test('aa标签',function(){
  130. var editor = te.obj[0];
  131. var range = te.obj[1];
  132. if(!ua.browser.ie){
  133. editor.setContent('<aa>hello</aa>');
  134. range.setStart(editor.body.firstChild.firstChild,0).collapse(1).select();
  135. editor.execCommand('blockquote');
  136. equal(ua.getChildHTML(editor.body),'<blockquote><aa>hello</aa></blockquote>','aa标签');
  137. editor.setContent('hello<aa>hello2</aa>');
  138. range.setStart(editor.body.lastChild.firstChild,0).setEnd(editor.body.lastChild.firstChild,3).select();
  139. editor.execCommand('blockquote');
  140. equal(ua.getChildHTML(editor.body),'<p>hello</p><blockquote><aa>hello2</aa></blockquote>','<aa>');
  141. }
  142. });
  143. /*trace 3284*/
  144. test('trace 3284:列表内引用',function(){
  145. var editor = te.obj[0];
  146. var range = te.obj[1];
  147. // var padding = ua.browser.ie&&ua.browser.ie<9?' style=\"padding-left: 30px\"':(ua.browser.webkit?' style=\"padding-left: 30px;\"':' style=\"padding-left: 30px;\"');
  148. var padding = ' class=\" list-paddingleft-2\"';
  149. editor.setContent('<ol><li><blockquote><p>hello1</p></blockquote></li><blockquote><li><p>hello2</p></li></blockquote></ol>');
  150. range.setStart(editor.body.firstChild.firstChild.firstChild.firstChild,0).setEnd(editor.body.firstChild.lastChild.firstChild.firstChild,6).select();
  151. editor.execCommand('blockquote');
  152. equal(ua.getChildHTML(editor.body ),'<ol'+padding+'><li><p>hello1</p></li><li><p>hello2</p></li></ol>','引用删除');
  153. });