got rid of all templates.prepare; pull blocks using templates.getBlock instead of parsing twice

This commit is contained in:
psychobunny
2014-03-28 13:29:51 -04:00
parent 339eafd6be
commit 7e11d29f06
11 changed files with 61 additions and 106 deletions

View File

@@ -210,7 +210,7 @@ var ajaxify = {};
data.relative_path = RELATIVE_PATH;
templates.parse(tpl_url, data, function(err, template) {
templates.parse(tpl_url, data, function(template) {
translator.translate(template, function(translatedTemplate) {
$('#content').html(translatedTemplate);
@@ -235,6 +235,23 @@ var ajaxify = {};
});
};
ajaxify.loadTemplate = function(template, callback) {
if (templates.cache[template]) {
callback(templates.cache[template]);
} else {
$.ajax({
url: RELATIVE_PATH + '/templates/' + template + '.tpl',
type: 'GET',
success: function(data) {
callback(data.toString());
},
error: function(error) {
throw new Error("Unable to load template: " + template + " (" + error.statusText + ")");
}
});
}
};
ajaxify.variables = (function() {
var parsedVariables = {};
@@ -297,9 +314,8 @@ var ajaxify = {};
socket.emit('widgets.render', {template: tpl_url + '.tpl', url: url, location: location}, function(err, renderedWidgets) {
if (area.html()) {
area.html(templates.parse(area.html(), {
widgets: renderedWidgets
})).removeClass('hidden');
area.html(templates.parse(area.html(), {widgets: renderedWidgets}))
.removeClass('hidden');
if (!renderedWidgets.length) {
ajaxify.repositionNoWidgets();
@@ -371,18 +387,7 @@ var ajaxify = {};
}
});
templates.registerLoader(function(template, callback) {
$.ajax({
url: RELATIVE_PATH + '/templates/' + template + '.tpl',
type: 'GET',
success: function(data) {
callback(null, data.toString());
},
error: function(error) {
callback({message: error.statusText}, false);
}
});
});
templates.registerLoader(ajaxify.loadTemplate);
$.when($.getJSON(RELATIVE_PATH + '/templates/config.json'), $.getJSON(RELATIVE_PATH + '/api/get_templates_listing')).done(function (config_data, templates_data) {
templatesConfig = config_data[0];