2013-11-25 22:00:19 +04:00
|
|
|
(function () {
|
|
|
|
var ns = $.namespace("pskl.utils");
|
|
|
|
|
|
|
|
ns.Template = {
|
|
|
|
get : function (templateId) {
|
|
|
|
var template = document.getElementById(templateId);
|
|
|
|
if (template) {
|
|
|
|
return template.innerHTML;
|
|
|
|
} else {
|
|
|
|
console.error("Could not find template for id :", templateId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
createFromHTML : function (html) {
|
|
|
|
var dummyEl = document.createElement("div");
|
|
|
|
dummyEl.innerHTML = html;
|
|
|
|
return dummyEl.children[0];
|
|
|
|
},
|
|
|
|
|
|
|
|
replace : function (template, dict) {
|
|
|
|
for (var key in dict) {
|
|
|
|
if (dict.hasOwnProperty(key)) {
|
|
|
|
var value = dict[key];
|
2014-03-30 05:12:56 +04:00
|
|
|
|
|
|
|
// special boolean keys keys key:default
|
|
|
|
// if the value is a boolean, use default as value
|
|
|
|
if (key.indexOf(':') !== -1) {
|
|
|
|
if (value === true) {
|
|
|
|
value = key.split(':')[1];
|
|
|
|
} else if (value === false) {
|
|
|
|
value = '';
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 22:00:19 +04:00
|
|
|
template = template.replace(new RegExp('\\{\\{'+key+'\\}\\}', 'g'), value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|