Skip to content

Commit

Permalink
added steven wood's implementation of tables and related elements. th…
Browse files Browse the repository at this point in the history
…anks and sorry for the delay.
  • Loading branch information
thatcher committed May 20, 2009
1 parent 0dd3a51 commit 16506da
Show file tree
Hide file tree
Showing 9 changed files with 1,212 additions and 127 deletions.
267 changes: 242 additions & 25 deletions dist/env.0.9.5.js
Expand Up @@ -3712,12 +3712,16 @@ function __parseLoop__(impl, doc, p) {
throw(new DOMException(DOMException.SYNTAX_ERR));
}
else if(iEvt == XMLP._NONE) { // no more events
if (iNodeParent == doc) { // confirm that we have recursed back up to root
//steven woods notes that unclosed tags are rejected elsewhere and this check
//breaks a table patching routine
/*if (iNodeParent == doc) { // confirm that we have recursed back up to root
break;
}
else {
throw(new DOMException(DOMException.SYNTAX_ERR)); // one or more Tags were not closed properly
}
}*/
break;

}
}

Expand Down Expand Up @@ -4676,7 +4680,7 @@ __extend__(HTMLDocument.prototype, {
else if(tagName.match(/SELECT/)) {node = new HTMLSelectElement(this);}
else if(tagName.match(/STYLE/)) {node = new HTMLStyleElement(this);}
else if(tagName.match(/TABLE/)) {node = new HTMLTableElement(this);}
//else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLSectionElement(this);}
else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLSectionElement(this);}
else if(tagName.match(/TD|TH/)) {node = new HTMLTableCellElement(this);}
else if(tagName.match(/TEXTAREA/)) {node = new HTMLElement(this);}
else if(tagName.match(/TITLE/)) {node = new HTMLElement(this);}
Expand Down Expand Up @@ -6747,6 +6751,79 @@ var HTMLTableElement = function(ownerDocument) {
HTMLTableElement.prototype = new HTMLElement;
__extend__(HTMLTableElement.prototype, {

get tFoot() {
//tFoot returns the table footer.
return this.getElementsByTagName("tfoot")[0];
},

createTFoot : function () {
var tFoot = this.tFoot;

if (!tFoot) {
tFoot = document.createElement("tfoot");
this.appendChild(tFoot);
}

return tFoot;
},

deleteTFoot : function () {
var foot = this.tFoot;
if (foot) {
foot.parentNode.removeChild(foot);
}
},

get tHead() {
//tHead returns the table head.
return this.getElementsByTagName("thead")[0];
},

createTHead : function () {
var tHead = this.tHead;

if (!tHead) {
tHead = document.createElement("thead");
this.insertBefore(tHead, this.firstChild);
}

return tHead;
},

deleteTHead : function () {
var head = this.tHead;
if (head) {
head.parentNode.removeChild(head);
}
},

appendChild : function (child) {

var tagName = child.tagName.toLowerCase();
if (tagName === "tr") {
// need an implcit <tbody> to contain this...
if (!this.currentBody) {
this.currentBody = document.createElement("tbody");

DOMNode.prototype.appendChild.apply(this, [this.currentBody]);
}

return this.currentBody.appendChild(child);

} else if (tagName === "tbody" || tagName === "tfoot" && this.currentBody) {
this.currentBody = child;
return DOMNode.prototype.appendChild.apply(this, arguments);

} else {
return DOMNode.prototype.appendChild.apply(this, arguments);
}
},

get tBodies() {
return new HTMLCollection(this.getElementsByTagName("tbody"));

},

get rows() {
return new HTMLCollection(this.getElementsByTagName("tr"));
},
Expand All @@ -6756,57 +6833,198 @@ __extend__(HTMLTableElement.prototype, {
throw new Error("Index omitted in call to HTMLTableElement.insertRow ");
}

var numRows = this.rows.length,
node = null;
var rows = this.rows,
numRows = rows.length,
node,
inserted,
lastRow;

if (idx > numRows) {
throw new Error("Index > rows.length in call to HTMLTableElement.insertRow");
}

var row = document.createElement("tr");
var inserted = document.createElement("tr");
// If index is -1 or equal to the number of rows,
// the row is appended as the last row. If index is omitted
// or greater than the number of rows, an error will result
if (idx === -1 || idx === numRows) {
this.appendChild(row);
lastRow = rows[rows.length-1];
lastRow.parentNode.appendChild(inserted);
} else {


node = this.firstChild;

for (var i=0; i<idx; i++) {
node = node.nextSibling;
}
rows[idx].parentNode.insertBefore(inserted, rows[idx]);
}

this.insertBefore(row, node);

return row;

return inserted;
},

deleteRow : function (idx) {
var elem = this.rows[idx];
this.removeChild(elem);
elem.parentNode.removeChild(elem);
},

get summary() {
return this.getAttribute("summary");
},

set summary(summary) {
this.setAttribute("summary", summary);
},

get align() {
return this.getAttribute("align");
},

set align(align) {
this.setAttribute("align", align);
},


get bgColor() {
return this.getAttribute("bgColor");
},

set bgColor(bgColor) {
return this.setAttribute("bgColor", bgColor);
},

get cellPadding() {
return this.getAttribute("cellPadding");
},

set cellPadding(cellPadding) {
return this.setAttribute("cellPadding", cellPadding);
},


get cellSpacing() {
return this.getAttribute("cellSpacing");
},

set cellSpacing(cellSpacing) {
this.setAttribute("cellSpacing", cellSpacing);
},

get frame() {
return this.getAttribute("frame");
},

set frame(frame) {
this.setAttribute("frame", frame);
},

get rules() {
return this.getAttribute("rules");
},

set rules(rules) {
this.setAttribute("rules", rules);
},

get width() {
return this.getAttribute("width");
},

set width(width) {
this.setAttribute("width", width);
}


});

$debug("Defining HTMLxElement");
/*
* HTMLxElement - DOM Level 2
* - Contributed by Steven Wood
*/
$w.__defineGetter__("HTMLxElement", function(){
$w.__defineGetter__("HTMLTableSectionElement", function(){
return function(){
throw new Error("Object cannot be created in this context");
};
});

var HTMLxElement = function(ownerDocument) {
var HTMLTableSectionElement = function(ownerDocument) {
this.HTMLElement = HTMLElement;
this.HTMLElement(ownerDocument);
};
HTMLxElement.prototype = new HTMLElement;
__extend__(HTMLxElement.prototype, {
HTMLTableSectionElement.prototype = new HTMLElement;
__extend__(HTMLTableSectionElement.prototype, {

appendChild : function (child) {

// disallow nesting of these elements.
if (child.tagName.match(/TBODY|TFOOT|THEAD/)) {
return this.parentNode.appendChild(child);
} else {
return DOMNode.prototype.appendChild.apply(this, arguments);
}

},

get align() {
return this.getAttribute("align");
},

get ch() {
return this.getAttribute("ch");
},

set ch(ch) {
this.setAttribute("ch", ch);
},

// ch gets or sets the alignment character for cells in a column.
set chOff(chOff) {
this.setAttribute("chOff", chOff);
},

get chOff(chOff) {
return this.getAttribute("chOff");
},

get vAlign () {
return this.getAttribute("vAlign");
},

get rows() {
return new HTMLCollection(this.getElementsByTagName("tr"));
},

insertRow : function (idx) {
if (idx === undefined) {
throw new Error("Index omitted in call to HTMLTableSectionElement.insertRow ");
}

var numRows = this.rows.length,
node = null;

if (idx > numRows) {
throw new Error("Index > rows.length in call to HTMLTableSectionElement.insertRow");
}

var row = document.createElement("tr");
// If index is -1 or equal to the number of rows,
// the row is appended as the last row. If index is omitted
// or greater than the number of rows, an error will result
if (idx === -1 || idx === numRows) {
this.appendChild(row);
} else {
node = this.firstChild;

for (var i=0; i<idx; i++) {
node = node.nextSibling;
}
}

this.insertBefore(row, node);

return row;
},

deleteRow : function (idx) {
var elem = this.rows[idx];
this.removeChild(elem);
}

});

$debug("Defining HTMLTableCellElement");
Expand Down Expand Up @@ -6939,8 +7157,7 @@ __extend__(HTMLTableRowElement.prototype, {
var elem = this.cells[idx];
this.removeChild(elem);
}



});

/**
Expand Down

0 comments on commit 16506da

Please sign in to comment.