|
|
@ -7,7 +7,15 @@ var templates = {};
|
|
|
|
//quick implementation because introducing a lib to handle several async callbacks
|
|
|
|
//quick implementation because introducing a lib to handle several async callbacks
|
|
|
|
if (callback == null && ready_callback) ready_callback();
|
|
|
|
if (callback == null && ready_callback) ready_callback();
|
|
|
|
else ready_callback = callback;
|
|
|
|
else ready_callback = callback;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates.prepare = function(raw_tpl, data) {
|
|
|
|
|
|
|
|
var template = {};
|
|
|
|
|
|
|
|
template.html = raw_tpl;
|
|
|
|
|
|
|
|
template.parse = parse;
|
|
|
|
|
|
|
|
template.blocks = {};
|
|
|
|
|
|
|
|
return template;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function loadTemplates(templatesToLoad) {
|
|
|
|
function loadTemplates(templatesToLoad) {
|
|
|
|
var timestamp = new Date().getTime();
|
|
|
|
var timestamp = new Date().getTime();
|
|
|
@ -24,9 +32,10 @@ var templates = {};
|
|
|
|
|
|
|
|
|
|
|
|
template.prototype.parse = parse;
|
|
|
|
template.prototype.parse = parse;
|
|
|
|
template.prototype.html = String(html);
|
|
|
|
template.prototype.html = String(html);
|
|
|
|
|
|
|
|
template.prototype.blocks = {};
|
|
|
|
templates[file] = new template;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates[file] = new template;
|
|
|
|
|
|
|
|
|
|
|
|
loaded--;
|
|
|
|
loaded--;
|
|
|
|
if (loaded == 0) templates.ready();
|
|
|
|
if (loaded == 0) templates.ready();
|
|
|
|
}).fail(function() {
|
|
|
|
}).fail(function() {
|
|
|
@ -49,6 +58,8 @@ var templates = {};
|
|
|
|
|
|
|
|
|
|
|
|
//modified from https://github.com/psychobunny/dcp.templates
|
|
|
|
//modified from https://github.com/psychobunny/dcp.templates
|
|
|
|
var parse = function(data) {
|
|
|
|
var parse = function(data) {
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
|
|
function replace(key, value, template) {
|
|
|
|
function replace(key, value, template) {
|
|
|
|
var searchRegex = new RegExp('{' + key + '}', 'g');
|
|
|
|
var searchRegex = new RegExp('{' + key + '}', 'g');
|
|
|
|
return template.replace(searchRegex, value);
|
|
|
|
return template.replace(searchRegex, value);
|
|
|
@ -62,6 +73,8 @@ var templates = {};
|
|
|
|
data = template.match(regex);
|
|
|
|
data = template.match(regex);
|
|
|
|
if (data == null) return;
|
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (block !== undefined) self.blocks[block] = data[0];
|
|
|
|
|
|
|
|
|
|
|
|
data = data[0]
|
|
|
|
data = data[0]
|
|
|
|
.replace("<!-- BEGIN " + block + " -->", "")
|
|
|
|
.replace("<!-- BEGIN " + block + " -->", "")
|
|
|
|
.replace("<!-- END " + block + " -->", "");
|
|
|
|
.replace("<!-- END " + block + " -->", "");
|
|
|
|