added regex matching to templates/ajaxify. needs cleanup, just unblocking baris

This commit is contained in:
psychobunny
2013-05-08 16:33:29 +00:00
parent 36e7baa84d
commit 31e845f4b0
3 changed files with 17 additions and 10 deletions

View File

@@ -5,7 +5,15 @@ var templates = {};
config = {};
templates.get_custom_map = function(tpl) {
return (config['custom_mapping'] && config['custom_mapping'][tpl]) ? config['custom_mapping'][tpl] : tpl;
if (config['custom_mapping'] && tpl) {
for (var pattern in config['custom_mapping']) {
console.log(pattern);
if (tpl.match(pattern)) {
return (config['custom_mapping'][pattern]);
}
}
}
return false;
}
templates.ready = function(callback) {
@@ -156,18 +164,15 @@ function load_template(callback, custom_tpl) {
jQuery.get(API_URL + url, function(data) {
var splits = url.split('/');
var tpl = url;
if(splits.length) {
tpl = splits[0];
tpl = templates.get_custom_map(tpl);
var tpl = templates.get_custom_map(url);
if (tpl == false) {
tpl = url.split('/')[0];
}
if (custom_tpl && custom_tpl != "undefined")
tpl = custom_tpl;
document.getElementById('content').innerHTML = templates[tpl].parse(JSON.parse(data));
if (callback) callback();
});