Revision: 3839
Author: metaweta
Date: Wed Nov 11 10:18:11 2009
Log: Fix 1153: add cellIndex, tbody.insertRow and deleteRow
http://codereview.appspot.com/151049
Fix 1153: add cellIndex, tbody.insertRow and deleteRow
[email protected]
http://code.google.com/p/google-caja/source/detail?r=3839
Modified:
/trunk/src/com/google/caja/plugin/domita.js
/trunk/tests/com/google/caja/plugin/domita_test_untrusted.html
=======================================
--- /trunk/src/com/google/caja/plugin/domita.js Mon Nov 9 19:39:03 2009
+++ /trunk/src/com/google/caja/plugin/domita.js Wed Nov 11 10:18:11 2009
@@ -2780,8 +2780,8 @@
TameElement.call(this, node, editable, editable);
classUtils.exportFields(
this,
- ['colSpan', 'cells', 'rowSpan', 'rows', 'rowIndex', 'align',
- 'vAlign', 'nowrap', 'sectionRowIndex']);
+ ['colSpan', 'cells', 'cellIndex', 'rowSpan', 'rows', 'rowIndex',
+ 'align', 'vAlign', 'nowrap', 'sectionRowIndex']);
}
___.extend(TameTableCompElement, TameElement);
TameTableCompElement.prototype.getColSpan = function () {
@@ -2796,6 +2796,9 @@
return tameNodeList(
this.node___.cells, this.editable___, defaultTameNode);
};
+ TameTableCompElement.prototype.getCellIndex = function () {
+ return this.node___.cellIndex;
+ };
TameTableCompElement.prototype.getRowSpan = function () {
return this.node___.rowSpan;
};
@@ -2837,6 +2840,18 @@
this.node___.nowrap = newValue;
return newValue;
};
+ TameTableCompElement.prototype.insertRow = function (index) {
+ if (!this.editable___) { throw new Error(NOT_EDITABLE); }
+ requireIntIn(index, -1, this.node___.rows.length);
+ return defaultTameNode(this.node___.insertRow(index),
this.editable___);
+ };
+ TameTableCompElement.prototype.deleteRow = function (index) {
+ if (!this.editable___) { throw new Error(NOT_EDITABLE); }
+ requireIntIn(index, -1, this.node___.rows.length);
+ this.node___.deleteRow(index);
+ };
+ ___.all2(___.grantTypedMethod, TameTableCompElement.prototype,
+ ['insertRow', 'deleteRow']);
function requireIntIn(idx, min, max) {
if (idx !== (idx | 0) || idx < min || idx > max) {
=======================================
--- /trunk/tests/com/google/caja/plugin/domita_test_untrusted.html Mon Nov
9 19:39:03 2009
+++ /trunk/tests/com/google/caja/plugin/domita_test_untrusted.html Wed Nov
11 10:18:11 2009
@@ -438,6 +438,7 @@
<div class="testcontainer" id="test-row-cell">
Test row cell
<table id="test-row-cell-1">
+ <tbody id="test-row-cell-2"></tbody>
</table>
</div>
@@ -3000,17 +3001,28 @@
assertEquals(table.rows.length, 1);
assertEquals(0, table.rows.item(0).cells.length);
table.rows.item(0).insertCell(-1);
- table.rows.item(0).insertCell(-1);
+ var cell = table.rows.item(0).insertCell(-1);
+ assertEquals(1, cell.cellIndex);
assertEquals(2, table.rows.item(0).cells.length);
table.rows.item(0).deleteCell(1);
table.rows.item(0).deleteCell(0);
assertEquals(0, table.rows.item(0).cells.length);
- try{
+ var tableDeleteRow = false, tbodyDeleteRow = false;
+ try {
table.deleteRow(2);
- } catch(e) {
+ } catch (e) {
assertEquals('Index size error.', e.message);
- }
- pass('test-row-cell');
+ tableDeleteRow = true;
+ }
+ try {
+ document.getElementById('test-row-cell-2').deleteRow(2);
+ } catch (e) {
+ assertEquals('Index size error.', e.message);
+ tbodyDeleteRow = true;
+ }
+ if (tableDeleteRow === true && tbodyDeleteRow === true) {
+ pass('test-row-cell');
+ }
});
jsunitRegister('testNegativeIndices',