]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/js/vendor/neon/stdlib/node_support.js
1 Module('NodeSupport')({
7 appendChild : function(child
) {
9 child
.parent
.removeChild(child
);
12 if(!this.hasOwnProperty('children')) {
16 this.children
.push(child
);
17 this[child
.name
] = child
;
18 child
.setParent(this);
22 insertBefore : function (child
, beforeChild
) {
26 child
.parent
.removeChild(child
);
29 if (!this.hasOwnProperty('children')) {
33 if (typeof beforeChild
=== 'undefined') {
34 this.appendChild(child
);
36 position
= this.children
.indexOf(beforeChild
);
37 this.children
.splice(position
, 0, child
);
39 this[child
.name
] = child
;
40 child
.setParent(this);
47 insertChild : function(child
, position
) {
48 console
.warn('NodeSupport insertChild method is deprecated, try insertBefore');
51 child
.parent
.removeChild(child
);
54 if (!this.hasOwnProperty('children')) {
58 if (typeof position
== 'undefined') {
59 this.children
.push(child
);
60 this[child
.name
] = child
;
61 child
.setParent(this);
65 this.children
.splice(position
, 0, child
);
66 this[child
.name
] = child
;
67 child
.setParent(this);
71 removeChild : function (child
) {
72 var position
= this.children
.indexOf(child
);
74 if (position
!== -1) {
75 this.children
.splice(position
, 1);
76 delete this[child
.name
];
83 setParent : function (parent
) {
88 getDescendants : function () {
90 this.children
.forEach(function (node
) {
93 this.children
.forEach(function (node
) {
94 nodes
= nodes
.concat(node
.getDescendants());
99 getPreviousSibling : function () {
100 if (typeof this.parent
=== 'undefined') {
104 if (this.parent
.children
[0] === this) {
108 return this.parent
.children
[ this.parent
.children
.indexOf(this) - 1 ];
111 getNextSibling : function () {
112 if (typeof this.parent
=== 'undefined') {
116 if (this.parent
.children
[ this.parent
.children
.length
- 1 ] === this) {
120 return this.parent
.children
[ this.parent
.children
.indexOf(this) + 1 ];