提交 40d2e2a9 编写于 作者: T taoqili

table.core

上级 2ec52cce
......@@ -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);
......
......@@ -749,11 +749,11 @@
queryCommandState:function () {
var me = this,
tableItems = getTableItemsByRange(me);
if(!tableItems.cell) return -1;
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;
for (var i = 0, cell; cell = cells[i++];) {
if (cell.rowSpan != 1 || cell.colSpan != 1) return -1;
}
return 0;
},
......@@ -770,32 +770,51 @@
this.fireEvent("tableForbidSort");
return;
}
ut.sortTable(cellIndex,fn);
ut.sortTable(cellIndex, fn);
range.moveToBookmark(bk).select();
}
};
UE.commands["enablesort"] = UE.commands["disablesort"] = {
queryCommandState:function(){
return getTableItemsByRange(this).table ? 0:-1;
queryCommandState:function () {
return getTableItemsByRange(this).table ? 0 : -1;
},
execCommand:function(cmd){
execCommand:function (cmd) {
var table = getTableItemsByRange(this).table;
table.setAttribute("data-sort",cmd == "enablesort" ? "sortEnabled":"sortDisabled");
table.setAttribute("data-sort", cmd == "enablesort" ? "sortEnabled" : "sortDisabled");
}
};
UE.commands["settablebackground"] = {
queryCommandState:function(){
return getTableItemsByRange(this).table ? 0: -1;
queryCommandState:function () {
return getTableItemsByRange(this).table ? 0 : -1;
},
execCommand:function(cmd,value,cells){
cells = cells|| getSelectedArr(this);
var ut = getUETable(cells[0]);
ut.setBackground(cells,value);
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[""] = {
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) {
......@@ -819,6 +838,6 @@
function getSelectedArr(editor) {
var cell = getTableItemsByRange(editor).cell,
ut = getUETable(cell);
return ut.selectedTds.length ? ut.selectedTds:[cell];
return ut.selectedTds.length ? ut.selectedTds : [cell];
}
})();
\ No newline at end of file
......@@ -1036,8 +1036,30 @@
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 = value;
cell.style.backgroundColor = "";
})
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册