提交 ba5fc3dc 编写于 作者: 许恒

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

Ueditor Change List
Version 1.2.5
新增功能
. table整体重构
. table支持插入表头和标题
. table支持拷贝
. table支持任意调整宽高
. table支持任意前插后插行列
. 粘贴支持纯文本和源码模式选择
. 添加计算字数的getContentLength接口
. 图片上传支持参数动态绑定
Version 1.2.4
新增功能
. 官网新增API文档
......
......@@ -26,6 +26,12 @@
<div class="clear"></div>
<div id="btns">
<div >
当前输入的字数(包括html标签)共 : <span id="htmlcount"></span>
</div>
<div >
当前输入的字数共 : <span id="txtcount"></span>
</div>
<div >
<input type="button" value="获得整个html的内容" onclick="getAllHtml()">
<input type="button" value="获得内容" onclick="getContent()">
......@@ -54,8 +60,11 @@
<script type="text/javascript">
//实例化编辑器
var ue=UE.getEditor('editor');
var ue = UE.getEditor('editor');
ue.addListener('selectionchange',function(){
document.getElementById('htmlcount').innerHTML = this.getContentLength();
document.getElementById('txtcount').innerHTML = this.getContentLength(true);
});
function createEditor(){
enableBtn();
UE.getEditor('editor')
......
......@@ -986,6 +986,25 @@
if ( !lang )break;
}
return lang;
},
/**
* 计算编辑器当前内容的长度
* @name getContentLength
* @grammar editor.getContentLength(ingoneHtml,tagNames) =>
* @example
* editor.getLang(true)
*/
getContentLength : function(ingoneHtml,tagNames){
var count = this.getContent().length;
if(ingoneHtml){
tagNames = (tagNames||[]).concat([ 'hr','img','iframe']);
count = this.getContentTxt().replace(/[\t\r\n]+/g,'').length;
for(var i= 0,ci;ci=tagNames[i++];){
count += this.document.getElementsByTagName(ci).length;
}
this.fireEvent('wordCount',count);
}
return count;
}
/**
* 得到dialog实例对象
......
......@@ -87,8 +87,9 @@ UE.plugins['autotypeset'] = function(){
// 行首缩进,段落方向,段间距,段内间距
for(var i=0,ci;ci=nodes[i++];){
if(!highlightCont && ci.tagName == 'DIV' && ci.getAttribute('highlighter')){
highlightCont = ci;
if(me.fireEvent('excludeNodeinautotype',ci) === true){
continue;
}
//font-size
if(opt.clearFontSize && ci.style.fontSize){
......
......@@ -24,7 +24,7 @@ UE.plugins['enterkey'] = function() {
if (/h\d/i.test(hTag)) {
if (browser.gecko) {
var h = domUtils.findParentByTagName(start, [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption'], true);
var h = domUtils.findParentByTagName(start, [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption','table'], true);
if (!h) {
me.document.execCommand('formatBlock', false, '<p>');
doSave = 1;
......
......@@ -144,8 +144,9 @@ UE.plugins['highlightcode'] = function() {
})
});
//避免table插件对于代码高亮的影响
me.addListener('excludetable',function(cmd,target){
me.addListener('excludetable excludeNodeinautotype',function (cmd,target){
if(target && domUtils.findParent(target,function(node){
return node.tagName == 'DIV' && domUtils.hasClass(node,'syntaxhighlighter');
},true)){
......
......@@ -33,31 +33,14 @@
UE.commands['unlink'] = {
execCommand : function() {
var as,
range = new dom.Range(this.document),
tds = this.currentSelectedArr,
var range = this.selection.getRange(),
bookmark;
if(tds && tds.length >0){
for(var i=0,ti;ti=tds[i++];){
as = domUtils.getElementsByTagName(ti,'a');
for(var j=0,aj;aj=as[j++];){
domUtils.remove(aj,true);
}
}
if(domUtils.isEmptyNode(tds[0])){
range.setStart(tds[0],0).setCursor();
}else{
range.selectNodeContents(tds[0]).select();
}
}else{
range = this.selection.getRange();
if(range.collapsed && !domUtils.findParentByTagName( range.startContainer, 'a', true )){
return;
}
bookmark = range.createBookmark();
optimize( range );
range.removeInlineStyle( 'a' ).moveToBookmark( bookmark ).select();
if(range.collapsed && !domUtils.findParentByTagName( range.startContainer, 'a', true )){
return;
}
bookmark = range.createBookmark();
optimize( range );
range.removeInlineStyle( 'a' ).moveToBookmark( bookmark ).select();
},
queryCommandState : function(){
return !this.highlight && this.queryCommandValue('link') ? 0 : -1;
......@@ -106,97 +89,61 @@
}
}
UE.commands['link'] = {
queryCommandState : function(){
return this.highlight ? -1 :0;
},
execCommand : function( cmdName, opt ) {
var range = new dom.Range(this.document),
tds = this.currentSelectedArr;
var range;
opt.data_ue_src && (opt.data_ue_src = utils.unhtml(opt.data_ue_src,/[<">]/g));
opt.href && (opt.href = utils.unhtml(opt.href,/[<">]/g));
opt.textValue && (opt.textValue = utils.unhtml(opt.textValue,/[<">]/g));
if(tds && tds.length){
for(var i=0,ti;ti=tds[i++];){
if(domUtils.isEmptyNode(ti)){
ti[browser.ie ? 'innerText' : 'textContent'] = utils.html(opt.textValue || opt.href);
}
doLink(range.selectNodeContents(ti),opt,this);
}
range.selectNodeContents(tds[0]).select();
doLink(range=this.selection.getRange(),opt,this);
//闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
range.collapse().select(true);
}else{
doLink(range=this.selection.getRange(),opt,this);
//闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
range.collapse().select(true);
}
},
queryCommandValue : function() {
var range = this.selection.getRange(),
node;
var range = new dom.Range(this.document),
tds = this.currentSelectedArr,
as,
node;
if(tds && tds.length){
for(var i=0,ti;ti=tds[i++];){
as = ti.getElementsByTagName('a');
if(as[0]){
return as[0];
}
if ( range.collapsed ) {
// node = this.selection.getStart();
//在ie下getstart()取值偏上了
node = range.startContainer;
node = node.nodeType == 1 ? node : node.parentNode;
if ( node && (node = domUtils.findParentByTagName( node, 'a', true )) && ! domUtils.isInNodeEndBoundary(range,node)) {
return node;
}
}else{
range = this.selection.getRange();
} else {
//trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
range.shrinkBoundary();
var start = range.startContainer.nodeType == 3 || !range.startContainer.childNodes[range.startOffset] ? range.startContainer : range.startContainer.childNodes[range.startOffset],
end = range.endContainer.nodeType == 3 || range.endOffset == 0 ? range.endContainer : range.endContainer.childNodes[range.endOffset-1],
common = range.getCommonAncestor();
if ( range.collapsed ) {
// node = this.selection.getStart();
//在ie下getstart()取值偏上了
node = range.startContainer;
node = node.nodeType == 1 ? node : node.parentNode;
node = domUtils.findParentByTagName( common, 'a', true );
if ( !node && common.nodeType == 1){
if ( node && (node = domUtils.findParentByTagName( node, 'a', true )) && ! domUtils.isInNodeEndBoundary(range,node)) {
var as = common.getElementsByTagName( 'a' ),
ps,pe;
return node;
}
} else {
//trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
range.shrinkBoundary();
var start = range.startContainer.nodeType == 3 || !range.startContainer.childNodes[range.startOffset] ? range.startContainer : range.startContainer.childNodes[range.startOffset],
end = range.endContainer.nodeType == 3 || range.endOffset == 0 ? range.endContainer : range.endContainer.childNodes[range.endOffset-1],
common = range.getCommonAncestor();
node = domUtils.findParentByTagName( common, 'a', true );
if ( !node && common.nodeType == 1){
var as = common.getElementsByTagName( 'a' ),
ps,pe;
for ( var i = 0,ci; ci = as[i++]; ) {
ps = domUtils.getPosition( ci, start ),pe = domUtils.getPosition( ci,end);
if ( (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
&&
(pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
) {
node = ci;
break;
}
for ( var i = 0,ci; ci = as[i++]; ) {
ps = domUtils.getPosition( ci, start ),pe = domUtils.getPosition( ci,end);
if ( (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
&&
(pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
) {
node = ci;
break;
}
}
return node;
}
return node;
}
}
};
})();
......@@ -520,7 +520,8 @@ UE.plugins['table'] = function () {
if (state != -1 && (firstState === undefined || firstState == state)) {
var isEmpty = domUtils.isEmptyNode(td);
result = oldExecCommand.apply(me, arguments);
if (isEmpty != domUtils.isEmptyNode(td)) {
var reg = new RegExp('[ \t\r\n' + domUtils.fillChar + ']', 'g');
if (isEmpty != domUtils.isEmptyNode(td) && !td[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').length) {
domUtils.fillNode(me.document, td)
}
}
......
......@@ -14,6 +14,7 @@ UE.plugins['wordcount'] = function(){
var me = this;
me.setOpt({
wordCount:true,
wordCountIngoreHtml:true,
maximumWords:10000,
wordCountMsg: me.options.wordCountMsg||me.getLang("wordCountMsg"),
wordOverFlowMsg:me.options.wordOverFlowMsg||me.getLang("wordOverFlowMsg")
......@@ -27,20 +28,15 @@ UE.plugins['wordcount'] = function(){
}
me.commands["wordcount"]={
queryCommandValue:function(cmd,onlyCount){
var length,contentText,reg;
var length;
if(onlyCount){
reg = new RegExp("[\r\t\n]","g");
contentText = this.getContentTxt().replace(reg,"");
return contentText.length;
return this.getContentLength(this.options.wordCountIngoreHtml);
}
reg = new RegExp("[\r\t\n]","g");
contentText = this.getContentTxt().replace(reg,"");
length = contentText.length;
length = this.getContentLength(this.options.wordCountIngoreHtml);
if(max-length<0){
me.fireEvent('wordcountoverflow',length);
return errMsg;
}
return msg.replace("{#leave}",max-length >= 0 ? max-length:0).replace("{#count}",length);
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册