nhz.lib
Version:
NHZ Library
120 lines (112 loc) • 3.17 kB
JavaScript
/* mixin.Child */
var Child,
extend = require("extends__"),
hasProp = {}.hasOwnProperty;
module.exports = Child = (function(superClass) {
extend(Child, superClass);
function Child() {
Object.defineProperties(this, {
parent: {
configurable: true,
enumerable: true,
get: function() {
return this.___parent;
},
set: (function(_this) {
return function(value) {
var parent;
parent = _this.___parent;
if (value != null) {
if (value !== parent && value.___is_parent) {
_this.___parent = null;
if (parent != null) {
if (typeof parent.removeChild === "function") {
parent.removeChild(_this);
}
}
_this.___parent = value;
if (typeof value.appendChild === "function") {
value.appendChild(_this);
}
}
} else {
_this.___parent = null;
if (parent != null) {
if (typeof parent.removeChild === "function") {
parent.removeChild(_this);
}
}
}
return _this.___parent;
};
})(this)
},
previousSibling: {
configurable: true,
enumerable: true,
get: function() {
var parent;
if (parent = this.___parent) {
return typeof parent.previousChild === "function" ? parent.previousChild(this) : void 0;
} else {
return null;
}
}
},
nextSibling: {
configurable: true,
enumerable: true,
get: function() {
var parent;
if (parent = this.___parent) {
return typeof parent.nextChild === "function" ? parent.nextChild(this) : void 0;
} else {
return null;
}
}
},
___is_child: {
configurable: false,
enumerable: false,
writable: false,
value: true
},
___parent: {
configurable: false,
enumerable: false,
writable: true,
value: null
}
});
}
Child.prototype.replaceWith = function(child) {
var parent;
if (child && child !== this && child.___is_child && this.___parent) {
if (this.___parent !== (parent = child.___parent)) {
child.___parent = null;
if (parent != null) {
if (typeof parent.removeChild === "function") {
parent.removeChild(child);
}
}
parent = child.___parent = this.___parent;
this.___parent = null;
if (typeof parent.replaceChild === "function") {
parent.replaceChild(this, child);
}
}
}
return this;
};
Child.prototype.remove = function() {
var parent;
if (parent = this.___parent) {
this.___parent = null;
if (typeof parent.removeChild === "function") {
parent.removeChild(this);
}
}
return this;
};
return Child;
})(require('./base'));