提交 b9006098 编写于 作者: T taoqili

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

Conflicts:
	_src/plugins/table.js
Ueditor Change List
UEditor Change List
Version 1.2.5
新增功能
......
......@@ -24,12 +24,6 @@
<div class="clear"></div>
<div id="btns">
<div >
当前输入的字数(包括html标签)共 : <span id="htmlcount"></span>
</div>
<div >
当前输入的字数共 : <span id="txtcount"></span>
</div>
<div >
<button onclick="getAllHtml()">获得整个html的内容</button>
<button onclick="getContent()">获得内容</button>
......@@ -43,7 +37,7 @@
<div >
<button onclick="getText()">获得当前选中的文本</button>
<button onclick="insertHtml()">插入给定的内容</button>
<button onclick="setEnabled()">可以编辑</button>
<button id="enable" onclick="setEnabled()">可以编辑</button>
<button onclick="setDisabled()">不可编辑</button>
<button onclick=" UE.getEditor('editor').setHide()">隐藏编辑器</button>
<button onclick=" UE.getEditor('editor').setShow()">显示编辑器</button>
......@@ -60,17 +54,12 @@
//实例化编辑器
var ue = UE.getEditor('editor');
ue.addListener('wordcount',function(){
document.getElementById('htmlcount').innerHTML = this.getContentLength();
document.getElementById('txtcount').innerHTML = this.getContentLength(true);
});
ue.addListener('ready',function(){
this.focus()
});
function insertHtml(){
var value = prompt('插入html代码');
var value = prompt('插入html代码','');
ue.execCommand('insertHtml',value)
}
function createEditor(){
......
......@@ -14,6 +14,10 @@
'core/Editor.js',
'core/ajax.js',
'core/filterword.js',
'core/node.js',
'core/htmlparser.js',
'core/filternode.js',
'plugins/defaultfilter.js',
'plugins/inserthtml.js',
'plugins/autotypeset.js',
'plugins/autosubmit.js',
......@@ -53,7 +57,7 @@
'plugins/autoheight.js',
'plugins/autofloat.js', //依赖UEditor UI,在IE6中,会覆盖掉body的背景图属性
'plugins/highlightcode.js',
'plugins/serialize.js',
'plugins/puretxtpaste.js',
'plugins/video.js',
'plugins/table.js',
'plugins/contextmenu.js',
......
......@@ -42,6 +42,7 @@
editor = UE.getEditor('simple');
this.value="销毁编辑器";
this.onclick = destroy;
timer = setInterval( setMsg, 100 );
}
}
function setMsg() {
......
......@@ -19,6 +19,7 @@
highlightCssUrl 代码高亮相关css的路径 如果展示有代码高亮,必须给定该属性
liiconpath 自定义列表样式的图标路径,可以不给定,默认'http://bs.baidu.com/listicon/',
listDefaultPaddingLeft : 自定义列表样式的左边宽度 默认'20',
customRule 可以传入你自己的处理规则函数,函数第一个参数是容器节点
*/
uParse('.content',{
......@@ -30,22 +31,31 @@
</head>
<body>
<h1>解析编辑的内容</h1>
<div class="content">
<div class="content" style="width:200px">
<ol class="custom_cn2 list-paddingleft-1"><li class="list-cn-3-1 list-cn2-paddingleft-1"><p>这里可以书写,编辑器的初始内容</p></li></ol><ul class="custom_dash list-paddingleft-1"><li class="list-dash list-dash-paddingleft"><p>sdfas</p></li></ul><ol class="custom_cn2 list-paddingleft-1"><ol style="list-style-type: decimal; " class=" list-paddingleft-3"><li><p>dfas</p></li></ol><li class="list-cn-3-1 list-cn2-paddingleft-1"><p>dfa</p></li><ol style="list-style-type: decimal; " class=" list-paddingleft-3"><li><p>sdfadf</p></li></ol></ol>
<p>
这里可以书写,编辑器的初始内容
</p>
<pre class="brush:as3;toolbar:false;">
sfasd
fasd
fas
dfasdf
<pre class="brush:js;toolbar:false;">
moveToBookmark:function (bookmark) {
var start = bookmark.id ? this.document.getElementById(bookmark.start) : bookmark.start,
end = bookmark.end && bookmark.id ? this.document.getElementById(bookmark.end) : bookmark.end;
this.setStartBefore(start);
domUtils.remove(start);
if (end) {
this.setEndBefore(end);
domUtils.remove(end);
} else {
this.collapse(true);
}
return this;
},
</pre>
<p>
<br />
</p>
</div>
<div class="content">
<div id="content" class="content">
<table width="960">
<caption>
sdf<br />
......
此差异已折叠。
///import editor.js
///import core/dom/dom.js
///import core/utils.js
/**
* dtd html语义化的体现类
* @constructor
......@@ -12,18 +13,7 @@ var dtd = dom.dtd = (function() {
}
return s;
}
function X( t ) {
var a = arguments;
for ( var i=1; i<a.length; i++ ) {
var x = a[i];
for ( var k in x ) {
if (!t.hasOwnProperty(k)) {
t[k] = x[k];
}
}
}
return t;
}
var X = utils.extend2;
var A = _({isindex:1,fieldset:1}),
B = _({input:1,button:1,select:1,textarea:1,label:1}),
C = X( _({a:1}), B ),
......@@ -49,8 +39,8 @@ var dtd = dom.dtd = (function() {
V = _({html:1});
var block = _({address:1,blockquote:1,center:1,dir:1,div:1,dl:1,fieldset:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,isindex:1,menu:1,noframes:1,ol:1,p:1,pre:1,table:1,ul:1}),
//针对优酷的embed他添加了结束标识,导致粘贴进来会变成两个,暂时去掉 ,embed:1
empty = _({area:1,base:1,br:1,col:1,hr:1,img:1,input:1,link:1,meta:1,param:1,embed:1});
empty = _({area:1,base:1,basefont:1,br:1,col:1,command:1,dialog:1,embed:1,hr:1,img:1,input:1,isindex:1,keygen:1,link:1,meta:1,param:1,source:1,track:1,wbr:1});
return _({
......
/**
* @file
* @name UE.filterNode
* @short filterNode
* @desc 根据给定的规则过滤节点
* @import editor.js,core/utils.js
* @anthor zhanyi
*/
var filterNode = UE.filterNode = function () {
function filterNode(node,rules){
switch (node.type) {
case 'text':
break;
case 'element':
var val;
if(val = rules[node.tagName]){
if(val === '-'){
node.parentNode.removeChild(node)
}else if(utils.isFunction(val)){
var parentNode = node.parentNode,
index = node.getIndex();
val(node);
for(var i = index,ci;ci=parentNode.children[i];){
filterNode(ci,rules);
if(ci.parentNode){
i++;
}
}
}else{
var attrs = val['$'];
if(attrs && node.attrs){
var tmpAttrs = {},tmpVal;
for(var a in attrs){
tmpVal = node.getAttr(a);
//todo 只先对style单独处理
if(a == 'style' && utils.isArray(attrs[a])){
var tmpCssStyle = [];
utils.each(attrs[a],function(v){
var tmp;
if(tmp = node.getStyle(v)){
tmpCssStyle.push(v + ':' + tmp);
}
});
tmpVal = tmpCssStyle.join(';')
}
if(tmpVal !== ""){
tmpAttrs[a] = tmpVal;
}
}
node.attrs = tmpAttrs;
}
if(node.children){
for(var i = 0,ci;ci=node.children[i];){
filterNode(ci,rules);
if(ci.parentNode){
i++;
}
}
}
}
}else{
//如果不在名单里扣出子节点并删除该节点,cdata除外
if(dtd.$cdata[node.tagName]){
node.parentNode.removeChild(node)
}else{
var parentNode = node.parentNode,
index = node.getIndex();
node.parentNode.removeChild(node,true);
for(var i = index,ci;ci=parentNode.children[i];){
filterNode(ci,rules);
if(ci.parentNode){
i++;
}
}
}
}
break;
case 'comment':
node.parentNode.removeChild(node)
}
}
return function(root,rules){
if(utils.isEmptyObject(rules)){
return root;
}
var val;
if(val = rules['-']){
utils.each(val.split(' '),function(k){
rules[k] = '-'
})
}
for(var i= 0,ci;ci=root.children[i];){
filterNode(ci,rules);
if(ci.parentNode){
i++;
}
}
return root;
}
}();
\ No newline at end of file
//html字符串转换成uNode节点
//by zhanyi
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, '><');
var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;
var uNode = UE.uNode,
needparentNode = {
'td':'tr',
'tr':'tbody',
'tbody':'table',
'th':'tr',
'thead':'table',
'tfoot':'table',
'caption':'table',
'li':['ul', 'ol'],
'dt':'dl',
'dd':'dl',
'option':'select'
};
function text(parent, data) {
parent.children.push(new uNode({
type:'text',
data:data,
parentNode:parent
}));
}
function element(parent, tagName, htmlattr) {
var needParentTag;
if (needParentTag = needparentNode[tagName]) {
if (tagName == parent.tagName) {
parent = parent.parentNode;
} else if (utils.isArray(needParentTag) ? utils.indexOf(needParentTag, parent.tagName) == -1 : needParentTag != parent.tagName) {
parent = element(parent, utils.isArray(needParentTag) ? needParentTag[0] : needParentTag)
}
}
var elm = new uNode({
parentNode:parent,
type:'element',
tagName:tagName,
//是自闭合的处理一下
children:dtd.$empty[tagName] ? null : []
});
//如果属性存在,处理属性
if (htmlattr) {
var attrs = {}, match;
while (match = re_attr.exec(htmlattr)) {
attrs[match[1].toLowerCase()] = match[2]
}
elm.attrs = attrs;
}
parent.children.push(elm);
//如果是自闭合节点返回父亲节点
return dtd.$empty[tagName] ? parent : elm
}
function comment(parent, data) {
parent.children.push(new uNode({
type:'comment',
data:data,
parentNode:parent
}));
}
var match, currentIndex = 0, nextIndex = 0;
//设置根节点
var root = new uNode({
type:'root',
children:[]
});
var currentParent = root;
while (match = re_tag.exec(htmlstr)) {
currentIndex = match.index;
if (currentIndex > nextIndex) {
//text node
text(currentParent, htmlstr.slice(nextIndex, currentIndex));
}
if (match[3]) {
//start tag
currentParent = element(currentParent, match[3], match[4]);
} else if (match[1]) {
//end tag
currentParent = currentParent.parentNode;
} else if (match[2]) {
//comment
comment(currentParent, match[2])
}
nextIndex = re_tag.lastIndex;
}
//如果结束是文本,就有可能丢掉,所以这里手动判断一下
//例如 <li>sdfsdfsdf<li>sdfsdfsdfsdf
if (nextIndex < htmlstr.length) {
text(currentParent, htmlstr.slice(nextIndex));
}
return root;
};
\ No newline at end of file
///import editor.js
///import core/utils.js
///import core/dom/dom.js
///import core/dom/dtd.js
///import core/htmlparser.js
//模拟的节点类
//by zhanyi
(function () {
var uNode = UE.uNode = function (obj) {
this.type = obj.type;
this.data = obj.data;
this.tagName = obj.tagName;
this.parentNode = obj.parentNode;
this.attrs = obj.attrs || {};
this.children = obj.children;
};
var indentChar = ' ',
breakChar = '\n';
function insertLine(arr, current, begin) {
arr.push(breakChar);
return current + (begin ? 1 : -1);
}
function insertIndent(arr, current) {
//插入缩进
for (var i = 0; i < current; i++) {
arr.push(indentChar);
}
}
//创建uNode的静态方法
//支持标签和html
uNode.createElement = function (html) {
if (/[<>]/.test(html)) {
return UE.htmlparser(html).children[0]
} else {
return new uNode({
type:'element',
children:[],
tagName:html
})
}
};
uNode.createText = function (data) {
return new UE.uNode({
type:'text',
'data':data || ''
})
};
function nodeToHtml(node, arr, formatter, current) {
switch (node.type) {
case 'root':
for (var i = 0, ci; ci = node.children[i++];) {
//插入新行
if (formatter && ci.type == 'element' && !dtd.$inline[ci.tagName] && i > 1) {
insertLine(arr, current, true);
insertIndent(arr, current)
}
nodeToHtml(ci, arr, formatter, current)
}
break;
case 'text':
isText(node, arr);
break;
case 'element':
isElement(node, arr, formatter, current);
break;
case 'comment':
isComment(node, arr, formatter);
}
return arr;
}
function isText(node, arr) {
arr.push(node.data)
}
function isElement(node, arr, formatter, current) {
var attrhtml = '';
if (node.attrs) {
attrhtml = [];
var attrs = node.attrs;
for (var a in attrs) {
attrhtml.push(a + (attrs[a] !== undefined ? '="' + utils.unhtml(attrs[a]) + '"' : ''))
}
attrhtml = attrhtml.join(' ');
}
arr.push('<' + node.tagName +
(attrhtml ? ' ' + attrhtml + ' ' : '') +
(dtd.$empty[node.tagName] ? '\/' : '' ) + '>'
);
//插入新行
if (formatter && !dtd.$inline[node.tagName]) {
current = insertLine(arr, current, true);
insertIndent(arr, current)
}
if (node.children && node.children.length) {
for (var i = 0, ci; ci = node.children[i++];) {
if (formatter && ci.type == 'element' && !dtd.$inline[ci.tagName] && i > 1) {
insertLine(arr, current);
insertIndent(arr, current)
}
nodeToHtml(ci, arr, formatter, current)
}
}
if (!dtd.$empty[node.tagName]) {
if (formatter && !dtd.$inline[node.tagName]) {
current = insertLine(arr, current);
insertIndent(arr, current)
}
arr.push('<\/' + node.tagName + '>');
}
}
function isComment(node, arr) {
arr.push('<!--' + node.data + '-->');
}
function getNodeById(root, id) {
var node;
if (root.type == 'element' && root.getAttr('id') == id) {
return root;
}
if (root.children && root.children.length) {
for (var i = 0, ci; ci = root.children[i++];) {
if (node = getNodeById(ci, id)) {
return node;
}
}
}
}
function getNodesByTagName(node, tagName, arr) {
if (node.type == 'element' && node.tagName == tagName) {
arr.push(node);
}
if (node.children && node.children.length) {
for (var i = 0, ci; ci = node.children[i++];) {
getNodesByTagName(ci, tagName, arr)
}
}
}
uNode.prototype = {
toHtml:function (formatter) {
var arr = [];
nodeToHtml(this, arr, formatter, 0);
return arr.join('')
},
innerHTML:function (htmlstr) {
if (this.type != 'element' || dtd.$empty[this.tagName]) {
return this;
}
if (htmlstr) {
for (var i = 0, ci; ci = this.children[i++];) {
ci.parentNode = null;
}
this.children = [];
var tmpRoot = UE.htmlparser(htmlstr);
for (var i = 0, ci; ci = tmpRoot.children[i++];) {
this.children.push(ci);
ci.parentNode = this;
}
return this;
} else {
var tmpRoot = new UE.uNode({
type:'root',
children:this.children
});
return tmpRoot.toHtml();
}
},
innerText:function () {
if (this.type != 'element' || dtd.$empty[this.tagName]) {
return this;
}
var html = this.toHtml();
return html.replace(/<[^>]+>/g, '');
},
getData:function () {
if (this.type == 'element')
return '';
return this.data
},
firstChild:function () {
if (this.type != 'element' || dtd.$empty[this.tagName]) {
return this;
}
return this.children ? this.children[0] : null;
},
lastChild:function () {
if (this.type != 'element' || dtd.$empty[this.tagName]) {
return this;
}
return this.children ? this.children[this.children.length - 1] : null;
},
replaceChild:function (target, source) {
if (this.children) {
if(target.parentNode){
target.parentNode.removeChild(target);
}
for (var i = 0, ci; ci = this.children[i]; i++) {
if (ci === source) {
this.children.splice(i, 1, target);
source.parentNode = null;
target.parentNode = this;
return target;
}
}
}
},
appendChild:function (node) {
if (this.type == 'element' && !dtd.$empty[this.tagName]) {
if (!this.children) {
this.children = []
}
if(node.parentNode){
node.parentNode.removeChild(node);
}
for (var i = 0, ci; ci = this.children[i]; i++) {
if (ci === node) {
this.children.splice(i, 1);
break;
}
}
this.children.push(node);
node.parentNode = this;
return node;
}
},
insertBefore:function (target, source) {
if (this.children) {
if(target.parentNode){
target.parentNode.removeChild(target);
}
for (var i = 0, ci; ci = this.children[i]; i++) {
if (ci === source) {
this.children.splice(i, 0, target);
target.parentNode = this;
return target;
}
}
}
},
insertAfter:function (target, source) {
if (this.children) {
if(target.parentNode){
target.parentNode.removeChild(target);
}
for (var i = 0, ci; ci = this.children[i]; i++) {
if (ci === source) {
this.children.splice(i + 1, 0, target);
target.parentNode = this;
return target;
}
}
}
},
removeChild:function (node,keepChildren) {
if (this.children) {
for (var i = 0, ci; ci = this.children[i]; i++) {
if (ci === node) {
this.children.splice(i, 1);
ci.parentNode = null;
if(keepChildren && ci.children && ci.children.length){
for(var j= 0,cj;cj=ci.children[j];j++){
this.children.splice(i+j,0,cj);
cj.parentNode = this;
}
}
return ci;
}
}
}
},
getAttr:function (attrName) {
return this.attrs[attrName.toLowerCase()]
},
setAttr:function (attrName, attrVal) {
if (!attrName) {
delete this.attrs;
return;
}
if (utils.isObject(attrName)) {
for (var a in attrName) {
if (!attrName[a]) {
delete this.attrs[a]
} else {
this.attrs[a.toLowerCase()] = attrName[a];
}
}
} else {
if (!attrVal) {
delete this.attrs[attrName]
} else {
this.attrs[attrName.toLowerCase()] = attrVal;
}
}
},
getIndex:function(){
var parent = this.parentNode;
for(var i= 0,ci;ci=parent.children[i];i++){
if(ci === this){
return i;
}
}
return -1;
},
getNodeById:function (id) {
var node;
if (this.children && this.children.length) {
for (var i = 0, ci; ci = this.children[i++];) {
if (node = getNodeById(ci, id)) {
return node;
}
}
}
},
getNodesByTagName:function (tagNames) {
tagNames = utils.trim(tagNames).replace(/[ ]{2,}/g, ' ').split(' ');
var arr = [], me = this;
utils.each(tagNames, function (tagName) {
if (me.children && me.children.length) {
for (var i = 0, ci; ci = me.children[i++];) {
getNodesByTagName(ci, tagName, arr)
}
}
});
return arr;
},
getStyle:function (name) {
var cssStyle = this.getAttr('style');
if (!cssStyle) {
return ''
}
var reg = new RegExp(name + ':([^;]+)');
var match = cssStyle.match(reg);
if (match && match[0]) {
return match[1]
}
return '';
},
setStyle:function (name, val) {
function exec(name, val) {
var reg = new RegExp(name + ':([^;]+);?', 'gi');
cssStyle = cssStyle.replace(reg, '');
if (val) {
cssStyle = name + ':' + utils.unhtml(val) + ';' + cssStyle
}
}
var cssStyle = this.getAttr('style');
if (!cssStyle) {
cssStyle = '';
}
if (utils.isObject(name)) {
for (var a in name) {
exec(a, name[a])
}
} else {
exec(name, val)
}
this.setAttr('style', cssStyle)
}
}
})();
......@@ -64,7 +64,18 @@ var utils = UE.utils = {
}
return t;
},
extend2 : function(t){
var a = arguments;
for ( var i=1; i<a.length; i++ ) {
var x = a[i];
for ( var k in x ) {
if (!t.hasOwnProperty(k)) {
t[k] = x[k];
}
}
}
return t;
},
/**
* 模拟继承机制,subClass继承superClass
* @name inherits
......@@ -198,13 +209,18 @@ var utils = UE.utils = {
* UE.utils.unhtml(html,/[<>]/g) ==> &lt;body&gt;You say:"你好!Baidu & UEditor!"&lt;/body&gt;
*/
unhtml:function (str, reg) {
return str ? str.replace(reg || /[&<">]/g, function (m) {
return {
'<':'&lt;',
'&':'&amp;',
'"':'&quot;',
'>':'&gt;'
}[m]
return str ? str.replace(reg || /[&<">](?:(amp|lt|quot|gt);)?/g, function (a,b) {
if(b){
return a;
}else{
return {
'<':'&lt;',
'&':'&amp;',
'"':'&quot;',
'>':'&gt;'
}[a]
}
}) : '';
},
/**
......@@ -572,7 +588,7 @@ var utils = UE.utils = {
* @name isNumber
* @grammar UE.utils.isNumber(obj) => true|false
*/
utils.each(['String','Function','Array','Number','RegExp'],function(v){
utils.each(['String','Function','Array','Number','RegExp','Object'],function(v){
UE.utils['is' + v] = function(obj){
return Object.prototype.toString.apply(obj) == '[object ' + v + ']';
}
......
......@@ -14,9 +14,36 @@ UE.plugins['anchor'] = function (){
me.ready(function(){
utils.cssRule('anchor',
'.anchorclass{background: url(\'' + me.options.UEDITOR_HOME_URL + 'themes/default/images/anchor.gif\') no-repeat scroll left center transparent;border: 1px dotted #0000FF;cursor: auto;display: inline-block;height: 16px;width: 15px;}',me.document)
'.anchorclass{background: url(\''
+ me.options.UEDITOR_HOME_URL +
'themes/default/images/anchor.gif\') no-repeat scroll left center transparent;border: 1px dotted #0000FF;cursor: auto;display: inline-block;height: 16px;width: 15px;}',
me.document)
});
me.addOutputRule(function(root){
utils.each(root.getNodesByTagName('img'),function(a){
var val;
if(val = a.getAttr('anchorname')){
a.tagName = 'a';
a.setAttr({
anchorname : '',
name : val,
'class' : ''
})
}
})
});
me.addInputRule(function(root){
utils.each(root.getNodesByTagName('a'),function(a){
var val;
if((val = a.getAttr('name')) && !a.getAttr('href')){
a.tagName = 'img';
a.setAttr({
anchorname :a.getAttr('name'),
'class' : 'anchorclass'
})
}
})
});
me.commands['anchor'] = {
execCommand:function (cmd, name) {
var range = this.selection.getRange(),img = range.getClosedNode();
......
......@@ -102,15 +102,8 @@
if(LteIE6){
fixIE6FixedPos();
}
me.addListener('autoheightchanged', function (t, enabled){
if (enabled) {
domUtils.on(window, ['scroll','resize'], updateFloating);
me.addListener('keydown', defer_updateFloating);
} else {
domUtils.un(window, ['scroll','resize'], updateFloating);
me.removeListener('keydown', defer_updateFloating);
}
});
domUtils.on(window, ['scroll','resize'], updateFloating);
me.addListener('keydown', defer_updateFloating);
me.addListener('beforefullscreenchange', function (t, enabled){
if (enabled) {
......
......@@ -9,6 +9,7 @@
* @param {String} cmdName bold加粗。italic斜体。subscript上标。superscript下标。
*/
UE.plugins['basestyle'] = function(){
var basestyles = {
'bold':['strong','b'],
'italic':['em','i'],
......@@ -25,6 +26,17 @@ UE.plugins['basestyle'] = function(){
"Italic" : "ctrl+73", //^I
"Underline" : "ctrl+85"//^U
});
me.addInputRule(function(root){
utils.each(root.getNodesByTagName('b i'),function(node){
switch (node.tagName){
case 'b':
node.tagName = 'strong';
break;
case 'i':
node.tagName = 'em';
}
});
});
for ( var style in basestyles ) {
(function( cmd, tagNames ) {
me.commands[cmd] = {
......
///import core
///commands 提供黑白名单功能
///commandsName filterNode
///commandsTitle filterNode
/**
* 提供黑白名单功能
* @function
* @name baidu.editor.execCommands
* @param {uNode} node
*/
UE.plugins['defaultfilter'] = function (){
var me = this;
//默认的过滤处理
//进入编辑器的内容处理
me.addInputRule(function (root) {
utils.each(root.getNodesByTagName('script style a img span p'), function (node) {
var val;
switch (node.tagName){
case 'style':
case 'script':
node.setAttr({
cdata_tag:node.tagName,
cdata_data:encodeURIComponent(node.innerText() || '')
});
node.tagName = 'div';
node.removeChild(node.firstChild());
break;
case 'a':
if (val = node.getAttr('href')) {
node.setAttr('_href', val)
}
break;
case 'img':
//todo base64暂时去掉,后边做远程图片上传后,干掉这个
if(val = node.getAttr('src')){
if(/^data:/.test(val)){
node.parentNode.removeChild(node);
break;
}
}
node.setAttr('_src',node.getAttr('src'));
break;
case 'span':
if(browser.webkit && (val = node.getStyle('white-space'))){
if(val == 'nowrap'){
node.setStyle('white-space','')
}
}
break;
case 'p':
if(val = node.getAttr('align')){
node.setAttr('align');
node.setStyle('text-align',val)
}
}
});
});
//从编辑器出去的内容处理
me.addOutputRule(function (root) {
utils.each(root.getNodesByTagName('div a img'), function (node) {
var val;
switch (node.tagName){
case 'div':
if (val = node.getAttr('cdata_tag')) {
node.tagName = val;
node.appendChild(UE.uNode.createText(node.getAttr('cdata_data')));
node.setAttr({cdata_tag:'', cdata_data:''});
}
break;
case 'a':
if (val = node.getAttr('_href')) {
node.setAttr({
'href':val,
'_href':''
})
}
break;
case 'img':
if(val = node.getAttr('_src')){
node.setAttr({
'src':node.getAttr('_src'),
'_src':''
})
}
}
});
});
};
......@@ -35,7 +35,37 @@ UE.plugins['font'] = function() {
],
'fontsize':[10, 11, 12, 14, 16, 18, 20, 24, 36]
});
me.addInputRule(function(root){
utils.each(root.getNodesByTagName('u s del font'),function(node){
if(node.tagName == 'font'){
var cssStyle = [];
for(var p in node.attrs){
switch (p){
case 'size':
cssStyle.push('font-size:' + node.attrs[p] + 'px');
break;
case 'color':
cssStyle.push('color:'+ node.attrs[p]);
break;
case 'face':
cssStyle.push('font-family:'+ node.attrs[p]);
break;
case 'style':
cssStyle.push(node.attrs[p]);
}
}
node.attrs = {
'style' : cssStyle.join(';')
};
}else{
var val = node.tagName == 'u' ? 'underline' : 'line-through';
node.attrs = {
'style' : (node.getAttr('style') || '') + 'text-decoration:'+val+';'
}
}
node.tagName = 'span';
});
});
for ( var p in fonts ) {
(function( cmd, style ) {
UE.commands[cmd] = {
......
......@@ -120,7 +120,8 @@ UE.plugins['highlightcode'] = function() {
utils.each(di.getElementsByTagName('code'),function(ci){
if(parentCode !== ci.parentNode){
parentCode = ci.parentNode;
str.push(parentCode[browser.ie?'innerText':'textContent'])
//去掉左右空格,针对ie的不能回退的问题
str.push(utils.trim(parentCode[browser.ie?'innerText':'textContent']))
}
});
......
......@@ -48,12 +48,16 @@ UE.commands['imagefloat'] = {
range.selectNode(img).select();
}
domUtils.setStyle(img, 'float', align);
domUtils.setStyle(img, 'float', align == 'none' ? '' : align);
if(align == 'none'){
domUtils.removeAttributes(img,'align');
}
break;
case 'center':
if (me.queryCommandValue('imagefloat') != 'center') {
pN = img.parentNode;
domUtils.setStyle(img, 'float', 'none');
domUtils.setStyle(img, 'float', '');
domUtils.removeAttributes(img,'align');
tmpNode = img;
while (pN && domUtils.getChildCount(pN, function (node) {
......@@ -96,7 +100,7 @@ UE.commands['imagefloat'] = {
}
startNode = range.getClosedNode();
if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
floatStyle = domUtils.getComputedStyle(startNode, 'float');
floatStyle = startNode.getAttribute('align')||domUtils.getComputedStyle(startNode, 'float');
if (floatStyle == 'none') {
floatStyle = domUtils.getComputedStyle(startNode.parentNode, 'text-align') == 'center' ? 'center' : floatStyle;
}
......@@ -152,7 +156,7 @@ UE.commands['insertimage'] = {
var html = [], str = '', ci;
ci = opt[0];
if (opt.length == 1) {
str = '<img src="' + ci.src + '" ' + (ci.data_ue_src ? ' data_ue_src="' + ci.data_ue_src + '" ' : '') +
str = '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.width ? 'width="' + ci.width + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
(ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right' ? ' style="float:' + ci['floatStyle'] + ';"' : '') +
......@@ -169,7 +173,7 @@ UE.commands['insertimage'] = {
} else {
for (var i = 0; ci = opt[i++];) {
str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="' + ci.src + '" ' +
(ci.width ? 'width="' + ci.width + '" ' : '') + (ci.data_ue_src ? ' data_ue_src="' + ci.data_ue_src + '" ' : '') +
(ci.width ? 'width="' + ci.width + '" ' : '') + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
' style="' + (ci['floatStyle'] && ci['floatStyle'] != 'center' ? 'float:' + ci['floatStyle'] + ';' : '') +
(ci.border || '') + '" ' +
......
......@@ -17,12 +17,16 @@ UE.commands['inserthtml'] = {
range = me.selection.getRange();
div = range.document.createElement( 'div' );
div.style.display = 'inline';
var serialize = me.serialize;
if (!notSerialize && serialize) {
var node = serialize.parseHTML(html);
node = serialize.transformInput(node);
node = serialize.filter(node);
html = serialize.toHTML(node);
if (!notSerialize) {
var root = UE.htmlparser(html);
//如果给了过滤规则就先进行过滤
if(me.options.filterRules){
UE.filterNode(root,me.options.filterRules);
}
//执行默认的处理
me.filterInputRule(root);
html = root.toHtml()
}
div.innerHTML = utils.trim( html );
......
......@@ -18,7 +18,8 @@
* @param {String} cmdName unlink取消链接
* @author zhanyi
*/
(function() {
UE.plugins['link'] = function(){
function optimize( range ) {
var start = range.startContainer,end = range.endContainer;
......@@ -91,7 +92,7 @@
UE.commands['link'] = {
execCommand : function( cmdName, opt ) {
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.href && (opt.href = utils.unhtml(opt.href,/[<">]/g));
opt.textValue && (opt.textValue = utils.unhtml(opt.textValue,/[<">]/g));
doLink(range=this.selection.getRange(),opt,this);
......@@ -102,9 +103,6 @@
queryCommandValue : function() {
var range = this.selection.getRange(),
node;
if ( range.collapsed ) {
// node = this.selection.getStart();
//在ie下getstart()取值偏上了
......@@ -150,4 +148,4 @@
return flag ? -1 : 0;
}
};
})();
};
\ No newline at end of file
......@@ -128,33 +128,35 @@ UE.plugins['list'] = function () {
}
return ''
}
//进入编辑器的li要套p标签
me.addInputRule(function(root){
utils.each(root.getNodesByTagName('li'),function(li){
var tmpP = UE.uNode.createElement('p');
for(var i= 0,ci;ci=li.children[i];){
if(ci.type == 'text' || dtd.$inline[ci.tagName]){
tmpP.appendChild(ci);
}else{
if(tmpP.firstChild()){
li.insertBefore(tmpP,ci);
tmpP = UE.uNode.createElement('p');
i = i + 2;
}else{
i++;
}
// function checkCustomStyle(list){
// if(domUtils.hasClass(list,/custom_/)){
// return ''
// }
// var style;
// utils.each(list.childNodes,function(li){
// if(li.tagName == 'LI'){
// if(domUtils.hasClass(li,/list-/)){
// var tmpStyle = li.className.match(/list-(\w+)-(\d+)?/);
// style = tmpStyle[1]+(tmpStyle[2] && tmpStyle[2] != '1'? tmpStyle[2]:'');
// return false
// }
// }
// })
// return style;
// }
}
}
if(tmpP.firstChild() && !tmpP.parentNode){
li.appendChild(tmpP);
}
})
});
//调整索引标签
me.addListener('contentchange',function(){
utils.each(domUtils.getElementsByTagName(me.document,'ol ul'),function(node){
if(!domUtils.inDoc(node,me.document))
return;
// var style;
// if(style = checkCustomStyle(node)){
// node.className = 'custom_' + style;
// }
var index = 0,type = 2,parent = node.parentNode;
if( domUtils.hasClass(node,/custom_/)){
if(!(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/))){
......
......@@ -9,23 +9,17 @@
** @description 粘贴
* @author zhanyi
*/
(function() {
UE.plugins['paste'] = function() {
function getClipboardData( callback ) {
var doc = this.document;
if ( doc.getElementById( 'baidu_pastebin' ) ) {
return;
}
var range = this.selection.getRange(),
bk = range.createBookmark(),
//创建剪贴的容器div
pastebin = doc.createElement( 'div' );
pastebin.id = 'baidu_pastebin';
// Safari 要求div必须有内容,才能粘贴内容进来
browser.webkit && pastebin.appendChild( doc.createTextNode( domUtils.fillChar + domUtils.fillChar ) );
doc.body.appendChild( pastebin );
......@@ -39,9 +33,7 @@
range.selectNodeContents( pastebin ).select( true );
setTimeout( function() {
if (browser.webkit) {
for(var i=0,pastebins = doc.querySelectorAll('#baidu_pastebin'),pi;pi=pastebins[i++];){
if(domUtils.isEmptyNode(pi)){
domUtils.remove(pi);
......@@ -50,262 +42,169 @@
break;
}
}
}
try{
pastebin.parentNode.removeChild(pastebin);
}catch(e){}
range.moveToBookmark( bk ).select(true);
callback( pastebin );
}, 0 );
}
UE.plugins['paste'] = function() {
var me = this;
var word_img_flag = {flag:""};
var pasteplain = me.options.pasteplain === true;
var modify_num = {flag:""};
me.commands['pasteplain'] = {
queryCommandState: function (){
return pasteplain;
},
execCommand: function (){
pasteplain = !pasteplain|0;
},
notNeedUndo : 1
};
var txtContent,htmlContent,address;
var me = this;
var word_img_flag = {flag:""};
function filter(div){
var txtContent,htmlContent,address;
var html;
if ( div.firstChild ) {
//去掉cut中添加的边界值
var nodes = domUtils.getElementsByTagName(div,'span');
for(var i=0,ni;ni=nodes[i++];){
if(ni.id == '_baidu_cut_start' || ni.id == '_baidu_cut_end'){
domUtils.remove(ni);
}
function filter(div){
var html;
if ( div.firstChild ) {
//去掉cut中添加的边界值
var nodes = domUtils.getElementsByTagName(div,'span');
for(var i=0,ni;ni=nodes[i++];){
if(ni.id == '_baidu_cut_start' || ni.id == '_baidu_cut_end'){
domUtils.remove(ni);
}
}
if(browser.webkit){
var brs = div.querySelectorAll('div br');
for(var i=0,bi;bi=brs[i++];){
var pN = bi.parentNode;
if(pN.tagName == 'DIV' && pN.childNodes.length ==1){
pN.innerHTML = '<p><br/></p>';
w
domUtils.remove(pN);
}
}
var divs = div.querySelectorAll('#baidu_pastebin');
for(var i=0,di;di=divs[i++];){
var tmpP = me.document.createElement('p');
di.parentNode.insertBefore(tmpP,di);
while(di.firstChild){
tmpP.appendChild(di.firstChild);
}
domUtils.remove(di);
}
if(browser.webkit){
var metas = div.querySelectorAll('meta');
for(var i=0,ci;ci=metas[i++];){
domUtils.remove(ci);
var brs = div.querySelectorAll('div br');
for(var i=0,bi;bi=brs[i++];){
var pN = bi.parentNode;
if(pN.tagName == 'DIV' && pN.childNodes.length ==1){
pN.innerHTML = '<p><br/></p>';
domUtils.remove(pN);
}
var brs = div.querySelectorAll('br');
for(i=0;ci=brs[i++];){
if(/^apple-/.test(ci)){
domUtils.remove(ci);
}
}
var divs = div.querySelectorAll('#baidu_pastebin');
for(var i=0,di;di=divs[i++];){
var tmpP = me.document.createElement('p');
di.parentNode.insertBefore(tmpP,di);
while(di.firstChild){
tmpP.appendChild(di.firstChild);
}
domUtils.remove(di);
}
utils.each(domUtils.getElementsByTagName(div,'span',function(node){
if(node.style.cssText){
node.style.cssText = node.style.cssText.replace(/white-space[^;]+;/g,'');
if(!node.style.cssText){
domUtils.removeAttributes(node,'style');
if(domUtils.hasNoAttributes(node)){
return 1
}
}
}
return 0
}),function(si){
domUtils.remove(si,true)
})
var metas = div.querySelectorAll('meta');
for(var i=0,ci;ci=metas[i++];){
domUtils.remove(ci);
}
if(browser.gecko){
var dirtyNodes = div.querySelectorAll('[_moz_dirty]');
for(i=0;ci=dirtyNodes[i++];){
ci.removeAttribute( '_moz_dirty' );
var brs = div.querySelectorAll('br');
for(i=0;ci=brs[i++];){
if(/^apple-/.test(ci)){
domUtils.remove(ci);
}
}
if(!browser.ie ){
var spans = div.querySelectorAll('span.Apple-style-span');
for(var i=0,ci;ci=spans[i++];){
domUtils.remove(ci,true);
}
}
if(browser.gecko){
var dirtyNodes = div.querySelectorAll('[_moz_dirty]');
for(i=0;ci=dirtyNodes[i++];){
ci.removeAttribute( '_moz_dirty' );
}
//ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
html = div.innerHTML.replace(/>(?:(\s|&nbsp;)*?)</g,'><');
var f = me.serialize;
if(f){
//如果过滤出现问题,捕获它,直接插入内容,避免出现错误导致粘贴整个失败
try{
html = UE.filterWord(html);
var node = f.transformInput(
f.parseHTML(
//todo: 暂时不走dtd的过滤
html//, true
),word_img_flag
);
//trace:924
//纯文本模式也要保留段落
node = f.filter(node,pasteplain ? {
whiteList: {
'p': {'br':1,'BR':1,$:{}},
'br':{'$':{}},
'div':{'br':1,'BR':1,'$':{}},
'li':{'$':{}},
'tr':{'td':1,'$':{}},
'td':{'$':{}}
},
blackList: {
'style':1,
'script':1,
'object':1
}
} : null, !pasteplain ? modify_num : null);
if(browser.webkit){
var length = node.children.length,
child;
while((child = node.children[length-1]) && child.tag == 'br'){
node.children.splice(length-1,1);
length = node.children.length;
}
}
html = f.toHTML(node,pasteplain);
txtContent = f.filter(node,{
whiteList: {
'p': {'br':1,'BR':1,$:{}},
'br':{'$':{}},
'div':{'br':1,'BR':1,'$':{},'table':1,'ul':1,'ol':1},
'li':{'$':{}},
'ul':{'li':1,'$':{}},
'ol':{'li':1,'$':{}},
'tr':{'td':1,'$':{}},
'td':{'$':{}},
'table': {'tr':1,'tbody':1,'td':1,'$':{}},
'tbody': {'tr':1,'td':1,'$':{}},
h1:{'$':{}},h2:{'$':{}},h3:{'$':{}},h4:{'$':{}},h5:{'$':{}},h6:{'$':{}}
},
blackList: {
'style':1,
'script':1,
'object':1
}
});
txtContent = f.toHTML(txtContent,true)
}catch(e){}
}
if(!browser.ie ){
var spans = div.querySelectorAll('span.Apple-style-span');
for(var i=0,ci;ci=spans[i++];){
domUtils.remove(ci,true);
}
}
//自定义的处理
html = {'html':html,'txtContent':txtContent};
//ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
html = div.innerHTML.replace(/>(?:(\s|&nbsp;)*?)</g,'><');
me.fireEvent('beforepaste',html);
//不用在走过滤了
if(html.html){
htmlContent = html.html;
address = me.selection.getRange().createAddress(true);
me.execCommand( 'insertHtml',htmlContent,true);
me.fireEvent("afterpaste");
}
//过滤word粘贴过来的冗余属性
html = UE.filterWord(html);
var root = UE.htmlparser(html);
//如果给了过滤规则就先进行过滤
if(me.options.filterRules){
UE.filterNode(root,me.options.filterRules);
}
//执行默认的处理
me.filterInputRule(root);
html = {'html':root.toHtml()};
me.fireEvent('beforepaste',html);
root = UE.htmlparser(html.html);
//如果开启了纯文本模式
if(me.queryCommandState('pasteplain')){
me.execCommand( 'insertHtml',UE.filterNode(root,me.options.filterTxtRules).toHtml(),true);
}else{
//文本模式
UE.filterNode(root,me.options.filterTxtRules);
txtContent = root.toHtml();
//完全模式
htmlContent = html.html;
address = me.selection.getRange().createAddress(true);
me.execCommand( 'insertHtml',htmlContent,true);
}
me.fireEvent("afterpaste");
}
}
me.addListener('pasteTransfer',function(cmd,plainType){
if(address && txtContent && htmlContent && txtContent != htmlContent){
var range = me.selection.getRange();
range.moveToAddress(address,true).deleteContents();
range.select(true);
me.__hasEnterExecCommand = true;
var html = htmlContent;
if(plainType === 2){
html = html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi,function(a,b,tagName,attrs){
tagName = tagName.toLowerCase();
if({img:1}[tagName]){
return a;
}
attrs = attrs.replace(/([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi,function(str,atr,val){
if({
'src':1,
'href':1,
'name':1
}[atr.toLowerCase()]){
return atr + '=' + val + ' '
}
return ''
});
me.addListener('pasteTransfer',function(cmd,plainType){
if(address && txtContent && htmlContent && txtContent != htmlContent){
var range = me.selection.getRange();
range.moveToAddress(address,true).deleteContents();
range.select(true);
me.__hasEnterExecCommand = true;
var html = htmlContent;
if(plainType === 2){
html = html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi,function(a,b,tagName,attrs){
tagName = tagName.toLowerCase();
if({img:1}[tagName]){
return a;
}
attrs = attrs.replace(/([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi,function(str,atr,val){
if({
'span':1,
'div':1
}[tagName]){
return ''
}else{
return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
'src':1,
'href':1,
'name':1
}[atr.toLowerCase()]){
return atr + '=' + val + ' '
}
return ''
});
}else if(plainType){
html = txtContent;
}
me.execCommand('inserthtml',html,true);
me.__hasEnterExecCommand = false;
var tmpAddress = me.selection.getRange().createAddress(true);
address.endAddress = tmpAddress.startAddress;
}
});
me.addListener('ready',function(){
domUtils.on(me.body,'cut',function(){
var range = me.selection.getRange();
if(!range.collapsed && me.undoManger){
me.undoManger.save();
}
if({
'span':1,
'div':1
}[tagName]){
return ''
}else{
});
//ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
domUtils.on(me.body, browser.ie || browser.opera ? 'keydown' : 'paste',function(e){
if((browser.ie || browser.opera) && ((!e.ctrlKey && !e.metaKey) || e.keyCode != '86')){
return;
}
getClipboardData.call( me, function( div ) {
filter(div);
} );
});
return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
}
});
});
}else if(plainType){
html = txtContent;
}
me.execCommand('inserthtml',html,true);
me.__hasEnterExecCommand = false;
var tmpAddress = me.selection.getRange().createAddress(true);
address.endAddress = tmpAddress.startAddress;
}
});
me.addListener('ready',function(){
domUtils.on(me.body,'cut',function(){
var range = me.selection.getRange();
if(!range.collapsed && me.undoManger){
me.undoManger.save();
}
};
});
//ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
domUtils.on(me.body, browser.ie || browser.opera ? 'keydown' : 'paste',function(e){
if((browser.ie || browser.opera) && ((!e.ctrlKey && !e.metaKey) || e.keyCode != '86')){
return;
}
getClipboardData.call( me, function( div ) {
filter(div);
} );
});
})();
});
};
......@@ -13,7 +13,12 @@ UE.commands['preview'] = {
var w = window.open('', '_blank', ''),
d = w.document;
d.open();
d.write(this.getAllHtml());
d.write('<html><head><script src="'+this.options.UEDITOR_HOME_URL+'uparse.js"></script><script>' +
"setTimeout(function(){uParse('div',{" +
" 'highlightJsUrl':'"+this.options.UEDITOR_HOME_URL+"third-party/SyntaxHighlighter/shCore.js'," +
" 'highlightCssUrl':'"+this.options.UEDITOR_HOME_URL+"third-party/SyntaxHighlighter/shCoreDefault.css'" +
"})},300)" +
'</script></head><body><div>'+this.getContent(null,null,true)+'</div></body></html>');
d.close();
},
notNeedUndo : 1
......
/**
* @description 纯文本粘贴
* @name puretxtpaste
* @author zhanyi
*/
UE.plugins['pasteplain'] = function(){
var me = this;
me.setOpt({
'pasteplain':false,
'filterTxtRules' : function(){
function transP(node){
node.tagName = 'p';
node.setStyle();
}
return {
//直接删除及其字节点内容
'-' : 'script style object iframe embed input select',
'p': {$:{}},
'br':{$:{}},
'div':{'$':{}},
'li':{'$':{}},
'caption':transP,
'th':transP,
'tr':transP,
'h1':transP,'h2':transP,'h3':transP,'h4':transP,'h5':transP,'h6':transP,
'td':function(node){
//没有内容的td直接删掉
var txt = !!node.innerText();
if(txt){
node.parentNode.insertAfter(UE.uNode.createText(' &nbsp; &nbsp;'),node);
}
node.parentNode.removeChild(node,node.innerText())
}
}
}()
});
//暂时这里支持一下老版本的属性
var pasteplain = me.options.pasteplain;
me.commands['pasteplain'] = {
queryCommandState: function (){
return pasteplain;
},
execCommand: function (){
pasteplain = !pasteplain|0;
},
notNeedUndo : 1
};
};
\ No newline at end of file
此差异已折叠。
......@@ -5,128 +5,6 @@
///commandsName Source
///commandsTitle 查看源码
(function (){
function SourceFormater(config){
config = config || {};
this.indentChar = config.indentChar || ' ';
this.breakChar = config.breakChar || '\n';
this.selfClosingEnd = config.selfClosingEnd || ' />';
}
var unhtml1 = function (){
var map = { '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
function rep( m ){ return map[m]; }
return function ( str ) {
str = str + '';
return str ? str.replace( /[<>"']/g, rep ) : '';
};
}();
var inline = utils.extend({a:1,A:1},dtd.$inline,true);
function printAttrs(attrs){
var buff = [];
for (var k in attrs) {
buff.push(k + '="' + unhtml1(attrs[k]) + '"');
}
return buff.join(' ');
}
SourceFormater.prototype = {
format: function (html){
var node = UE.serialize.parseHTML(html);
this.buff = [];
this.indents = '';
this.indenting = 1;
this.visitNode(node);
return this.buff.join('');
},
visitNode: function (node){
if (node.type == 'fragment') {
this.visitChildren(node.children);
} else if (node.type == 'element') {
var selfClosing = dtd.$empty[node.tag];
this.visitTag(node.tag, node.attributes, selfClosing);
this.visitChildren(node.children);
if (!selfClosing) {
this.visitEndTag(node.tag);
}
} else if (node.type == 'comment') {
this.visitComment(node.data);
} else {
this.visitText(node.data,dtd.$notTransContent[node.parent.tag]);
}
},
visitChildren: function (children){
for (var i=0; i<children.length; i++) {
this.visitNode(children[i]);
}
},
visitTag: function (tag, attrs, selfClosing){
if (this.indenting) {
this.indent();
} else if (!inline[tag]) { // todo: 去掉a, 因为dtd的inline里面没有a
this.newline();
this.indent();
}
this.buff.push('<', tag);
var attrPart = printAttrs(attrs);
if (attrPart) {
this.buff.push(' ', attrPart);
}
if (selfClosing) {
this.buff.push(this.selfClosingEnd);
if (tag == 'br') {
this.newline();
}
} else {
this.buff.push('>');
this.indents += this.indentChar;
}
if (!inline[tag]) {
this.newline();
}
},
indent: function (){
this.buff.push(this.indents);
this.indenting = 0;
},
newline: function (){
this.buff.push(this.breakChar);
this.indenting = 1;
},
visitEndTag: function (tag){
this.indents = this.indents.slice(0, -this.indentChar.length);
if (this.indenting) {
this.indent();
} else if (!inline[tag]) {
this.newline();
this.indent();
}
this.buff.push('</', tag, '>');
},
visitText: function (text,notTrans){
if (this.indenting) {
this.indent();
}
// if(!notTrans){
// text = text.replace(/&nbsp;/g, ' ').replace(/[ ][ ]+/g, function (m){
// return new Array(m.length + 1).join('&nbsp;');
// }).replace(/(?:^ )|(?: $)/g, '&nbsp;');
// }
text = text.replace(/&nbsp;/g, ' ');
this.buff.push(text);
},
visitComment: function (text){
if (this.indenting) {
this.indent();
}
this.buff.push('<!--', text, '-->');
}
};
var sourceEditors = {
textarea: function (editor, holder){
var textarea = holder.ownerDocument.createElement('textarea');
......@@ -206,7 +84,6 @@
UE.plugins['source'] = function (){
var me = this;
var opt = this.options;
var formatter = new SourceFormater(opt.source);
var sourceMode = false;
var sourceEditor;
......@@ -237,8 +114,9 @@
bakCssText = me.iframe.style.cssText;
me.iframe.style.cssText += 'position:absolute;left:-32768px;top:-32768px;';
var root = UE.htmlparser(me.getContent());
var content = formatter.format(me.hasContents() ? me.getContent() : '');
var content = me.hasContents() ? root.toHtml(true) : '';
sourceEditor = createSourceEditor(me.iframe.parentNode);
......@@ -254,12 +132,12 @@
//重置getContent,源码模式下取值也能是最新的数据
me.getContent = function (){
var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
return cont.replace(/>[\n\r\t]+([ ]{4})+/g,'>').replace(/[\n\r\t]+([ ]{4})+</g,'<').replace(/>[\n\r\t]+</g,'><');
return cont.replace(/>[ \n\r\t]+/g,'>').replace(/[ \n\r\t]+</g,'<').replace(/>[\n\r\t]+</g,'><');
};
} else {
me.iframe.style.cssText = bakCssText;
var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
cont = cont.replace(/>[\n\r\t]+([ ]{4})+/g,'>').replace(/[\n\r\t]+([ ]{4})+</g,'<').replace(/>[\n\r\t]+</g,'><');
cont = cont.replace(/>[ \n\r\t]+/g,'>').replace(/[ \n\r\t]+</g,'<').replace(/>[\n\r\t]+</g,'><');
me.setContent(cont);
sourceEditor.dispose();
sourceEditor = null;
......
......@@ -98,7 +98,7 @@ UE.plugins['table'] = function () {
}
var caption = domUtils.findParentByTagName(me.selection.getStart(), 'caption', true),
range = me.selection.getRange();
range = me.selection.getRange();
if (range.collapsed && caption && isEmptyBlock(caption)) {
me.fireEvent('saveScene');
var table = caption.parentNode;
......@@ -127,7 +127,7 @@ UE.plugins['table'] = function () {
if (keyCode == 13) {
var rng = me.selection.getRange(),
caption = domUtils.findParentByTagName(rng.startContainer, 'caption',true);
caption = domUtils.findParentByTagName(rng.startContainer, 'caption', true);
if (caption) {
var table = domUtils.findParentByTagName(caption, 'table');
if (!rng.collapsed) {
......@@ -200,7 +200,7 @@ UE.plugins['table'] = function () {
rowIndex++;
}
for (var i = 0, ci; ci = tableCopyList[i++];) {
var tr = ut.insertRow(rowIndex++,"td");
var tr = ut.insertRow(rowIndex++, "td");
for (var j = 0, cj; cj = ci[j]; j++) {
var cell = tr.cells[j];
if (!cell) {
......@@ -289,7 +289,7 @@ UE.plugins['table'] = function () {
(needIEHack ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (me.options.offsetWidth || 0);
me.execCommand('insertHTML', '<table ' +
( isFullCol && isFullRow ? 'width="' + width + '"' : '') +
'>' + table.innerHTML.replace(/>\s*</g, '><').replace(/th/gi,"td") + '</table>')
'>' + table.innerHTML.replace(/>\s*</g, '><').replace(/\bth\b/gi, "td") + '</table>')
}
me.fireEvent('contentchange');
me.fireEvent('saveScene');
......@@ -348,7 +348,7 @@ UE.plugins['table'] = function () {
}, 100);
});
me.addListener("selectionchange",function(){
me.addListener("selectionchange", function () {
toggleDragableState(me, false, "", null);
});
......@@ -505,21 +505,21 @@ UE.plugins['table'] = function () {
me.addListener("mouseup", mouseUpEvent);
var currentRowIndex = 0;
me.addListener("mousedown", function(){
me.addListener("mousedown", function () {
currentRowIndex = 0;
});
me.addListener('tabkeydown', function () {
var range = this.selection.getRange(),
common = range.getCommonAncestor(true,true),
table = domUtils.findParentByTagName(common,'table');
common = range.getCommonAncestor(true, true),
table = domUtils.findParentByTagName(common, 'table');
if (table) {
if (domUtils.findParentByTagName(common,'caption',true)) {
if (domUtils.findParentByTagName(common, 'caption', true)) {
var cell = domUtils.getElementsByTagName(table, 'th td');
if (cell && cell.length) {
range.setStart(cell[0], 0).setCursor(false, true)
}
} else {
var cell = domUtils.findParentByTagName(common,['td', 'th'],true),
var cell = domUtils.findParentByTagName(common, ['td', 'th'], true),
ua = getUETable(cell);
currentRowIndex = cell.rowSpan > 1 ? currentRowIndex : ua.getCellInfo(cell).rowIndex;
var nextCell = ua.getTabNextCell(cell, currentRowIndex);
......@@ -543,7 +543,7 @@ UE.plugins['table'] = function () {
}
});
browser.ie && me.addListener('selectionchange',function(){
browser.ie && me.addListener('selectionchange', function () {
toggleDragableState(this, false, "", null);
});
me.addListener("keydown", function (type, evt) {
......@@ -571,7 +571,7 @@ UE.plugins['table'] = function () {
me.addListener("aftergetcontent", function () {
switchBoderColor(true);
});
me.addListener("getAllHtml",function(){
me.addListener("getAllHtml", function () {
removeSelectedClass(me.document.getElementsByTagName("td"));
});
//修正全屏状态下插入的表格宽度在非全屏状态下撑开编辑器的情况
......@@ -608,7 +608,7 @@ UE.plugins['table'] = function () {
me.__hasEnterExecCommand = true;
me.fireEvent("beforeexeccommand", cmd);
tds = ut.selectedTds;
var lastState = -2, lastValue = -2,value,state;
var lastState = -2, lastValue = -2, value, state;
for (var i = 0, td; td = tds[i]; i++) {
if (isEmptyBlock(td)) {
range.setStart(td, 0).setCursor(false, true)
......@@ -617,8 +617,8 @@ UE.plugins['table'] = function () {
}
state = me.queryCommandState(cmd);
value = me.queryCommandValue(cmd);
if (state != -1 ) {
if(lastState !== state || lastValue !== value){
if (state != -1) {
if (lastState !== state || lastValue !== value) {
me._ignoreContentChange = true;
result = oldExecCommand.apply(me, arguments);
me._ignoreContentChange = false;
......@@ -713,7 +713,7 @@ UE.plugins['table'] = function () {
//当鼠标处于table上时,修改移动过程中的光标状态
if (target) {
//针对使用table作为容器的组件不触发拖拽效果
if(me.fireEvent('excludetable',target) === true)
if (me.fireEvent('excludetable', target) === true)
return;
pos = mouseCoords(evt);
var state = getRelation(target, pos),
......@@ -945,7 +945,7 @@ UE.plugins['table'] = function () {
removeSelectedClass(domUtils.getElementsByTagName(me.body, "th"));
//trace:3113
//选中单元格,点击table外部,不会清掉table上挂的ueTable,会引起getUETableBySelected方法返回值
utils.each(me.document.getElementsByTagName('table'),function(t){
utils.each(me.document.getElementsByTagName('table'), function (t) {
t.ueTable = null;
});
startTd = getTargetTd(me, evt);
......@@ -1120,7 +1120,7 @@ UE.plugins['table'] = function () {
startTd = null;
me.removeListener('mouseover', mouseOverEvent);
}
me._selectionChange(250,evt);
me._selectionChange(250, evt);
}
function mouseOverEvent(type, evt) {
......@@ -1233,7 +1233,7 @@ UE.plugins['table'] = function () {
var tableArr = domUtils.getElementsByTagName(me.body, "table"), color;
for (var i = 0, node; node = tableArr[i++];) {
var td = domUtils.getElementsByTagName(node, "td");
if(td[0] ){
if (td[0]) {
if (flag) {
color = (td[0].style.borderColor).replace(/\s/g, "");
if (/(#ffffff)|(rgb\(255,f55,255\))/ig.test(color))
......@@ -1280,12 +1280,12 @@ UE.plugins['table'] = function () {
var range = this.selection.getRange(),
start = range.startContainer,
firstParentBlock = domUtils.findParent(start,function(node){
firstParentBlock = domUtils.findParent(start, function (node) {
return domUtils.isBlockElm(node);
},true);
}, true);
var me = this,
defaultValue = getDefaultValue(me),
tableWidth = getTableWidth(me, needIEHack, defaultValue) - (firstParentBlock ? parseInt(domUtils.getXY(firstParentBlock).x,10):0),
tableWidth = getTableWidth(me, needIEHack, defaultValue) - (firstParentBlock ? parseInt(domUtils.getXY(firstParentBlock).x, 10) : 0),
tdWidth = Math.floor(tableWidth / opt.numCols - defaultValue.tdPadding * 2 - defaultValue.tdBorder);
//todo其他属性
!opt.tdvalign && (opt.tdvalign = me.options.tdvalign);
......@@ -1414,7 +1414,6 @@ UE.plugins['table'] = function () {
return -1;
},
execCommand:function () {
debugger
var table = getTableItemsByRange(this).table;
if (table) {
getUETable(table).insertRow(0, 'th');
......@@ -1876,7 +1875,8 @@ UE.plugins['table'] = function () {
function getAverageHeight() {
var averageHeight, rowNum, sumHeight = 0,
tb = ut.table,
tbAttr = getDefaultValue(me, tb);
tbAttr = getDefaultValue(me, tb),
tdpadding = parseInt(domUtils.getComputedStyle(tb.getElementsByTagName('td')[0], "padding-top"));
if (ut.isFullCol()) {
var captionArr = domUtils.getElementsByTagName(tb, "caption"),
......@@ -1907,7 +1907,7 @@ UE.plugins['table'] = function () {
if (browser.ie && browser.version < 9) {
averageHeight = Math.ceil(sumHeight / rowNum);
} else {
averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2;
averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2 - tdpadding * 2;
}
return averageHeight;
}
......@@ -1967,8 +1967,8 @@ UE.plugins['table'] = function () {
var obj = {};
obj[data[0]] = data[1];
table.style[utils.cssStyleToDomStyle("float")]="";
table.style.margin="";
table.style[utils.cssStyleToDomStyle("float")] = "";
table.style.margin = "";
domUtils.setStyles(table, obj);
}
}
......@@ -2004,7 +2004,7 @@ UE.plugins['table'] = function () {
if (!ut) {
var start = me.selection.getStart(),
cell = start && domUtils.findParentByTagName(start, ["td", "th","caption"], true);
cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
if (cell) {
cell.style.backgroundColor = bkColor;
}
......@@ -2605,7 +2605,7 @@ UE.plugins['table'] = function () {
//首行直接插入,无需考虑部分单元格被rowspan的情况
if (rowIndex == 0 || rowIndex == this.rowsNum) {
for (var colIndex = 0; colIndex < numCols; colIndex++) {
cell = this.cloneCell(sourceCell,true);
cell = this.cloneCell(sourceCell, true);
this.setCellContent(cell);
cell.getAttribute('vAlign') && cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
row.appendChild(cell);
......@@ -2620,7 +2620,7 @@ UE.plugins['table'] = function () {
cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
cell.rowSpan = cellInfo.rowSpan + 1;
} else {
cell = this.cloneCell(sourceCell,true);
cell = this.cloneCell(sourceCell, true);
this.setCellContent(cell);
row.appendChild(cell);
}
......@@ -2691,7 +2691,7 @@ UE.plugins['table'] = function () {
//this.table.deleteRow(rowIndex);
this.update();
},
insertCol:function (colIndex,sourceCell,defaultValue) {
insertCol:function (colIndex, sourceCell, defaultValue) {
var rowsNum = this.rowsNum,
rowIndex = 0,
tableRow, cell,
......@@ -2714,7 +2714,7 @@ UE.plugins['table'] = function () {
for (; rowIndex < rowsNum; rowIndex++) {
tableRow = this.table.rows[rowIndex];
preCell = tableRow.cells[colIndex == 0 ? colIndex : tableRow.cells.length];
cell = this.cloneCell(sourceCell,true); //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length);
cell = this.cloneCell(sourceCell, true); //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length);
this.setCellContent(cell);
cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
preCell && cell.setAttribute('width', preCell.getAttribute('width'));
......@@ -2735,7 +2735,7 @@ UE.plugins['table'] = function () {
tableRow = this.table.rows[rowIndex];
preCell = tableRow.cells[cellInfo.cellIndex];
cell = this.cloneCell(sourceCell,true);//tableRow.insertCell(cellInfo.cellIndex);
cell = this.cloneCell(sourceCell, true);//tableRow.insertCell(cellInfo.cellIndex);
this.setCellContent(cell);
cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
preCell && cell.setAttribute('width', preCell.getAttribute('width'))
......@@ -2746,13 +2746,13 @@ UE.plugins['table'] = function () {
}
//框选时插入不触发contentchange,需要手动更新索引
this.update();
this.updateWidth(backWidth,defaultValue||{tdPadding:10,tdBorder:1});
this.updateWidth(backWidth, defaultValue || {tdPadding:10, tdBorder:1});
},
updateWidth:function (width,defaultValue) {
updateWidth:function (width, defaultValue) {
var table = this.table,
tmpWidth = getWidth(table) - defaultValue.tdPadding * 2 - defaultValue.tdBorder + width;
if( tmpWidth<table.ownerDocument.body.offsetWidth){
table.setAttribute("width",tmpWidth);
if (tmpWidth < table.ownerDocument.body.offsetWidth) {
table.setAttribute("width", tmpWidth);
return;
}
var tds = domUtils.getElementsByTagName(this.table, "td");
......@@ -2831,7 +2831,7 @@ UE.plugins['table'] = function () {
return num;
},
splitToCols:function (cell) {
var backWidth = (cell.offsetWidth/cell.colSpan-22).toFixed(0),
var backWidth = (cell.offsetWidth / cell.colSpan - 22).toFixed(0),
cellInfo = this.getCellInfo(cell),
rowIndex = cellInfo.rowIndex,
......@@ -2839,7 +2839,7 @@ UE.plugins['table'] = function () {
results = [];
// 修改Cell的rowSpan
cell.colSpan = 1;
cell.setAttribute("width",backWidth);
cell.setAttribute("width", backWidth);
results.push(cell);
// 补齐单元格
for (var j = colIndex, endCol = colIndex + cellInfo.colSpan; j < endCol; j++) {
......@@ -2848,9 +2848,9 @@ UE.plugins['table'] = function () {
tmpCell = tableRow.insertCell(this.indexTable[rowIndex][j].cellIndex + 1);
tmpCell.rowSpan = cellInfo.rowSpan;
this.setCellContent(tmpCell);
tmpCell.setAttribute('vAlign',cell.getAttribute('vAlign'));
tmpCell.setAttribute('align',cell.getAttribute('align'));
tmpCell.setAttribute('width',backWidth);
tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
tmpCell.setAttribute('align', cell.getAttribute('align'));
tmpCell.setAttribute('width', backWidth);
if (cell.style.cssText) {
tmpCell.style.cssText = cell.style.cssText;
}
......@@ -2945,14 +2945,14 @@ UE.plugins['table'] = function () {
return target && !(editor.fireEvent("excludetable", target) === true) ? target : null;
}
function cloneCell(cell,ingoreMerge) {
if(!cell || utils.isString(cell)){
function cloneCell(cell, ingoreMerge) {
if (!cell || utils.isString(cell)) {
return this.table.ownerDocument.createElement(cell || 'td');
}
var flag = domUtils.hasClass(cell, "selectTdClass");
flag && domUtils.removeClasses(cell, "selectTdClass");
var tmpCell = cell.cloneNode(true);
if(ingoreMerge){
if (ingoreMerge) {
tmpCell.rowSpan = tmpCell.colSpan = 1;
}
tmpCell.style.borderLeftStyle = "";
......
......@@ -30,32 +30,22 @@ UE.plugins['video'] = function (){
' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
}
function switchImgAndEmbed(img2embed){
var tmpdiv,
nodes =domUtils.getElementsByTagName(me.document, !img2embed ? "embed" : "img");
for(var i=0,node;node = nodes[i++];){
if(node.className!="edui-faked-video"){
continue;
function switchImgAndEmbed(root,img2embed){
utils.each(root.getNodesByTagName(img2embed ? 'img' : 'embed'),function(node){
if(node.getAttr('class') == 'edui-faked-video'){
var align = node.getStyle('float');
align = align == 'none' ? (node.getAttr('align')||'') : align;
var html = creatInsertStr( img2embed ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),align,img2embed);
node.parentNode.replaceChild(UE.uNode.createElement(html),node)
}
tmpdiv = me.document.createElement("div");
//先看float在看align,浮动有的是时候是在float上定义的
var align = domUtils.getComputedStyle(node,'float');
align = align == 'none' ? (node.getAttribute('align') || '') : align;
tmpdiv.innerHTML = creatInsertStr(img2embed ? node.getAttribute("_url"):node.getAttribute("src"),node.width,node.height,align,img2embed);
node.parentNode.replaceChild(tmpdiv.firstChild,node);
}
})
}
me.addListener("beforegetcontent",function(){
switchImgAndEmbed(true);
});
me.addListener('aftersetcontent',function(){
switchImgAndEmbed(false);
me.addOutputRule(function(root){
switchImgAndEmbed(root,true)
});
me.addListener('aftergetcontent',function(cmdName){
if(cmdName == 'aftergetcontent' && me.queryCommandState('source')){
return;
}
switchImgAndEmbed(false);
me.addInputRule(function(root){
switchImgAndEmbed(root)
});
me.commands["insertvideo"] = {
......@@ -66,7 +56,7 @@ UE.plugins['video'] = function (){
vi = videoObjs[i];
html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, vi.align||"none",false,true));
}
me.execCommand("inserthtml",html.join(""));
me.execCommand("inserthtml",html.join(""),true);
},
queryCommandState : function(){
var img = me.selection.getRange().getClosedNode(),
......
......@@ -699,9 +699,9 @@
var iframeholder = editor.ui.getDom('iframeholder');
//给实例添加一个编辑器的容器引用
editor.container = editor.ui.getDom();
var width = editor.options.initialFrameWidth;
if (!/%/g.test(width)) width += "px";
editor.container.style.cssText = "z-index:" + editor.options.zIndex + ";width:" + width;
var options=editor.options;
var width =Math.max(options.initialFrameWidth,options.minFrameWidth) ;
editor.container.style.cssText = "z-index:" + options.zIndex + ";width:" + width+"px";
oldRender.call(editor, iframeholder);
}
......
......@@ -253,7 +253,25 @@ test("setContent", function() {
ua.haveSameAllChildAttribs(div2, div_new, 'check contents');
});
test("setContent 追加", function() {
var editor = te.obj[1];
var div = te.dom[0];
editor.focus();
expect(2);
editor.addListener("beforesetcontent", function() {
ok(true, "beforesetcontent");
});
editor.addListener("aftersetcontent", function() {
ok(true, "aftersetcontent");
});
var html = '<span><span></span><strong>xx</strong><em>em</em><em></em><u></u></span><div>xxxx</div>';
editor.setContent(html);
var div_new = document.createElement('div');
div_new.innerHTML = '<p><span><span></span><strong>xx</strong><em>em</em><em></em><span style="text-decoration: underline"></span></span></p><div>xxxx</div>';
var div2 = document.createElement('div');
div2.innerHTML = editor.body.innerHTML;
ua.haveSameAllChildAttribs(div2, div_new, 'check contents');
});
//test( "focus", function() {
// var editor = te.obj[1];
// expect( 1 );
......
......@@ -51,9 +51,9 @@ test( 'setStart/setEnd--nodeType为1', function() {
ua.checkResult( range, div, div, 0, 1, false, "startContainer is not null" );
} );
/*
* 测的内容比较多,updateCollapse,setEndPoint,setStart,setEnd,collapse
* 因为updateCollapse和setEndPoint无法通过Range对象获取, 必须间接调用验证
*/
* 测的内容比较多,updateCollapse,setEndPoint,setStart,setEnd,collapse
* 因为updateCollapse和setEndPoint无法通过Range对象获取, 必须间接调用验证
*/
test( 'setStartAfter,setStartBefore', function() {
var div = te.dom[2];
div.innerHTML = '<span></span><a></a>';
......@@ -1458,10 +1458,10 @@ test('b节点取range',function(){
ua.checkResult(range, editor.body.firstChild.lastChild.previousSibling, editor.body.firstChild.lastChild.previousSibling, 0, 0, true, '节点后--check range');
range.setStart(editor.body.firstChild.firstChild.nextSibling,0).collapse(1)
debugger
range.select();
// debugger
range.select();
range = editor.selection.getRange();
debugger
// debugger
if(ua.browser.webkit )
ua.checkResult(range, editor.body.firstChild.firstChild.nextSibling.firstChild, editor.body.firstChild.firstChild.nextSibling.firstChild, 1, 1, true, '节点内文本节点前--check range');
else if(ua.browser.ie)
......@@ -1497,7 +1497,7 @@ test('文本节点中间取range',function(){
ua.checkResult(range, editor.body.firstChild.lastChild, editor.body.firstChild.lastChild, 0, 0, true, 'check range');
else
ua.checkResult(range, editor.body.firstChild.lastChild, editor.body.firstChild.lastChild, 2, 2, true, 'check range');
start();
start();
},50);
},50);
});
......@@ -1572,3 +1572,14 @@ test('range.createAddress,range.moveAddress',function(){
rng.setStart(div.firstChild,3).collapse(true);
ok(equalRange(rng,rng1));
});
test('equals',function(){
var div = te.dom[2];
var rng = new UE.dom.Range(document);
div.innerHTML = '<b>xxxx</b>';
rng.setStart(div.firstChild,0).collapse(true);
var rng2 = rng.cloneRange();
ok(rng.equals(rng2))
});
\ No newline at end of file
module( 'core.filternode' );
test( '', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa"><p>sdf<b>sdf</b></p><i>sdf</i></div>');
UE.filterNode(node,{
'p':{},
'b':'-'
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p>sdf</p>sdf</div>');
node.innerHTML('<p style="color:#ccc;border:1px solid #ccc;"><table><tbody><tr><td></td></tr></tbody></table></p><div>sdfasdf</div>');
UE.filterNode(node,{
'p':{$:{
style:['color']
}},
'td':{}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p style="color:#ccc"><td></td></p>sdfasdf</div>');
node.innerHTML('<p style="color:#ccc;border:1px solid #ccc;"><table><tbody><tr><td>sdfs</td><td>sdfs</td></tr></tbody></table></p><div>sdfasdf</div>');
UE.filterNode(node,{
'p':{$:{
style:['color']
}},
'tr':function(node){
node.tagName = 'p';
node.setAttr();
},
'td':function(node){
node.parentNode.removeChild(node,true)
}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p style="color:#ccc"><p>sdfssdfs</p></p>sdfasdf</div>');
UE.filterNode(node,{
'p':{$:{}}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p><p>sdfssdfs</p></p>sdfasdf</div>');
});
\ No newline at end of file
module( 'core.htmlparser' );
test( '', function() {
var div = te.dom[0];
var root = UE.htmlparser('<i>sdfsdfsdfsf</i>');
equals(root.toHtml(),'<i>sdfsdfsdfsf</i>');
root = UE.htmlparser('<i>sdf<b>sdfsdsd</b>fsdfsf</i>');
equals(root.toHtml(),'<i>sdf<b>sdfsdsd</b>fsdfsf</i>');
root = UE.htmlparser('<i dsf="sdf" sdf="wewe" readonly >sdf</i>');
equals(root.toHtml(),'<i dsf="sdf" sdf="wewe" readonly >sdf</i>');
root = UE.htmlparser('<i dsf="sdf" sdf="wewe" readonly >sd<!--fasdf-->f</i>');
equals(root.toHtml(),'<i dsf="sdf" sdf="wewe" readonly >sd<!--fasdf-->f</i>');
root = UE.htmlparser('<p><td></td></p>');
equals(root.toHtml(),'<p><table><tbody><tr><td></td></tr></tbody></table></p>');
root = UE.htmlparser('<p><td>sdfsdfsdf</p>');
equals(root.toHtml(),'<p><table><tbody><tr><td>sdfsdfsdf</td></tr></tbody></table></p>');
root = UE.htmlparser('<img src="file:///C:/DOCUME~1/DONGYA~1/LOCALS~1/Temp/msohtmlclip1/01/clip_image002.jpg" width="553" height="275" />');
equals(root.toHtml(),'<img src="file:///C:/DOCUME~1/DONGYA~1/LOCALS~1/Temp/msohtmlclip1/01/clip_image002.jpg" width="553" height="275" />');
root = UE.htmlparser('<td></td>' + '\n\r' + '<td></td>');
equals(root.toHtml(),'<table><tbody><tr><td></td><td></td></tr></tbody></table>');
root = UE.htmlparser('<li>sdfsdfsdf<li>sdfsdfsdfsdf');
equals(root.toHtml(),'<ul><li>sdfsdfsdf</li><li>sdfsdfsdfsdf</li></ul>');
root = UE.htmlparser('<script type="text/javascript" charset="utf-8" src="editor_api.js"></script>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<script type="text/javascript" charset="utf-8" src="editor_api.js"></script>');
root = UE.htmlparser('<table width="960"><tbody><tr><td width="939" valign="top"><br></td></tr></tbody></table><p><br></p>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<table width="960"><tbody><tr><td width="939" valign="top"><br/></td></tr></tbody></table><p><br/></p>');
});
\ No newline at end of file
module( 'core.node' );
test( '', function() {
var uNode = UE.uNode;
var node = uNode.createElement('div');
equals(node.tagName,'div');
equals(node.type,'element');
node = uNode.createElement('<div id="aa">sdfadf</div>');
equals(node.tagName,'div');
equals(node.children[0].data,'sdfadf');
node = uNode.createElement('<div id="aa"><div id="bb"></div>sdfadf</div>');
node = node.getNodeById('bb');
equals(node.getAttr('id'),'bb');
node = uNode.createElement('<div id="aa"><div id="bb"><div id="cc"></div> </div>sdfadf</div>');
node = node.getNodeById('cc');
equals(node.getAttr('id'),'cc');
node = uNode.createElement('<div id="aa"><div id="bb"><div id="cc"></div> </div>sdfadf</div>');
var nodelist = node.getNodesByTagName('div');
equals(nodelist.length,2);
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<div id="bb"><div id="cc"></div> </div>sdfadf');
node.innerHTML('<p><td></td></p>');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p>');
var tmp = uNode.createElement('div');
node.appendChild(tmp);
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div>');
node.insertBefore(tmp,node.firstChild());
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<div></div><p><table><tbody><tr><td></td></tr></tbody></table></p>');
node.appendChild(tmp);
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div>');
tmp = uNode.createElement('p');
tmp.setAttr({'class':'test','id':'aa'});
node.insertBefore(tmp,node.lastChild());
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><p class="test" id="aa"></p><div></div>');
node.replaceChild(uNode.createElement('div'),tmp);
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div><div></div>');
node.innerHTML('<p>dfsdfsdf<b>eee</b>sdf</p>');
equals(node.innerText(),'dfsdfsdfeeesdf');
node.innerHTML('<div><div><div></div></div></div>');
nodelist =node.getNodesByTagName('div');
equals(nodelist.length,3);
for(var i= 0,ci;ci=nodelist[i++];){
ci.tagName = 'p';
}
equals(node.innerHTML(),'<p><p><p></p></p></p>');
node.innerHTML('<div style="border:1px solid #ccc"><div>');
node = node.firstChild();
equals(node.getStyle('border'),'1px solid #ccc');
node.innerHTML('<div style="border:1px solid #ccc;color:#ccc"><div>');
node = node.firstChild();
equals(node.getStyle('border'),'1px solid #ccc');
node.setStyle('border','2px solid #ccc');
equals(node.getAttr('style'),'border:2px solid #ccc;color:#ccc');
node.setStyle({
'font':'12px',
'background':'#ccc'
});
equals(node.getAttr('style'),'background:#ccc;font:12px;border:2px solid #ccc;color:#ccc');
node.setStyle({
'font':'',
'background':'',
'border':'',
'color':''
});
equals(node.getAttr('style'),undefined);
node.setStyle('border','<script>alert("")</script>');
equals(node.getAttr('style'),"border:&lt;script&gt;alert(&quot;&quot;)&lt;/script&gt;;");
equals(node.toHtml(),'<div style=\"border:&lt;script&gt;alert(&quot;&quot;)&lt;/script&gt;;\" ><div></div></div>')
node.innerHTML('<div>asdfasdf<b>sdf</b></div>')
node.removeChild(node.firstChild(),true);
equals(node.toHtml(),'<div style=\"border:&lt;script&gt;alert(&quot;&quot;)&lt;/script&gt;;\" >asdfasdf<b>sdf</b></div>')
var tmp = new UE.uNode.createElement('div');
node.appendChild(tmp);
equals(tmp.getIndex(),2)
});
\ No newline at end of file
......@@ -235,6 +235,8 @@ test('unhtml 字符转义', function(){
var str='<p>"as&cd"</p>';
var str_html=utils.unhtml(str);
equal(str_html,'&lt;p&gt;&quot;as&amp;cd&quot;&lt;/p&gt;','转义字符成功');
str = 'border:&lt;script&gt;alert(&quot;&quot;)&lt;/script&gt;"'
equal(utils.unhtml(str),'border:&lt;script&gt;alert(&quot;&quot;)&lt;/script&gt;&quot;','转义字符成功');
});
test('html 反转义', function(){
var utils=te.obj[0];
......
......@@ -13,7 +13,9 @@
///import core.Editor;
///import core.ajax;
///import core.filterword;
///import core.node;
///import core.htmlparser;
///import core.filternode;
///import plugins.emotion;
///import plugins.map;
///import plugins.scrawl;
......
......@@ -16,11 +16,11 @@ test('插入代码',function(){
editor.ready(function(){
var br = baidu.editor.browser.ie ? '&nbsp;' : '<br />';
editor.setContent('<p>' + br + '</p>');
debugger
// debugger
range.setStart(editor.body.firstChild,0).collapse(1).select();
debugger
// debugger
setTimeout(function(){
debugger
// debugger
editor.execCommand('highlightcode','<?php echo "Hello World"; ?>','php');
ua.manualDeleteFillData(editor.body);
equal( editor.getContent().substring(0, 78),'<pre class=\"brush:php;toolbar:false;\">&lt;?php echo "Hello World"; ?&gt;</pre>','代码高亮');
......
......@@ -11,8 +11,8 @@
<div class="wrapper">
<div id="imageTab">
<div id="tabHeads" class="tabhead">
<span tabSrc="remote"><var id="lang_tab_remote"></var></span>
<span tabSrc="local" class="focus"><var id="lang_tab_local"></var></span>
<span tabSrc="remote" class="focus"><var id="lang_tab_remote"></var></span>
<span tabSrc="local"><var id="lang_tab_local"></var></span>
<span tabSrc="imgManager"><var id="lang_tab_imgManager"></var></span>
<span tabSrc="imgSearch"><var id="lang_tab_imgSearch"></var></span>
</div>
......
......@@ -16,7 +16,7 @@
var editTable = function () {
me = this;
this.init();
me.init();
};
editTable.prototype = {
init:function () {
......
......@@ -38,6 +38,10 @@
tone.value = arguments[1];
colorPop.hide();
});
colorPiker.addListener("picknocolor", function () {
tone.value="";
colorPop.hide();
});
dialog.onok=function(){
editor.execCommand("edittd",tone.value);
};
......
......@@ -121,7 +121,7 @@
//,initialContent:'欢迎使用ueditor!' //初始化编辑器的内容,也可以通过textarea/script给值,看官网例子
//,initialFrameWidth:1000 //初始化编辑器宽度,1000,同时支持百分比,例如:"70%"
//,initialFrameWidth:1000 //初始化编辑器宽度,默认1000
//,initialFrameHeight:320 //初始化编辑器高度,默认320
//,autoClearinitialContent:true //是否自动清除编辑器初始内容,注意:如果focus属性设置为true,这个也为真,那么编辑器一上来就会触发导致初始化的内容看不到了
......@@ -136,7 +136,7 @@
//,fullscreen : false //是否开启初始化时即全屏,默认关闭
//,readonly : false /编辑器初始化结束后,编辑区域是否是只读的,默认是false
//,readonly : false //编辑器初始化结束后,编辑区域是否是只读的,默认是false
//,zIndex : 900 //编辑器层级的基数,默认是900
......@@ -146,8 +146,34 @@
//,emotionLocalization:false //是否开启表情本地化,默认关闭。若要开启请确保emotion文件夹下包含官网提供的images表情文件夹
//,pasteplain:false //是否纯文本粘贴。false为不使用纯文本粘贴,true为使用纯文本粘贴
//,pasteplain:false //是否默认为纯文本粘贴。false为不使用纯文本粘贴,true为使用纯文本粘贴
//纯文本粘贴模式下的过滤规则
// 'filterTxtRules' : function(){
// function transP(node){
// node.tagName = 'p';
// node.setStyle();
// }
// return {
// //直接删除及其字节点内容
// '-' : 'script style object iframe embed input select',
// 'p': {$:{}},
// 'br':{$:{}},
// 'div':{'$':{}},
// 'li':{'$':{}},
// 'caption':transP,
// 'th':transP,
// 'tr':transP,
// 'h1':transP,'h2':transP,'h3':transP,'h4':transP,'h5':transP,'h6':transP,
// 'td':function(node){
// //没有内容的td直接删掉
// var txt = !!node.innerText();
// if(txt){
// node.parentNode.insertAfter(UE.uNode.createText(' &nbsp; &nbsp;'),node);
// }
// node.parentNode.removeChild(node,node.innerText())
// }
// }
// }()
//,allHtmlEnabled:false //提交到后台的数据是否包含整个html字符串
//iframeUrlMap
//dialog内容的路径 ~会被替换成URL,垓属性一旦打开,将覆盖所有的dialog的默认路径
......@@ -323,16 +349,6 @@
//编辑器初始化完成后是否进入源码模式,默认为否。
//,sourceEditorFirst:false
//serialize
// 配置编辑器的过滤规则
// serialize是个object,可以有属性blackList,whiteList属性,默认是{}
// 例子:
// , serialize : {
// //黑名单,编辑器会过滤掉一下标签
// blackList:{object:1, applet:1, input:1, meta:1, base:1, button:1, select:1, textarea:1, '#comment':1, 'map':1, 'area':1}
// }
//autotypeset
// //自动排版参数
// ,autotypeset:{
......@@ -349,6 +365,8 @@
// removeTagNames : {标签名字:1},
// indent : false, // 行首缩进
// indentValue : '2em' //行首缩进的大小
// }
// },
//填写过滤规则
//filterRules : {}
};
})();
<%@ page language="java" pageEncoding="utf-8"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script src="../uparse.js" type="text/javascript"></script>
<script>
uParse('.content',{
'highlightJsUrl':'../third-party/SyntaxHighlighter/shCore.js',
'highlightCssUrl':'../third-party/SyntaxHighlighter/shCoreDefault.css'
})
</script>
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
......@@ -7,7 +15,7 @@ String content1 = request.getParameter("myEditor1");
response.getWriter().print("第1个编辑器的值");
response.getWriter().print(content);
response.getWriter().print("<div class='content'>"+content+"</div>");
response.getWriter().print("<br/>第2个编辑器的值<br/>");
response.getWriter().print("<textarea style='width:500px;height:300px;'>"+content1+"</textarea><br/>");
%>
\ No newline at end of file
......@@ -4,6 +4,6 @@
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime requestValidationMode="2.0" maxRequestLength="102400 "/>
<pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"></pages>
<globalization fileEncoding="utf-8" culture="zh-CN"/>
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="zh-CN"/>
</system.web>
</configuration>
......@@ -17,14 +17,23 @@ public class getContent : IHttpHandler {
//获取数据
string content = context.Server.HtmlEncode(context.Request.Form["myEditor"]);
string content1 = context.Server.HtmlEncode(context.Request.Form["myEditor1"]);
//存入数据库或者其他操作
//-------------
//显示
context.Response.Write("<script src='../uparse.js' type='text/javascript'></script>");
context.Response.Write(
"<script>uParse('.content',{"+
"'highlightJsUrl':'../third-party/SyntaxHighlighter/shCore.js',"+
"'highlightCssUrl':'../third-party/SyntaxHighlighter/shCoreDefault.css'"+
"})"+
"</script>");
context.Response.Write("第1个编辑器的值");
context.Response.Write(context.Server.HtmlDecode(content));
context.Response.Write("<div class='content'>" + context.Server.HtmlDecode(content) + "</div>");
context.Response.Write("<br/>第2个编辑器的值<br/>");
context.Response.Write(context.Server.HtmlDecode("<textarea style='width:500px;height:300px;'>"+content1+"</textarea><br/>"));
context.Response.Write("<textarea class='content' style='width:500px;height:300px;'>"+context.Server.HtmlDecode(content1)+"</textarea><br/>");
}
public bool IsReusable {
......
......@@ -176,7 +176,8 @@ function uParse(selector,opt){
liiconpath : 'http://bs.baidu.com/listicon/',
listDefaultPaddingLeft : '20',
'highlightJsUrl':'',
'highlightCssUrl':''
'highlightCssUrl':'',
customRule:function(){}
};
if(opt){
for(var p in opt){
......@@ -190,9 +191,14 @@ function uParse(selector,opt){
contents = document.querySelectorAll(selector)
}else{
if(/^#/.test(selector)){
contents = [document.getElementById(selector)]
contents = [document.getElementById(selector.replace(/^#/,''))]
}else if(/^\./.test(selector)){
contents = document.getElementsByClassName(selector)
var contents = [];
_each(document.getElementsByTagName('*'),function(node){
if(node.className && new RegExp('\\b' + selector.replace(/^\./,'') + '\\b','i').test(node.className)){
contents.push(node)
}
})
}else{
contents = document.getElementsByTagName(selector)
}
......@@ -277,7 +283,7 @@ function uParse(selector,opt){
customCss.push(selector +' .list-paddingleft-2{padding-left:'+defaultOption.listDefaultPaddingLeft+'px}');
customCss.push(selector +' .list-paddingleft-3{padding-left:'+defaultOption.listDefaultPaddingLeft*2+'px}');
//如果不给宽度会在自定应样式里出现滚动条
cssRule('list', selector +' ol,'+selector +' ul{margin:0;pading:0;}li{clear:both;}'+customCss.join('\n'), document);
cssRule('list', selector +' ol,'+selector +' ul{margin:0;padding:0;}li{clear:both;}'+customCss.join('\n'), document);
}
//解析内容
var needParseTagName = {
......@@ -307,6 +313,18 @@ function uParse(selector,opt){
_each(nodes,function(pi){
if(/brush/i.test(pi.className)){
SyntaxHighlighter.highlight(pi);
var tables = document.getElementsByTagName('table');
for(var t= 0,ti;ti=tables[t++];){
if(/SyntaxHighlighter/i.test(ti.className)){
var tds = ti.getElementsByTagName('td');
for(var i=0,li,ri;li=tds[0].childNodes[i];i++){
ri = tds[1].firstChild.childNodes[i];
if(ri){
ri.style.height = li.style.height = ri.offsetHeight + 'px';
}
}
}
}
}
});
});
......@@ -331,7 +349,9 @@ function uParse(selector,opt){
needParseTagName[tag](nodes)
}
}
})
defaultOption.customRule(content);
});
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册