Skip to content

Node.js based forum software built for the modern web

url fixes for templates

Baris Soner Usakli43e73e3aba46
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
index d86225070e..44c45884fa 100644
--- a/public/src/ajaxify.js
+++ b/public/src/ajaxify.js
@@ -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);
diff --git a/public/src/templates.js b/public/src/templates.js
index 07080492a6..53befa5db6 100644
--- a/public/src/templates.js
+++ b/public/src/templates.js
@@ -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;