43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
/* globals $,ibuyproperties,Handlebars*/
|
|
|
|
ibuyproperties.templateHelper = (function () {
|
|
"use strict";
|
|
|
|
var templates = {},
|
|
|
|
load = function (allTemplates) {
|
|
var deferreds = [];
|
|
|
|
$.each(allTemplates, function (index, tpl) {
|
|
deferreds.push(
|
|
$.get("templates/" + tpl + ".html")
|
|
.then(function (text) {
|
|
if (ibuyproperties.isDebugMode) { console.log("Loading Template",tpl,ibuyproperties.isDebugMode); }
|
|
templates[tpl] = Handlebars.compile(text);
|
|
}, 'html').fail(function(result){
|
|
console.error("Failed Loading Template",tpl,result);
|
|
})
|
|
);
|
|
});
|
|
|
|
return $.when.apply(null, deferreds);
|
|
},
|
|
|
|
get = function (name) {
|
|
if (templates[name]) {
|
|
if (ibuyproperties.isDebugMode) { console.log("Requested template",name); }
|
|
return templates[name];
|
|
} else {
|
|
console.error("Requested unknown template",name);
|
|
return null;
|
|
}
|
|
};
|
|
|
|
// The public API
|
|
return {
|
|
load: load,
|
|
get: get
|
|
};
|
|
|
|
}());
|