mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +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);
|
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) {
|
ajaxify.go = function(url, callback, template, quiet) {
|
||||||
// leave room and join global
|
// leave room and join global
|
||||||
app.enter_room('global');
|
app.enter_room('global');
|
||||||
|
|
||||||
var url = url.replace(/\/$/, "");
|
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);
|
var tpl_url = templates.get_custom_map(url);
|
||||||
|
|
||||||
if (tpl_url == false && !templates[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]) {
|
} else if (templates[url]) {
|
||||||
tpl_url = url;
|
tpl_url = url;
|
||||||
}
|
}
|
||||||
@@ -43,7 +59,7 @@ var ajaxify = {};
|
|||||||
if (quiet !== true) {
|
if (quiet !== true) {
|
||||||
window.history.pushState({
|
window.history.pushState({
|
||||||
"url": url
|
"url": url
|
||||||
}, url, RELATIVE_PATH + '/' + url);
|
}, url, generatePushUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery('#footer, #content').fadeOut(100);
|
jQuery('#footer, #content').fadeOut(100);
|
||||||
|
|||||||
@@ -105,6 +105,16 @@
|
|||||||
loadTemplates(templates_to_load || []);
|
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) {
|
templates.load_template = function(callback, url, template) {
|
||||||
@@ -116,17 +126,11 @@
|
|||||||
var tpl_url = templates.get_custom_map(api_url);
|
var tpl_url = templates.get_custom_map(api_url);
|
||||||
|
|
||||||
var trimmed = api_url;
|
var trimmed = api_url;
|
||||||
while (tpl_url == false && trimmed.length > 0) {
|
|
||||||
if (templates.is_available(trimmed)) {
|
|
||||||
tpl_url = trimmed;
|
|
||||||
}
|
|
||||||
|
|
||||||
trimmed = trimmed.split('/');
|
if(!tpl_url) {
|
||||||
trimmed.pop();
|
tpl_url = templates.getTemplateNameFromUrl(api_url);
|
||||||
trimmed = trimmed.join('/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var template_data = null;
|
var template_data = null;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user