@sujalchoudhari/solaris-ui
Version:
A UI framework to create HTML pages with just JavaScript.
63 lines • 1.84 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = __importDefault(require("../utils/logger"));
const scriptmanager_1 = __importDefault(require("../utils/scriptmanager"));
/**
* Script
* -----
* Script is an representation of Javascript scripts in html
* @author Ansh Sharma
*/
class Script {
/**
* The actual string of script
*/
script = ``;
/**
* The URL of the Script.
* only used when external is selected as type of script
*/
url = "";
/**
* The Type of the script
*/
type = "";
/**
* The Parameters of the script
*/
params = {};
/**
* Create a new instance of Script
* @param type the type of the script either external or infile
* @param url the url of an external source script
* @param script the actual script when url is specified
* @param params the parameters of the script
*/
constructor(type, url = "", script = ``, params = {}) {
this.script = script;
this.url = url;
this.type = type;
this.params = params;
if (!scriptmanager_1.default.isScriptAdded(this))
scriptmanager_1.default.addscript(this);
else
logger_1.default.warn(__filename, `Script ${this.toString()} already added`);
}
/**
* Get the script as a string
* @returns the script as a string
*/
toString() {
if (this.type === "infile") {
return `<script>${this.script}</script>`;
}
else {
return `<script src="${this.url}"></script>`;
}
}
}
exports.default = Script;
//# sourceMappingURL=scripts.js.map