提交 1c043d05 编写于 作者: T taoqili

Merge remote-tracking branch 'origin/dev-1.2.5' into dev-1.2.5

......@@ -70,7 +70,7 @@ var htmlparser = UE.htmlparser = function (htmlstr) {
if (htmlattr) {
var attrs = {}, match;
while (match = re_attr.exec(htmlattr)) {
attrs[match[1].toLowerCase()] = match[2]
attrs[match[1].toLowerCase()] = match[2] || match[3] || match[4]
}
elm.attrs = attrs;
}
......
......@@ -229,7 +229,7 @@
}
},
appendChild:function (node) {
if (this.type == 'element' && !dtd.$empty[this.tagName]) {
if (this.type == 'root' || (this.type == 'element' && !dtd.$empty[this.tagName])) {
if (!this.children) {
this.children = []
}
......@@ -247,6 +247,7 @@
return node;
}
},
insertBefore:function (target, source) {
if (this.children) {
......
......@@ -120,6 +120,35 @@ UE.plugins['list'] = function () {
//如果不给宽度会在自定应样式里出现滚动条
utils.cssRule('list', 'ol,ul{margin:0;pading:0;'+(browser.ie ? '' : 'width:95%')+'}li{clear:both;}'+customCss.join('\n'), me.document);
});
//单独处理剪切的问题
me.ready(function(){
domUtils.on(me.body,'cut',function(){
setTimeout(function(){
var rng = me.selection.getRange(),li;
if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
if(!li.nextSibling && domUtils.isEmptyBlock(li)){
var pn = li.parentNode,node;
if(node = pn.previousSibling){
domUtils.remove(pn);
rng.setStartAtLast(node).collapse(true);
rng.select(true);
}else if(node = pn.nextSibling){
domUtils.remove(pn);
rng.setStartAtFirst(node).collapse(true);
rng.select(true);
}else{
var tmpNode = me.document.createElement('p');
domUtils.fillNode(me.document,tmpNode);
pn.parentNode.insertBefore(tmpNode,pn);
domUtils.remove(pn);
rng.setStart(tmpNode,0).collapse(true);
rng.select(true);
}
}
}
})
})
});
function getStyle(node){
var cls = node.className;
......
......@@ -31,9 +31,19 @@ test( '补全不完整table', function() {
equals(root.toHtml(),'<table><tbody><tr><td></td><td></td></tr></tbody></table>','包含\n,补全table');
});
test( '补全不完整li', function() {
var root = UE.htmlparser('<ol><li><em><u>sdf<li>sdfsdf</ol>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<ol><li><em><u>sdf</u></em></li><li>sdfsdf</li></ol>','补全u,em');
root = UE.htmlparser('<ol><li><em>sdf</em></li><ul><li>a</li><li>b</li><li>c</ul><li>jkl</ol>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<ol><li><em>sdf</em></li><ul><li>a</li><li>b</li><li>c</li></ul><li>jkl</li></ol>','补全li');
});
test( '属性引号问题', function() {
var root = UE.htmlparser('<img width=200 height=200 />');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<img width="200" height="200" />');
var root = UE.htmlparser("<img width='200' height='200' />");
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<img width="200" height="200" />');
var root = UE.htmlparser('<img width="200" height="200" />');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<img width="200" height="200" />');
});
\ No newline at end of file
......@@ -19,8 +19,8 @@
var domUtils = baidu.editor.dom.domUtils;
var div_dom = document.body.appendChild( document.createElement( 'div' ) );
div_dom.id = 'test';
stop();
setTimeout(function(){
// stop();
// setTimeout(function(){
te.dom.push( div );
te.dom.push( iframe );
te.dom.push( div_dom);
......@@ -28,7 +28,7 @@
te.obj.push( editor );
te.obj.push( range );
te.obj.push( domUtils );
},50);
// },50);
}
var s = QUnit.testStart;
......
module( "plugins.basestyle" );
test( 'sub--table', function () {
var editor = te.obj[0];
editor.setContent( '<table border="solid"><tr><td>hello1</td><td>hello2</td></tr><tr><td>hello3</td><td>hello4</td></tr></table>' );
var editor = te.obj[0];
editor.setContent( '<table border="solid"><tr><td>hello1</td><td>hello2</td></tr><tr><td>hello3</td><td>hello4</td></tr></table>' );
setTimeout(function(){
var range = te.obj[1];
var body = editor.document.body;
......@@ -13,7 +12,6 @@ test( 'sub--table', function () {
var tds = body.firstChild.getElementsByTagName( 'td' );
var td;
// for ( var index = 0; td = tds[index++]; ) {
//
// editor.currentSelectedArr.push( td );
// }
editor.execCommand( 'subscript' );
......@@ -23,16 +21,16 @@ test( 'sub--table', function () {
equal( ua.getChildHTML( tbody.lastChild.firstChild.nextSibling ), '<sub>hello4</sub>', '检查第4个单元格中文本是否是下标' );
equal( editor.queryCommandState( 'superscript' ), 0, 'check sup state' );
equal( editor.queryCommandState( 'subscript' ), 1, 'check sub state' );
/**trace 943,为表格去上下标**/
editor.execCommand( 'subscript' );
editor.execCommand( 'subscript' ); /**trace 943,为表格去上下标**/
equal( tbody.firstChild.firstChild.innerHTML, 'hello1', '检查第1个单元格中文本是否不是下标' );
equal( tbody.firstChild.firstChild.nextSibling.innerHTML, 'hello2', '检查第2个单元格中文本是否不是下标' );
equal( tbody.lastChild.firstChild.innerHTML, 'hello3', '检查第3个单元格中文本是否不是下标' );
equal( tbody.lastChild.firstChild.nextSibling.innerHTML, 'hello4', '检查第4个单元格中文本是否你是下标' );
equal( editor.queryCommandState( 'superscript' ), 0, 'check sup state' );
equal( editor.queryCommandState( 'subscript' ), 0, 'check sub state' );
/*上下标互斥*/
editor.execCommand( 'superscript' );
editor.execCommand( 'superscript' ); /*上下标互斥*/
equal( ua.getChildHTML( tbody.firstChild.firstChild ), '<sup>hello1</sup>', '检查第1个单元格中文本是否是上标' );
equal( ua.getChildHTML( tbody.firstChild.firstChild.nextSibling ), '<sup>hello2</sup>', '检查第2个单元格中文本是否是上标' );
equal( ua.getChildHTML( tbody.lastChild.firstChild ), '<sup>hello3</sup>', '检查第3个单元格中文本是否是上标' );
......@@ -43,196 +41,180 @@ test( 'sub--table', function () {
},50);
stop();
} );
//如果没有setTimeout在FF(3.6和9都是)中range会出错,其他浏览器没问题
test( '闭合插入上下标', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( '<p>你好</p>' );
var body = editor.body;
stop()
setTimeout( function () {
range.setStart( body.firstChild.firstChild, 1 ).collapse( 1 ).select( true );
editor.execCommand( 'superscript' );
equal( ua.getChildHTML( body.firstChild ), '你<sup></sup>好', '查看执行上标后的结果' );
range = editor.selection.getRange();
range.insertNode( editor.document.createTextNode( 'hello' ) );
equal( ua.getChildHTML( body.firstChild ), '你<sup>hello</sup>好', '上标标签中插入文本' );
start()
}, 100 )
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( '<p>你好</p>' );
var body = editor.body;
stop();
setTimeout( function () {
range.setStart( body.firstChild.firstChild, 1 ).collapse( 1 ).select( true );
editor.execCommand( 'superscript' );
equal( ua.getChildHTML( body.firstChild ), '你<sup></sup>好', '查看执行上标后的结果' );
range = editor.selection.getRange();
range.insertNode( editor.document.createTextNode( 'hello' ) );
equal( ua.getChildHTML( body.firstChild ), '你<sup>hello</sup>好', '上标标签中插入文本' );
start();
}, 100 )
} );
//如果没有setTimeout在FF(3.6和9都是)中range会出错,其他浏览器没问题
test( '不闭合插入上下标', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( '<strong>hello1<em>hello2</em></strong><a href="http://www.baid.com/"><strong>baidu_link</strong></a>hello3' );
var body = editor.document.body;
stop();
setTimeout( function () {
range.setStart( body.firstChild.firstChild, 0 ).setEnd( body.firstChild.lastChild, 3 ).select();
editor.execCommand( 'superscript' );
ua.manualDeleteFillData( body );
equal( ua.getChildHTML( body.firstChild ), '<sup><strong>hello1<em>hello2</em></strong></sup><a href="http://www.baid.com/" _src="http://www.baid.com/"><sup><strong>baidu_link</strong></sup></a><sup>hel</sup>lo3', '普通文本添加上标' );
start();
}, 100 )
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( '<strong>hello1<em>hello2</em></strong><a href="http://www.baid.com/"><strong>baidu_link</strong></a>hello3' );
var body = editor.document.body;
stop();
setTimeout( function () {
range.setStart( body.firstChild.firstChild, 0 ).setEnd( body.firstChild.lastChild, 3 ).select();
editor.execCommand( 'superscript' );
ua.manualDeleteFillData( body );
equal( ua.getChildHTML( body.firstChild ), '<sup><strong>hello1<em>hello2</em></strong></sup><a href="http://www.baid.com/"><sup><strong>baidu_link</strong></sup></a><sup>hel</sup>lo3', '普通文本添加上标' );
start();
}, 100 );
} );
/*trace 870*/
//无法模拟光标自动移到的场景,因此模拟输入文本通过插入文本节点实现的方法,在插入文本后光标仍然在原来的位置
// 我们不确定光标实际在哪
test( 'trace 870:加粗文本前面去加粗', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<p><br></p>' );
range.setStart( body.firstChild, 0 ).collapse( true ).select();
editor.execCommand( 'bold' );
range = editor.selection.getRange();
range.insertNode( editor.document.createTextNode( 'hello' ) );
equal( editor.queryCommandState( 'bold' ), 1, '加粗' );
editor.execCommand( 'bold' );
range = editor.selection.getRange();
equal( editor.queryCommandState( 'bold' ), 0, '不加粗' );
/*插入一个文本节点*/
range.insertNode( editor.document.createTextNode( 'hello2' ) );
ua.manualDeleteFillData( editor.body );
/*ie下插入节点后会自动移动光标到节点后面,而其他浏览器不会*/
if ( baidu.editor.browser.ie || baidu.editor.browser.opera)
equal( editor.getContent(), '<p><strong>hello</strong>hello2<br /></p>' );
else
equal( editor.getContent(), '<p>hello2<strong>hello</strong><br /></p>' )
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<p><br></p>' );
range.setStart( body.firstChild, 0 ).collapse( true ).select();
editor.execCommand( 'bold' );
range = editor.selection.getRange();
range.insertNode( editor.document.createTextNode( 'hello' ) );
equal( editor.queryCommandState( 'bold' ), 1, '加粗' );
editor.execCommand( 'bold' );
range = editor.selection.getRange();
equal( editor.queryCommandState( 'bold' ), 0, '不加粗' );
range.insertNode( editor.document.createTextNode( 'hello2' ) ); /*插入一个文本节点*/
ua.manualDeleteFillData( editor.body );
if ( baidu.editor.browser.ie || baidu.editor.browser.opera) /*ie下插入节点后会自动移动光标到节点后面,而其他浏览器不会*/
equal( editor.getContent(), '<p><strong>hello</strong>hello2<br/></p>' );
else
equal( editor.getContent(), '<p>hello2<strong>hello</strong><br/></p>' );
} );
/*trace 1043*/
test( 'bold-在已加粗文本中间去除加粗', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<b>hello</b>ssss' );
range.setStart( body.firstChild.firstChild, 0 ).collapse( true ).select();
editor.execCommand( 'bold' );
range = editor.selection.getRange();
equal( editor.queryCommandState( 'bold' ), 0, "<strong> 被去掉" );
/*在当前的range选区插入文本节点*/
range.insertNode( range.document.createTextNode( 'aa' ) );
ua.manualDeleteFillData( editor.body );
equal( ua.getChildHTML( body.firstChild ), "aa<strong>hello</strong>ssss", "新文本节点没有加粗" );
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<b>hello</b>ssss' );
range.setStart( body.firstChild.firstChild, 0 ).collapse( true ).select();
editor.execCommand( 'bold' );
range = editor.selection.getRange();
equal( editor.queryCommandState( 'bold' ), 0, "<strong> 被去掉" );
range.insertNode( range.document.createTextNode( 'aa' ) ); /*在当前的range选区插入文本节点*/
ua.manualDeleteFillData( editor.body );
equal( ua.getChildHTML( body.firstChild ), "aa<strong>hello</strong>ssss", "新文本节点没有加粗" );
} );
/*trace 958*/
test( 'bold-在已加粗文本中间去除加粗', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '' );
editor.execCommand( 'bold' );
ok( ua.getChildHTML( body ), "<stong></stong>", "editor不focus时点加粗,不会多一个空行" );
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '' );
editor.execCommand( 'bold' );
ok( ua.getChildHTML( body ), "<stong></stong>", "editor不focus时点加粗,不会多一个空行" );
} );
/*trace 958*/
//如果没有setTimeout在FF(3.6和9都是)中range会出错,其他浏览器没问题
test( 'bold-加粗状态反射', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( 'this is a dog' );
stop();
setTimeout( function () {
range.selectNode( body.firstChild ).select();
editor.execCommand( 'bold' );
range.setStart( body.firstChild.firstChild.firstChild, 2 ).collapse( true ).select();
equal( editor.queryCommandState( 'bold' ), 1, '闭合选择,加粗高亮' );
ua.manualDeleteFillData( editor.body );
range.setStart( body.firstChild.firstChild.firstChild, 0 ).setEnd( body.firstChild.firstChild.lastChild, 4 ).select();
equal( editor.queryCommandState( 'bold' ), 1, '不闭合选择,加粗高亮' );
start();
}, 100 )
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<p>this is a dog</p>' );
stop();
setTimeout( function () {
range.selectNode( body.firstChild ).select();
editor.execCommand( 'bold' );
range.setStart( body.firstChild.firstChild.firstChild, 2 ).collapse( true ).select();
equal( editor.queryCommandState( 'bold' ), 1, '闭合选择,加粗高亮' );
ua.manualDeleteFillData( editor.body );
range.setStart( body.firstChild.firstChild.firstChild, 0 ).setEnd( body.firstChild.firstChild.lastChild, 4 ).select();
equal( editor.queryCommandState( 'bold' ), 1, '不闭合选择,加粗高亮' );
start();
}, 100 )
} );
/*trace 580*/
test( 'bold-连续加粗2次', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( 'this is a dog' );
var text = body.firstChild.firstChild;
range.setStart( text, 0 ).setEnd( text, 3 ).select();
/*第一次加粗*/
editor.execCommand( 'bold' );
equal( editor.queryCommandState( 'bold' ), 1, '加粗按钮高亮' );
text = body.firstChild.lastChild;
range.setStart( text, 1 ).setEnd( text, 3 ).select();
/*不闭合选区文本*/
equal( editor.queryCommandState( 'bold' ), 0, '不闭合选择,加粗不高亮' );
/*第二次加粗*/
ua.manualDeleteFillData( editor.body );
editor.execCommand( 'bold' );
equal( editor.queryCommandState( 'bold' ), 1, '加粗高亮' );
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<p>this is a dog</p>' );
var text = body.firstChild.firstChild;
range.setStart( text, 0 ).setEnd( text, 3 ).select();
editor.execCommand( 'bold' ); /*第一次加粗*/
equal( editor.queryCommandState( 'bold' ), 1, '加粗按钮高亮' );
text = body.firstChild.lastChild;
range.setStart( text, 1 ).setEnd( text, 3 ).select(); /*不闭合选区文本*/
equal( editor.queryCommandState( 'bold' ), 0, '不闭合选择,加粗不高亮' );
ua.manualDeleteFillData( editor.body );
editor.execCommand( 'bold' ); /*第二次加粗*/
equal( editor.queryCommandState( 'bold' ), 1, '加粗高亮' );
} );
/*trace 1983*/
test( 'bold-2个单词,中间有空格第一个单词加粗,第二个单词加粗再去加粗', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
// editor.setContent( '<p>hello world</p>' );
body.innerHTML = '<p>hello world</p>';//用setContent复现不了这个问题
var text = body.firstChild.firstChild;
range.setStart( text, 0 ).setEnd( text, 5 ).select();
editor.execCommand( 'bold' );
text = body.firstChild.lastChild;
range.setStart( text, 1 ).setEnd( text, 6 ).select();
editor.execCommand( 'bold' );
editor.execCommand( 'bold' );
ok( body.firstChild.childNodes.length==3&&body.firstChild.childNodes[1].length ==1, '空格保留');
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
body.innerHTML = '<p>hello world</p>'; //用setContent复现不了这个问题
var text = body.firstChild.firstChild;
range.setStart( text, 0 ).setEnd( text, 5 ).select();
editor.execCommand( 'bold' );
text = body.firstChild.lastChild;
range.setStart( text, 1 ).setEnd( text, 6 ).select();
editor.execCommand( 'bold' );
editor.execCommand( 'bold' );
ok( body.firstChild.childNodes.length==3&&body.firstChild.childNodes[1].length ==1, '空格保留');
} );
test( '测试 userAction.manualdeleteFilldata', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<p></p>' );
// var fillData = document.createTextNode(domUtils.fillChar);
// 在ie 6,7下,使用appendChild时,需要body先加载,必须将上句document前加editor,否则出错
var fillData = editor.document.createTextNode( domUtils.fillChar );
body.appendChild( fillData );
var space = ua.browser.ie ? '&nbsp;' : '<br>';//getContent()结果:‘<br />’,innerHTML结果:<br>
notEqual( body.innerHTML.toLowerCase(), '<p>' + space + '</p>', '清除不可见字符前不相等' );
ua.manualDeleteFillData( body );
equal( body.innerHTML.toLowerCase(), '<p>' + space + '</p>', '清除不可见字符后相等' );
test( '测试 userAction.manualdeleteFilldata', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<p></p>' );
var fillData = editor.document.createTextNode( domUtils.fillChar ); // 在ie 6,7下,使用appendChild时,需要body先加载,必须将上句document前加editor,否则出错
body.appendChild( fillData );
var space = ua.browser.ie ? '&nbsp;' : '<br>';//getContent()结果:‘<br />’,innerHTML结果:<br>
notEqual( body.innerHTML.toLowerCase(), '<p>' + space + '</p>', '清除不可见字符前不相等' );
ua.manualDeleteFillData( body );
equal( body.innerHTML.toLowerCase(), '<p>' + space + '</p>', '清除不可见字符后相等' );
} );
test( 'trace 1884:单击B再单击I ', function () {
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'bold' );
equal( editor.queryCommandState( 'bold' ), 1, 'b高亮' );
editor.execCommand( 'italic' );
equal( editor.queryCommandState( 'italic' ), 1, 'b高亮' );
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'bold' );
equal( editor.queryCommandState( 'bold' ), 1, 'b高亮' );
editor.execCommand( 'italic' );
equal( editor.queryCommandState( 'italic' ), 1, 'b高亮' );
} );
test( '单击B再在其他地方单击I,空的strong标签被删除 ', function () {
//ie下有问题不能修,屏蔽ie
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<p>hello</p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'bold' );
equal( editor.queryCommandState( 'bold' ), 1, 'b高亮' );
range.setStart( body.firstChild, 1 ).collapse( 1 ).select();
editor.execCommand( 'italic' );
equal( editor.queryCommandState( 'italic' ), 1, 'b高亮' );
ua.manualDeleteFillData( body );
if(!ua.browser.ie){
equal( body.innerHTML.toLowerCase(), '<p><em></em>hello</p>', '空strong标签被删除' )
}
var editor = te.obj[0];
var body = editor.body;
var range = te.obj[1];
editor.setContent( '<p>hello</p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'bold' );
equal( editor.queryCommandState( 'bold' ), 1, 'b高亮' );
range.setStart( body.firstChild, 1 ).collapse( 1 ).select();
editor.execCommand( 'italic' );
equal( editor.queryCommandState( 'italic' ), 1, 'b高亮' );
ua.manualDeleteFillData( body );
if(!ua.browser.ie){ //ie下有问题不能修,屏蔽ie
equal( body.innerHTML.toLowerCase(), '<p><em></em>hello</p>', '空strong标签被删除' )
}
} );
\ No newline at end of file
......@@ -2,151 +2,135 @@ module( "plugins.blockquote" );
/*trace 967*/
//这个用例暂不测ie,因为ie中输入回车无效
/*
test( '切换到源码模式再切换回来点引用', function () {
if(!ua.browser.ie){
var editor = te.obj[0];
var body = editor.body;
editor.setContent( 'hello' );
editor.execCommand( 'source' );
var tas = editor.iframe.parentNode.getElementsByTagName( 'textarea' );
tas[tas.length - 1].value = '';
stop();
//source.js中有延时操作
setTimeout( function () {
editor.execCommand( 'source' );
editor.execCommand( 'blockquote' );
// //模拟回车,在引用后回车两段都是引用
setTimeout( function () {
//// //firefox竟然要多触发一次。。什么乱七八糟的bug啊
////// if ( ua.getBrowser() == "firefox" )
////// te.presskey( "enter", "" );
editor.focus();
te.presskey( "enter", "" );
setTimeout( function () {
editor.focus();
setTimeout( function () {
var bq = body.firstChild;
equal( body.childNodes.length, 1, 'body有1个孩子' );
equal( bq.childNodes.length, 2, 'blockquote有2个孩子' );
ok( bq.childNodes[0]&&bq.childNodes[0].tagName.toLowerCase()=='p', '第一个孩子是p' );
ok( bq.childNodes[1]&&bq.childNodes[1].tagName.toLowerCase()=='p', '第二个孩子是p' );
start();
}, 50 );
}, 30 );//
}, 60 );
}, 50 );
}
else
ok(ua.browser.ie,'这个用例暂不测,因为ie中输入回车无效');
} );
*/
//test( '切换到源码模式再切换回来点引用', function () {
// if(!ua.browser.ie){
// var editor = te.obj[0];
// var body = editor.body;
// editor.setContent( 'hello' );
// editor.execCommand( 'source' );
// var tas = editor.iframe.parentNode.getElementsByTagName( 'textarea' );
// tas[tas.length - 1].value = '';
// stop();
// setTimeout( function () { //source.js中有延时操作
// editor.execCommand( 'source' );
// editor.execCommand( 'blockquote' );
// setTimeout( function () { //模拟回车,在引用后回车两段都是引用
// //firefox竟然要多触发一次。。什么乱七八糟的bug啊
// //if ( ua.getBrowser() == "firefox" )
// //te.presskey( "enter", "" );
// debugger;
// editor.focus();
// te.presskey( "enter", "" );
// setTimeout( function () {
// editor.focus();
// setTimeout( function () {
// var bq = body.firstChild;
// equal( body.childNodes.length, 1, 'body有1个孩子' );
// equal( bq.childNodes.length, 2, 'blockquote有2个孩子' );
// ok( bq.childNodes[0]&&bq.childNodes[0].tagName.toLowerCase()=='p', '第一个孩子是p' );
// ok( bq.childNodes[1]&&bq.childNodes[1].tagName.toLowerCase()=='p', '第二个孩子是p' );
// start();
// }, 50 );
// }, 30 );
// }, 60 );
// }, 50 );
// }
// else
// ok(ua.browser.ie,'这个用例暂不测,因为ie中输入回车无效');
//} );
test( '在表格中添加和去除引用', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( 'hello<table><tbody><tr><td>hello</td></tr></tbody></table>' );
var body = editor.body;
/*闭合选取*/
var tds = body.lastChild.getElementsByTagName( 'td' );
range.setStart( tds[0].firstChild, 2 ).collapse( true ).select();
editor.execCommand( 'blockquote' );
equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '引用加到表格外面去了' );
equal( tds[0].firstChild.nodeType, 3, 'td里仍然是文本' );
equal( tds[0].firstChild.data, 'he', 'td里仍然是文本he' );
/*再执行一次引用,会去掉引用*/
range.setStart( tds[0].firstChild, 2 ).collapse( true ).select();
editor.execCommand( 'blockquote' );
//1.2版本table外加了div
ok( body.lastChild.tagName.toLowerCase() != 'blockquote', '引用去掉了' );
/*不闭合选中表格,添加引用*/
range.selectNode( tds[0] ).select();
editor.execCommand( 'blockquote' );
equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '非闭合方式选中添加引用' );
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( 'hello<table><tbody><tr><td>hello</td></tr></tbody></table>' );
var body = editor.body;
var tds = body.lastChild.getElementsByTagName( 'td' );
range.setStart( tds[0].firstChild, 2 ).collapse( true ).select(); /*闭合选取*/
editor.execCommand( 'blockquote' );
equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '引用加到表格外面去了' );
equal( tds[0].firstChild.nodeType, 3, 'td里仍然是文本' );
equal( tds[0].firstChild.data, 'he', 'td里仍然是文本he' );
range.setStart( tds[0].firstChild, 2 ).collapse( true ).select();
editor.execCommand( 'blockquote' ); /*再执行一次引用,会去掉引用*/
ok( body.lastChild.tagName.toLowerCase() != 'blockquote', '引用去掉了' ); //1.2版本table外加了div
range.selectNode( tds[0] ).select(); /*不闭合选中表格,添加引用*/
editor.execCommand( 'blockquote' );
equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '非闭合方式选中添加引用' );
} );
test( '在列表中添加引用', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( 'hello<ol><li><p>hello1</p></li><li><p>hello2</p></li></ol>' );
var body = editor.body;
/*闭合选取*/
var lis = body.lastChild.getElementsByTagName( 'li' );
range.setStart( lis[0].firstChild, 1 ).collapse( 1 ).select();
editor.execCommand( 'blockquote' );
equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '引用加到列表外面去了' );
equal( lis[0].firstChild.nodeType, 1, '列表里套着p' );
equal( lis[0].firstChild.firstChild.data, 'hello1', '列表里仍然是文本hello1' );
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( 'hello<ol><li><p>hello1</p></li><li><p>hello2</p></li></ol>' );
var body = editor.body;
var lis = body.lastChild.getElementsByTagName( 'li' );
range.setStart( lis[0].firstChild, 1 ).collapse( 1 ).select(); /*闭合选取*/
editor.execCommand( 'blockquote' );
equal( body.lastChild.tagName.toLowerCase(), 'blockquote', '引用加到列表外面去了' );
equal( lis[0].firstChild.nodeType, 1, '列表里套着p' );
equal( lis[0].firstChild.firstChild.data, 'hello1', '列表里仍然是文本hello1' );
} );
/*trace 1183*/
test( 'trace1183:选中列表中添加引用,再去掉引用', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( '<p>hello1</p><p>hello2</p>' );
var body = editor.body;
range.setStart( body, 0 ).setEnd( body, 2 ).select();
/*添加列表*/
editor.execCommand( 'insertorderedlist' );
ua.manualDeleteFillData( editor.body );
var ol = body.getElementsByTagName( 'ol' )[0];
var html = ua.getChildHTML( ol );
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( '<p>hello1</p><p>hello2</p>' );
var body = editor.body;
range.setStart( body, 0 ).setEnd( body, 2 ).select();
editor.execCommand( 'insertorderedlist' ); /*添加列表*/
ua.manualDeleteFillData( editor.body );
var ol = body.getElementsByTagName( 'ol' )[0];
var html = ua.getChildHTML( ol );
editor.execCommand( 'blockquote' );
editor.execCommand( 'blockquote' );
ua.manualDeleteFillData( editor.body );
equal( ua.getChildHTML( body.getElementsByTagName( 'ol' )[0] ), html, '引用前后列表没有发生变化' );
equal( body.getElementsByTagName( 'ol' ).length, 1, '只有一个有序列表' );
editor.execCommand( 'blockquote' );
editor.execCommand( 'blockquote' );
ua.manualDeleteFillData( editor.body );
equal( ua.getChildHTML( body.getElementsByTagName( 'ol' )[0] ), html, '引用前后列表没有发生变化' );
equal( body.getElementsByTagName( 'ol' ).length, 1, '只有一个有序列表' );
} );
test( '对段落添加引用和去除引用', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( '<p><strong><em>hello1</em></strong></p><p>hello2 world</p>' );
var body = editor.body;
/*不闭合添加引用*/
range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select();
editor.execCommand( 'blockquote' );
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( '<p><strong><em>hello1</em></strong></p><p>hello2 world</p>' );
var body = editor.body;
range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select(); /*不闭合添加引用*/
editor.execCommand( 'blockquote' );
equal( ua.getChildHTML( body ), '<blockquote><p><strong><em>hello1</em></strong></p><p>hello2&nbsp;world</p></blockquote>', '不闭合添加引用' );
equal( editor.queryCommandState( 'blockquote' ), 1, '引用高亮' );
equal( ua.getChildHTML( body ), '<blockquote><p><strong><em>hello1</em></strong></p><p>hello2&nbsp;world</p></blockquote>', '不闭合添加引用' );
equal( editor.queryCommandState( 'blockquote' ), 1, '引用高亮' );
/*闭合去除引用*/
range.setStart( body.firstChild.lastChild, 0 ).collapse( true ).select();
editor.execCommand( 'blockquote' );
equal( ua.getChildHTML( body ), '<blockquote><p><strong><em>hello1</em></strong></p></blockquote><p>hello2&nbsp;world</p>', '闭合去除引用' );
equal( editor.queryCommandState( 'blockquote' ), 0, '引用不高亮' );
/*非闭合去除引用*/
range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select();
editor.execCommand( 'blockquote' );
equal( ua.getChildHTML( body ), '<p><strong><em>hello1</em></strong></p><p>hello2&nbsp;world</p>' );
equal( editor.queryCommandState( 'blockquote' ), 0, '非闭合去除引用后,引用不高亮' );
/*闭合添加引用*/
range.setStart( body.lastChild, 0 ).collapse( true ).select();
editor.execCommand( 'blockquote' );
equal( ua.getChildHTML( body ), '<p><strong><em>hello1</em></strong></p><blockquote><p>hello2&nbsp;world</p></blockquote>', '闭合添加引用 ' );
} );
range.setStart( body.firstChild.lastChild, 0 ).collapse( true ).select(); /*闭合去除引用*/
editor.execCommand( 'blockquote' );
equal( ua.getChildHTML( body ), '<blockquote><p><strong><em>hello1</em></strong></p></blockquote><p>hello2&nbsp;world</p>', '闭合去除引用' );
equal( editor.queryCommandState( 'blockquote' ), 0, '引用不高亮' );
range.setStart( body.firstChild, 0 ).setEnd( body.lastChild, 1 ).select(); /*非闭合去除引用*/
editor.execCommand( 'blockquote' );
equal( ua.getChildHTML( body ), '<p><strong><em>hello1</em></strong></p><p>hello2&nbsp;world</p>' );
equal( editor.queryCommandState( 'blockquote' ), 0, '非闭合去除引用后,引用不高亮' );
range.setStart( body.lastChild, 0 ).collapse( true ).select(); /*闭合添加引用*/
editor.execCommand( 'blockquote' );
equal( ua.getChildHTML( body ), '<p><strong><em>hello1</em></strong></p><blockquote><p>hello2&nbsp;world</p></blockquote>', '闭合添加引用 ' );
} );
test( 'startContainer为body添加引用', function () {
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( 'hello<ol><li>hello1</li><li>hello2</li></ol>' );
var body = editor.body;
/*不闭合选取*/
range.setStart( body, 0 ).setEnd( body, 2 ).select();
editor.execCommand( 'blockquote' );
// var padding = ua.browser.ie&&ua.browser.ie<9?' style=\" list-paddingleft-2\"':(ua.browser.webkit?' class=\" list-paddingleft-2\"':' style=\" list-paddingleft-2\"');
var padding = ' class=\" list-paddingleft-2\"';
equal( ua.getChildHTML( body ), '<blockquote><p>hello</p><ol'+padding+'><li><p>hello1</p></li><li><p>hello2</p></li></ol></blockquote>', '选中body加引用' );
equal( editor.queryCommandState( 'blockquote' ), 1, '引用高亮' );
/*闭合选取*/
editor.undoManger.undo();
range.setStart( body, 1 ).collapse( true ).select();
equal( editor.queryCommandState( 'blockquote' ), 0, '引用不高亮' );
var editor = te.obj[0];
var range = te.obj[1];
editor.setContent( 'hello<ol><li>hello1</li><li>hello2</li></ol>' );
var body = editor.body;
range.setStart( body, 0 ).setEnd( body, 2 ).select(); /*不闭合选取*/
editor.execCommand( 'blockquote' );
// var padding = ua.browser.ie&&ua.browser.ie<9?' style=\" list-paddingleft-2\"':(ua.browser.webkit?' class=\" list-paddingleft-2\"':' style=\" list-paddingleft-2\"');
var padding = ' class=\" list-paddingleft-2\"';
equal( ua.getChildHTML( body ), '<blockquote><p>hello</p><ol'+padding+'><li><p>hello1</p></li><li><p>hello2</p></li></ol></blockquote>', '选中body加引用' );
equal( editor.queryCommandState( 'blockquote' ), 1, '引用高亮' );
editor.undoManger.undo();
range.setStart( body, 1 ).collapse( true ).select(); /*闭合选取*/
equal( editor.queryCommandState( 'blockquote' ), 0, '引用不高亮' );
} );
//ie 不通过
test('aa标签',function(){
var editor = te.obj[0];
......@@ -163,6 +147,7 @@ test('aa标签',function(){
}
});
/*trace 3284*/
test('列表内引用',function(){
var editor = te.obj[0];
var range = te.obj[1];
......
......@@ -6,190 +6,182 @@ module( 'plugins.image' );
* 表格中插入图像
*/
test( '插入新图像', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p><br></p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0001.gif', width:50, height:51} );
ua.manualDeleteFillData( editor.body );
var img = body.getElementsByTagName( 'img' )[0];
equal( img.getAttribute( 'src' ), 'http://img.baidu.com/hi/jx2/j_0001.gif', '比较src' );
equal( img.getAttribute( 'width' ), '50', '比较width' );
equal( img.getAttribute( 'height' ), '51', '比较height' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p><br></p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0001.gif', width:50, height:51} );
ua.manualDeleteFillData( editor.body );
var img = body.getElementsByTagName( 'img' )[0];
equal( img.getAttribute( 'src' ), 'http://img.baidu.com/hi/jx2/j_0001.gif', '比较src' );
equal( img.getAttribute( 'width' ), '50', '比较width' );
equal( img.getAttribute( 'height' ), '51', '比较height' );
} );
/*trace 1490 不设宽高,插入图片*/
test( 'trace 1490 不设宽高,插入图片', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p><br></p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0001.gif'} );
ua.manualDeleteFillData( editor.body );
var img = body.getElementsByTagName( 'img' )[0];
equal( img.getAttribute( 'src' ), 'http://img.baidu.com/hi/jx2/j_0001.gif', '比较src' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p><br></p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0001.gif'} );
ua.manualDeleteFillData( editor.body );
var img = body.getElementsByTagName( 'img' )[0];
equal( img.getAttribute( 'src' ), 'http://img.baidu.com/hi/jx2/j_0001.gif', '比较src' );
} );
test( '插入对齐方式为居中对齐的图像,新建一个p,在p上设置居中对齐', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello</p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0001.gif', width:50, height:51, floatStyle:'center'} );
ua.manualDeleteFillData( editor.body );
var img = body.getElementsByTagName( 'img' )[0];
equal( body.childNodes.length, 2, '2个p' );
var p = body.firstChild;
equal( p.style['textAlign'], 'center', '居中对齐' );
//1.2版本在FF中,hello前有不可见字符
ok( p.nextSibling.innerHTML.indexOf( 'hello' ) > -1, '第二个p里面是hello' );
if ( baidu.editor.browser.ie )
equal( img.style['styleFloat'], '', 'float为空' );
else
equal( img.style['cssFloat'], '', 'float为空' );
equal( img.getAttribute( 'src' ), 'http://img.baidu.com/hi/jx2/j_0001.gif', '比较src' );
equal( img.getAttribute( 'width' ), '50', '比较width' );
equal( img.getAttribute( 'height' ), '51', '比较height' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello</p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0001.gif', width:50, height:51, floatStyle:'center'} );
ua.manualDeleteFillData( editor.body );
var img = body.getElementsByTagName( 'img' )[0];
equal( body.childNodes.length, 2, '2个p' );
var p = body.firstChild;
equal( p.style['textAlign'], 'center', '居中对齐' );
ok( p.nextSibling.innerHTML.indexOf( 'hello' ) > -1, '第二个p里面是hello' ); //1.2版本在FF中,hello前有不可见字符
if ( baidu.editor.browser.ie )
equal( img.style['styleFloat'], '', 'float为空' );
else
equal( img.style['cssFloat'], '', 'float为空' );
equal( img.getAttribute( 'src' ), 'http://img.baidu.com/hi/jx2/j_0001.gif', '比较src' );
equal( img.getAttribute( 'width' ), '50', '比较width' );
equal( img.getAttribute( 'height' ), '51', '比较height' );
} );
test( '修改已有图片的属性', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p><img src="http://img.baidu.com/hi/jx2/j_0004.gif" >hello<img src="http://img.baidu.com/hi/jx2/j_0053.gif" ></p>' );
range.selectNode( body.firstChild.firstChild ).select();
/*加_src这个参数,否则结果不对,在image.html中也是加了这个参数的*/
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0018.gif', _src:"http://img.baidu.com/hi/jx2/j_0018.gif"} );
equal( ua.getChildHTML( body.firstChild ), '<img src="http://img.baidu.com/hi/jx2/j_0018.gif" _src=\"http://img.baidu.com/hi/jx2/j_0018.gif\">hello<img src="http://img.baidu.com/hi/jx2/j_0053.gif" _src=\"http://img.baidu.com/hi/jx2/j_0053.gif\">', '检查插入的图像地址' );
equal( body.firstChild.childNodes.length, 3, '2个img孩子' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p><img src="http://img.baidu.com/hi/jx2/j_0004.gif" >hello<img src="http://img.baidu.com/hi/jx2/j_0053.gif" ></p>' );
range.selectNode( body.firstChild.firstChild ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0018.gif'} );
equal( ua.getChildHTML( body.firstChild ), '<img src="http://img.baidu.com/hi/jx2/j_0018.gif">hello<img src="http://img.baidu.com/hi/jx2/j_0053.gif">', '检查插入的图像地址' );
equal( body.firstChild.childNodes.length, 3, '2个img孩子' );
} );
/*trace1491 修改动图的宽高*/
test( 'trace1491 修改动图的宽高', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p><br></p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'insertimage', {src:'../data/test.JPG'} );
ua.manualDeleteFillData( editor.body );
range.selectNode( body.firstChild.firstChild ).select();
var img = body.getElementsByTagName( 'img' )[0];
//这里必须要等一下才能过
img.onload = function () {
equal( $( img ).attr( 'width' ), '30', '比较width' );
equal( $( img ).attr( 'height' ), '853', '比较width' );
start();
}
editor.execCommand( 'insertimage', {src:'../data/test.JPG', width:50, height:80} );
img.onload = function () {
equal( $( img ).attr( 'width' ), '50', '比较width' );
equal( $( img ).attr( 'height' ), '80', '比较width' );
start();
}
ok(/data\/test\.JPG/.test( img.getAttribute( 'src' )), '比较src' );
stop();
} );
test( '选区不闭合插入图像', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello1</p><p>hello2<img src="http://img.baidu.com/hi/jx2/j_0004.gif"></p>' );
setTimeout(function(){
range.setStart( body.firstChild.firstChild, 2 ).setEnd( body.lastChild, 2 ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0016.gif', width:'100', height:'100'} );
ua.manualDeleteFillData( editor.body );
equal( body.childNodes.length, 1, '只有一个p' );
ua.clearWhiteNode(body.firstChild);
var img = body.firstChild.lastChild;
equal( img.getAttribute( 'src' ), 'http://img.baidu.com/hi/jx2/j_0016.gif', '比较src' );
equal( img.getAttribute( 'width' ), '100', '比较width' );
equal( img.getAttribute( 'height' ), '100', '比较height' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p><br></p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'insertimage', {src:'../data/test.JPG'} );
ua.manualDeleteFillData( editor.body );
range.selectNode( body.firstChild.firstChild ).select();
var img = body.getElementsByTagName( 'img' )[0];
img.onload = function () { //这里必须要等一下才能过
equal( $( img ).attr( 'width' ), '30', '比较width' );
equal( $( img ).attr( 'height' ), '853', '比较width' );
start();
},50);
};
editor.execCommand( 'insertimage', {src:'../data/test.JPG', width:50, height:80} );
img.onload = function () {
equal( $( img ).attr( 'width' ), '50', '比较width' );
equal( $( img ).attr( 'height' ), '80', '比较width' );
start();
};
ok(/data\/test\.JPG/.test( img.getAttribute( 'src' )), '比较src' );
stop();
} );
test( '选区不闭合插入图像', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello1</p><p>hello2<img src="http://img.baidu.com/hi/jx2/j_0004.gif"></p>' );
setTimeout(function(){
range.setStart( body.firstChild.firstChild, 2 ).setEnd( body.lastChild, 2 ).select();
editor.execCommand( 'insertimage', {src:'http://img.baidu.com/hi/jx2/j_0016.gif', width:'100', height:'100'} );
ua.manualDeleteFillData( editor.body );
equal( body.childNodes.length, 1, '只有一个p' );
ua.clearWhiteNode(body.firstChild);
var img = body.firstChild.lastChild;
equal( img.getAttribute( 'src' ), 'http://img.baidu.com/hi/jx2/j_0016.gif', '比较src' );
equal( img.getAttribute( 'width' ), '100', '比较width' );
equal( img.getAttribute( 'height' ), '100', '比较height' );
start();
},50);
stop();
} );
test( '图像设置左右浮动', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello1</p><p>hello2<img src="http://img.baidu.com/hi/jx2/j_0004.gif"></p>' );
range.selectNode( body.lastChild.lastChild ).select();
editor.execCommand( 'imagefloat', 'left' );
equal( body.getElementsByTagName( 'img' )[0].style['cssFloat'] || body.getElementsByTagName( 'img' )[0].style['styleFloat'], 'left', '左浮动' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello1</p><p>hello2<img src="http://img.baidu.com/hi/jx2/j_0004.gif"></p>' );
range.selectNode( body.lastChild.lastChild ).select();
editor.execCommand( 'imagefloat', 'left' );
equal( body.getElementsByTagName( 'img' )[0].style['cssFloat'] || body.getElementsByTagName( 'img' )[0].style['styleFloat'], 'left', '左浮动' );
// equal( body.getElementsByTagName( 'img' )[0].style['float'], 'left', '左浮动' );
equal( editor.queryCommandValue( 'imagefloat' ), 'left' );
editor.execCommand( 'imagefloat', 'right' );
equal( body.getElementsByTagName( 'img' )[0].style['cssFloat'] || body.getElementsByTagName( 'img' )[0].style['styleFloat'], 'right', '右浮动' );
equal( editor.queryCommandValue( 'imagefloat' ), 'right' );
equal( editor.queryCommandState( 'imagefloat' ), 0, '图片被选中,因此图片菜单高亮' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
equal( editor.queryCommandState( 'imagefloat' ), -1, '光标闭合,因此图片菜单高不高亮' );
equal( editor.queryCommandValue( 'justify' ), 'left', '段落的对齐方式为左对齐' );
equal( editor.queryCommandValue( 'imagefloat' ), 'none', '图片对齐方式在闭合情况获取为空' )
range.selectNode( body.firstChild.firstChild ).select();
equal( editor.queryCommandValue( 'imagefloat' ), 'none', '选中文本,因此图片菜单高不高亮' );
equal( editor.queryCommandValue( 'imagefloat' ), 'left' );
editor.execCommand( 'imagefloat', 'right' );
equal( body.getElementsByTagName( 'img' )[0].style['cssFloat'] || body.getElementsByTagName( 'img' )[0].style['styleFloat'], 'right', '右浮动' );
equal( editor.queryCommandValue( 'imagefloat' ), 'right' );
equal( editor.queryCommandState( 'imagefloat' ), 0, '图片被选中,因此图片菜单高亮' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
equal( editor.queryCommandState( 'imagefloat' ), -1, '光标闭合,因此图片菜单高不高亮' );
equal( editor.queryCommandValue( 'justify' ), 'left', '段落的对齐方式为左对齐' );
equal( editor.queryCommandValue( 'imagefloat' ), 'none', '图片对齐方式在闭合情况获取为空' )
range.selectNode( body.firstChild.firstChild ).select();
equal( editor.queryCommandValue( 'imagefloat' ), 'none', '选中文本,因此图片菜单高不高亮' );
} );
test( '左浮动变为默认的样式和居中', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello1</p><p>hello2<img src="http://img.baidu.com/hi/jx2/j_0004.gif" style="float:left"></p>' );
range.selectNode( body.lastChild.lastChild ).select();
editor.execCommand( 'imagefloat', 'none' );
equal( ua.getFloatStyle( body.getElementsByTagName( 'img' )[0] ), 'none', '没有浮动方式' );
equal( editor.queryCommandValue( 'imagefloat' ), 'none' );
$( body.getElementsByTagName( 'img' )[0] ).css( 'float' );
range.selectNode( body.getElementsByTagName( 'img' )[0] ).select();
editor.execCommand( 'imagefloat', 'center' );
equal( editor.queryCommandValue( 'imagefloat' ), 'center' );
equal( body.childNodes.length, 3, '3个p,image被切出一个p出来了' );
var p = body.childNodes[2];
equal( p.tagName.toLowerCase(), 'p', '第2个是p' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello1</p><p>hello2<img src="http://img.baidu.com/hi/jx2/j_0004.gif" style="float:left"></p>' );
range.selectNode( body.lastChild.lastChild ).select();
editor.execCommand( 'imagefloat', 'none' );
equal( ua.getFloatStyle( body.getElementsByTagName( 'img' )[0] ), '', '没有浮动方式' );
equal( editor.queryCommandValue( 'imagefloat' ), 'none' );
$( body.getElementsByTagName( 'img' )[0] ).css( 'float' );
range.selectNode( body.getElementsByTagName( 'img' )[0] ).select();
editor.execCommand( 'imagefloat', 'center' );
equal( editor.queryCommandValue( 'imagefloat' ), 'center' );
equal( body.childNodes.length, 3, '3个p,image被切出一个p出来了' );
var p = body.childNodes[2];
equal( p.tagName.toLowerCase(), 'p', '第2个是p' );
equal( p.firstChild.tagName.toLowerCase(), 'img', 'p的孩子为image' );
equal( ua.getFloatStyle( p.firstChild ), '', 'image对齐方式float为空' );
equal( editor.queryCommandValue( 'justify' ), 'center', '段落的对齐方式为居中' );
} );
test( ' 带有超链接的图片', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello1</p><p>hello2<a href="www.baidu.com"><img src="http://img.baidu.com/hi/jx2/j_0004.gif" style="float:left"></a></p>' );
range.selectNode( body.lastChild.lastChild ).select();
editor.execCommand( 'imagefloat', 'center' );
var p = body.childNodes[2];
equal( p.firstChild.tagName.toLowerCase(), 'a', 'p的孩子为a' );
equal( ua.getFloatStyle( p.firstChild ), '', 'image对齐方式float为空' );
equal( editor.queryCommandValue( 'justify' ), 'center', '段落的对齐方式为居中' );
editor.execCommand( 'imagefloat', 'left' );
equal( p.firstChild.tagName.toLowerCase(), 'a', 'p的孩子为a' );
equal( ua.getFloatStyle( p.firstChild.firstChild ), 'left', 'image对齐方式float为left' );
editor.execCommand( 'imagefloat', 'none' );
equal( p.firstChild.tagName.toLowerCase(), 'a', 'p的孩子为a' );
equal( ua.getFloatStyle( p.firstChild.firstChild ), 'none', 'image对齐方式float为空' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello1</p><p>hello2<a href="www.baidu.com"><img src="http://img.baidu.com/hi/jx2/j_0004.gif" style="float:left"></a></p>' );
range.selectNode( body.lastChild.lastChild ).select();
editor.execCommand( 'imagefloat', 'center' );
var p = body.childNodes[2];
equal( p.firstChild.tagName.toLowerCase(), 'a', 'p的孩子为a' );
equal( ua.getFloatStyle( p.firstChild ), '', 'image对齐方式float为空' );
equal( editor.queryCommandValue( 'justify' ), 'center', '段落的对齐方式为居中' );
editor.execCommand( 'imagefloat', 'left' );
equal( p.firstChild.tagName.toLowerCase(), 'a', 'p的孩子为a' );
equal( ua.getFloatStyle( p.firstChild.firstChild ), 'left', 'image对齐方式float为left' );
editor.execCommand( 'imagefloat', 'none' );
equal( p.firstChild.tagName.toLowerCase(), 'a', 'p的孩子为a' );
equal( ua.getFloatStyle( p.firstChild.firstChild ), '', 'image对齐方式float为空' );
} );
test( ' 默认样式切换到居中再切换回默认,会把居中导致的3个p合并', function () {
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello2<a href="www.baidu.com"><img src="http://img.baidu.com/hi/jx2/j_0004.gif" style="float:left"></a>hello3</p>' );
var editor = te.obj[0];
var range = te.obj[1];
var body = editor.body;
editor.setContent( '<p>hello2<a href="www.baidu.com"><img src="http://img.baidu.com/hi/jx2/j_0004.gif" style="float:left"></a>hello3</p>' );
setTimeout( function () {
range.selectNode( body.getElementsByTagName( 'a' )[0] ).select();
editor.execCommand( 'imagefloat', 'center' );
......
......@@ -125,12 +125,19 @@
}
try {
setTimeout(function() {
callback.call(testEnvironment);
if (config.stopCount == 1) {
start();
}
}, 100);
if (config.stopCount == 1) {
setTimeout(function() {
callback.call(testEnvironment);
if (config.stopCount == 1) {
start();
}
}, 100);
}
else{
callback.call(testEnvironment);
}
} catch(e) {
fail("Test " + name + " died, exception and test follows", e, callback);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册