mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-13 16:32:17 +01:00
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
(function(app){
|
|
app.service('html', {
|
|
builder: function () {
|
|
return new HtmlBuilder();
|
|
}
|
|
})
|
|
|
|
function HtmlBuilder() {
|
|
this.sb = [];
|
|
}
|
|
|
|
HtmlBuilder.prototype.element = function(tagName, attrs, content) {
|
|
var attributes = arguments.length == 3 ? attrs : null,
|
|
elementContent = arguments.length == 3 ? content : attrs;
|
|
|
|
this.sb.push('<' + tagName + ' ' + getAttributesStr(attributes) + ">");
|
|
|
|
if(typeof elementContent == 'function') {
|
|
elementContent();
|
|
} else if (elementContent != null) {
|
|
this.sb.push(elementContent.toString());
|
|
}
|
|
|
|
|
|
this.sb.push('</' + tagName + '>');
|
|
};
|
|
|
|
HtmlBuilder.prototype.toString = function () {
|
|
return this.sb.join('\r\n');
|
|
};
|
|
|
|
function getAttributesStr(attr) {
|
|
if(attr == null) {
|
|
return '';
|
|
}
|
|
var str = [];
|
|
|
|
for(var key in attr)
|
|
{
|
|
str.push(key + '="' + attr[key] + '"');
|
|
}
|
|
|
|
return str.join(' ');
|
|
}
|
|
|
|
})(window.app); |