📄 script_editor.js
字号:
return currentRow;}//This is a utility function to return the number of cells in one row.//Nested table in a row is considered as one cell. function IBM_RTE_getNumOfCells(editorName, tagName, nextRow) { var currentRow = IBM_RTE_getCurrentRow(editorName); var cells; if(!nextRow || (nextRow && (currentRow.nextSibling != 'null' && currentRow.nextSibling != 'undefined'))){ if(tagName == 'TH') cells = currentRow.getElementsByTagName("TH"); else cells = currentRow.getElementsByTagName("TD"); }else{ var row1; if(currentRow.nextSibling != 'null' && currentRow.nextSibling != 'undefined'){ row1 = currentRow.nextSibling; if(tagName == 'TH') cells = currentRow.nextSibling.getElementsByTagName("TH"); else cells = currentRow.nextSibling.getElementsByTagName("TD"); } else{ } } // Can not return cells.length directly because if there is // a sub-table embedded, the cells.length will include the sub // table cells. Using nextSibling can solve this issue. // See below. var j=0; if (cells.length > 0) { var cellNode = cells[0]; if (IBM_RTE_isMozilla()) { for (;;) { if (cellNode!=null && cellNode.nodeName == tagName){ j++; cellNode = cellNode.nextSibling; }else { break; } } } else { for (;;) { if (cellNode!=null && cellNode.tagName == tagName){ j++; cellNode = cellNode.nextSibling; }else { break; } } } } if(nextRow && (currentRow.nextSibling != 'null' && currentRow.nextSibling != 'undefined')) return j-1; else return j;}//Utility function to create a new cell.//In Mozilla, <BR> has to be added in each cell.function IBM_RTE_createNewCell(editorName, thCell) { // In Mozilla, the new cell needs to add a <br> to a new cell. var doc = IBM_RTE_getDocument(editorName); var newCell; if(thCell) newCell = doc.createElement("TH"); else newCell = doc.createElement("TD"); if (IBM_RTE_isMozilla()) { var brElem = doc.createElement("BR"); newCell.appendChild(brElem); }else{ newCell.insertAdjacentText("afterBegin"," "); } return newCell;}function IBM_RTE_deleteRow(editorName, text, error_rowDelete) { var currentRow = IBM_RTE_getCurrentRow(editorName); if (currentRow == null) return; var numOfTDCells = IBM_RTE_getNumOfCells(editorName,"TD",false); if(numOfTDCells == 0){ alert(error_rowDelete); return; } if(IBM_RTE_isMozilla() || IBM_RTE_isNetscape()){ var ret = confirm(text); if (!ret) { return; } } var container = currentRow.parentNode; container.removeChild(currentRow); //When child nodes in TBODY is 0, delete the whole table. if (container.nodeName == "TBODY" && container.childNodes.length == 0){ var parTable = container.parentNode; parTable.parentNode.removeChild(parTable); }}function IBM_RTE_insertRowAbove(editorName, error_rowInsert) { if(!IBM_RTE_isMozilla()){ if(isAccessible) this.opener.IBM_RTE_backup(editorName); else IBM_RTE_backup(editorName); } var currentRow = IBM_RTE_getCurrentRow(editorName); if (currentRow == null) return; var numOfTHCells = IBM_RTE_getNumOfCells(editorName,"TH",false); var numOfTDCells = IBM_RTE_getNumOfCells(editorName,"TD",false); // find if currentRow is a header row.. var prevRow = currentRow.previousSibling; var isTHCell = false; if(prevRow == null || prevRow == 'undefined'){ // see if it is a purely Header Row if( (numOfTHCells + numOfTDCells) == numOfTHCells){ alert(error_rowInsert); // Put the resource bundle error msg. return; } } var newRow = IBM_RTE_getDocument(editorName).createElement("TR"); for (i=0; i<numOfTHCells; i++) { var col = IBM_RTE_createNewCell(editorName, true); newRow.appendChild(col); } for (i=0; i<numOfTDCells; i++) { var col= IBM_RTE_createNewCell(editorName, false); newRow.appendChild(col); } var container = currentRow.parentNode; var newRow=container.insertBefore(newRow, currentRow); newRow.focus();}function IBM_RTE_insertRowBelow(editorName) { if(!IBM_RTE_isMozilla()){ if(isAccessible) this.opener.IBM_RTE_backup(editorName); else IBM_RTE_backup(editorName); } var currentRow = IBM_RTE_getCurrentRow(editorName); if (currentRow == null) return; var numOfTHCells = IBM_RTE_getNumOfCells(editorName,"TH",false); var numOfTDCells = IBM_RTE_getNumOfCells(editorName,"TD",false); if (numOfTDCells == 0) { var numTDCells = IBM_RTE_getNumOfCells(editorName,"TD", true); var numTHCells = IBM_RTE_getNumOfCells(editorName,"TH", true); if(numTDCells == -1) { numOfTDCells = numOfTHCells -1; numOfTHCells = 1; }else{ numOfTHCells = numTHCells; numOfTDCells = numTDCells; } } var newRow = IBM_RTE_getDocument(editorName).createElement("TR"); for (i=0; i<numOfTHCells; i++) { var col = IBM_RTE_createNewCell(editorName, true); newRow.appendChild(col); } for (i=0; i<numOfTDCells; i++) { var col = IBM_RTE_createNewCell(editorName,false); newRow.appendChild(col); } var container = currentRow.parentNode; var prevRow = currentRow.nextSibling; var newRow=container.insertBefore(newRow, prevRow); newRow.focus();}//Utility function to return the cellIndex in the current row. // Cell index starts from 0.function IBM_RTE_getColumnIndex(editorName) { var selRange = IBM_RTE_getSelectionRange(editorName); var currentCell; if (IBM_RTE_isMozilla()) { currentCell = selRange.startContainer; var strName = currentCell.nodeName; while(strName != "TD" && strName != "TH") { currentCell = currentCell.parentNode; if (currentCell == null) return null; strName = currentCell.nodeName; } } else { currentCell = selRange.parentElement(); var strName = currentCell.tagName; while(strName != "TD" && strName != "TH") { currentCell = currentCell.parentNode; if (currentCell == null) return null; strName = currentCell.tagName; } } return currentCell.cellIndex;}//Utility function to return the current table.function IBM_RTE_getTable(editorName) { var currRow = IBM_RTE_getCurrentRow(editorName); if (currRow == null) return null; var currTable; if (IBM_RTE_isMozilla()) { currTable = currRow.parentNode.parentNode; } else { currTable = currRow.parentNode; var strName = currTable.tagName; while(strName != "TABLE") { currTable = currTable.parentNode; strName = currTable.tagName; } } return currTable;}function IBM_RTE_deleteColumn(editorName, text, error_columnDelete) { var currColIndex = IBM_RTE_getColumnIndex(editorName); var currTable = IBM_RTE_getTable(editorName); if (currTable == null) return; var rows = currTable.rows; var numOfRows = rows.length // check to see if the first col is the header. if(currColIndex == 0){ var numOfTHCells = 0; var numOfTDCells = 0; // check to see if the coulmn is header col. for (var k = 0 ; k < numOfRows ; k++ ){ var row = rows[k]; var col = row.cells[currColIndex]; var tagname; if(IBM_RTE_isMozilla()) tagname = col.nodeName; else tagname = col.tagName; if(tagname == 'TH') numOfTHCells++; else numOfTDCells++; } if (numOfTDCells == 0) { alert(error_columnDelete); return; } } if(IBM_RTE_isMozilla() || IBM_RTE_isNetscape()){ var ret = confirm(text); if (!ret) { return; } } for (i=0; i<numOfRows; i++) { var rowElement = rows[i]; if (rowElement.cells.length > currColIndex) { var cellNode = rowElement.cells[currColIndex]; rowElement.removeChild(cellNode); } } if (rows[0].cells.length == 0) { // When a row has no cell, delete the whole table; var parNode = currTable.parentNode; parNode.removeChild(currTable); }}function IBM_RTE_insertColumn(isLeft, editorName, error_columnInsert) { if(!IBM_RTE_isMozilla()){ if(isAccessible) this.opener.IBM_RTE_backup(editorName); else IBM_RTE_backup(editorName); } var currColIndex = IBM_RTE_getColumnIndex(editorName); var currTable = IBM_RTE_getTable(editorName); if (currTable == null) return; var rows = currTable.rows; var numOfRows = rows.length; var numOfTHCells = 0; var numOfTDCells = 0; // check to see if the coulmn is header col. for (var k = 0 ; k < numOfRows ; k++ ){ var row = rows[k]; var col = row.cells[currColIndex]; var tagname; if(IBM_RTE_isMozilla()) tagname = col.nodeName; else tagname = col.tagName; if(tagname == 'TH') numOfTHCells++; else numOfTDCells++; } if ((numOfTDCells == 0) && isLeft){ alert(error_columnInsert); return; } if(currColIndex == 0 && (row.cells[currColIndex+1] == null || row.cells[currColIndex+1] == 'undefined')){ numOfTHCells = 1; numOfTDCells = numOfRows -1; }else if(currColIndex == 0){ numOfTHCells = 0; numOfTDCells = 0; for (var k = 0 ; k < numOfRows ; k++ ){ var row = rows[k]; var col = row.cells[currColIndex+1]; var tagname; if(IBM_RTE_isMozilla()) tagname = col.nodeName; else tagname = col.tagName; if(tagname == 'TH') numOfTHCells++; else numOfTDCells++; } } for (i=0; i<numOfRows; i++) { var rowElement = rows[i]; if (rowElement.cells.length > currColIndex) { var cellNode = rowElement.cells[currColIndex]; var newCell; if((numOfTHCells > 0) && (i < numOfTHCells)) newCell = IBM_RTE_createNewCell(editorName, true); else newCell = IBM_RTE_createNewCell(editorName, false); if (isLeft) { rowElement.insertBefore(newCell, cellNode); } else { if (rowElement.cells.length == currColIndex + 1) { rowElement.appendChild(newCell); } else { cellNode = rowElement.cells[currColIndex + 1]; rowElement.insertBefore(newCell, cellNode); } } } } //End of for loop.}function IBM_RTE_insertColumnLeft(editorName, error_columnInsert) { IBM_RTE_insertColumn(true, editorName, error_columnInsert); }function IBM_RTE_insertColumnRight(editorName, error_columnInsert) { IBM_RTE_insertColumn(false, editorName, error_columnInsert); }// In IE, when move from one op to another, the selRange.parentElement // becomes BODY for the second op. You have to reselect a cell using // mouse or keyboard. This seems like an IE bug. // Mozilla does not have this problem. // The following two functions are to prove this.function IBM_RTE_insertColumnLeft1(editorName) { var selRange = IBM_RTE_getSelectionRange(editorName);}function IBM_RTE_insertColumnRight1(editorName) { var selRange = IBM_RTE_getSelectionRange(editorName);}//Other issues with the advanced table support:// 1. After delete a row/column, the selection goes away. This makes sense.// 2. Undo/redo does not take effect since these new functions are DOM manipulation.function IBM_RTE_insertPageBreak(editorName){ if(!IBM_RTE_isMozilla()){ if(isAccessible) this.opener.IBM_RTE_backup(editorName); else{ IBM_RTE_backup(editorName); IBM_RTE_getWindow(editorName).focus(); } } var rand = Math.round(Math.random()*100000000000000000); var pageBreakID = "pagebreak_"+rand; var rng = IBM_RTE_getSelectionRange(editorName); newNode = IBM_RTE_getDocument(editorName).createElement("div"); if (IBM_RTE_isMozilla()) { //Since Mozilla does not support contentEditable attribute, //per M. Kaply's suggestion, use <HR> as the page break indicator. newNode.setAttribute("id", pageBreakID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -