Initial checkin
This commit is contained in:
42
js/templateHelper.js
Normal file
42
js/templateHelper.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/* 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
|
||||
};
|
||||
|
||||
}());
|
||||
Reference in New Issue
Block a user