url fixes for templates

v1.18.x
Baris Soner Usakli 12 years ago
parent 6eb9af77e6
commit 43e73e3aba

@ -25,16 +25,32 @@ var ajaxify = {};
if (event !== null && event.state && event.state.url !== undefined) ajaxify.go(event.state.url, null, null, true);
};
function generatePushUrl(url) {
if(url.indexOf(RELATIVE_PATH.slice(1)) === -1)
return RELATIVE_PATH + '/' + url;
else
return url.slice(RELATIVE_PATH.length);
}
ajaxify.go = function(url, callback, template, quiet) {
// leave room and join global
app.enter_room('global');
var url = url.replace(/\/$/, "");
if(url.indexOf(RELATIVE_PATH.slice(1)) !== -1) {
url = url.slice(RELATIVE_PATH.length);
}
var tpl_url = templates.get_custom_map(url);
if (tpl_url == false && !templates[url]) {
tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0];
if(url === '' || url === '/') {
tpl_url = 'home';
} else {
tpl_url = url.split('/')[0];
}
} else if (templates[url]) {
tpl_url = url;
}
@ -43,7 +59,7 @@ var ajaxify = {};
if (quiet !== true) {
window.history.pushState({
"url": url
}, url, RELATIVE_PATH + '/' + url);
}, url, generatePushUrl(url));
}
jQuery('#footer, #content').fadeOut(100);

@ -105,7 +105,17 @@
loadTemplates(templates_to_load || []);
}
templates.getTemplateNameFromUrl = function(url) {
var parts = url.split('/');
for(var i=0; i<parts.length; ++i) {
if (templates.is_available(parts[i])) {
return parts[i];
}
}
return '';
}
templates.load_template = function(callback, url, template) {
var location = document.location || window.location,
@ -116,16 +126,10 @@
var tpl_url = templates.get_custom_map(api_url);
var trimmed = api_url;
while (tpl_url == false && trimmed.length > 0) {
if (templates.is_available(trimmed)) {
tpl_url = trimmed;
}
trimmed = trimmed.split('/');
trimmed.pop();
trimmed = trimmed.join('/');
}
if(!tpl_url) {
tpl_url = templates.getTemplateNameFromUrl(api_url);
}
var template_data = null;

Loading…
Cancel
Save