📄 table_tools.js
字号:
/*
* Samuels [Xoops Project]
*
*
*
// $Id: table_tools.js,v 1.1.2.1 2005/06/04 02:11:53 phppp Exp $
*
*/
//-----------------------------------CLASSES-------------------------------------------
//Class table
function XK_table(id)
{
this.id = id;
this.rows = 0;
this.columns = 0;
this.width = 200;
this.widthUnits = 'px';
this.height = 100;
this.heightUnits= 'px';
this.border = 1;
this.halignment = '';
this.valignment = '';
this.spacing = 0;
this.padding = 1;
this.head = false;
};
//Class tableNode
function XK_tableNode (id)
{
this.id = id;
this.td = this.getTd(); if (this.td==null) return;
this.table = this.getTable();
this.rowSelect = this.td.parentNode;
this.tableSelect= this.rowSelect.parentNode;
};
//-----------------------------------END CLASSES-------------------------------------------
//Functions for doing things
function XK_useTableOps(Option,id)
{
myTableNode = new XK_tableNode(id);
if (myTableNode.td==null)return;
if (Option=='TableOps')XK_showHideDiv(id,'tpropbutton','TableOps');
else
{
eval('myTableNode.'+Option+''+'()');
}
};
//---------------------------DIVS AND POPUPS------------------------------------------
function XK_useTableDivs(id,option)
{
myTableNode = new XK_tableNode(id);
if (myTableNode.td==null)return;
switch(option)
{
case 'borders':
XK_showHideDiv(id,'cbbutton','CellBorders');
break;
case 'align':
XK_showHideDiv(id,'cellpropbutton','CellAlign');
break;
}
}
//---------------------------END DIVS AND POPUPS------------------------------------------
function XK_isInsideCell(id)
{
myTableNode = new XK_tableNode(id);
if (myTableNode.td==null)return false;
else return true;
};
function XK_CellColor(id,color)
{
myTableNode = new XK_tableNode(id);
if (myTableNode.td==null)return;
myTableNode.td.bgColor=color;
};
function XK_TTools(id,url,name,width,height)
{
myTableNode = new XK_tableNode(id);
if (myTableNode.td==null)return;
else XK_openPopup(url,name,width,height);
return;
};
function XK_cellAlign(id,Halign,Valign)
{
myTableNode = new XK_tableNode(id);
if (myTableNode.td==null)return;
myTableNode.td.align=Halign;
myTableNode.td.vAlign=Valign;
};
function XK_quickBorders(id,borders,color)
{
myTableNode = new XK_tableNode(id);
if (myTableNode.td==null)return;
var style='1px solid '+color;
switch(borders)
{
case 'all':
myTableNode.td.style.borderLeft= style;
myTableNode.td.style.borderRight= style;
myTableNode.td.style.borderBottom= style;
myTableNode.td.style.borderTop= style;
break;
case 'none':
myTableNode.td.style.borderLeft= 'none';
myTableNode.td.style.borderRight= 'none';
myTableNode.td.style.borderBottom= 'none';
myTableNode.td.style.borderTop= 'none';
break;
case 'top':
myTableNode.td.style.borderTop= style;
break;
case 'left':
myTableNode.td.style.borderLeft= style;
break;
case 'right':
myTableNode.td.style.borderRight= style;
break;
case 'bottom':
myTableNode.td.style.borderBottom= style;
break;
}
};
function XK_Easytable(id,rows,columns)
{
var iframeId='iframe'+id;
myTable = new XK_table(id);
myTable.rows = rows;
myTable.columns = columns;
document.getElementById(iframeId).contentWindow.focus();
myTable.createTable();
};
function XK_createTable(id,table)
{
myTable = new XK_table(id);
myTable.rows = table.rows;
myTable.columns = table.columns;
myTable.spacing = table.spacing;
myTable.padding = table.padding;
myTable.border = table.border;
myTable.width = table.width;
myTable.widthUnits = "px";
myTable.height = table.height;
myTable.heightUnits = "px";
myTable.createTable();
};
//--------------------------------CONSTRUCTORS----------------------------------------
XK_table.prototype.createTable = function()
{
rows = this.rows;
cols = this.columns;
head = false;
border = this.border+'px';
spacing = this.spacing+'px';
padding = this.padding+'px';
width = this.width+''+this.widthUnits;
height = this.height+''+this.heightUnits;
if ((rows > 0) && (cols > 0))
{
table = ' <table style=\x22height: '+height+'; width: '+width+';\x22 cellspacing='+spacing+' cellpadding='+padding+' border=' + border + '>';
for (var i=0; i < rows; i++)
{
table = table + ' <tr>';
for (var j=0; j < cols; j++)
{
if(i==0 && head=='1')
{
table += ' <th> </th>';
}
else
{
table += ' <td> </td>';
}
}
table += ' </tr>';
}
table += ' </table><br>';
XK_insertHTML(table,this.id);
}
};
XK_tableNode.prototype.deleteCol = function()
{
if (this.td.parentNode.cells.length == 1)
{
if (isie)
{
this.table.removeNode(true);
}
return;
}
var lines= this.tableSelect.rows;
var colx= this.getColumnNo(this.td);
var rspan= new Array();
var newCell;
var cs;
for(var i=0; i<lines.length; i++)
{
row= this.tableSelect.rows[i];
idx=0;
for(var j=0; j<=colx ; j++)
{
if(!rspan[j+idx])rspan[j+idx]=0;
while(rspan[j+idx]){rspan[j+idx]--; idx++ }
if(row.cells[j]) rspan[j+idx]=row.cells[j].rowSpan-1;
if(!row.cells[j] || (j+idx>=colx) )
{
if(isie)
{
if(row.cells[j-1]) cs=row.cells[j-1].colSpan;
else cs=1;
}else cs=1;
if(cs==1) row.deleteCell(j);
else row.cells[j-1].colSpan -= 1;
break ;
}
idx += row.cells[j].colSpan-1;
}
}
};
XK_tableNode.prototype.deleteRow = function()
{
//if number of rows=1 don't do anything under gecko and remove table under iexplore
var nr=this.table.rows.length;
if (nr==1)
{
if(isie)this.table.removeNode(true);
return;
}
var ridx = this.rowSelect.rowIndex;
var row = this.rowSelect;
var rlen= row.cells.length;
for(var i=0; i<rlen; i++)
{
if(row.cells[i].rowSpan>1)
{
var newCell= this.tableSelect.rows[ridx+1].insertCell(i);
newCell.rowSpan= row.cells[i].rowSpan - 1 ;
newCell.innerHTML= row.cells[i].innerHTML ;
row.cells[i].rowSpan =1;
}
}
while(row.cells.length) { row.deleteCell(0); }
for(var i=0; i<=ridx; i++)
{
row= this.tableSelect.rows[i];
for(var j=0; j<row.cells.length; j++)
{
if(row.cells[j].rowSpan>1 && i+row.cells[j].rowSpan>ridx)
row.cells[j].rowSpan -= 1;
}
}
if(row.cells.length==0) this.tableSelect.deleteRow(ridx);
};
XK_tableNode.prototype.deleteCell = function()
{
var col= this.td.cellIndex;
this.rowSelect.deleteCell(col);
this.td = this.rowSelect.cells[col];
if(!this.td) this.td = this.rowSelect.cells[col-1];
};
XK_tableNode.prototype.decreaseRowSpan = function()
{
var rowSpan= this.td.rowSpan;
var rowNum= this.tableSelect.rows.length;
var ridx= this.rowSelect.rowIndex+rowSpan-1; // next
var colx= this.getColumnNo(this.td) ; // current
var rowNext= this.tableSelect.rows[ridx];
var cidx=getCellIndex(colx, rowNext); // Next
this.td.rowSpan -= 1;
var newCell= rowNext.insertCell(cidx,1);
newCell.innerHTML= ' ' ;
rowNext.cells[cidx].colSpan = this.td.colSpan;
};
XK_tableNode.prototype.increaseRowSpan = function()
{
var rowSpan= this.td.rowSpan;
var rowNum= this.tableSelect.rows.length;
var ridx= this.rowSelect.rowIndex+rowSpan; // next
if( ridx>=rowNum) return;
var colx= this.getColumnNo(this.td) ; // current
var rowNext= this.tableSelect.rows[ridx];
var cidx=getCellIndex(colx, rowNext); // Next
var cellNext= rowNext.cells[cidx];
if(!cellNext) return;
var coln= this.getColumnNo(cellNext) ; // cell Next row
if(coln != colx || cellNext.colSpan != this.td.colSpan )return;
this.td.rowSpan += rowNext.cells[cidx].rowSpan;
this.td.innerHTML += rowNext.cells[cidx].innerHTML;
rowNext.deleteCell(cidx);
};
XK_tableNode.prototype.increaseSpan = function()
{
var cidx= this.td.cellIndex;
var row= this.td.parentNode;
var nxt= row.cells[cidx+1];
if(!nxt) return;
var maxcol= this.getMaxColumn();
var colx= this.getColumnNo(this.td) ; // current
var coln= this.getColumnNo(nxt) ; // next
if(colx+this.td.colSpan>=maxcol || colx+this.td.colSpan<coln || this.td.rowSpan != nxt.rowSpan) return;
this.td.innerHTML += nxt.innerHTML;
this.td.colSpan += nxt.colSpan;
row.deleteCell(cidx+1);
};
XK_tableNode.prototype.decreaseSpan = function()
{
if(this.td.colSpan==1) return;
var col= this.td.cellIndex;
this.td.colSpan -= 1;
var newCell= this.td.parentNode.insertCell(col+1,1);
newCell.innerHTML= ' ' ;
newCell.rowSpan= this.td.rowSpan ;
};
XK_tableNode.prototype.insertCol = function()
{
var lines= this.tableSelect.rows;
var colx= this.getColumnNo(this.td);
var rspan= new Array();
var newCell, cs,rc ;
for(var i=0; i<lines.length; i++)
{
row= this.tableSelect.rows[i];
idx=0;
for(var j=0; j<=colx ; j++) // j= cellIndex
{
if(!rspan[j+idx])rspan[j+idx]=0;
while(rspan[j+idx]){rspan[j+idx]--; idx++ }
if(row.cells[j]) rspan[j+idx]=row.cells[j].rowSpan-1;
if(!row.cells[j] || (j+idx>=colx) )
{
if(isie)
{
if(row.cells[j-1]) cs=row.cells[j-1].colSpan;
else cs=1;
}else cs=1;
if(cs==1)
{
newCell=row.insertCell(j);
newCell.innerHTML=' ';
break;
}
else
{
row.cells[j-1].colSpan += 1;
break ;
}
}
idx += row.cells[j].colSpan-1;
}
}
};
XK_tableNode.prototype.insertCell = function()
{
var newCell= this.rowSelect.insertCell(this.td.cellIndex+1,1);
newCell.innerHTML= this.td.innerHTML ;
};
XK_tableNode.prototype.insertRow = function()
{
var ridx= this.rowSelect.rowIndex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -