2013-09-07 19:50:43 +04:00
|
|
|
(function () {
|
2013-10-17 01:14:41 +04:00
|
|
|
var ns = $.namespace("pskl.utils");
|
2013-09-07 19:50:43 +04:00
|
|
|
|
2013-10-17 01:14:41 +04:00
|
|
|
ns.Template = {
|
2013-09-07 19:50:43 +04:00
|
|
|
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];
|
|
|
|
template = template.replace(new RegExp('\\{\\{'+key+'\\}\\}', 'g'), value);
|
|
|
|
}
|
2013-09-29 01:52:51 +04:00
|
|
|
}
|
2013-09-07 19:50:43 +04:00
|
|
|
return template;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|