mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
removed templates config and mapping 🐑
This commit is contained in:
@@ -3,321 +3,266 @@
|
|||||||
var ajaxify = ajaxify || {};
|
var ajaxify = ajaxify || {};
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
require(['templates'], function (templatesModule) {
|
|
||||||
/*global app, templates, utils, socket, translator, config, RELATIVE_PATH*/
|
|
||||||
|
|
||||||
var location = document.location || window.location,
|
/*global app, templates, utils, socket, translator, config, RELATIVE_PATH*/
|
||||||
rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''),
|
|
||||||
apiXHR = null;
|
|
||||||
|
|
||||||
|
var location = document.location || window.location,
|
||||||
|
rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''),
|
||||||
|
apiXHR = null;
|
||||||
|
|
||||||
window.onpopstate = function (event) {
|
window.onpopstate = function (event) {
|
||||||
if (event !== null && event.state && event.state.url !== undefined && !ajaxify.initialLoad) {
|
if (event !== null && event.state && event.state.url !== undefined && !ajaxify.initialLoad) {
|
||||||
ajaxify.go(event.state.url, function() {
|
ajaxify.go(event.state.url, function() {
|
||||||
$(window).trigger('action:popstate', {url: event.state.url});
|
$(window).trigger('action:popstate', {url: event.state.url});
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ajaxify.currentPage = null;
|
ajaxify.currentPage = null;
|
||||||
ajaxify.initialLoad = false;
|
ajaxify.initialLoad = false;
|
||||||
|
|
||||||
|
ajaxify.go = function (url, callback, quiet) {
|
||||||
|
// "quiet": If set to true, will not call pushState
|
||||||
|
app.enterRoom('');
|
||||||
|
|
||||||
function onAjaxError(err, url, callback, quiet) {
|
$(window).off('scroll');
|
||||||
var data = err.data,
|
|
||||||
textStatus = err.textStatus;
|
|
||||||
|
|
||||||
if (data) {
|
if ($('#content').hasClass('ajaxifying') && apiXHR) {
|
||||||
var status = parseInt(data.status, 10);
|
apiXHR.abort();
|
||||||
|
|
||||||
if (status === 403 || status === 404 || status === 500) {
|
|
||||||
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
|
|
||||||
return renderTemplate(url, status.toString(), data.responseJSON, (new Date()).getTime(), callback);
|
|
||||||
} else if (status === 401) {
|
|
||||||
app.alertError('[[global:please_log_in]]');
|
|
||||||
app.previousUrl = url;
|
|
||||||
return ajaxify.go('login');
|
|
||||||
} else if (status === 302) {
|
|
||||||
if (data.responseJSON.path) {
|
|
||||||
if (!ajaxify.go(data.responseJSON.path, callback, quiet)) {
|
|
||||||
window.location.href = data.responseJSON.path;
|
|
||||||
}
|
|
||||||
} else if (data.responseJSON) {
|
|
||||||
ajaxify.go(data.responseJSON.slice(1), callback, quiet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (textStatus !== 'abort') {
|
|
||||||
app.alertError(data.responseJSON.error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ajaxify.go = function (url, callback, quiet) {
|
// Remove relative path and trailing slash
|
||||||
// "quiet": If set to true, will not call pushState
|
url = ajaxify.removeRelativePath(url.replace(/\/$/, ''));
|
||||||
app.enterRoom('');
|
|
||||||
|
|
||||||
$(window).off('scroll');
|
$(window).trigger('action:ajaxify.start', {url: url});
|
||||||
|
|
||||||
if ($('#content').hasClass('ajaxifying') && apiXHR) {
|
|
||||||
apiXHR.abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove relative path and trailing slash
|
|
||||||
url = ajaxify.removeRelativePath(url.replace(/\/$/, ''));
|
|
||||||
|
|
||||||
var tpl_url = ajaxify.getTemplateMapping(url);
|
|
||||||
|
|
||||||
$(window).trigger('action:ajaxify.start', {url: url, tpl_url: tpl_url});
|
|
||||||
|
|
||||||
var hash = '';
|
|
||||||
if(ajaxify.initialLoad) {
|
|
||||||
hash = window.location.hash ? window.location.hash : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ajaxify.isTemplateAvailable(tpl_url) && !!!templatesModule.config.force_refresh[tpl_url]) {
|
|
||||||
ajaxify.currentPage = url;
|
|
||||||
|
|
||||||
if (window.history && window.history.pushState) {
|
|
||||||
window.history[!quiet ? 'pushState' : 'replaceState']({
|
|
||||||
url: url + hash
|
|
||||||
}, url, RELATIVE_PATH + '/' + url + hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
translator.load(config.defaultLang, tpl_url);
|
|
||||||
|
|
||||||
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
|
|
||||||
|
|
||||||
var startTime = (new Date()).getTime();
|
|
||||||
|
|
||||||
ajaxify.variables.flush();
|
|
||||||
ajaxify.loadData(url, function(err, data) {
|
|
||||||
if (err) {
|
|
||||||
return onAjaxError(err, url, callback, quiet);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderTemplate(url, tpl_url, data, startTime, callback);
|
|
||||||
|
|
||||||
require(['search'], function(search) {
|
|
||||||
search.topicDOM.end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
function renderTemplate(url, tpl_url, data, startTime, callback) {
|
|
||||||
var animationDuration = parseFloat($('#content').css('transition-duration')) || 0.2;
|
|
||||||
$(window).trigger('action:ajaxify.loadingTemplates', {});
|
|
||||||
|
|
||||||
templates.parse(tpl_url, data, function(template) {
|
|
||||||
translator.translate(template, function(translatedTemplate) {
|
|
||||||
setTimeout(function() {
|
|
||||||
$('#content').html(translatedTemplate);
|
|
||||||
|
|
||||||
ajaxify.variables.parse();
|
|
||||||
|
|
||||||
ajaxify.widgets.render(tpl_url, url, function() {
|
|
||||||
$(window).trigger('action:ajaxify.end', {url: url, tpl_url: tpl_url});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(window).trigger('action:ajaxify.contentLoaded', {url: url});
|
|
||||||
|
|
||||||
ajaxify.loadScript(tpl_url);
|
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
app.processPage();
|
|
||||||
|
|
||||||
$('#content, #footer').removeClass('ajaxifying');
|
|
||||||
ajaxify.initialLoad = false;
|
|
||||||
|
|
||||||
app.refreshTitle(url);
|
|
||||||
}, animationDuration * 1000 - ((new Date()).getTime() - startTime));
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
var hash = '';
|
||||||
|
if(ajaxify.initialLoad) {
|
||||||
|
hash = window.location.hash ? window.location.hash : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
ajaxify.removeRelativePath = function(url) {
|
ajaxify.currentPage = url;
|
||||||
if (url.indexOf(RELATIVE_PATH.slice(1)) === 0) {
|
|
||||||
url = url.slice(RELATIVE_PATH.length);
|
if (window.history && window.history.pushState) {
|
||||||
|
window.history[!quiet ? 'pushState' : 'replaceState']({
|
||||||
|
url: url + hash
|
||||||
|
}, url, RELATIVE_PATH + '/' + url + hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
|
||||||
|
|
||||||
|
var startTime = (new Date()).getTime();
|
||||||
|
|
||||||
|
ajaxify.variables.flush();
|
||||||
|
ajaxify.loadData(url, function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
return onAjaxError(err, url, callback, quiet);
|
||||||
}
|
}
|
||||||
return url;
|
|
||||||
};
|
|
||||||
|
|
||||||
ajaxify.refresh = function() {
|
app.template = data.template.name;
|
||||||
ajaxify.go(ajaxify.currentPage);
|
|
||||||
};
|
|
||||||
|
|
||||||
ajaxify.loadScript = function(tpl_url, callback) {
|
translator.load(config.defaultLang, data.template.name);
|
||||||
var location = !app.inAdmin ? 'forum/' : '';
|
|
||||||
|
|
||||||
require([location + tpl_url], function(script) {
|
renderTemplate(url, data.template.name, data, startTime, callback);
|
||||||
if (script && script.init) {
|
|
||||||
script.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
require(['search'], function(search) {
|
||||||
callback();
|
search.topicDOM.end();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
ajaxify.isTemplateAvailable = function(tpl) {
|
|
||||||
return $.inArray(tpl + '.tpl', templatesModule.available) !== -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
ajaxify.getTemplateMapping = function(url) {
|
|
||||||
var tpl_url = ajaxify.getCustomTemplateMapping(url.split('?')[0]);
|
|
||||||
|
|
||||||
if (tpl_url === false && !templates[url]) {
|
|
||||||
tpl_url = url.split('/');
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tpl_url;
|
|
||||||
};
|
|
||||||
|
|
||||||
ajaxify.getCustomTemplateMapping = function(tpl) {
|
|
||||||
if (templatesModule.config && templatesModule.config.custom_mapping && tpl !== undefined) {
|
|
||||||
for (var pattern in templatesModule.config.custom_mapping) {
|
|
||||||
if (templatesModule.config.custom_mapping.hasOwnProperty(pattern)) {
|
|
||||||
var match = tpl.match(pattern);
|
|
||||||
if (match && match[0] === tpl) {
|
|
||||||
return (templatesModule.config.custom_mapping[pattern]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
ajaxify.loadData = function(url, callback) {
|
|
||||||
url = ajaxify.removeRelativePath(url);
|
|
||||||
|
|
||||||
$(window).trigger('action:ajaxify.loadingData', {url: url});
|
|
||||||
|
|
||||||
var location = document.location || window.location,
|
|
||||||
tpl_url = ajaxify.getCustomTemplateMapping(url.split('?')[0]);
|
|
||||||
|
|
||||||
if (!tpl_url) {
|
|
||||||
tpl_url = ajaxify.getTemplateMapping(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
apiXHR = $.ajax({
|
|
||||||
url: RELATIVE_PATH + '/api/' + url,
|
|
||||||
cache: false,
|
|
||||||
success: function(data) {
|
|
||||||
if (!data) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.relative_path = RELATIVE_PATH;
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
callback(null, data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function(data, textStatus) {
|
|
||||||
callback({
|
|
||||||
data: data,
|
|
||||||
textStatus: textStatus
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ajaxify.loadTemplate = function(template, callback) {
|
|
||||||
if (templates.cache[template]) {
|
|
||||||
callback(templates.cache[template]);
|
|
||||||
} else {
|
|
||||||
$.ajax({
|
|
||||||
url: RELATIVE_PATH + '/templates/' + template + '.tpl' + (config['cache-buster'] ? '?v=' + config['cache-buster'] : ''),
|
|
||||||
type: 'GET',
|
|
||||||
success: function(data) {
|
|
||||||
callback(data.toString());
|
|
||||||
},
|
|
||||||
error: function(error) {
|
|
||||||
throw new Error("Unable to load template: " + template + " (" + error.statusText + ")");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$('document').ready(function () {
|
|
||||||
templates.registerLoader(ajaxify.loadTemplate);
|
|
||||||
templatesModule.refresh(app.load);
|
|
||||||
|
|
||||||
if (!window.history || !window.history.pushState) {
|
|
||||||
return; // no ajaxification for old browsers
|
|
||||||
}
|
|
||||||
|
|
||||||
function hrefEmpty(href) {
|
|
||||||
return href === undefined || href === '' || href === 'javascript:;' || href === window.location.href + "#" || href.slice(0, 1) === "#";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enhancing all anchors to ajaxify...
|
|
||||||
$(document.body).on('click', 'a', function (e) {
|
|
||||||
if (this.target !== '') {
|
|
||||||
return;
|
|
||||||
} else if (hrefEmpty(this.href) || this.protocol === 'javascript:' || $(this).attr('data-ajaxify') === 'false') {
|
|
||||||
return e.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!window.location.pathname.match(/\/(403|404)$/g)) {
|
|
||||||
app.previousUrl = window.location.href;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!e.ctrlKey && !e.shiftKey && !e.metaKey && e.which === 1) {
|
|
||||||
if (this.host === '' || this.host === window.location.host) {
|
|
||||||
// Internal link
|
|
||||||
var url = this.href.replace(rootUrl + '/', '');
|
|
||||||
|
|
||||||
if(window.location.pathname === this.pathname && this.hash) {
|
|
||||||
if (this.hash !== window.location.hash) {
|
|
||||||
window.location.hash = this.hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
ajaxify.loadScript(ajaxify.getTemplateMapping(url));
|
|
||||||
e.preventDefault();
|
|
||||||
} else {
|
|
||||||
if (ajaxify.go(url)) {
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (window.location.pathname !== '/outgoing') {
|
|
||||||
// External Link
|
|
||||||
if (config.openOutgoingLinksInNewTab) {
|
|
||||||
window.open(this.href, '_blank');
|
|
||||||
e.preventDefault();
|
|
||||||
} else if (config.useOutgoingLinksPage) {
|
|
||||||
ajaxify.go('outgoing?url=' + encodeURIComponent(this.href));
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
function onAjaxError(err, url, callback, quiet) {
|
||||||
|
var data = err.data,
|
||||||
|
textStatus = err.textStatus;
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
var status = parseInt(data.status, 10);
|
||||||
|
|
||||||
|
if (status === 403 || status === 404 || status === 500) {
|
||||||
|
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
|
||||||
|
return renderTemplate(url, status.toString(), data.responseJSON, (new Date()).getTime(), callback);
|
||||||
|
} else if (status === 401) {
|
||||||
|
app.alertError('[[global:please_log_in]]');
|
||||||
|
app.previousUrl = url;
|
||||||
|
return ajaxify.go('login');
|
||||||
|
} else if (status === 302) {
|
||||||
|
if (data.responseJSON.path) {
|
||||||
|
if (!ajaxify.go(data.responseJSON.path, callback, quiet)) {
|
||||||
|
window.location.href = data.responseJSON.path;
|
||||||
|
}
|
||||||
|
} else if (data.responseJSON) {
|
||||||
|
ajaxify.go(data.responseJSON.slice(1), callback, quiet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (textStatus !== 'abort') {
|
||||||
|
app.alertError(data.responseJSON.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTemplate(url, tpl_url, data, startTime, callback) {
|
||||||
|
var animationDuration = parseFloat($('#content').css('transition-duration')) || 0.2;
|
||||||
|
$(window).trigger('action:ajaxify.loadingTemplates', {});
|
||||||
|
|
||||||
|
templates.parse(tpl_url, data, function(template) {
|
||||||
|
translator.translate(template, function(translatedTemplate) {
|
||||||
|
setTimeout(function() {
|
||||||
|
$('#content').html(translatedTemplate);
|
||||||
|
|
||||||
|
ajaxify.variables.parse();
|
||||||
|
|
||||||
|
ajaxify.widgets.render(tpl_url, url, function() {
|
||||||
|
$(window).trigger('action:ajaxify.end', {url: url});
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).trigger('action:ajaxify.contentLoaded', {url: url});
|
||||||
|
|
||||||
|
ajaxify.loadScript(tpl_url);
|
||||||
|
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.processPage();
|
||||||
|
|
||||||
|
$('#content, #footer').removeClass('ajaxifying');
|
||||||
|
ajaxify.initialLoad = false;
|
||||||
|
|
||||||
|
app.refreshTitle(url);
|
||||||
|
}, animationDuration * 1000 - ((new Date()).getTime() - startTime));
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ajaxify.removeRelativePath = function(url) {
|
||||||
|
if (url.indexOf(RELATIVE_PATH.slice(1)) === 0) {
|
||||||
|
url = url.slice(RELATIVE_PATH.length);
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
};
|
||||||
|
|
||||||
|
ajaxify.refresh = function() {
|
||||||
|
ajaxify.go(ajaxify.currentPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
ajaxify.loadScript = function(tpl_url, callback) {
|
||||||
|
var location = !app.inAdmin ? 'forum/' : '';
|
||||||
|
|
||||||
|
require([location + tpl_url], function(script) {
|
||||||
|
if (script && script.init) {
|
||||||
|
script.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ajaxify.loadData = function(url, callback) {
|
||||||
|
url = ajaxify.removeRelativePath(url);
|
||||||
|
|
||||||
|
$(window).trigger('action:ajaxify.loadingData', {url: url});
|
||||||
|
|
||||||
|
var location = document.location || window.location;
|
||||||
|
|
||||||
|
apiXHR = $.ajax({
|
||||||
|
url: RELATIVE_PATH + '/api/' + url,
|
||||||
|
cache: false,
|
||||||
|
success: function(data) {
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.relative_path = RELATIVE_PATH;
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback(null, data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(data, textStatus) {
|
||||||
|
callback({
|
||||||
|
data: data,
|
||||||
|
textStatus: textStatus
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ajaxify.loadTemplate = function(template, callback) {
|
||||||
|
if (templates.cache[template]) {
|
||||||
|
callback(templates.cache[template]);
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
url: RELATIVE_PATH + '/templates/' + template + '.tpl' + (config['cache-buster'] ? '?v=' + config['cache-buster'] : ''),
|
||||||
|
type: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
callback(data.toString());
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
throw new Error("Unable to load template: " + template + " (" + error.statusText + ")");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function ajaxifyAnchors() {
|
||||||
|
templates.registerLoader(ajaxify.loadTemplate);
|
||||||
|
|
||||||
|
if (!window.history || !window.history.pushState) {
|
||||||
|
return; // no ajaxification for old browsers
|
||||||
|
}
|
||||||
|
|
||||||
|
function hrefEmpty(href) {
|
||||||
|
return href === undefined || href === '' || href === 'javascript:;' || href === window.location.href + "#" || href.slice(0, 1) === "#";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enhancing all anchors to ajaxify...
|
||||||
|
$(document.body).on('click', 'a', function (e) {
|
||||||
|
if (this.target !== '') {
|
||||||
|
return;
|
||||||
|
} else if (hrefEmpty(this.href) || this.protocol === 'javascript:' || $(this).attr('data-ajaxify') === 'false') {
|
||||||
|
return e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!window.location.pathname.match(/\/(403|404)$/g)) {
|
||||||
|
app.previousUrl = window.location.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!e.ctrlKey && !e.shiftKey && !e.metaKey && e.which === 1) {
|
||||||
|
if (this.host === '' || this.host === window.location.host) {
|
||||||
|
// Internal link
|
||||||
|
var url = this.href.replace(rootUrl + '/', '');
|
||||||
|
|
||||||
|
if(window.location.pathname === this.pathname && this.hash) {
|
||||||
|
if (this.hash !== window.location.hash) {
|
||||||
|
window.location.hash = this.hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
} else {
|
||||||
|
if (ajaxify.go(url)) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (window.location.pathname !== '/outgoing') {
|
||||||
|
// External Link
|
||||||
|
if (config.openOutgoingLinksInNewTab) {
|
||||||
|
window.open(this.href, '_blank');
|
||||||
|
e.preventDefault();
|
||||||
|
} else if (config.useOutgoingLinksPage) {
|
||||||
|
ajaxify.go('outgoing?url=' + encodeURIComponent(this.href));
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ajaxifyAnchors();
|
||||||
|
app.load();
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -482,16 +482,12 @@ app.cacheBuster = null;
|
|||||||
app.load = function() {
|
app.load = function() {
|
||||||
$('document').ready(function () {
|
$('document').ready(function () {
|
||||||
var url = ajaxify.removeRelativePath(window.location.pathname.slice(1).replace(/\/$/, "")),
|
var url = ajaxify.removeRelativePath(window.location.pathname.slice(1).replace(/\/$/, "")),
|
||||||
tpl_url = ajaxify.getTemplateMapping(url),
|
tpl_url = app.template,
|
||||||
search = window.location.search,
|
search = window.location.search,
|
||||||
hash = window.location.hash,
|
hash = window.location.hash,
|
||||||
$window = $(window);
|
$window = $(window);
|
||||||
|
|
||||||
|
$window.trigger('action:ajaxify.start', {url: url});
|
||||||
$window.trigger('action:ajaxify.start', {
|
|
||||||
url: url,
|
|
||||||
tpl_url: tpl_url
|
|
||||||
});
|
|
||||||
|
|
||||||
collapseNavigationOnClick();
|
collapseNavigationOnClick();
|
||||||
|
|
||||||
@@ -532,8 +528,7 @@ app.cacheBuster = null;
|
|||||||
ajaxify.widgets.render(tpl_url, url, function() {
|
ajaxify.widgets.render(tpl_url, url, function() {
|
||||||
app.processPage();
|
app.processPage();
|
||||||
$window.trigger('action:ajaxify.end', {
|
$window.trigger('action:ajaxify.end', {
|
||||||
url: url,
|
url: url
|
||||||
tpl_url: tpl_url
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ define('forum/categories', function() {
|
|||||||
var categories = {};
|
var categories = {};
|
||||||
|
|
||||||
$(window).on('action:ajaxify.start', function(ev, data) {
|
$(window).on('action:ajaxify.start', function(ev, data) {
|
||||||
if (data.tpl_url !== 'categories') {
|
if (ajaxify.currentPage !== data.url) {
|
||||||
socket.removeListener('event:new_post', categories.onNewPost);
|
socket.removeListener('event:new_post', categories.onNewPost);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ define('forum/category', [
|
|||||||
var Category = {};
|
var Category = {};
|
||||||
|
|
||||||
$(window).on('action:ajaxify.start', function(ev, data) {
|
$(window).on('action:ajaxify.start', function(ev, data) {
|
||||||
if(data && data.tpl_url !== 'category') {
|
if (ajaxify.currentPage !== data.url) {
|
||||||
navigator.hide();
|
navigator.hide();
|
||||||
|
|
||||||
removeListeners();
|
removeListeners();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) {
|
|||||||
newPostCount = 0;
|
newPostCount = 0;
|
||||||
|
|
||||||
$(window).on('action:ajaxify.start', function(ev, data) {
|
$(window).on('action:ajaxify.start', function(ev, data) {
|
||||||
if (data.tpl_url !== 'recent') {
|
if (ajaxify.currentPage !== data.url) {
|
||||||
Recent.removeListeners();
|
Recent.removeListeners();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ define('forum/topic', [
|
|||||||
currentUrl = '';
|
currentUrl = '';
|
||||||
|
|
||||||
$(window).on('action:ajaxify.start', function(ev, data) {
|
$(window).on('action:ajaxify.start', function(ev, data) {
|
||||||
if(data.tpl_url !== 'topic') {
|
if (ajaxify.currentPage !=== data.url) {
|
||||||
navigator.hide();
|
navigator.hide();
|
||||||
$('.header-topic-title').find('span').text('').hide();
|
$('.header-topic-title').find('span').text('').hide();
|
||||||
app.removeAlert('bookmark');
|
app.removeAlert('bookmark');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
var Unread = {};
|
var Unread = {};
|
||||||
|
|
||||||
$(window).on('action:ajaxify.start', function(ev, data) {
|
$(window).on('action:ajaxify.start', function(ev, data) {
|
||||||
if (data.tpl_url !== 'unread') {
|
if (ajaxify.currentPage !== data.url) {
|
||||||
recent.removeListeners();
|
recent.removeListeners();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -130,7 +130,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
|
|
||||||
function createCategoryLink(category) {
|
function createCategoryLink(category) {
|
||||||
var link = $('<a role="menuitem" href="#"></a>');
|
var link = $('<a role="menuitem" href="#"></a>');
|
||||||
|
|
||||||
if (category.icon) {
|
if (category.icon) {
|
||||||
link.append('<i class="fa fa-fw ' + category.icon + '"></i> ' + category.name);
|
link.append('<i class="fa fa-fw ' + category.icon + '"></i> ' + category.name);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
/*globals define, RELATIVE_PATH*/
|
|
||||||
|
|
||||||
define('templates', function() {
|
|
||||||
var Templates = {};
|
|
||||||
|
|
||||||
Templates.refresh = function(callback) {
|
|
||||||
$.getJSON(RELATIVE_PATH + '/api/get_templates_listing', function (data) {
|
|
||||||
Templates.config = data.templatesConfig;
|
|
||||||
Templates.available = data.availableTemplates;
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return Templates;
|
|
||||||
});
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
var async = require('async'),
|
|
||||||
nconf = require('nconf'),
|
|
||||||
fs = require('fs'),
|
|
||||||
path = require('path'),
|
|
||||||
meta = require('../meta'),
|
|
||||||
plugins = require('../plugins'),
|
|
||||||
utils = require('../../public/src/utils'),
|
|
||||||
templatesController = {};
|
|
||||||
|
|
||||||
|
|
||||||
var availableTemplatesCache = null;
|
|
||||||
var configCache = null;
|
|
||||||
|
|
||||||
templatesController.getTemplatesListing = function(req, res, next) {
|
|
||||||
async.parallel({
|
|
||||||
availableTemplates: function(next) {
|
|
||||||
getAvailableTemplates(next);
|
|
||||||
},
|
|
||||||
templatesConfig: function(next) {
|
|
||||||
async.waterfall([
|
|
||||||
function(next) {
|
|
||||||
readConfigFile(next);
|
|
||||||
},
|
|
||||||
function(config, next) {
|
|
||||||
config.custom_mapping['^/?$'] = meta.config.homePageRoute || 'categories';
|
|
||||||
|
|
||||||
plugins.fireHook('filter:templates.get_config', config, next);
|
|
||||||
}
|
|
||||||
], next);
|
|
||||||
},
|
|
||||||
}, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.json(results);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function readConfigFile(callback) {
|
|
||||||
if (configCache) {
|
|
||||||
return callback(null, configCache);
|
|
||||||
}
|
|
||||||
fs.readFile(path.join(nconf.get('views_dir'), 'config.json'), function(err, config) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
config = JSON.parse(config.toString());
|
|
||||||
} catch (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
configCache = config;
|
|
||||||
callback(null, config);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAvailableTemplates(callback) {
|
|
||||||
if (availableTemplatesCache) {
|
|
||||||
return callback(null, availableTemplatesCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.parallel({
|
|
||||||
views: function(next) {
|
|
||||||
utils.walk(nconf.get('views_dir'), next);
|
|
||||||
},
|
|
||||||
extended: function(next) {
|
|
||||||
plugins.fireHook('filter:templates.get_virtual', [], next);
|
|
||||||
}
|
|
||||||
}, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
var availableTemplates = results.views.filter(function(value, index, self) {
|
|
||||||
return value && self.indexOf(value) === index;
|
|
||||||
}).map(function(el) {
|
|
||||||
return el && el.replace(nconf.get('views_dir') + '/', '');
|
|
||||||
});
|
|
||||||
|
|
||||||
availableTemplatesCache = availableTemplates.concat(results.extended);
|
|
||||||
callback(null, availableTemplatesCache);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = templatesController;
|
|
||||||
@@ -348,6 +348,9 @@ middleware.renderHeader = function(req, res, callback) {
|
|||||||
templateValues.customJS = results.customJS;
|
templateValues.customJS = results.customJS;
|
||||||
templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin;
|
templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin;
|
||||||
|
|
||||||
|
templateValues.template = {name: res.locals.template};
|
||||||
|
templateValues.template[res.locals.template] = true;
|
||||||
|
|
||||||
app.render('header', templateValues, callback);
|
app.render('header', templateValues, callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -378,6 +381,7 @@ middleware.processRender = function(req, res, next) {
|
|||||||
options.loggedIn = req.user ? parseInt(req.user.uid, 10) !== 0 : false;
|
options.loggedIn = req.user ? parseInt(req.user.uid, 10) !== 0 : false;
|
||||||
options.template = {name: template};
|
options.template = {name: template};
|
||||||
options.template[template] = true;
|
options.template[template] = true;
|
||||||
|
res.locals.template = template;
|
||||||
|
|
||||||
if ('function' !== typeof fn) {
|
if ('function' !== typeof fn) {
|
||||||
fn = defaultFn;
|
fn = defaultFn;
|
||||||
@@ -453,7 +457,6 @@ middleware.maintenanceMode = function(req, res, next) {
|
|||||||
'/nodebb.min.js',
|
'/nodebb.min.js',
|
||||||
'/vendor/fontawesome/fonts/fontawesome-webfont.woff',
|
'/vendor/fontawesome/fonts/fontawesome-webfont.woff',
|
||||||
'/src/modules/[\\w]+\.js',
|
'/src/modules/[\\w]+\.js',
|
||||||
'/api/get_templates_listing',
|
|
||||||
'/api/login',
|
'/api/login',
|
||||||
'/api/?',
|
'/api/?',
|
||||||
'/language/.+'
|
'/language/.+'
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ var express = require('express'),
|
|||||||
|
|
||||||
posts = require('../posts'),
|
posts = require('../posts'),
|
||||||
categories = require('../categories'),
|
categories = require('../categories'),
|
||||||
uploadsController = require('../controllers/uploads'),
|
uploadsController = require('../controllers/uploads');
|
||||||
templatesController = require('../controllers/templates');
|
|
||||||
|
|
||||||
module.exports = function(app, middleware, controllers) {
|
module.exports = function(app, middleware, controllers) {
|
||||||
|
|
||||||
@@ -17,7 +16,6 @@ module.exports = function(app, middleware, controllers) {
|
|||||||
|
|
||||||
router.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID);
|
router.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID);
|
||||||
router.get('/post/:pid', controllers.posts.getPost);
|
router.get('/post/:pid', controllers.posts.getPost);
|
||||||
router.get('/get_templates_listing', templatesController.getTemplatesListing);
|
|
||||||
router.get('/categories/:cid/moderators', getModerators);
|
router.get('/categories/:cid/moderators', getModerators);
|
||||||
router.get('/recent/posts/:term?', getRecentPosts);
|
router.get('/recent/posts/:term?', getRecentPosts);
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"custom_mapping": {
|
|
||||||
"^\/?$": "categories",
|
|
||||||
"^admin?$": "admin/general/dashboard",
|
|
||||||
"^users/sort-posts": "users",
|
|
||||||
"^users/latest": "users",
|
|
||||||
"^users/sort-reputation": "users",
|
|
||||||
"^users/search": "users",
|
|
||||||
"^user/.*/edit": "account/edit",
|
|
||||||
"^user/.*/following": "account/following",
|
|
||||||
"^user/.*/followers": "account/followers",
|
|
||||||
"^user/.*/settings": "account/settings",
|
|
||||||
"^user/.*/favourites": "account/favourites",
|
|
||||||
"^user/.*/watched": "account/watched",
|
|
||||||
"^user/.*/posts": "account/posts",
|
|
||||||
"^user/.*/topics": "account/topics",
|
|
||||||
"^user/.*/groups": "account/groups",
|
|
||||||
"^user/[^\/]+": "account/profile",
|
|
||||||
"^reset/.*": "reset_code",
|
|
||||||
"^tags/.*": "tag",
|
|
||||||
"^groups/?$": "groups/list",
|
|
||||||
"^groups/.*": "groups/details"
|
|
||||||
},
|
|
||||||
"force_refresh": {
|
|
||||||
"logout": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user