nhz.lib
Version:
NHZ Library
134 lines (113 loc) • 3.84 kB
JavaScript
/* Component */
var Base, Child, Component, EventSource, EventTarget, Parent,
extend = require("extends__"),
hasProp = {}.hasOwnProperty;
Base = require('./base');
Child = require('./child');
Parent = require('./parent');
EventSource = require('./event-source');
EventTarget = require('./event-target');
module.exports = Component = (function(superClass) {
extend(Component, superClass);
function Component() {
Component.__super__.constructor.apply(this, arguments);
Object.defineProperties(this, {
___is_component: {
configurable: false,
enumerable: false,
writable: false,
value: true
}
});
}
Component.prototype.appendChild = function(child) {
if (child != null ? child.___is_component : void 0) {
return Component.__super__.appendChild.apply(this, arguments);
} else {
return this;
}
};
Component.prototype.removeChild = function(child) {
if (child != null ? child.___is_component : void 0) {
return Component.__super__.removeChild.apply(this, arguments);
} else {
return this;
}
};
Component.prototype.replaceChild = function(child, withChild) {
if ((child != null ? child.___is_component : void 0) && (withChild != null ? withChild.___is_component : void 0)) {
return Component.__super__.replaceChild.apply(this, arguments);
} else {
return this;
}
};
Component.prototype.nextChild = function(child) {
if (child != null ? child.___is_component : void 0) {
return Component.__super__.nextChild.apply(this, arguments);
} else {
return null;
}
};
Component.prototype.previousChild = function(child) {
if (child != null ? child.___is_component : void 0) {
return Component.__super__.previousChild.apply(this, arguments);
} else {
return null;
}
};
Component.prototype.insertBefore = function(child, newChild) {
if ((child != null ? child.___is_component : void 0) && (newChild != null ? newChild.___is_component : void 0)) {
return Component.__super__.insertBefore.apply(this, arguments);
} else {
return this;
}
};
Component.prototype.insertAfter = function(child, newChild) {
if ((child != null ? child.___is_component : void 0) && (newChild != null ? newChild.___is_component : void 0)) {
return Component.__super__.insertAfter.apply(this, arguments);
} else {
return this;
}
};
Component.prototype.hasChild = function(child) {
if (child != null ? child.___is_component : void 0) {
return Component.__super__.hasChild.apply(this, arguments);
} else {
return null;
}
};
Component.prototype.dispatchEvent = function(event) {
var child, i, len, ref;
if (event != null ? event.___is_event : void 0) {
Component.__super__.dispatchEvent.apply(this, arguments);
if (!(event.target === this || event.stopped)) {
ref = this.children;
for (i = 0, len = ref.length; i < len; i++) {
child = ref[i];
if (child != null) {
if (typeof child.dispatchEvent === "function") {
child.dispatchEvent(event);
}
}
if (event.stopped || event.phase === Event.BUBBLING_PHASE) {
break;
}
}
if ((!event.stopped) && event.phase === Event.BUBBLING_PHASE) {
Component.__super__.dispatchEvent.call(this, event);
}
}
}
return this;
};
Component.prototype.emitEvent = function(event, target) {
if (target == null) {
target = this;
}
if (target != null ? target.___is_component : void 0) {
Component.__super__.emitEvent.apply(this, arguments);
}
return this;
};
return Component;
})([Base, Child, Parent, EventSource, EventTarget]);