mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 15:35:47 +01:00
url fixes for templates
This commit is contained in:
@@ -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,6 +105,16 @@
|
||||
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) {
|
||||
@@ -116,17 +126,11 @@
|
||||
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;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user