UNPKG

1.94 kBJavaScriptView Raw
1
2(function (window) { 'use strict';
3
4 if (!('firstElementChild' in window.DocumentFragment.prototype)) {
5 Object.defineProperty(window.DocumentFragment.prototype, 'firstElementChild', {
6 get: function () {
7 var node, nodes = this.childNodes, i = 0;
8 while (node = nodes[i++]) {
9 if (node.nodeType === 1) {
10 return node;
11 }
12 }
13 return null;
14 }
15 });
16 }
17
18 if (!('children' in window.DocumentFragment.prototype)) {
19 Object.defineProperty(window.DocumentFragment.prototype, 'children', {
20 get: function () {
21 var i = 0, node, nodes = this.childNodes, children = [];
22 while (node = nodes[i++]) {
23 if (node.nodeType === 1) {
24 children.push(node);
25 }
26 }
27 return children;
28 }
29 });
30 }
31
32 if (!('lastElementChild' in window.DocumentFragment.prototype)) {
33 Object.defineProperty(window.DocumentFragment.prototype, 'lastElementChild', {
34 get: function () {
35 var node, nodes = this.childNodes, i = nodes.length - 1;
36 while (node = nodes[i--]) {
37 if (node.nodeType === 1) {
38 return node;
39 }
40 }
41 return null;
42 }
43 });
44 }
45
46 if (!('childElementCount' in window.DocumentFragment.prototype)) {
47 Object.defineProperty(window.DocumentFragment.prototype, 'childElementCount', {
48 get: function () {
49 var i = 0, count = 0, node, nodes = this.childNodes;
50 while (node = nodes[i++]) {
51 if (node.nodeType === 1) count++;
52 }
53 return count;
54 }
55 });
56 }
57
58})(window);