提交 dec5c0c1 编写于 作者: C campaign

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

Conflicts:
	_test/core/htmlparser.js
	_test/core/node.js
......@@ -64,7 +64,7 @@
}
function createEditor(){
enableBtn();
UE.getEditor('editor')
UE.getEditor('editor');
}
function getAllHtml() {
alert( UE.getEditor('editor').getAllHtml() )
......
......@@ -70,6 +70,41 @@ UE.plugins['contextmenu'] = function () {
label:lang.inserttable,
cmdName:'inserttable'
},
{
label:"清除表格背景",
cmdName:"cleartablebackground",
exec:function(){
this.execCommand("cleartablebackground");
}
},
{
label:"整个表格隔行变色",
cmdName:"settablebackground",
exec:function(){
this.execCommand("settablebackground",{repeat:true,colorList:["#bbb","#ccc"]},true);
}
},
{
label:"三色渐变",
cmdName:"settablebackground",
exec:function(){
this.execCommand("settablebackground",{repeat:true,colorList:["#aaa","#bbb","#ccc"]});
}
},
{
label:"隔行变色",
cmdName:"settablebackground",
exec:function(){
this.execCommand("settablebackground",{repeat:true,colorList:["#bbb","#ccc"]});
}
},
{
label:"红蓝相间",
cmdName:"settablebackground",
exec:function(){
this.execCommand("settablebackground",{repeat:true,colorList:["red","blue"]});
}
},
{
label:lang.deletetable,
cmdName:'deletetable'
......@@ -174,6 +209,54 @@ UE.plugins['contextmenu'] = function () {
}
]
},
{
group:"表格排序",
icon:'tablesort',
subMenu:[
{
label:"逆序当前",
cmdName:'sorttable',
value:1
},
{
label:"按ASCII字符升序",
cmdName:'sorttable'
},
{
label:"按ASCII字符降序",
cmdName:'sorttable',
exec:function(){
this.execCommand("sorttable",function(td1,td2){
var value1 = td1.innerHTML,
value2 = td2.innerHTML;
return value2.localeCompare(value1);
});
}
},
{
label:"按数值大小升序",
cmdName:'sorttable',
exec:function(){
this.execCommand("sorttable",function(td1,td2){
var value1 = parseInt(td1.innerHTML,10),
value2 = parseInt(td2.innerHTML,10);
return (value1||0) - (value2||0);
});
}
},
{
label:"按数值大小降序",
cmdName:'sorttable',
exec:function(){
this.execCommand("sorttable",function(td1,td2){
var value1 = parseInt(td1.innerHTML,10),
value2 = parseInt(td2.innerHTML,10);
return (value2||0) - (value1||0);
});
}
}
]
},
{
group:lang.aligntd,
icon:'aligntd',
......@@ -330,6 +413,8 @@ UE.plugins['contextmenu'] = function () {
return me.getLang("contextMenu.aligntd");
case "aligntable":
return me.getLang("contextMenu.aligntable");
case "tablesort":
return "表格排序";
default :
return '';
}
......
......@@ -47,7 +47,8 @@ UE.plugins['table'] = function () {
'defaultRows':5,
'tdvalign':'top',
'cursorpath':me.options.UEDITOR_HOME_URL + "themes/default/images/cursor_",
'tableDragable':false
'tableDragable':false,
'classList':[".back1",".back2"]
});
me.getUETable = getUETable;
var commands = {
......@@ -84,7 +85,7 @@ UE.plugins['table'] = function () {
'table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}' +
//插入的表格的默认样式
'table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
'td,th{ background:white; padding: 5px 10px;border: 1px solid #DDD;}' +
'td,th{padding: 5px 10px;border: 1px solid #DDD;}' +
'caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
'th{border-top:2px solid #BBB;background:#F7F7F7;}' +
'td p{margin:0;padding:0;}', me.document);
......@@ -513,6 +514,11 @@ UE.plugins['table'] = function () {
toggleDraggableState(me, false, "", null);
}
});
me.addListener("interlacetable",function(type,table){
var rows = table.rows,
len;
});
me.addListener("mousedown", mouseDownEvent);
......
......@@ -5,18 +5,19 @@
* Time: 下午6:25
* To change this template use File | Settings | File Templates.
*/
;(function(){
;
(function () {
var UT = UE.UETable,
getTableItemsByRange = function(editor){
getTableItemsByRange = function (editor) {
return UT.getTableItemsByRange(editor);
},
getUETableBySelected = function(editor){
getUETableBySelected = function (editor) {
return UT.getUETableBySelected(editor)
},
getDefaultValue = function(editor,table){
return UT.getDefaultValue(editor,table);
getDefaultValue = function (editor, table) {
return UT.getDefaultValue(editor, table);
},
getUETable = function(tdOrTable){
getUETable = function (tdOrTable) {
return UT.getUETable(tdOrTable);
};
......@@ -526,10 +527,10 @@
table = tableItems.table;
if (table) {
if (cmd == 'adaptbywindow') {
resetTdWidth(table,this);
resetTdWidth(table, this);
} else {
var cells = domUtils.getElementsByTagName(table,"td th");
utils.each(cells,function(cell){
var cells = domUtils.getElementsByTagName(table, "td th");
utils.each(cells, function (cell) {
cell.removeAttribute("width");
});
table.removeAttribute("width");
......@@ -696,7 +697,6 @@
if (table) {
var obj = {};
obj[data[0]] = data[1];
table.style[utils.cssStyleToDomStyle("float")] = "";
table.style.margin = "";
domUtils.setStyles(table, obj);
......@@ -745,25 +745,99 @@
}
}
};
UE.commands['sorttable'] = {
queryCommandState:function () {
var me = this,
tableItems = getTableItemsByRange(me);
if (!tableItems.cell) return -1;
var table = tableItems.table,
cells = table.getElementsByTagName("td");
for (var i = 0, cell; cell = cells[i++];) {
if (cell.rowSpan != 1 || cell.colSpan != 1) return -1;
}
return 0;
},
execCommand:function (cmd, fn) {
var me = this,
range = me.selection.getRange(),
bk = range.createBookmark(true),
tableItems = getTableItemsByRange(me),
cell = tableItems.cell,
ut = getUETable(tableItems.table),
cellIndex = ut.getCellInfo(cell).cellIndex,
cells = ut.getSameEndPosCells(cell, "x");
if (cells.length < ut.rowsNum) {
this.fireEvent("tableForbidSort");
return;
}
ut.sortTable(cellIndex, fn);
range.moveToBookmark(bk).select();
}
};
function resetTdWidth(table,editor){
UE.commands["enablesort"] = UE.commands["disablesort"] = {
queryCommandState:function () {
return getTableItemsByRange(this).table ? 0 : -1;
},
execCommand:function (cmd) {
var table = getTableItemsByRange(this).table;
table.setAttribute("data-sort", cmd == "enablesort" ? "sortEnabled" : "sortDisabled");
}
};
UE.commands["settablebackground"] = {
queryCommandState:function () {
return getTableItemsByRange(this).table ? 0 : -1;
},
execCommand:function (cmd, value, allCells) {
var table, cells, ut;
if (allCells) {
table = getTableItemsByRange(this).table;
cells = table.getElementsByTagName("td");
} else {
cells = getSelectedArr(this);
}
ut = getUETable(cells[0]);
ut.setBackground(cells, value);
}
};
UE.commands["cleartablebackground"] = {
execCommand:function () {
var cells = getSelectedArr(this),
ut = getUETable(cells[0]);
ut.removeBackground(cells);
}
};
UE.commands["interlacedtable"] = UE.commands["uninterlacedtable"] = {
execCommand:function (cmd) {
var table = getTableItemsByRange(this).table;
table.setAttribute("interlaced", cmd == "interlacedtable" ? "enabled" : "disabled");
this.fireEvent("interlacetable",table);
}
};
function resetTdWidth(table, editor) {
var tds = table.getElementsByTagName("td");
utils.each(tds, function (td) {
td.removeAttribute("width");
});
table.setAttribute('width', getTableWidth(editor,true,getDefaultValue(editor,table)));
setTimeout(function(){
utils.each(tds,function(td){
(td.colSpan ==1) && td.setAttribute("width",td.offsetWidth + "");
table.setAttribute('width', getTableWidth(editor, true, getDefaultValue(editor, table)));
setTimeout(function () {
utils.each(tds, function (td) {
(td.colSpan == 1) && td.setAttribute("width", td.offsetWidth + "");
})
},0);
}, 0);
}
function getTableWidth(editor, needIEHack, defaultValue) {
var body = editor.body;
return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
}
function getSelectedArr(editor) {
var ut = getTableItemsByRange(editor).cell || getUETableBySelected(editor);
return ut ? (ut.nodeType ? [ut] : ut.selectedTds) : [];
var cell = getTableItemsByRange(editor).cell,
ut = getUETable(cell);
return ut.selectedTds.length ? ut.selectedTds : [cell];
}
})();
\ No newline at end of file
......@@ -11,7 +11,7 @@
* @constructor
*/
(function () {
var UETable = UE.UETable = function(table) {
var UETable = UE.UETable = function (table) {
this.table = table;
this.indexTable = [];
this.selectedTds = [];
......@@ -20,29 +20,29 @@
};
//===以下为静态工具方法===
UETable.removeSelectedClass = function(cells) {
UETable.removeSelectedClass = function (cells) {
utils.each(cells, function (cell) {
domUtils.removeClasses(cell, "selectTdClass");
})
};
UETable.addSelectedClass = function(cells){
UETable.addSelectedClass = function (cells) {
utils.each(cells, function (cell) {
domUtils.addClass(cell, "selectTdClass");
})
};
UETable.isEmptyBlock = function(node) {
UETable.isEmptyBlock = function (node) {
var reg = new RegExp(domUtils.fillChar, 'g');
if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
return 0;
}
for (var i in dtd.$isNotEmpty) if(dtd.$isNotEmpty.hasOwnProperty(i)) {
for (var i in dtd.$isNotEmpty) if (dtd.$isNotEmpty.hasOwnProperty(i)) {
if (node.getElementsByTagName(i).length) {
return 0;
}
}
return 1;
};
UETable.getWidth = function(cell) {
UETable.getWidth = function (cell) {
if (!cell)return 0;
return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
};
......@@ -51,7 +51,7 @@
* 根据当前选区获取相关的table信息
* @return {Object}
*/
UETable.getTableItemsByRange = function(editor) {
UETable.getTableItemsByRange = function (editor) {
var start = editor.selection.getStart(),
//在table或者td边缘有可能存在选中tr的情况
cell = start && domUtils.findParentByTagName(start, ["td", "th"], true),
......@@ -66,7 +66,7 @@
caption:caption
}
};
UETable.getUETableBySelected = function(editor){
UETable.getUETableBySelected = function (editor) {
var table = UETable.getTableItemsByRange(editor).table;
if (table && table.ueTable && table.ueTable.selectedTds.length) {
return table.ueTable;
......@@ -74,7 +74,7 @@
return null;
};
UETable.getDefaultValue = function(editor,table){
UETable.getDefaultValue = function (editor, table) {
var borderMap = {
thin:'0px',
medium:'1px',
......@@ -117,7 +117,7 @@
* 根据当前点击的td或者table获取索引对象
* @param tdOrTable
*/
UETable.getUETable = function(tdOrTable) {
UETable.getUETable = function (tdOrTable) {
var tag = tdOrTable.tagName.toLowerCase();
tdOrTable = (tag == "td" || tag == "th" || tag == 'caption') ? domUtils.findParentByTagName(tdOrTable, "table", true) : tdOrTable;
if (!tdOrTable.ueTable) {
......@@ -261,14 +261,14 @@
setCellContent:function (cell, content) {
cell.innerHTML = content || (browser.ie ? domUtils.fillChar : "<br />");
},
cloneCell:function(cell,ignoreMerge){
if(!cell || utils.isString(cell)){
cloneCell:function (cell, ignoreMerge) {
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(ignoreMerge){
if (ignoreMerge) {
tmpCell.rowSpan = tmpCell.colSpan = 1;
}
tmpCell.style.borderLeftStyle = "";
......@@ -312,10 +312,12 @@
this.cellsRange = {};
this.indexTable = [];
var rows = this.table.rows,
//暂时采用rows Length,对残缺表格可能存在问题,
//todo 可以考虑取最大值
rowsNum = rows.length,
rowsNum = this.getMaxRows(),
dNum = rowsNum - rows.length,
colsNum = this.getMaxCols();
while (dNum--) {
this.table.insertRow(rows.length);
}
this.rowsNum = rowsNum;
this.colsNum = colsNum;
for (var i = 0, len = rows.length; i < len; i++) {
......@@ -1009,7 +1011,58 @@
var tds = this.table.getElementsByTagName("td"),
range = this.getCellsRange(tds[0], tds[tds.length - 1]);
this.setSelected(range);
},
sortTable:function(sortByCellIndex,compareFn){
var table = this.table,
rows = table.rows,
trArray = [],
flag = rows[0].cells[0].tagName === "TH";
for (var i = 0, len = rows.length; i < len; i++) {
trArray[i] = rows[i];
}
//th不参与排序
flag && trArray.splice(0,1);
trArray.sort(function (tr1, tr2) {
return compareFn ? (typeof compareFn === "number" ? compareFn : compareFn.call(this,tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex])) : function () {
var value1 = tr1.cells[sortByCellIndex].innerHTML,
value2 = tr2.cells[sortByCellIndex].innerHTML;
return value1.localeCompare(value2);
}();
});
var fragment = table.ownerDocument.createDocumentFragment();
for (var j = 0, len = trArray.length; j < len; j++) {
fragment.appendChild(trArray[j]);
}
table.getElementsByTagName("tbody")[0].appendChild(fragment);
},
setBackground:function(cells,value){
if(typeof value ==="string"){
utils.each(cells,function(cell){
cell.style.backgroundColor = value;
})
}else if(typeof value === "object"){
value = utils.extend({
repeat:true,
colorList:["#ddd","#fff"]
},value);
var rowIndex = this.getCellInfo(cells[0]).rowIndex,
count = 0,
colors = value.colorList,
getColor = function(list,index,repeat){
return list[index] ? list[index] : repeat ? list[index % list.length]: "";
};
for(var i = 0,cell;cell= cells[i++];){
var cellInfo = this.getCellInfo(cell);
cell.style.backgroundColor = getColor(colors,((rowIndex + count) == cellInfo.rowIndex) ? count : ++count, value.repeat);
}
}
},
removeBackground:function(cells){
utils.each(cells,function(cell){
cell.style.backgroundColor = "";
})
}
};
function showError(e) {}
function showError(e) {
}
})();
\ No newline at end of file
......@@ -14,7 +14,7 @@ UE.plugins["wordimage"] = function () {
flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43,
opt = me.options,
src = opt.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif';
if (attrs['_src'].indexOf("file:///")!==-1) {
if (attrs['_src'] && attrs['_src'].indexOf("file:///")!==-1) {
img.setAttr({
width:attrs.width,
height:attrs.height,
......
......@@ -25,9 +25,18 @@
},
onpicknocolor: function (t, color){
me._onPickNoColor(color);
},
onchangeheight:function(){
var color = this.getPreview().style.backgroundColor,
popbody = me.popup.getDom("body");
domUtils.setStyle(popbody,"height",me.popup.getDom("content").offsetHeight+"px");
me.setColor(color);
}
}),
editor:me.editor
editor:me.editor,
onhide:function(){
this.content.toggleAdv(1);
}
});
this.initSplitButton();
},
......
......@@ -2,6 +2,7 @@
///import uicore
(function (){
var utils = baidu.editor.utils,
uiUtils = baidu.editor.ui.uiUtils,
UIBase = baidu.editor.ui.UIBase,
ColorPicker = baidu.editor.ui.ColorPicker = function (options){
this.initOptions(options);
......@@ -10,9 +11,28 @@
};
ColorPicker.prototype = {
hue:360,
ishide : true,
saturation:100,
brightness:100,
getHtmlTpl: function (){
return genColorPicker(this.noColorText,this.editor);
},
getPad:function(){
return this.getDom("pad");
},
getSliderMain:function(){
return this.getDom("sliderMain");
},
getThumb:function(){
return this.getDom("thumb");
},
getPreview:function(){
return this.getDom('preview');
},
getAdv:function(){
return this.getDom("adv");
},
_onTableClick: function (evt){
var tgt = evt.target || evt.srcElement;
var color = tgt.getAttribute('data-color');
......@@ -24,14 +44,208 @@
var tgt = evt.target || evt.srcElement;
var color = tgt.getAttribute('data-color');
if (color) {
this.getDom('preview').style.backgroundColor = color;
this.getPreview().style.backgroundColor = color;
}
},
_onTableOut: function (){
this.getDom('preview').style.backgroundColor = '';
this.getPreview().style.backgroundColor = '';
},
_onPickNoColor: function (){
this.fireEvent('picknocolor');
},
_onShowAdv:function(){
if(browser.ie && browser.version<=6){
alert("您的浏览器版本太低,请使用高级版本的浏览器")
return;
}
this.toggleAdv();
},
toggleAdv:function(ishide){
var obj = this.getDom("togglehandle");
if(ishide&&this.ishide){
return;
}
this.getAdv().style.display=this.ishide?"block":"none";
domUtils.removeClasses(obj,["arrow_down","arrow_up"]);
this.ishide?domUtils.addClass(obj,"arrow_up"):domUtils.addClass(obj,"arrow_down");
this.ishide = !this.ishide;
this.fireEvent("changeheight");
},
_onPadDotMouseDown:function(evt){
var me = this;
uiUtils.startDrag(evt, {
ondragstart: function (){},
ondragmove: function (x, y,evt){
me._onClickPad(evt);
},
ondragstop:function(){}
});
},
/**
* 校准value值,保证它在合理范围内
* @private
* @param {Number} x 范围上限,被校准的数值不能超过这个数值.
* @param {Number} y 需要校准的数值.
* @return {Number} 校准过的数值.
*/
_adjustValue: function(x, y) {
return Math.max(0, Math.min(x, y));
},
_onClickPad:function(evt){
var me = this,
paddot = me.getDom("paddot"),
pdrect = uiUtils.getClientRect(paddot),
rect = uiUtils.getClientRect(me.getPad()),
evtoffset = uiUtils.getViewportOffsetByEvent(evt);
//计算鼠标坐标相对调色板左上角距离
me.padDotY = me._adjustValue(rect.height, evtoffset.top - rect.top);
me.padDotX = me._adjustValue(rect.width, evtoffset.left - rect.left);
me.safeSetOffset(paddot,{
top: me.padDotY-pdrect.height/2 ,
left: me.padDotX-pdrect.width/2
});
me.saturation = parseInt(100 * me.padDotX / rect.width, 10); //根据调色块top值计算饱和度
me.brightness = parseInt(100 * (rect.height - me.padDotY) / rect.height, 10); //根据调色块left值计算亮度
me._setNewColor();
},
/**
* 将rgb格式转成hex格式
* @private
* @param {Object} rgb rgb格式颜色值.
* @return {String} hex格式颜色值.
*/
_RGBToHex: function(rgb) {
var hex = [rgb.r.toString(16), rgb.g.toString(16), rgb.b.toString(16)];
for(var i= 0;i<hex.length;i++){
if(hex[i].length == 1){
hex[i] = '0'+hex[i];
}
}
return hex.join('');
},
/**
* 将HSB格式转成RGB格式
* @private
* @param {Object} hsb hsb格式颜色值.
* @return {Object} rgb格式颜色值.
*/
_HSBToRGB: function(hsb) {
var rgb = {},
h = Math.round(hsb.h),
s = Math.round(hsb.s * 255 / 100),
v = Math.round(hsb.b * 255 / 100);
if (s == 0) {
rgb.r = rgb.g = rgb.b = v;
} else {
var t1 = v,
t2 = (255 - s) * v / 255,
t3 = (t1 - t2) * (h % 60) / 60;
if (h == 360) h = 0;
if (h < 60) {rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3;}
else if (h < 120) {rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3;}
else if (h < 180) {rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3;}
else if (h < 240) {rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3;}
else if (h < 300) {rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3;}
else if (h < 360) {rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3;}
else {rgb.r = 0; rgb.g = 0; rgb.b = 0;}
}
return {
r: Math.round(rgb.r),
g: Math.round(rgb.g),
b: Math.round(rgb.b)
};
},
/**
* 将hsb格式转成hex格式
* @private
* @param {Object} hsb hsb格式颜色值.
* @return {String} hex格式颜色值.
*/
_HSBToHex: function(hsb) {
var me = this;
return me._RGBToHex(me._HSBToRGB(hsb));
},
_setNewColor: function() {
var me = this;
//记录当前hex格式颜色值
me.hex = '#' + me._HSBToHex({
h: me.hue,
s: me.saturation,
b: me.brightness
});
domUtils.setStyle(this.getPreview(),"background",me.hex);
},
_onSliderMouseDown:function(evt,obj){
var rect,sliderrect,
me = this,
slider = me.getThumb(),
sliderMain = me.getSliderMain();
uiUtils.startDrag(evt, {
ondragstart: function (){
rect = uiUtils.getClientRect(sliderMain);
sliderrect = uiUtils.getClientRect(slider);
},
ondragmove: function (x, y,evt){
var top = sliderrect.top - rect.top + y,
mousePos = uiUtils.getViewportOffsetByEvent(evt),
val = mousePos.top - rect.top - sliderrect.height / 2,
len = rect.height - sliderrect.height;
me.safeSetOffset(slider,{
top: Math.min(rect.bottom-rect.top-sliderrect.height,top)
});
me.value = (rect.height - 0) / len * val + 0;
me.setPadBackground();
},
ondragstop: function (){}
});
},
_onClickSliderMain:function(evt,obj){
var me = this,
mousePos = uiUtils.getViewportOffsetByEvent(evt),
thumb = me.getThumb(),
thumbRect = uiUtils.getClientRect(thumb),
sliderMainRect = uiUtils.getClientRect(me.getSliderMain()),
len = sliderMainRect.height - thumbRect.height,
val = mousePos.top - sliderMainRect.top - thumbRect.height / 2;
me.value = (sliderMainRect.height - 0) / len * val + 0;
thumb.style.top = me.value+"px";
me.setPadBackground();
},
safeSetOffset: function (obj,offset){
var el = obj;
var vpRect = uiUtils.getViewportRect();
var rect = uiUtils.getClientRect(el);
var left = offset.left||0;
if (left + rect.width > vpRect.right) {
left = vpRect.right - rect.width;
}
var top = offset.top||0;
if (top + rect.height > vpRect.bottom) {
top = vpRect.bottom - rect.height;
}
domUtils.setStyle(el,"left",Math.max(left, 0) + 'px');
domUtils.setStyle(el,"top",Math.max(top, 0) + 'px');
},
/**
* 设置pad背景色
*/
setPadBackground:function(){
var me = this,
pad = me.getPad(),
thumb = me.getThumb(),
sliderMainRect = uiUtils.getClientRect(me.getSliderMain());
me.hue = parseInt(360 * (sliderMainRect.height - Math.min(me.value,sliderMainRect.height)) / sliderMainRect.height,10);
//设置面板背景色
domUtils.setStyle(pad,'background-color','#' + me._HSBToHex({
h: Math.max(me.hue,0),
s: 100,
b: 100
}));
me._setNewColor();
}
};
utils.inherits(ColorPicker, UIBase);
......@@ -68,7 +282,27 @@
'"' +
'></a></td>':'';
}
html += '</tr></table></div>';
html += '</tr></table>';
//高级按钮
html += '<span id="##_togglehandle" class="edui-colorpicker-advbtn arrow_down" onclick="$$._onShowAdv(event, this);"></span>';
html += getAdvColorPicker();
html += '</div>';
return html;
}
function getAdvColorPicker(){
var html = '<div id="##_adv" class="edui-colorpicker-adv" >' +
'<div id="##_pad" class="edui-colorpicker-pad" style="background-color: rgb(255, 0, 0);" onclick = "$$._onClickPad(event,this)">' +
'<div class="edui-colorpicker-cover"></div>' +
'<div id="##_paddot" class="edui-colorpicker-padDot" style="top: 48px; left: 59px;" onmousedown="$$._onPadDotMouseDown(event,this)" ></div>'+
'</div>' +
'<div class="edui-colorpicker-sliderMain" id="##_sliderMain" onclick="$$._onClickSliderMain(event,this)">' +
'<div class="edui-colorpicker-slider" id="##_slider">' +
'<div id="##_thumb" class="edui-colorpicker-thumb" style="top: -3px;" onmousedown="$$._onSliderMouseDown(event, this);"></div>' +
'</div>' +
'</div>' +
'</div> ';
return html;
}
})();
......@@ -161,7 +161,7 @@
function handleMouseMove(evt){
var x = evt.clientX - startX;
var y = evt.clientY - startY;
callbacks.ondragmove(x, y);
callbacks.ondragmove(x, y,evt);
if (evt.stopPropagation) {
evt.stopPropagation();
} else {
......@@ -171,7 +171,7 @@
if (doc.addEventListener) {
function handleMouseUp(evt){
doc.removeEventListener('mousemove', handleMouseMove, true);
doc.removeEventListener('mouseup', handleMouseMove, true);
doc.removeEventListener('mouseup', handleMouseUp, true);
window.removeEventListener('mouseup', handleMouseUp, true);
callbacks.ondragstop();
}
......
......@@ -6,6 +6,8 @@
<property name="coverage.path" value="_test/coverage"/>
<property name="report.file" value="_test/tools/br/report.html"/>
<property name="svn.project" value="ueditor_svn"/>
<property name="git.project" value="ueditor_git"/>
<property name="git.user" value=""/>
<path id="ext.classpath">
<fileset dir="_test/tools/lib">
......@@ -59,8 +61,8 @@
<!--</target>-->
<target name="executeAll" depends="init,coverage">
<get src="http://${serverip}/${svn.project}/_test/tools/br/runall.php?ci=true&amp;cov=true"
dest="/tmp/${git.user}_${svn.project}.php"/>
<get src="http://${serverip}/${git.project}/_test/tools/br/runall.php?ci=true&amp;cov=true"
dest="/tmp/${git.user}_${git.project}.php"/>
</target>
<target name="getreportAll" depends="init,coverage,executeAll">
<waitfor maxwait="3000" maxwaitunit="second">
......@@ -72,8 +74,8 @@
</target>
<target name="executeIE" depends="init,coverage">
<get src="http://${serverip}/${svn.project}IE/_test/tools/br/runall.php?ci=true&amp;cov=true&amp;browserSet=ie6_ie7_ie8_ie9"
dest="/tmp/${git.user}_${svn.project}IE.php"/>
<get src="http://${serverip}/${git.project}IE/_test/tools/br/runall.php?ci=true&amp;cov=true&amp;browserSet=ie6_ie7_ie8_ie9"
dest="/tmp/${git.user}_${git.project}IE.php"/>
</target>
<target name="getreportIE" depends="init,coverage,executeIE">
<waitfor maxwait="3000" maxwaitunit="second">
......
......@@ -6,6 +6,7 @@
<property name="coverage.path" value="_test/coverage"/>
<property name="report.file" value="_test/tools/br/report.html"/>
<property name="svn.project" value="ueditor_svn"/>
<property name="git.project" value="ueditor_git"/>
<property name="git.user" value=""/>
<path id="ext.classpath">
<fileset dir="_test/tools/lib">
......@@ -59,8 +60,8 @@
<!--</target>-->
<target name="executecore" depends="init,coverage">
<get src="http://${serverip}/${svn.project}/_test/tools/br/runall.php?ci=true&amp;cov=true&amp;filter=core"
dest="/tmp/${git.user}_${svn.project}core.php"/>
<get src="http://${serverip}/${git.project}/_test/tools/br/runall.php?ci=true&amp;cov=true&amp;filter=core"
dest="/tmp/${git.user}_${git.project}core.php"/>
</target>
<target name="getreportcore" depends="init,coverage,executecore">
<waitfor maxwait="3000" maxwaitunit="second">
......
......@@ -6,6 +6,8 @@
<property name="coverage.path" value="_test/coverage"/>
<property name="report.file" value="_test/tools/br/report.html"/>
<property name="svn.project" value="ueditor_svn"/>
<property name="git.project" value="ueditor_git"/>
<property name="git.user" value=""/>
<path id="ext.classpath">
<fileset dir="_test/tools/lib">
......@@ -59,8 +61,8 @@
<!--</target>-->
<target name="executeplugin" depends="init,coverage">
<get src="http://${serverip}/${svn.project}/_test/tools/br/runall.php?ci=true&amp;cov=true&amp;filter=plugins"
dest="/tmp/${git.user}_${svn.project}plugin.php"/>
<get src="http://${serverip}/${git.project}/_test/tools/br/runall.php?ci=true&amp;cov=true&amp;filter=plugins"
dest="/tmp/${git.user}_${git.project}plugin.php"/>
</target>
<target name="getreportplugin" depends="init,coverage,executeplugin">
<waitfor maxwait="3000" maxwaitunit="second">
......
......@@ -6,6 +6,7 @@
<property name="coverage.path" value="_test/coverage"/>
<property name="report.file" value="_test/tools/br/report.html"/>
<property name="svn.project" value="ueditor_svn"/>
<property name="git.project" value="ueditor_git"/>
<property name="git.user" value=""/>
<path id="ext.classpath">
<fileset dir="_test/tools/lib">
......@@ -59,8 +60,8 @@
<!--</target>-->
<target name="executeui" depends="init,coverage">
<get src="http://${serverip}/${svn.project}/_test/tools/br/runall.php?ci=true&amp;cov=true&amp;filter=ui"
dest="/tmp/${git.user}_${svn.project}ui.php"/>
<get src="http://${serverip}/${git.project}/_test/tools/br/runall.php?ci=true&amp;cov=true&amp;filter=ui"
dest="/tmp/${git.user}_${git.project}ui.php"/>
</target>
<target name="getreportui" depends="init,coverage,executeui">
<waitfor maxwait="3000" maxwaitunit="second">
......
......@@ -115,78 +115,6 @@ test( "render-- options", function() {
// //todo
//} );
//TODO 现在在过滤机制里面去除无用的标签
test( "getContent--去除无用的空标签:autoClearEmptyNode==true", function() {
var editor = new UE.Editor({autoClearEmptyNode:true,'autoFloatEnabled':false});
stop();
setTimeout(function(){
var div = document.body.appendChild(document.createElement('div'));
editor.render(div);
te.dom.push(div);
editor.focus();
var innerHTML = '<span><span></span><strong>xx</strong><em>em</em><em></em></span><div>xxxx</div>';
editor.setContent( innerHTML );
editor.execCommand('source');
editor.execCommand('source');
equal( editor.getContent(), '<p><strong>xx</strong><em>em</em></p><div>xxxx</div>', "span style空,套空的em和不空的em" );
//style="color:#c4bd97;"
innerHTML = '<span style="color:#c4bd97"><span></span><strong>xx</strong><em>em</em><em></em></span>';
editor.setContent( innerHTML );
if(ua.browser.ie ==9){
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97;"><strong>xx</strong><em>em</em></span></p>', "span style不空,套空的em和不空的em" );
}
else{
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97"><strong>xx</strong><em>em</em></span></p>', "span style不空,套空的em和不空的em" );
}
innerHTML = '<span style="color:#c4bd97"></span><strong>xx</strong><em>em</em><em></em>';
editor.setContent( innerHTML );
/*inline标签上只要有属性就不清理*/
if(ua.browser.ie ==9){
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97;"></span><strong>xx</strong><em>em</em></p>', "span 有style但内容为空" );
}
else{
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97"></span><strong>xx</strong><em>em</em></p>', "span 有style但内容为空" );
}
innerHTML = '<span style="color:#c4bd97">asdf<strong>xx</strong><em>em</em><em></em></span>';
editor.setContent( innerHTML );
if(ua.browser.ie ==9){
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97;">asdf<strong>xx</strong><em>em</em></span></p>', "span 有style内容不空" );
}
else{
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97">asdf<strong>xx</strong><em>em</em></span></p>', "span 有style内容不空" );
}
innerHTML = '<a href="http://www.baidu.com"></a><a>a</a><strong>xx</strong><em>em</em><em></em>';
editor.setContent( innerHTML );
equal( editor.getContent(), '<p><a href="http://www.baidu.com"></a><a>a</a><strong>xx</strong><em>em</em></p>', "a 有href但内容为空,不过滤a标签" );
start()
},100);
} );
//editor.options.autoClearEmptyNode
test("getContent--不去除无用的空标签:autoClearEmptyNode==false", function() {
var editor = new UE.Editor({autoClearEmptyNode:false,'autoFloatEnabled':false});
stop();
setTimeout(function(){
var div = document.body.appendChild(document.createElement('div'));
editor.render(div);
te.dom.push(div);
editor.focus();
var innerHTML = '<span><span></span><strong>xx</strong><em>em</em><em></em><strong></strong></span>';
editor.setContent(innerHTML);
equal(editor.getContent().toLowerCase(), '<p><span><span></span><strong>xx</strong><em>em</em><em></em><strong></strong></span></p>', "span style空,套空的em和不空的em");
innerHTML = '<span style="color:#c4bd97"></span><strong>xx</strong><em>em</em><em></em><strong></strong>';
editor.setContent(innerHTML);
ua.manualDeleteFillData(editor.body);
if (ua.browser.ie == 9) {
equal(editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97;"></span><strong>xx</strong><em>em</em><em></em><strong></strong></p>', "span 有style但内容为空");
}
else {
equal(editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97"></span><strong>xx</strong><em>em</em><em></em><strong></strong></p>', "span 有style但内容为空");
}
start();
},100);
});
test("getContent--转换空格,nbsp与空格相间显示", function() {
var editor = te.obj[1];
var div = te.dom[0];
......@@ -202,8 +130,9 @@ test('getContent--参数为函数', function() {
var div = te.dom[0];
editor.render(div);
editor.focus();
editor.setContent("<p><br />dd</p>");
equal(editor.getContent(), "<p><br />dd</p>", 'hasContents判断不为空');
editor.setContent("<p><br/>dd</p>");
equal(editor.getContent(), "<p><br/>dd</p>", 'hasContents判断不为空');
equal(editor.getContent(function() {
return false
}), "", '为空');
......@@ -214,8 +143,8 @@ test('getContent--2个参数,第一个参数为参数为函数', function() {
var div = te.dom[0];
editor.render(div);
editor.focus();
editor.setContent("<p><br />dd</p>");
equal(editor.getContent(), "<p><br />dd</p>", 'hasContents判断不为空');
editor.setContent("<p><br/>dd</p>");
equal(editor.getContent(), "<p><br/>dd</p>", 'hasContents判断不为空');
equal(editor.getContent("", function() {
return false
}), "", '为空');
......@@ -405,7 +334,7 @@ test("execCommand", function() {
var editor = te.obj[1];
var div = te.dom[0];
editor.focus();
editor.setContent("<span>xx</span><p>xxx</p>");
editor.setContent("<p>xx</p><p>xxx</p>");
var doc = editor.document;
var range = new baidu.editor.dom.Range(doc);
var p = doc.getElementsByTagName('p')[1];
......@@ -416,7 +345,8 @@ test("execCommand", function() {
range.selectNode(p).select();
editor.execCommand("forecolor", "red");
/*span发生了变化,需要重新获取*/
span = doc.getElementsByTagName('span')[0];
var span = doc.getElementsByTagName('span')[0];
equal(span.style['color'], 'red', 'check execCommand color');
var div_new = document.createElement('div');
div_new.innerHTML = '<p><span style="color: red; ">xx</span></p><p style="text-align: right; ">xxx</p>';
......
module( 'core.filternode' );
test( '', function() {
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>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p>sdf</p>sdf</div>','保留p,过滤b');
node.innerHTML('<p><p>sdfs</p><br/><br/><br/><br/></p>');
UE.filterNode(node,{
'p':{$:{
style:['color']
}},
'td':{}
'p':{},
'br':'-'
});
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>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p><p>sdfs</p></p></div>','保留p,过滤br');
});
test( '过滤标签全部属性', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa"><p>sdf<b>sdf</b></p><i>sdf</i></div>');
node.innerHTML('<div id="aa"><p style="color:#ccc"><p>sdfssdfs</p></p>sdfasdf</div>');
UE.filterNode(node,{
'p':{$:{
style:['color']
}},
'tr':function(node){
node.tagName = 'p';
node.setAttr();
},
'td':function(node){
node.parentNode.removeChild(node,true)
}
'p':{$:{}}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p style="color:#ccc"><p>sdfssdfs</p></p>sdfasdf</div>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p><p>sdfssdfs</p></p>sdfasdf</div>','过滤p全部属性');
node.innerHTML('<h6>asd<b>lk</b><i>fj</i></h6>');
UE.filterNode(node,{
'p':{$:{}}
'h6':function(node){
node.tagName = 'p';
node.setAttr();
},
'-':'b i',
'p':{}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p><p>sdfssdfs</p></p>sdfasdf</div>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p>asd</p></div>','同时过滤多个标签属性');
});
node.innerHTML('<p><p>sdfs</p><br/><br/><br/><br/></p>');
test( '过滤标签部分属性', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa"><p>sdf<b>sdf</b></p><i>sdf</i></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':{},
'br':'-'
'p':{$:{
style:['color']
}},
'td':{}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p><p>sdfs</p></p></div>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p style="color:#ccc"><td></td></p>sdfasdf</div>','保留p的color属性');
node.innerHTML('<p style="text-indent:28px;line-height:200%;margin-top:62px;"><strong>sdfs</strong><span style="font-family:宋体">sdfs</span></p>');
UE.filterNode(node,{
......@@ -51,7 +58,7 @@ test( '', function() {
'span':{$:{}},
'strong':'-'
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p style="line-height:200%"><span>sdfs</span></p></div>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p style="line-height:200%"><span>sdfs</span></p></div>','过滤span全部属性,保留p部分属性,过滤strong标签');
node.innerHTML('<p><a></a><u class="ad" id="underline">sdfs<sub class="ab">sdfs</sub><i>sdfs</i></u><i>sdfs</i></p>');
UE.filterNode(node,{
......@@ -62,14 +69,37 @@ test( '', function() {
'sub':{$:{}},
'i':'-'
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p><u class="ad">sdfs<sub>sdfs</sub></u></p></div>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p><u class="ad">sdfs<sub>sdfs</sub></u></p></div>','过滤sub全部属性,保留u部分属性,过滤i标签');
});
node.innerHTML('<img src="http://img.baidu.com/hi/jx2/j_0020.gif" height="10px"/><script></script>');
test( '标签替换过滤', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa"><p>sdf<b>sdf</b></p><i>sdf</i></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>','tr替换为p,过滤掉td');
node.innerHTML('<img src="http://img.baidu.com/hi/jx2/j_0020.gif" height="10px"/><table><caption>aldkfj</caption><tbody><tr style="background-color: #ccc;"><th>adf</th></tr><tr><td>lkj</td></tbody></table>');
UE.filterNode(node,{
'img':{$:{
src:['']
}},
'script':function(node){
'table':{},
'tbody':{},
'tr':{$:{}},
'td':{$:{}},
'th':function(node){
var txt = !!node.innerText();
if(txt){
node.parentNode.insertAfter(UE.uNode.createText(' &nbsp; &nbsp;'),node);
......@@ -77,15 +107,41 @@ test( '', function() {
node.parentNode.removeChild(node,node.innerText())
}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><img src="http://img.baidu.com/hi/jx2/j_0020.gif" /></div>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><img src="http://img.baidu.com/hi/jx2/j_0020.gif" /><table>aldkfj<tbody><tr>adf &nbsp; &nbsp;</tr><tr><td>lkj</td></tr></tbody></table></div>','th按文本内容替换,保留img部分属性');
});
test( '保留标签全部属性', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa"><p>sdf<b>sdf</b></p><i>sdf</i></div>');
node.innerHTML('<ol><li><em>sdf</em></li><ul class=" list-paddingleft-2"><li>a</li><li>b</li><li>c</ul><li>jkl</ol>');
UE.filterNode(node,{
'ol':{},
'ul':{$:{}},
'li':{}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><ol><li>sdf</li><ul><li>a</li><li>b</li><li>c</li></ul><li>jkl</li></ol></div>');
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><ol><li>sdf</li><ul><li>a</li><li>b</li><li>c</li></ul><li>jkl</li></ol></div>','保留ol、li全部属性,过滤ul全部属性');
});
test( '过滤规则为空', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa"><p>sdf<b>sdf</b></p><i>sdf</i></div>');
node.innerHTML('<p style="color:#ccc;border:1px solid #ccc;"><table><tbody><tr><td><h1>asd</h1></td></tr></tbody></table></p><div>sdfasdf</div>');
UE.filterNode(node,{});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p style="color:#ccc;border:1px solid #ccc;"><table><tbody><tr><td><h1>asd</h1></td></tr></tbody></table></p><div>sdfasdf</div></div>','过滤规则为空');
});
test( '特殊规则过滤', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa"><p>sdf</p><i>sdf</i></div>');
node.innerHTML('<script></script>');
UE.filterNode(node,{
'b':'-'
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"></div>','过滤规则中包含html中不存在的标签');
node.innerHTML('<p><!--asdfjasldkfjasldkfj--></p>');
UE.filterNode(node,{
'p':{}
});
equals(node.toHtml().replace(/[ ]+>/g,'>'),'<div id="aa"><p></p></div>','innerHTML中包含注释');
});
\ No newline at end of file
module( 'core.htmlparser' );
test( '', function() {
var div = te.dom[0];
test( '普通标签处理', function() {
var root = UE.htmlparser('<i>sdfsdfsdfsf</i>');
equals(root.toHtml(),'<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>');
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>');
equals(root.toHtml(),'<i dsf="sdf" sdf="wewe" readonly >sdf</i>','添加属性的标签');
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>' + '\n\r' + '<td></td></tr></tbody></table>');
root = UE.htmlparser('<li>sdfsdfsdf<li>sdfsdfsdfsdf');
equals(root.toHtml(),'<ul><li>sdfsdfsdf</li><li>sdfsdfsdfsdf</li></ul>');
equals(root.toHtml(),'<img src="file:///C:/DOCUME~1/DONGYA~1/LOCALS~1/Temp/msohtmlclip1/01/clip_image002.jpg" width="553" height="275" />','img标签');
});
test( '特殊标签处理', function() {
var 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('<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>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<script type="text/javascript" charset="utf-8" src="editor_api.js"></script>','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>');
root = UE.htmlparser('<ol><li><em><u>sdf<li>sdfsdf</ol>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<ol><li><em><u>sdf</u></em></li><li>sdfsdf</li></ol>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<table width="960"><tbody><tr><td width="939" valign="top"><br/></td></tr></tbody></table><p><br/></p>','br标签');
root = UE.htmlparser('<li>sdfsdfsdf<li>sdfsdfsdfsdf');
equals(root.toHtml(),'<ul><li>sdfsdfsdf</li><li>sdfsdfsdfsdf</li></ul>','以文本结束的html');
});
test( '补全不完整table', function() {
var root = UE.htmlparser('<p><td></td></p>');
equals(root.toHtml(),'<p><table><tbody><tr><td></td></tr></tbody></table></p>','td完整,补全table');
root = UE.htmlparser('<p><td>sdfsdfsdf</p>');
equals(root.toHtml(),'<p><table><tbody><tr><td>sdfsdfsdf</td></tr></tbody></table></p>','td不完整,补全table');
root = UE.htmlparser('<td></td>' + '\n\r' + '<td></td>');
equals(root.toHtml(),'<table><tbody><tr><td></td><td></td></tr></tbody></table>','包含\n,补全table');
});
test( '补全不完整li', function() {
var root = UE.htmlparser('<ol><li><em><u>sdf<li>sdfsdf</ol>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<ol><li><em><u>sdf</u></em></li><li>sdfsdf</li></ol>','补全u,em');
root = UE.htmlparser('<ol><li><em>sdf</em></li><ul><li>a</li><li>b</li><li>c</ul><li>jkl</ol>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<ol><li><em>sdf</em></li><ul><li>a</li><li>b</li><li>c</li></ul><li>jkl</li></ol>');
root = UE.htmlparser('<ol><li>asdfas</li>dfasdfa</ol>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<ol><li>asdfas</li><li>dfasdfa</li></ol>');
equals(root.toHtml().replace(/[ ]+>/g,'>'),'<ol><li><em>sdf</em></li><ul><li>a</li><li>b</li><li>c</li></ul><li>jkl</li></ol>','补全li');
});
\ No newline at end of file
module( 'core.node' );
test( '', function() {
test( 'createElement', function() {
var uNode = UE.uNode;
var node = uNode.createElement('div');
equals(node.tagName,'div');
equals(node.type,'element');
equals(node.tagName,'div','空div ——tagname');
equals(node.type,'element','空div ——节点类型');
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>');
equals(node.tagName,'div','非空div——tagname');
equals(node.children[0].data,'sdfadf','非空div——数据内容');
});
test( 'getNodeById', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa"><div id="bb"></div>sdfadf</div>');
node = node.getNodeById('bb');
equals(node.getAttr('id'),'bb');
equals(node.getAttr('id'),'bb','获取标签id');
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>');
equals(node.getAttr('id'),'cc','获取标签id');
});
test( 'getNodesByTagName', function() {
var uNode = UE.uNode;
var 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');
equals(nodelist.length,2,'div节点列表长度');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<div id="bb"><div id="cc"></div> </div>sdfadf','innerHTML内容');
});
test( 'innerHTML', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa">sdfadf</div>');
node.innerHTML('<div><div><div></div></div></div>');
var nodelist =node.getNodesByTagName('div');
equals(nodelist.length,3,'div节点列表长度');
for(var i= 0,ci;ci=nodelist[i++];){
ci.tagName = 'p';
}
equals(node.innerHTML(),'<p><p><p></p></p></p>','innerHTML内容');
});
test( 'innerText', function() {
var tmp = new UE.uNode.createElement('area');
tmp.innerHTML('<p></p>');
equals(tmp.innerText(),tmp,'标签类型特殊');
var tmp = new UE.uNode.createText('');
tmp.innerHTML('<p></p>');
equals(tmp.innerText(),tmp,'对象类型不为element');
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa">sdfadf</div>');
node.innerHTML('<p>dfsdfsdf<b>eee</b>sdf</p>');
equals(node.innerText(),'dfsdfsdfeeesdf','获取标签中纯文本');
});
test( 'getData', function() {
var tmp = new UE.uNode.createElement('div');
equals(tmp.getData(),'','element元素');
var tmp = new UE.uNode.createText('askdj');
equals(tmp.getData(),"askdj",'其他类型');
});
test( 'appendChild && insertBefore', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa">sdfadf</div>');
node.innerHTML('<p><td></td></p>');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p>');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p>','补全html标签');
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>');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div>','appendChild');
node.insertBefore(tmp,node.firstChild());
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<div></div><p><table><tbody><tr><td></td></tr></tbody></table></p>');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<div></div><p><table><tbody><tr><td></td></tr></tbody></table></p>','insertBefore');
node.appendChild(tmp);
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div>');
tmp = uNode.createElement('p');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div>','appendChild');
});
test( 'replaceChild && setAttr', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa">sdfadf</div>');
node.innerHTML('<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div>');
var 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>');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><p class="test" id="aa"></p><div></div>','setAttr不为空');
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>');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div><div></div>','replaceChild');
node.removeChild(node.lastChild(),true);
tmp = uNode.createElement('p');
tmp.setAttr();
node.insertAfter(tmp,node.lastChild());
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div><p></p>','setAttr为空');
node.innerHTML('<p><td></td></p>');
var tmp = uNode.createElement('div');
node.appendChild(tmp);
node.replaceChild(node.firstChild(),tmp);
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p>','replaceChild');
});
test( 'insertAfter', function() {
var uNode = UE.uNode;
var node = uNode.createElement('<div id="aa">sdfadf</div>');
node.innerHTML('<p><td></td></p>');
var tmp = uNode.createElement('div');
node.appendChild(tmp);
node.insertAfter(tmp,node.firstChild());
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<p><table><tbody><tr><td></td></tr></tbody></table></p><div></div>','在第一个子节点后插入');
});
test( 'getStyle', function() {
var uNode = UE.uNode;
var node = uNode.createElement('div');
node.innerHTML('<div style=""><div>');
node = node.firstChild();
equals(node.getStyle(''),'','空cssStyle');
node.innerHTML('<div style="border:1px solid #ccc"><div>');
node = node.firstChild();
equals(node.getStyle('border'),'1px solid #ccc');
equals(node.getStyle('border'),'1px solid #ccc','有border,取border样式');
node.innerHTML('<div style="border:1px solid #ccc"><div>');
node = node.firstChild();
equals(node.getStyle('color'),'','无color样式,取color样式');
node.innerHTML('<div style="border:1px solid #ccc;color:#ccc"><div>');
node = node.firstChild();
equals(node.getStyle('border'),'1px solid #ccc','有2个样式,取其一');
});
test( 'setStyle', function() {
var uNode = UE.uNode;
var node = uNode.createElement('div');
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');
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');
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);
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>','脚本转html');
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>','移除子节点');
});
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>')
test( 'getIndex', function() {
var uNode = UE.uNode;
var node = uNode.createElement('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)
equals(tmp.getIndex(),2,'节点索引');
});
\ No newline at end of file
......@@ -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();
......
/**
* Created by JetBrains PhpStorm.
* User: dongyancen
* Date: 13-2-28
* Time: 下午3:20
* To change this template use File | Settings | File Templates.
*/
module( 'plugins.defaultfilter' );
//TODO 现在在过滤机制里面去除无用的标签
test( "getContent--去除无用的空标签:autoClearEmptyNode==true", function() {
var editor = new UE.Editor({autoClearEmptyNode:true,'autoFloatEnabled':false});
stop();
setTimeout(function(){
var div = document.body.appendChild(document.createElement('div'));
editor.render(div);
te.dom.push(div);
editor.focus();
var innerHTML = '<span><span></span><strong>xx</strong><em>em</em><em></em></span><div>xxxx</div>';
editor.setContent( innerHTML );
editor.execCommand('source');
editor.execCommand('source');
equal( editor.getContent(), '<p><strong>xx</strong><em>em</em></p><div>xxxx</div>', "span style空,套空的em和不空的em" );
//style="color:#c4bd97;"
innerHTML = '<span style="color:#c4bd97"><span></span><strong>xx</strong><em>em</em><em></em></span>';
editor.setContent( innerHTML );
if(ua.browser.ie ==9){
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97;"><strong>xx</strong><em>em</em></span></p>', "span style不空,套空的em和不空的em" );
}
else{
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97"><strong>xx</strong><em>em</em></span></p>', "span style不空,套空的em和不空的em" );
}
innerHTML = '<span style="color:#c4bd97"></span><strong>xx</strong><em>em</em><em></em>';
editor.setContent( innerHTML );
/*inline标签上只要有属性就不清理*/
if(ua.browser.ie ==9){
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97;"></span><strong>xx</strong><em>em</em></p>', "span 有style但内容为空" );
}
else{
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97"></span><strong>xx</strong><em>em</em></p>', "span 有style但内容为空" );
}
innerHTML = '<span style="color:#c4bd97">asdf<strong>xx</strong><em>em</em><em></em></span>';
editor.setContent( innerHTML );
if(ua.browser.ie ==9){
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97;">asdf<strong>xx</strong><em>em</em></span></p>', "span 有style内容不空" );
}
else{
equal( editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97">asdf<strong>xx</strong><em>em</em></span></p>', "span 有style内容不空" );
}
innerHTML = '<a href="http://www.baidu.com"></a><a>a</a><strong>xx</strong><em>em</em><em></em>';
editor.setContent( innerHTML );
equal( editor.getContent(), '<p><a href="http://www.baidu.com"></a><a>a</a><strong>xx</strong><em>em</em></p>', "a 有href但内容为空,不过滤a标签" );
start()
},100);
} );
//editor.options.autoClearEmptyNode
test("getContent--不去除无用的空标签:autoClearEmptyNode==false", function() {
var editor = new UE.Editor({autoClearEmptyNode:false,'autoFloatEnabled':false});
stop();
setTimeout(function(){
var div = document.body.appendChild(document.createElement('div'));
editor.render(div);
te.dom.push(div);
editor.focus();
var innerHTML = '<span><span></span><strong>xx</strong><em>em</em><em></em><strong></strong></span>';
editor.setContent(innerHTML);
equal(editor.getContent().toLowerCase(), '<p><span><span></span><strong>xx</strong><em>em</em><em></em><strong></strong></span></p>', "span style空,套空的em和不空的em");
innerHTML = '<span style="color:#c4bd97"></span><strong>xx</strong><em>em</em><em></em><strong></strong>';
editor.setContent(innerHTML);
ua.manualDeleteFillData(editor.body);
if (ua.browser.ie == 9) {
equal(editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97;"></span><strong>xx</strong><em>em</em><em></em><strong></strong></p>', "span 有style但内容为空");
}
else {
equal(editor.getContent().toLowerCase(), '<p><span style="color:#c4bd97"></span><strong>xx</strong><em>em</em><em></em><strong></strong></p>', "span 有style但内容为空");
}
start();
},100);
});
test("getContent--转换空格,nbsp与空格相间显示", function() {
var editor = te.obj[1];
var div = te.dom[0];
editor.render(div);
editor.focus();
var innerHTML = '<div> x x x&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;&nbsp; &nbsp;</div>';
editor.setContent(innerHTML);
equal(editor.getContent(), '<div> x &nbsp;x &nbsp; x &nbsp; &nbsp;x &nbsp; &nbsp; </div>', "转换空格,nbsp与空格相间显示");
});
此差异已折叠。
......@@ -12,26 +12,39 @@ function getTable(str) {
div.id = "testTable";
document.body.appendChild(div);
}
div.innerHTML = "<table>" + str + "</table>";
div.innerHTML = "<table border='1'>" + str + "</table>";
return div.firstChild;
}
UT = UE.UETable;
test("create UETable",function(){
var table = getTable("<tr><td>ddd</td></tr>"),
ut = new UE.UETable(table);
ut = new UT(table);
ok(ut.table === table,"UT对象创建成功");
equal(ut.colsNum,1,"单元格列数为1");
equal(ut.rowsNum,1,"单元格行数为1");
ok(ut.colsNum == 1 && ut.rowsNum == 1,"单元格行、列数为1");
});
test("getMaxRows",function(){
var table = getTable("<tr><td>1</td><td>2</td><td>3</td></tr>" +
"<tr><td>1</td><td>2</td><td>3</td></tr>"),
ut = new UE.UETable(table);
ut = new UT(table);
var maxRows = ut.getMaxRows();
equal(maxRows,2,"最大行数为2");
table = getTable("<tr><td rowspan='2'>1</td><td>2</td><td rowspan='2'>3</td></tr>" +
table = getTable("<tr><td rowspan='3'>1</td><td>2</td><td rowspan='2'>3</td></tr>" +
"<tr><td>2</td></tr>");
ut = new UT(table);
maxRows = ut.getMaxRows();
equal(maxRows,3,"最大行数为3");
});
test("getMaxCols",function(){
var table = getTable("<tr><td>1</td><td>2</td><td>3</td></tr>" +
"<tr><td>1</td><td>2</td><td>3</td></tr>"),
ut = new UT(table);
var maxCols = ut.getMaxCols();
equal(maxCols,3,"最大列数为3");
table = getTable("<tr><td rowspan='3'>1</td><td>2</td><td rowspan='2'>3</td></tr>" +
"<tr><td>2</td><td colspan='3'></td></tr>");
ut = new UT(table);
maxCols = ut.getMaxCols();
equal(maxCols,6,"最大列数为6");
});
\ No newline at end of file
此差异已折叠。
......@@ -2,7 +2,7 @@ function run( kiss, runnext ) {
window.document.title = kiss;
var wb = window.brtest = window.brtest || {};
wb.timeout = wb.timeout || 30000;
wb.timeout = wb.timeout || 50000;
wb.breakOnError = /breakonerror=true/gi.test( location.search )
|| $( 'input#id_control_breakonerror' ).attr( 'checked' );
wb.runnext = /batchrun=true/gi.test( location.search ) || runnext
......
......@@ -42,11 +42,11 @@
var langImgPath = editor.options.langPath + editor.options.lang + "/images/";
//针对静态资源
for ( var i in lang.static ) {
for ( var i in lang["static"] ) {
var dom = $G( i );
if(!dom) continue;
var tagName = dom.tagName,
content = lang.static[i];
content = lang["static"][i];
if(content.src){
//clone
content = utils.extend({},content,false);
......
......@@ -40,4 +40,80 @@
width: 14px;
height: 14px;
margin: 0;
}
.edui-default .edui-colorpicker-advbtn{
display: block;
text-align: center;
cursor: pointer;
height:20px;
}
.arrow_down{
background: white url('../images/arrow_down.png') no-repeat center;
}
.arrow_up{
background: white url('../images/arrow_up.png') no-repeat center;
}
/*高级的样式*/
.edui-colorpicker-adv{
position: relative;
overflow: hidden;
height: 180px;
display: none;
}
.edui-colorpicker-plant, .edui-colorpicker-hue {
border: solid 1px #666;
}
.edui-colorpicker-pad {
width: 150px;
height: 150px;
left: 14px;
top: 13px;
position: absolute;
background: red;
overflow: hidden;
cursor: crosshair;
}
.edui-colorpicker-cover{
position: absolute;
top: 0;
left: 0;
width: 150px;
height: 150px;
background: url("../images/tangram-colorpicker.png") -160px -200px;
}
.edui-colorpicker-padDot{
position: absolute;
top: 0;
left: 0;
width: 11px;
height: 11px;
overflow: hidden;
background: url(../images/tangram-colorpicker.png) 0px -200px repeat-x;
z-index: 1000;
}
.edui-colorpicker-sliderMain {
position: absolute;
left: 171px;
top: 13px;
width: 19px;
height: 152px;
background: url(../images/tangram-colorpicker.png) -179px -12px no-repeat;
}
.edui-colorpicker-slider {
width: 100%;
height: 100%;
cursor: pointer;
}
.edui-colorpicker-thumb{
position: absolute;
top: 0;
cursor: pointer;
height: 3px;
left: -1px;
right: -1px;
border: 1px solid black;
background: white;
opacity: .8;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册