mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
30 lines
775 B
JavaScript
30 lines
775 B
JavaScript
(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];
|
|
template = template.replace(new RegExp('\\{\\{'+key+'\\}\\}', 'g'), value);
|
|
}
|
|
}
|
|
return template;
|
|
}
|
|
};
|
|
})(); |