tableDom.js (3853B)
1 /* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 4 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 var count = 1; 7 function genName(prefix) { 8 return "X" + count++ + "\n"; 9 } 10 11 function appendCell(aRow, aRowSpan, aColSpan) { 12 var cell = document.createElement("TD", null); 13 cell.rowSpan = aRowSpan; 14 cell.colSpan = aColSpan; 15 var text = document.createTextNode(genName()); 16 cell.appendChild(text); 17 aRow.appendChild(cell); 18 } 19 20 function appendCellAt(aRowIndex, aRowSpan, aColSpan) { 21 var row = document.getElementsByTagName("TR")[aRowIndex]; 22 appendCell(row, aRowSpan, aColSpan); 23 } 24 25 function insertCell(aRow, aColIndex, aRowSpan, aColSpan) { 26 var cells = aRow.cells; 27 var refCell = cells.item(aColIndex); 28 var newCell = document.createElement("TD", null); 29 newCell.rowSpan = aRowSpan; 30 newCell.colSpan = aColSpan; 31 var text = document.createTextNode(genName()); 32 newCell.appendChild(text); 33 aRow.insertBefore(newCell, refCell); 34 //dump("SCRIPT: inserted CELL as first cell in first row\n"); 35 } 36 37 function insertCellAt(aRowIndex, aColIndex, aRowSpan, aColSpan) { 38 var row = document.getElementsByTagName("TR")[aRowIndex]; 39 insertCell(row, aColIndex, aRowSpan, aColSpan); 40 } 41 42 function deleteCell(aRow, aColIndex) { 43 aRow.deleteCell(aColIndex); 44 } 45 46 function deleteCellAt(aRowIndex, aColIndex) { 47 var row = document.getElementsByTagName("TR")[aRowIndex]; 48 deleteCell(row, aColIndex); 49 } 50 51 //function appendRow(aRowGroup) { 52 // var row = document.createElement("TR", null); 53 // cell = document.createElement("TD", null); 54 // row.appendChild(cell); 55 // aRowGroup.appendChild(row); 56 //} 57 58 function appendRow(aRowGroup) { 59 var row = document.createElement("TR", null); 60 cell = document.createElement("TD", null); 61 aRowGroup.appendChild(row); 62 //row.appendChild(cell); 63 //appendCell(row, 1, 1); 64 } 65 66 function appendRowAt(aRowGroupIndex) { 67 var rowGroup = document.getElementsByTagName("TBODY")[aRowGroupIndex]; 68 appendRow(rowGroup); 69 } 70 71 function insertRow(aRowGroup, aRowIndex) { 72 var rows = aRowGroup.rows; 73 var refRow = rows.item(aRowIndex); 74 var row = document.createElement("TR", null); 75 aRowGroup.insertBefore(row, refRow); 76 //appendCell(row, 1, 1); 77 } 78 79 function insertRowAt(aRowGroupIndex, aRowIndex) { 80 var rowGroup = document.getElementsByTagName("TBODY")[aRowGroupIndex]; 81 insertRow(rowGroup, aRowIndex); 82 } 83 84 function deleteRow(aRowGroup, aRowIndex) { 85 aRowGroup.deleteRow(aRowIndex); 86 } 87 88 function deleteRowAt(aRowGroupIndex, aRowIndex) { 89 var row = document.getElementsByTagName("TBODY")[aRowGroupIndex]; 90 deleteRow(row, aRowIndex); 91 } 92 93 function insertTbody(aTable, aTbodyIndex) { 94 var tbodies = aTable.tBodies; 95 var refTbody = tbodies.item(aTbodyIndex); 96 var tbody = document.createElement("TBODY", null); 97 aTable.insertBefore(tbody, refTbody); 98 } 99 100 function insertTbodyAt(aTableIndex, aTbodyIndex) { 101 var table = document.getElementsByTagName("TABLE")[aTableIndex]; 102 insertTbodyAt(table, aTbodyIndex); 103 } 104 105 function deleteTbody(aTable, aTbodyIndex) { 106 var tbodies = aTable.tBodies; 107 var tbody = tbodies.item(aTbodyIndex); 108 aTable.removeChild(tbody); 109 } 110 111 function deleteTbodyAt(aTableIndex, aTbodyIndex) { 112 var table = document.getElementsByTagName("TABLE")[aTableIndex]; 113 deleteTbody(table, aTbodyIndex); 114 } 115 116 function buildTable(aNumRows, aNumCols) { 117 var table = document.getElementsByTagName("TABLE")[0]; 118 for (rowX = 0; rowX < aNumRows; rowX++) { 119 var row = document.createElement("TR", null); 120 for (colX = 0; colX < aNumCols; colX++) { 121 var cell = document.createElement("TD", null); 122 var text = document.createTextNode(genName()); 123 cell.appendChild(text); 124 row.appendChild(cell); 125 } 126 table.appendChild(row); 127 } 128 }