提交 74695454 编写于 作者: Y yancen

Merge branch 'dev-1.2.5' of https://github.com/campaign/ueditor into dev-1.2.5

......@@ -437,50 +437,7 @@
* return false //编辑器没有内容 ,getContent直接返回空
* })
*/
getContent:function (cmd,fn,isPreview) {
// var me = this;
// if ( cmd && utils.isFunction( cmd ) ) {
// fn = cmd;
// cmd = '';
// }
// if ( fn ? !fn() : !this.hasContents() ) {
// return '';
// }
//// var range = me.selection.getRange(),
//// address = range.createAddress();
// var root = UE.htmlparser(me.body.innerHTML);
// me.fireEvent( 'beforegetcontent');
//
// me.filterOutputRule(root);
// var reg = new RegExp( domUtils.fillChar, 'g' ),
// //ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
// html = me.body.innerHTML.replace( reg, '' ).replace( />[\t\r\n]*?</g, '><' );
// me.fireEvent( 'aftergetcontent', cmd );
// try{
// range.moveToAddress(address).select(true);
// }catch(e){}
// if ( me.serialize ) {
// var node = me.serialize.parseHTML( html );
// node = me.serialize.transformOutput( node );
// html = me.serialize.toHTML( node );
// }
//
// if ( ie && isPreview ) {
// //trace:2471
// //两个br会导致空行,所以这里先注视掉
// html = html//.replace(/<\s*br\s*\/?\s*>/gi,'<br/><br/>')
// .replace( /<p>\s*?<\/p>/g, '<p>&nbsp;</p>' );
// } else {
// //多个&nbsp;要转换成空格加&nbsp;的形式,要不预览时会所成一个
// html = html.replace( /(&nbsp;)+/g, function ( s ) {
// for ( var i = 0, str = [], l = s.split( ';' ).length - 1; i < l; i++ ) {
// str.push( i % 2 == 0 ? ' ' : '&nbsp;' );
// }
// return str.join( '' );
// } );
// }
//
// return html;
getContent:function (cmd,fn) {
var me = this;
if (cmd && utils.isFunction(cmd)) {
fn = cmd;
......@@ -501,22 +458,7 @@
range.moveToAddress(address).select(true);
}catch(e){}
var html = root.toHtml();
if (ie && isPreview) {
//trace:2471
//两个br会导致空行,所以这里先注视掉
html = html.replace(/<p>\s*?<\/p>/g, '<p>&nbsp;</p>');
} else {
//多个&nbsp;要转换成空格加&nbsp;的形式,要不预览时会所成一个
html = html.replace(/(&nbsp;)+/g, function (s) {
for (var i = 0, str = [], l = s.split(';').length - 1; i < l; i++) {
str.push(i % 2 == 0 ? ' ' : '&nbsp;');
}
return str.join('');
});
}
return html;
return root.toHtml();
},
/**
* 取得完整的html代码,可以直接显示成完整的html文档
......@@ -583,116 +525,19 @@
* })
*/
setContent:function (html, isAppendTo, notFireSelectionchange) {
// var me = this,
// inline = utils.extend( {a:1, A:1}, dtd.$inline, true ),
// lastTagName;
//
// html = html
// .replace( /^[ \t\r\n]*?</, '<' )
// .replace( />[ \t\r\n]*?$/, '>' )
// //ie有时的源码会有>&nbsp;<的情况
// .replace(/>(?:(\s|&nbsp;)*?)</g,'><' )//代码高量的\n不能去除
// .replace( /[\s\/]?(\w+)?>[ \t\r\n]*?<\/?(\w+)/gi, function ( a, b, c ) {
// if ( b ) {
// lastTagName = c;
// } else {
// b = lastTagName;
// }
// return !inline[b] && !inline[c] ? a.replace( />[ \t\r\n]*?</, '><' ) : a;
// } );
// html = {'html':html};
// me.fireEvent( 'beforesetcontent',html,root);
// html = html.html;
// var serialize = this.serialize;
// if ( serialize ) {
// var node = serialize.parseHTML( html );
// node = serialize.transformInput( node );
// node = serialize.filter( node );
// html = serialize.toHTML( node );
// }
// //html.replace(new RegExp('[\t\n\r' + domUtils.fillChar + ']*','g'),'');
// //去掉了\t\n\r 如果有插入的代码,在源码切换所见即所得模式时,换行都丢掉了
// //\r在ie下的不可见字符,在源码切换时会变成多个&nbsp;
// //trace:1559
// this.body.innerHTML = (isAppendTo ? this.getContent() : '') + html.replace( new RegExp( '[\r' + domUtils.fillChar + ']*', 'g' ), '' );
// //处理ie6下innerHTML自动将相对路径转化成绝对路径的问题
// if ( browser.ie && browser.version < 7 ) {
// replaceSrc( this.document.body );
// }
// //给文本或者inline节点套p标签
// if ( me.options.enterTag == 'p' ) {
//
// var child = this.body.firstChild, tmpNode;
// if ( !child || child.nodeType == 1 &&
// (dtd.$cdata[child.tagName] ||
// domUtils.isCustomeNode( child )
// )
// && child === this.body.lastChild ) {
// this.body.innerHTML = '<p>' + (browser.ie ? '&nbsp;' : '<br/>') + '</p>' + this.body.innerHTML;
//
// } else {
// var p = me.document.createElement( 'p' );
// while ( child ) {
// while ( child && (child.nodeType == 3 || child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName]) ) {
// tmpNode = child.nextSibling;
// p.appendChild( child );
// child = tmpNode;
// }
// if ( p.firstChild ) {
// if ( !child ) {
// me.body.appendChild( p );
// break;
// } else {
// child.parentNode.insertBefore( p, child );
// p = me.document.createElement( 'p' );
// }
// }
// child = child.nextSibling;
// }
// }
// }
// me.fireEvent( 'aftersetcontent' );
// me.fireEvent( 'contentchange' );
// console.log(root.toHtml())
// !notFireSelectionchange && me._selectionChange();
// //清除保存的选区
// me._bakRange = me._bakIERange = null;
// //trace:1742 setContent后gecko能得到焦点问题
// var geckoSel;
// if ( browser.gecko && (geckoSel = this.selection.getNative()) ) {
// geckoSel.removeAllRanges();
// }
var me = this,
inline = utils.extend({a:1, A:1}, dtd.$inline, true),
lastTagName;
html = html
.replace(/^[ \t\r\n]*?</, '<')
.replace(/>[ \t\r\n]*?$/, '>')
//ie有时的源码会有>&nbsp;<的情况
.replace(/>(?:(\s|&nbsp;)*?)</g, '><')//代码高量的\n不能去除
.replace(/[\s\/]?(\w+)?>[ \t\r\n]*?<\/?(\w+)/gi, function (a, b, c) {
if (b) {
lastTagName = c;
} else {
b = lastTagName;
}
return !inline[b] && !inline[c] ? a.replace(/>[ \t\r\n]*?</, '><') : a;
});
var me = this;
me.fireEvent( 'beforesetcontent',html);
var root = UE.htmlparser(html);
me.filterInputRule(root);
html = root.toHtml();
//html.replace(new RegExp('[\t\n\r' + domUtils.fillChar + ']*','g'),'');
//去掉了\t\n\r 如果有插入的代码,在源码切换所见即所得模式时,换行都丢掉了
//\r在ie下的不可见字符,在源码切换时会变成多个&nbsp;
//trace:1559
this.body.innerHTML = (isAppendTo ? this.getContent() : '') + html.replace(new RegExp('[\r' + domUtils.fillChar + ']*', 'g'), '');
me.body.innerHTML = (isAppendTo ? this.getContent() : '') + html;
//处理ie6下innerHTML自动将相对路径转化成绝对路径的问题
if (browser.ie && browser.version < 7) {
replaceSrc(this.body);
replaceSrc(me.body);
}
//给文本或者inline节点套p标签
if (me.options.enterTag == 'p') {
......@@ -1193,4 +1038,3 @@
};
utils.inherits(Editor, EventBase);
})();
......@@ -1223,6 +1223,19 @@
}
return true;
},
traversal:function(doFn,filterFn){
if (this.collapsed)
return this;
var bookmark = this.createBookmark(),
end = bookmark.end,
current = domUtils.getNextDomNode(bookmark.start, false, filterFn);
while (current && current !== end && (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
var tmpNode = domUtils.getNextDomNode(current,false,filterFn);
doFn(current);
current = tmpNode;
}
return this.moveToBookmark(bookmark);
}
};
})();
\ No newline at end of file
......@@ -3,7 +3,10 @@
var htmlparser = UE.htmlparser = function (htmlstr) {
var reg = new RegExp(domUtils.fillChar, 'g');
//ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
htmlstr = htmlstr.replace(reg, '').replace(/>[\t\r\n]*?</g, '><');
htmlstr = htmlstr.replace(reg, '')
.replace(/(?:^[ \t\r\n]*?<)/, '<')
.replace(/(?:>[ \t\r\n]*?$)/, '>')
.replace(/>(?:[ \t\r\n]*)/g, '>').replace(/(?:[ \t\r\n]*)</g, '<');
var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;
......@@ -21,14 +24,22 @@ var htmlparser = UE.htmlparser = function (htmlstr) {
'dt':'dl',
'dd':'dl',
'option':'select'
},
needChild = {
'ol':'li',
'ul':'li'
};
function text(parent, data) {
parent.children.push(new uNode({
type:'text',
data:data,
parentNode:parent
}));
if(needChild[parent.tagName]){
var tmpNode = uNode.createElement(needChild[parent.tagName]);
parent.appendChild(tmpNode);
tmpNode.appendChild(uNode.createText(data));
parent = tmpNode;
}else{
parent.appendChild(uNode.createText(data));
}
}
function element(parent, tagName, htmlattr) {
......@@ -47,10 +58,6 @@ var htmlparser = UE.htmlparser = function (htmlstr) {
parent = element(parent, utils.isArray(needParentTag) ? needParentTag[0] : needParentTag)
}
}
// //根据dtd判断是否当前节点可以放入新的节点
// while(dtd[parent.tagName] && !dtd[parent.tagName][tagName]){
// parent = parent.parentNode;
// }
var elm = new uNode({
parentNode:parent,
......
......@@ -196,6 +196,23 @@
}
return this.children ? this.children[this.children.length - 1] : null;
},
previousSibling : function(){
var parent = this.parentNode;
for (var i = 0, ci; ci = parent.children[i]; i++) {
if (ci === this) {
return i == 0 ? null : parent.children[i-1];
}
}
},
nextSibling : function(){
var parent = this.parentNode;
for (var i = 0, ci; ci = parent.children[i++];) {
if (ci === this) {
return parent.children[i];
}
}
},
replaceChild:function (target, source) {
if (this.children) {
if(target.parentNode){
......
......@@ -40,7 +40,9 @@ UE.plugins['anchor'] = function (){
a.setAttr({
anchorname :a.getAttr('name'),
'class' : 'anchorclass'
})
});
a.setAttr('name')
}
})
});
......
......@@ -59,9 +59,6 @@ UE.plugins['snapscreen'] = function(){
}catch(e){
me.ui._dialogs['snapscreenDialog'].open();
}
},
queryCommandState: function(){
return this.highlight ? -1 :0;
}
};
}
......
......@@ -131,13 +131,11 @@
});
//重置getContent,源码模式下取值也能是最新的数据
me.getContent = function (){
var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
return cont.replace(/>[ \n\r\t]+/g,'>').replace(/[ \n\r\t]+</g,'<').replace(/>[\n\r\t]+</g,'><');
return sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
};
} else {
me.iframe.style.cssText = bakCssText;
var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
cont = cont.replace(/>[ \n\r\t]+/g,'>').replace(/[ \n\r\t]+</g,'<').replace(/>[\n\r\t]+</g,'><');
me.setContent(cont);
sourceEditor.dispose();
sourceEditor = null;
......
......@@ -5,17 +5,14 @@ test( '插入锚点后切换源码', function() {
var range = te.obj[1];
var body = editor.body;
stop();
//1.2版本,ie中‘’-〉'&nbsp;'
var br = baidu.editor.browser.ie ? '&nbsp;' : '<br />';
var br = baidu.editor.browser.ie ? '&nbsp;' : '<br />'; //1.2版本,ie中‘’-〉'&nbsp;'
setTimeout( function() {
editor.setContent( '<p>' + br + '</p>' );
range.setStart( body.firstChild, 0 ).collapse( 1 ).select();
editor.execCommand( 'anchor', 'hello' );
//1.2版本后,在img前有的不可见字符没有删去,这里改成之比较img内的内容
// ua.checkHTMLSameStyle( '<img anchorname="hello" class="anchorclass">' + br, editor.document, body.firstChild, '检查锚点html' );
ua.checkHTMLSameStyle( '<img anchorname="hello" class="anchorclass">' + br, editor.document, body.firstChild, '检查锚点html' ); //1.2版本后,在img前有的不可见字符没有删去,这里改成之比较img内的内容
ok(body.getElementsByTagName('img')[0].attributes['anchorname'].nodeValue=="hello"&&body.getElementsByTagName('img')[0].attributes['class'].nodeValue=="anchorclass",'检查锚点');
editor.execCommand( 'source' );
/*切到源码模式下会有一个超时*/
editor.execCommand( 'source' ); /*切到源码模式下会有一个超时*/
setTimeout( function() {
var tas = editor.iframe.parentNode.getElementsByTagName( 'textarea' );
ok( tas[0].value.indexOf( '<a name="hello"' ) != -1 || tas[0].value.indexOf( '<a anchorname="1"' ) != -1, '查看是否转换成功' );
......@@ -29,55 +26,18 @@ test( '插入锚点后切换源码', function() {
}, 10 );
}, 20 );
} );
//两次设定textarea中的内容总会出错,把这个用例拆成两个
//test( '在源码模式设置超链接的name属性,切换到编辑器模式检查超链接是否变为锚点', function() {
// var editor = te.obj[0];
// editor.setContent( '' );
// var body = editor.body;
// stop();
// /*切到源码模式下会有一个超时*/
// setTimeout( function() {
// editor.execCommand( 'source' );
// setTimeout( function() {
// var ta = editor.iframe.parentNode.getElementsByTagName( 'textarea' )[0];
// /*这种情况认为是锚点*/
//// ta.value
//// ta.textContent='<p><a name="source" anchorname="1"></a></p>';
// ta.value = '<p><a name="source" anchorname="1"></a></p>';
// setTimeout( function() {
// editor.execCommand( 'source' );
// ua.checkHTMLSameStyle( '<img anchorname="source" class="anchorclass">', editor.document, body.firstChild, '检查锚点html' );
// /*这种情况不应当转换为锚点*/
// editor.execCommand( 'source' );
// setTimeout( function() {
//// ta = editor.iframe.parentNode.getElementsByTagName( 'textarea' )[0];
// editor.iframe.parentNode.getElementsByTagName( 'textarea' )[0].value = '<p><a name="source">你好</a></p>';
// setTimeout( function() {
// editor.execCommand( 'source' );
// equal( body.firstChild.firstChild.tagName.toLowerCase(), 'a', 'a标签不会转化' );
// /*用例结束前等一下,因为还有个超时操作会获取窗口*/
// setTimeout( function() {
// start();
// }, 50 );
// }, 50 );
// }, 50 );
// }, 20 );
// }, 10 );
// }, 20 );
//} );
test( '在源码模式设置超链接的name属性,切换到编辑器模式检查超链接是否变为锚点', function() {
var editor = te.obj[0];
var body = editor.body;
stop();
setTimeout(function(){
editor.setContent( '' );
/*切到源码模式下会有一个超时*/
setTimeout( function() {
editor.execCommand( 'source' );
setTimeout( function() {
var ta = editor.iframe.parentNode.getElementsByTagName( 'textarea' )[0];
/*这种情况认为是锚点*/
ta.value = '<p><a name="source" anchorname="1"></a></p>';
ta.value = '<p><a name="source" anchorname="1"></a></p>'; /*这种情况认为是锚点*/
setTimeout( function() {
editor.execCommand( 'source' );
ua.checkHTMLSameStyle( '<img anchorname="source" class="anchorclass">', editor.document, body.firstChild, '检查锚点html' );
......@@ -88,22 +48,20 @@ test( '在源码模式设置超链接的name属性,切换到编辑器模式检
},100);
} );
test( '在源码模式设置超链接没有name属性,切换到编辑器模式检查超链接不变为锚点', function() {
var editor = te.obj[0];
editor.setContent( '' );
var body = editor.body;
stop();
/*切到源码模式下会有一个超时*/
setTimeout( function() {
editor.execCommand( 'source' );
setTimeout( function() {
var ta = editor.iframe.parentNode.getElementsByTagName( 'textarea' )[0];
ta.value = '<p><a name="source">你好</a></p>';
ta.value = '<p><a name="source" href="www.baidu.com">你好</a></p>';
setTimeout( function() {
editor.execCommand( 'source' );
ua.manualDeleteFillData(editor.body);
equal( body.firstChild.firstChild.tagName.toLowerCase(), 'a', 'a标签不会转化' );
start();
}, 50 );
......@@ -120,7 +78,6 @@ test( '已存在锚点', function() {
range.selectNode(body.firstChild).select();
editor.execCommand( 'anchor', 'hello' );
var name=body.firstChild.firstChild.getAttribute('anchorname');
// equal(ua.getChildHTML(editor.body),'<p><img anchorname=\"hello\" class=\"anchorclass\" _src=\"undefined\"></p>','更改name');
equal(name, 'hello', '更改name');
editor.setContent( '<p><img anchorname="1" class="anchorclass"/></p>' );
range.selectNode(body.firstChild).select();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册