From 667a78902e7c9218eb4b66bb97ebbd3e423630cb Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 27 May 2014 13:29:14 -0400 Subject: [PATCH] closed #1586 --- public/src/ajaxify.js | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index b49500e0d2..eb1b9cf28f 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -37,7 +37,7 @@ var ajaxify = ajaxify || {}; return ajaxify.go('login'); } else if (data.status === 302) { return ajaxify.go(data.responseJSON.slice(1)); - } + } } else if (textStatus !== "abort") { app.alertError(data.responseJSON.error); } @@ -146,24 +146,18 @@ var ajaxify = ajaxify || {}; var tpl_url = ajaxify.getCustomTemplateMapping(url.split('?')[0]); if (tpl_url === false && !templates[url]) { - if (url === '' || url === '/') { - tpl_url = 'home'; - } else if (url === 'admin' || url === 'admin/') { - tpl_url = 'admin/index'; - } else { - tpl_url = url.split('/'); - - while(tpl_url.length) { - if (ajaxify.isTemplateAvailable(tpl_url.join('/'))) { - tpl_url = tpl_url.join('/'); - break; - } - tpl_url.pop(); - } + tpl_url = url.split('/'); - if (!tpl_url.length) { - tpl_url = url.split('/')[0].split('?')[0]; + while(tpl_url.length) { + if (ajaxify.isTemplateAvailable(tpl_url.join('/'))) { + tpl_url = tpl_url.join('/'); + break; } + tpl_url.pop(); + } + + if (!tpl_url.length) { + tpl_url = url.split('/')[0].split('?')[0]; } } else if (templates[url]) { tpl_url = url; @@ -173,7 +167,7 @@ var ajaxify = ajaxify || {}; }; ajaxify.getCustomTemplateMapping = function(tpl) { - if (templatesConfig.custom_mapping && tpl) { + if (templatesConfig.custom_mapping && tpl !== undefined) { for (var pattern in templatesConfig.custom_mapping) { if (tpl.match(pattern)) { return (templatesConfig.custom_mapping[pattern]); @@ -186,17 +180,17 @@ var ajaxify = ajaxify || {}; ajaxify.loadData = function(callback, url, template) { $(window).trigger('action:ajaxify.loadingData', {url: url}); - + if (ajaxify.preloader && ajaxify.preloader.url === url) { return callback(null, ajaxify.preloader.data); } var location = document.location || window.location, api_url = (url === '' || url === '/') ? 'home' : url, - tpl_url = ajaxify.getCustomTemplateMapping(api_url.split('?')[0]); + tpl_url = ajaxify.getCustomTemplateMapping(url.split('?')[0]); if (!tpl_url) { - tpl_url = ajaxify.getTemplateMapping(api_url); + tpl_url = ajaxify.getTemplateMapping(url); } apiXHR = $.ajax({