selectall.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. module( "plugins.selectall" );
  2. test( 'normal', function () {
  3. var editor = te.obj[0], db = editor.body;
  4. editor.setContent( '<p><em>xxxx</em></p>ssss' );
  5. editor.focus();
  6. editor.execCommand( 'selectAll' );
  7. //equal( UE.plugins['selectall'].notNeedUndo, 1, "notNeedUndo==1" );
  8. editor.execCommand( "bold" );
  9. equal( ua.getChildHTML( db ), "<p><strong><em>xxxx</em></strong></p><p><strong>ssss</strong></p>", "after calling selectAll command" );
  10. } );
  11. test( 'a part of the content is selected', function () {
  12. var editor = te.obj[0], d = editor.document, range = te.obj[1], db = editor.body;
  13. editor.setContent( '<p><em>xxxx</em></p>ssss' );
  14. range.selectNode( db.lastChild.firstChild ).select();
  15. editor.execCommand( "bold" );
  16. equal( ua.getChildHTML( db ), "<p><em>xxxx</em></p><p><strong>ssss</strong></p>", "before calling selectAll command" );
  17. editor.execCommand( 'selectAll' );
  18. //equal( UE.plugins['selectall'].notNeedUndo, 1, "notNeedUndo==1" );
  19. editor.execCommand( "bold" );
  20. equal( ua.getChildHTML( db ), "<p><strong><em>xxxx</em></strong></p><p><strong>ssss</strong></p>", "after calling selectAll command" );
  21. } );
  22. test( 'trace1743 :content is null', function () {
  23. var editor = te.obj[0];
  24. var range = te.obj[1];
  25. editor.setContent( '<p><br></p>' );
  26. //TODO 现在必须先focus再selectall,trace1743
  27. editor.execCommand( 'selectAll' );
  28. equal( ua.getChildHTML( editor.body ), "<p><br></p>", "content is null" );
  29. //equal(UE.plugins['selectall'].notNeedUndo, 1, "notNeedUndo==1" );
  30. range.setStart( editor.body.firstChild, 0 ).collapse( 1 ).select();
  31. editor.execCommand( "bold" );
  32. ua.manualDeleteFillData( editor.body );
  33. equal( ua.getChildHTML( editor.body ), "<p><strong></strong><br></p>", "after calling command bold" );
  34. } );
  35. test( 'ctrl+a', function() {
  36. var editor = te.obj[0];
  37. var range = te.obj[1];
  38. var body = editor.body;
  39. editor.setContent( '<p>全选的文本1</p><h1>全选的文本2</h1>' );
  40. range.selectNode( body.firstChild ).select();
  41. var p = body.firstChild;
  42. ua.keydown(editor.body,{'keyCode':65,'ctrlKey':true});
  43. setTimeout( function() {
  44. var range = editor.selection.getRange();
  45. // if ( ua.browser.gecko||ua.browser.ie>8 )
  46. // ua.checkResult( range, body, body, 0, 2, false, '查看全选后的range' );
  47. // else
  48. if(ua.browser.gecko||ua.browser.webkit){
  49. ua.checkResult( range, body, body, 0, 2, false, '查看全选后的range' );
  50. }else{
  51. ua.checkResult( range, body.firstChild.firstChild, body.lastChild.firstChild, 0, 6, false, '查看全选后的range' );
  52. }
  53. start();
  54. }, 150 );
  55. stop();
  56. } );
  57. test('contextmenu 右键全选', function () {
  58. var editor = te.obj[0];
  59. var range = te.obj[1];
  60. stop();
  61. editor.setContent('asdfg');
  62. ua.contextmenu(editor.body);
  63. var lang = editor.getLang("contextMenu");
  64. var menuBody = document.getElementsByClassName("edui-menu-body")[0];
  65. equal(editor.selection.getRange().collapsed, true, '检查选区--闭合');
  66. ua.click(menuBody.childNodes[0]);
  67. setTimeout(function () {
  68. equal(editor.selection.getRange().collapsed, false, '检查选区--非闭合');
  69. document.getElementById('edui_fixedlayer').parentNode.removeChild(document.getElementById('edui_fixedlayer'));
  70. te.dom.push(editor.container);
  71. start();
  72. }, 50);
  73. });