/** * Created by JetBrains PhpStorm. * User: shenlixia01 * Date: 11-8-15 * Time: 下午3:47 * To change this template use File | Settings | File Templates. */ module( 'plugins.cleardoc' ); test( '取得焦点后清空后查看range', function () { var editor = te.obj[0]; editor.setContent( '

hello1

hello2
' ); editor.focus(); var body = editor.body; editor.execCommand( 'cleardoc' ); ua.manualDeleteFillData( editor.body ); if ( UE.browser.ie ) { equal( ua.getChildHTML( body ), '

' ); //目前ie清空文档后不放空格占位符 } else { equal( ua.getChildHTML( body ), '


', '清空文档' ); } } ); test( '编辑器没有焦点,清空', function () { var editor = te.obj[0]; editor.setContent( '

hello1

hello2
' ); var body = editor.body; editor.execCommand( 'cleardoc' ); ua.manualDeleteFillData( editor.body ); if ( UE.browser.ie ) { equal( ua.getChildHTML( body ), '

' ); } else { equal( ua.getChildHTML( body ), '


', '清空文档' ); } } ); test( 'enterTag为br', function () { var editor = te.obj[0]; editor.options.enterTag='br'; editor.setContent( '
hello
' ); var body = editor.body; editor.execCommand( 'cleardoc' ); ua.manualDeleteFillData( editor.body ); if (UE.browser.ie) { equal(ua.getChildHTML(body), '
', '清空文档'); } else { equal(ua.getChildHTML(body), '
', '清空文档'); } } ); /*trace1061*/ test( '删除时不会删除block元素', function() { if(ua.browser.opera) return 0; var editor = te.obj[0]; editor.setContent( '

hello

' ); setTimeout(function() { var range = te.obj[1]; range.selectNode( editor.body.firstChild ).select(); editor.execCommand( 'cleardoc' ); equal( editor.body.lastChild.tagName.toLowerCase(), 'p', 'h1替换为p' ); ua.manualDeleteFillData(editor.body); if ( !baidu.editor.browser.ie ) equal( editor.body.lastChild.innerHTML, '
', '内容被删除了' ); else equal( editor.body.lastChild.innerHTML, '', '内容被删除了' ); // if(!ua.browser.opera){ // range = editor.selection.getRange(); // equal( range.startContainer.tagName.toLowerCase(), 'p', '光标位置' ); // } start(); },50); stop(); } ); test('选中文本,清空',function(){ var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('

hello

hello1

') range.selectNode(editor.body.firstChild).select(); editor.execCommand('cleardoc'); var br = ua.browser.ie?'':'
'; equal(ua.getChildHTML(editor.body),'

'+br+'

',''); }); /*trace 1104*/ test( '全选后删除', function() { var editor = te.obj[0]; if ( baidu.editor.browser.ie ) editor.setContent( '

dsafds 

 

 

 

 

 

 

' ); else editor.setContent( '




d






' ); setTimeout(function() { editor.focus(); editor.execCommand( 'selectall' ); editor.execCommand( 'cleardoc' ); ua.manualDeleteFillData(editor.body); equal( editor.body.childNodes.length, 1, '删除后只剩一个bolock元素' ); equal( editor.body.firstChild.tagName.toLowerCase(), 'p', '删除后只剩一个p' ); if ( !UE.browser.ie ) equal( editor.body.lastChild.innerHTML, '
', '内容被删除了' ); else equal( editor.body.lastChild.innerHTML, '', '内容被删除了' ); start(); },50); stop(); } ); test( '删除所有列表', function() { var editor = te.obj[0]; editor.setContent('
  1. hello1
  2. 你好
'); setTimeout(function() { var body = editor.body; editor.focus(); editor.execCommand( 'selectall' ); editor.execCommand( 'cleardoc' ); equal( body.childNodes.length, 1, '删除后只剩一个ol元素' ); var br = UE.browser.ie?"":"
"; equal( ua.getChildHTML(body), '

'+br+'

', '删除后只剩一个p' ); start(); },50); stop(); } );