Added styles to application

This commit is contained in:
Borys Levytskyi
2015-04-03 18:04:49 +03:00
parent 97eed3fa1e
commit d301d0c317
7 changed files with 83 additions and 29 deletions

View File

@@ -38,7 +38,17 @@
return HtmlBuilder.createElement(this.toString());
};
HtmlBuilder.createElement = function(html) {
HtmlBuilder.createElement = function(template, model) {
var regex = /(?:{([^}]+)})/g, html;
if(model == null){
html = template;
} else {
html = template.replace(regex, function(m, g1) {
return HtmlBuilder.escapeHtml(model[g1]);
});
}
var el = document.createElement('div');
el.innerHTML = html;
return el.children[0];
@@ -53,12 +63,21 @@
for(var key in attr) {
if(key == 'html')
continue;
str.push(key + '="' + attr[key] + '"');
str.push(key + '="' + HtmlBuilder.escapeHtml(attr[key]) + '"');
}
return str.join(' ');
}
HtmlBuilder.escapeHtml = function(html) {
return html
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
};
window.HtmlBuilder = HtmlBuilder;
})();