Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 7578669

Browse files
committed
Merge pull request #380 from arv/html-table-element
Implement the HTML Table DOM APIs
2 parents a2e1c75 + def35ae commit 7578669

11 files changed

+376
-0
lines changed

build.json

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"src/MutationObserver.js",
77
"src/wrappers/events.js",
88
"src/wrappers/NodeList.js",
9+
"src/wrappers/HTMLCollection.js",
910
"src/wrappers/Node.js",
1011
"src/querySelector.js",
1112
"src/wrappers/node-interfaces.js",
@@ -22,6 +23,9 @@
2223
"src/wrappers/HTMLAudioElement.js",
2324
"src/wrappers/HTMLOptionElement.js",
2425
"src/wrappers/HTMLSelectElement.js",
26+
"src/wrappers/HTMLTableElement.js",
27+
"src/wrappers/HTMLTableSectionElement.js",
28+
"src/wrappers/HTMLTableRowElement.js",
2529
"src/wrappers/HTMLUnknownElement.js",
2630
"src/wrappers/SVGElement.js",
2731
"src/wrappers/SVGUseElement.js",

shadowdom.js

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'src/MutationObserver.js',
2323
'src/wrappers/events.js',
2424
'src/wrappers/NodeList.js',
25+
'src/wrappers/HTMLCollection.js',
2526
'src/wrappers/Node.js',
2627
'src/querySelector.js',
2728
'src/wrappers/node-interfaces.js',
@@ -38,6 +39,9 @@
3839
'src/wrappers/HTMLAudioElement.js',
3940
'src/wrappers/HTMLOptionElement.js',
4041
'src/wrappers/HTMLSelectElement.js',
42+
'src/wrappers/HTMLTableElement.js',
43+
'src/wrappers/HTMLTableSectionElement.js',
44+
'src/wrappers/HTMLTableRowElement.js',
4145
'src/wrappers/HTMLUnknownElement.js',
4246
'src/wrappers/SVGElement.js',
4347
'src/wrappers/SVGUseElement.js',

src/wrappers/HTMLCollection.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
(function(scope) {
8+
'use strict';
9+
10+
// TODO(arv): Implement.
11+
12+
scope.wrapHTMLCollection = scope.wrapNodeList;
13+
scope.wrappers.HTMLCollection = scope.wrappers.NodeList;
14+
15+
})(window.ShadowDOMPolyfill);

src/wrappers/HTMLTableElement.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
(function(scope) {
8+
'use strict';
9+
10+
var HTMLElement = scope.wrappers.HTMLElement;
11+
var mixin = scope.mixin;
12+
var registerWrapper = scope.registerWrapper;
13+
var unwrap = scope.unwrap;
14+
var wrap = scope.wrap;
15+
var wrapHTMLCollection = scope.wrapHTMLCollection;
16+
17+
var OriginalHTMLTableElement = window.HTMLTableElement;
18+
19+
function HTMLTableElement(node) {
20+
HTMLElement.call(this, node);
21+
}
22+
HTMLTableElement.prototype = Object.create(HTMLElement.prototype);
23+
mixin(HTMLTableElement.prototype, {
24+
get caption() {
25+
return wrap(unwrap(this).caption);
26+
},
27+
createCaption: function() {
28+
return wrap(unwrap(this).createCaption());
29+
},
30+
31+
get tHead() {
32+
return wrap(unwrap(this).tHead);
33+
},
34+
createTHead: function() {
35+
return wrap(unwrap(this).createTHead());
36+
},
37+
38+
createTFoot: function() {
39+
return wrap(unwrap(this).createTFoot());
40+
},
41+
get tFoot() {
42+
return wrap(unwrap(this).tFoot);
43+
},
44+
45+
get tBodies() {
46+
return wrapHTMLCollection(unwrap(this).tBodies);
47+
},
48+
createTBody: function() {
49+
return wrap(unwrap(this).createTBody());
50+
},
51+
52+
get rows() {
53+
return wrapHTMLCollection(unwrap(this).rows);
54+
},
55+
insertRow: function(index) {
56+
return wrap(unwrap(this).insertRow(index));
57+
}
58+
});
59+
60+
registerWrapper(OriginalHTMLTableElement, HTMLTableElement,
61+
document.createElement('table'));
62+
63+
scope.wrappers.HTMLTableElement = HTMLTableElement;
64+
})(window.ShadowDOMPolyfill);

src/wrappers/HTMLTableRowElement.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
(function(scope) {
8+
'use strict';
9+
10+
var HTMLElement = scope.wrappers.HTMLElement;
11+
var mixin = scope.mixin;
12+
var registerWrapper = scope.registerWrapper;
13+
var wrapHTMLCollection = scope.wrapHTMLCollection;
14+
var unwrap = scope.unwrap;
15+
var wrap = scope.wrap;
16+
17+
var OriginalHTMLTableRowElement = window.HTMLTableRowElement;
18+
19+
function HTMLTableRowElement(node) {
20+
HTMLElement.call(this, node);
21+
}
22+
HTMLTableRowElement.prototype = Object.create(HTMLElement.prototype);
23+
mixin(HTMLTableRowElement.prototype, {
24+
get cells() {
25+
return wrapHTMLCollection(unwrap(this).cells);
26+
},
27+
28+
insertCell: function(index) {
29+
return wrap(unwrap(this).insertCell(index));
30+
}
31+
});
32+
33+
registerWrapper(OriginalHTMLTableRowElement, HTMLTableRowElement,
34+
document.createElement('tr'));
35+
36+
scope.wrappers.HTMLTableRowElement = HTMLTableRowElement;
37+
})(window.ShadowDOMPolyfill);
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
(function(scope) {
8+
'use strict';
9+
10+
var HTMLElement = scope.wrappers.HTMLElement;
11+
var mixin = scope.mixin;
12+
var registerWrapper = scope.registerWrapper;
13+
var wrapHTMLCollection = scope.wrapHTMLCollection;
14+
var unwrap = scope.unwrap;
15+
var wrap = scope.wrap;
16+
17+
var OriginalHTMLTableSectionElement = window.HTMLTableSectionElement;
18+
19+
function HTMLTableSectionElement(node) {
20+
HTMLElement.call(this, node);
21+
}
22+
HTMLTableSectionElement.prototype = Object.create(HTMLElement.prototype);
23+
mixin(HTMLTableSectionElement.prototype, {
24+
get rows() {
25+
return wrapHTMLCollection(unwrap(this).rows);
26+
},
27+
insertRow: function(index) {
28+
return wrap(unwrap(this).insertRow(index));
29+
}
30+
});
31+
32+
registerWrapper(OriginalHTMLTableSectionElement, HTMLTableSectionElement,
33+
document.createElement('thead'));
34+
35+
scope.wrappers.HTMLTableSectionElement = HTMLTableSectionElement;
36+
})(window.ShadowDOMPolyfill);

test/js/HTMLTableElement.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
suite('HTMLTableElement', function() {
8+
9+
test('instanceof', function() {
10+
var table = createTable();
11+
assert.instanceOf(table, HTMLTableElement);
12+
});
13+
14+
test('caption', function() {
15+
var table = createTable();
16+
assert.equal(table.caption.localName, 'caption');
17+
});
18+
19+
test('createCaption', function() {
20+
var table = createTable();
21+
var caption = table.createCaption();
22+
assert.equal(caption.localName, 'caption');
23+
assert.instanceOf(caption, HTMLElement);
24+
});
25+
26+
test('tHead', function() {
27+
var table = createTable();
28+
assert.equal(table.tHead.localName, 'thead');
29+
assert.instanceOf(table.tHead, HTMLTableSectionElement);
30+
});
31+
32+
test('createTHead', function() {
33+
var table = createTable();
34+
var thead = table.createTHead();
35+
assert.equal(thead.localName, 'thead');
36+
assert.instanceOf(thead, HTMLTableSectionElement);
37+
});
38+
39+
test('tFoot', function() {
40+
var table = createTable();
41+
assert.equal(table.tFoot.localName, 'tfoot');
42+
assert.instanceOf(table.tFoot, HTMLTableSectionElement);
43+
});
44+
45+
test('createTFoot', function() {
46+
var table = createTable();
47+
var tfoot = table.createTFoot();
48+
assert.equal(tfoot.localName, 'tfoot');
49+
assert.instanceOf(tfoot, HTMLTableSectionElement);
50+
});
51+
52+
test('tBodies', function() {
53+
var table = createTable();
54+
assert.instanceOf(table.tBodies, HTMLCollection);
55+
assert.equal(table.tBodies.length, 2);
56+
57+
assert.equal(table.tBodies[0], table.querySelector('tbody'));
58+
});
59+
60+
test('createTBody', function() {
61+
var table = createTable();
62+
var tbody = table.createTBody();
63+
assert.equal(tbody.localName, 'tbody');
64+
assert.instanceOf(tbody, HTMLTableSectionElement);
65+
});
66+
67+
test('rows', function() {
68+
var table = createTable();
69+
assert.instanceOf(table.rows, HTMLCollection);
70+
assert.equal(table.rows.length, 8);
71+
});
72+
73+
test('insertRow', function() {
74+
var table = createTable();
75+
var tr = table.insertRow(1);
76+
assert.instanceOf(tr, HTMLTableRowElement);
77+
assert.equal(tr.localName, 'tr');
78+
});
79+
80+
});

test/js/HTMLTableRowElement.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
suite('HTMLTableRowElement', function() {
8+
9+
test('instanceof', function() {
10+
var table = createTable();
11+
var row = table.querySelector('tr');
12+
assert.instanceOf(row, HTMLTableRowElement);
13+
});
14+
15+
test('cells', function() {
16+
var table = createTable();
17+
var row = table.querySelector('tr');
18+
assert.instanceOf(row.cells, HTMLCollection);
19+
assert.equal(row.cells.length, 3);
20+
});
21+
22+
test('insertCell', function() {
23+
var table = createTable();
24+
var row = table.querySelector('tr');
25+
var newCell = row.insertCell(0);
26+
assert.equal(newCell.localName, 'td');
27+
});
28+
29+
});

test/js/HTMLTableSectionElement.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
suite('HTMLTableSectionElement', function() {
8+
9+
test('instanceof', function() {
10+
var table = createTable();
11+
var thead = table.querySelector('thead');
12+
assert.instanceOf(thead, HTMLTableSectionElement);
13+
var tfoot = table.querySelector('tfoot');
14+
assert.instanceOf(tfoot, HTMLTableSectionElement);
15+
});
16+
17+
test('rows', function() {
18+
var table = createTable();
19+
var thead = table.querySelector('thead');
20+
assert.instanceOf(thead.rows, HTMLCollection);
21+
assert.equal(thead.rows.length, 2);
22+
23+
var tbody = table.querySelector('tbody');
24+
assert.instanceOf(tbody.rows, HTMLCollection);
25+
assert.equal(tbody.rows.length, 2);
26+
27+
var tfoot = table.querySelector('tfoot');
28+
assert.instanceOf(tfoot.rows, HTMLCollection);
29+
assert.equal(tfoot.rows.length, 2);
30+
});
31+
32+
test('insertRow', function() {
33+
var table = createTable();
34+
var thead = table.querySelector('thead');
35+
var tr = thead.insertRow(1);
36+
assert.instanceOf(tr, HTMLTableRowElement);
37+
assert.equal(tr.localName, 'tr');
38+
39+
var tbody = table.querySelector('tbody');
40+
tr = thead.insertRow(1);
41+
assert.instanceOf(tr, HTMLTableRowElement);
42+
assert.equal(tr.localName, 'tr');
43+
44+
var tfoot = table.querySelector('tfoot');
45+
tr = thead.insertRow(1);
46+
assert.instanceOf(tr, HTMLTableRowElement);
47+
assert.equal(tr.localName, 'tr');
48+
});
49+
50+
});

0 commit comments

Comments
 (0)