module( "plugins.paragraph" ); /** * h1和p之间的转换 * 表格中添加p和h1 * 列表里加h1 * 传入2个参数,style和attrs */ test( '不闭合h1和p之间的转换', function() { var editor = te.obj[0]; var range = te.obj[1]; var body = editor.body; editor.setContent( '
hello
' ); setTimeout(function(){ range.selectNode( body.firstChild.firstChild ).select(); /*p===>h1*/ editor.execCommand( 'paragraph', 'h1' ); equal( ua.getChildHTML( body ), 'hello
' ); /*多个段落的部分文本*/ editor.setContent( 'hello
hello
hello2
' ); setTimeout(function(){ range.setStart( body.firstChild.firstChild, 1 ).collapse( 1 ).select(); /*p===>h1*/ editor.execCommand( 'paragraph', 'h1' ); equal( ua.getChildHTML( body ), 'hello2
' ); /*h1===>p*/ range.setStart( body.firstChild.firstChild, 1 ).collapse( 1 ).select(); editor.execCommand( 'paragraph', 'p' ); equal( ua.getChildHTML( body ), 'hello
hello2
' ); equal( editor.queryCommandValue( 'paragraph' ), 'p', '当前的blcok元素为p' ); start(); },50); stop(); } ); /*如果是h1===>p并且传参的话,h1不会变化。因为这段代码的操作是为了indent和justify做的,传入参数p只是为了好处理,所以不支持h1变为p*/ test( '传入段落的样式', function() { var editor = te.obj[0]; var range = te.obj[1]; var body = editor.body; editor.setContent( 'hello
hello2
' ); setTimeout(function(){ range.setStart( body.firstChild.firstChild, 1 ).collapse( 1 ).select(); /*p===>p,但是变化了样式*/ editor.execCommand( 'paragraph', 'p', {style:'text-indent:2em'} ); equal( body.firstChild.style.textIndent, '2em', '改变了第一个孩子的缩进量' ); equal( body.firstChild.tagName.toLowerCase(), 'p', 'tagName仍然是p' ); /*p===>h4,但是变化了样式*/ editor.execCommand( 'paragraph', 'h4', {style:'text-indent:3em'} ); equal( body.firstChild.style['textIndent'], '3em', '改变了第一个孩子的缩进量' ); equal( body.firstChild.tagName.toLowerCase(), 'h4', 'tagName是h4' ); start(); },50); stop(); } ); test( '对表格设置样式', function() { var editor = te.obj[0]; var range = te.obj[1]; var body = editor.body; editor.setContent( 'hello1 |