ajsfw
Version:
Ajs Framework
101 lines (100 loc) • 3.91 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ajs = require("ajsfw");
var exceptions = require("./exceptions");
var Body_1 = require("./view/Body");
var StyleSheet_1 = require("./view/StyleSheet");
var Console = (function () {
function Console(config) {
this.__config = config;
this.__modules = [];
this.__styleElements = [];
this.__bodyElement = null;
this.__infoElement = null;
ajs.setAjsConsole(this);
}
Object.defineProperty(Console.prototype, "_config", {
get: function () { return this.__config; },
enumerable: true,
configurable: true
});
Object.defineProperty(Console.prototype, "modules", {
get: function () { return this.__modules; },
enumerable: true,
configurable: true
});
Console.prototype.registerModule = function (consoleModule) {
if (this.__modules.indexOf(consoleModule) !== -1) {
return;
}
this.__modules.push(consoleModule);
if (this.__modules.length === 1) {
this.__init(this.__modules[0]);
}
};
Console.prototype.setInfo = function (info) {
if (this.__infoElement === null) {
return;
}
this.__infoElement.textContent = info;
};
Console.prototype.show = function () {
if (this.__modules.length === 0) {
throw new exceptions.NoDebugModulesConfiguredException();
}
if (this.__bodyElement !== null) {
return;
}
this.__bodyElement = this.__body.render();
this.__config.bodyRenderTarget.appendChild(this.__bodyElement);
var styleElement = this.__styleSheet.render();
this.__config.styleRenderTarget.appendChild(styleElement);
this.__styleElements.push(styleElement);
for (var _i = 0, _a = this.__modules; _i < _a.length; _i++) {
var m = _a[_i];
styleElement = m.renderStyleSheet();
this.__config.styleRenderTarget.appendChild(styleElement);
this.__styleElements.push(styleElement);
}
this.__infoElement = this.__config.bodyRenderTarget.ownerDocument.getElementById("ajsDebugInfo");
this.__body.currentModule.bodyRendered();
};
Console.prototype.hide = function () {
if (this.__bodyElement === null) {
return;
}
this.__bodyElement.parentElement.removeChild(this.__bodyElement);
this.__bodyElement = null;
for (var i = 0; i < this.__styleElements.length; i++) {
this.__styleElements[i].parentElement.removeChild(this.__styleElements[i]);
}
this.__styleElements = [];
};
Console.prototype.refresh = function () {
if (this.__bodyElement === null) {
return;
}
this.__bodyElement.parentElement.removeChild(this.__bodyElement);
this.__bodyElement = this.__body.render();
this.__config.bodyRenderTarget.appendChild(this.__bodyElement);
this.__infoElement = this.__config.bodyRenderTarget.ownerDocument.getElementById("ajsDebugInfo");
this.__body.currentModule.bodyRendered();
};
Console.prototype.__init = function (defaultModule) {
var _this = this;
this.__body = new Body_1.Body(this, defaultModule);
this.__styleSheet = new StyleSheet_1.StyleSheet();
if (this.__config.showOnBootDelay > 0) {
var delay = void 0;
if (this.__config.showOnBootDelay < 500) {
delay = 500;
}
else {
delay = this.__config.showOnBootDelay;
}
setTimeout(function () { _this.show(); }, delay);
}
};
return Console;
}());
exports.Console = Console;