mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-24 05:33:02 +01:00
Introduced core.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
(function(app){
|
||||
(function(app, core){
|
||||
|
||||
var should = core.should;
|
||||
|
||||
function Command(name) {
|
||||
this.name = name;
|
||||
this.executionHandlers = [];
|
||||
@@ -49,4 +52,5 @@
|
||||
};
|
||||
|
||||
window.commandr = commandr;
|
||||
})(window.app);
|
||||
|
||||
})(window.app, window.core);
|
||||
@@ -1,22 +1,20 @@
|
||||
(function(app, should, Container) {
|
||||
(function(app, core) {
|
||||
|
||||
var controllerDi = app.di; // TODO: Compbine
|
||||
var should = core.should;
|
||||
|
||||
app.controller = function(name, instOrFactory) {
|
||||
|
||||
should.beString(name, "name");
|
||||
|
||||
if(instOrFactory == null) {
|
||||
return controllerDi.resolve(name);
|
||||
return this.get(name);
|
||||
}
|
||||
|
||||
var reg = new Container.Registration(instOrFactory);
|
||||
var reg = new core.Container.Registration(instOrFactory);
|
||||
|
||||
reg.onFirstTimeResolve = function (inst) {
|
||||
addControllerMixin(inst);
|
||||
};
|
||||
|
||||
controllerDi.register(name, reg);
|
||||
this.set(name, reg);
|
||||
};
|
||||
|
||||
app.run(function(){
|
||||
@@ -78,4 +76,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
})(window.app, window.should, window.Container);
|
||||
})(window.app, window.core);
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
(function(){
|
||||
|
||||
var HtmlBuilder = {};
|
||||
|
||||
HtmlBuilder.element = function(template, model) {
|
||||
var el = document.createElement('div');
|
||||
el.innerHTML = HtmlBuilder.template(template, model);
|
||||
return el.children[0];
|
||||
};
|
||||
|
||||
HtmlBuilder.template = function(template, model) {
|
||||
should.beString(template, "template");
|
||||
var regex = /(?:{([^}]+)})/g, html;
|
||||
|
||||
if(model == null){
|
||||
html = template;
|
||||
} else {
|
||||
html = template.replace(regex, function(m, g1) {
|
||||
return HtmlBuilder.escapeHtml(model[g1]);
|
||||
});
|
||||
}
|
||||
|
||||
return html;
|
||||
};
|
||||
|
||||
function getAttributesStr(attr) {
|
||||
if(attr == null) {
|
||||
return '';
|
||||
}
|
||||
var str = [];
|
||||
|
||||
for(var key in attr) {
|
||||
if(key == 'html')
|
||||
continue;
|
||||
str.push(key + '="' + HtmlBuilder.escapeHtml(attr[key]) + '"');
|
||||
}
|
||||
|
||||
return str.join(' ');
|
||||
}
|
||||
|
||||
HtmlBuilder.escapeHtml = function(obj) {
|
||||
if(obj == null) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
if(typeof obj != 'string') {
|
||||
obj = obj.toString();
|
||||
}
|
||||
|
||||
return obj
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
};
|
||||
|
||||
window.HtmlBuilder = HtmlBuilder;
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user