|
|
|
@ -3,321 +3,266 @@
|
|
|
|
|
var ajaxify = ajaxify || {};
|
|
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
require(['templates'], function (templatesModule) {
|
|
|
|
|
/*global app, templates, utils, socket, translator, config, RELATIVE_PATH*/
|
|
|
|
|
|
|
|
|
|
var location = document.location || window.location,
|
|
|
|
|
rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''),
|
|
|
|
|
apiXHR = null;
|
|
|
|
|
/*global app, templates, utils, socket, translator, config, RELATIVE_PATH*/
|
|
|
|
|
|
|
|
|
|
var location = document.location || window.location,
|
|
|
|
|
rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''),
|
|
|
|
|
apiXHR = null;
|
|
|
|
|
|
|
|
|
|
window.onpopstate = function (event) {
|
|
|
|
|
if (event !== null && event.state && event.state.url !== undefined && !ajaxify.initialLoad) {
|
|
|
|
|
ajaxify.go(event.state.url, function() {
|
|
|
|
|
$(window).trigger('action:popstate', {url: event.state.url});
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ajaxify.currentPage = null;
|
|
|
|
|
ajaxify.initialLoad = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
window.onpopstate = function (event) {
|
|
|
|
|
if (event !== null && event.state && event.state.url !== undefined && !ajaxify.initialLoad) {
|
|
|
|
|
ajaxify.go(event.state.url, function() {
|
|
|
|
|
$(window).trigger('action:popstate', {url: event.state.url});
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ajaxify.go = function (url, callback, quiet) {
|
|
|
|
|
// "quiet": If set to true, will not call pushState
|
|
|
|
|
app.enterRoom('');
|
|
|
|
|
ajaxify.currentPage = null;
|
|
|
|
|
ajaxify.initialLoad = false;
|
|
|
|
|
|
|
|
|
|
$(window).off('scroll');
|
|
|
|
|
ajaxify.go = function (url, callback, quiet) {
|
|
|
|
|
// "quiet": If set to true, will not call pushState
|
|
|
|
|
app.enterRoom('');
|
|
|
|
|
|
|
|
|
|
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 : '';
|
|
|
|
|
}
|
|
|
|
|
$(window).off('scroll');
|
|
|
|
|
|
|
|
|
|
if (ajaxify.isTemplateAvailable(tpl_url) && !!!templatesModule.config.force_refresh[tpl_url]) {
|
|
|
|
|
ajaxify.currentPage = url;
|
|
|
|
|
if ($('#content').hasClass('ajaxifying') && apiXHR) {
|
|
|
|
|
apiXHR.abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (window.history && window.history.pushState) {
|
|
|
|
|
window.history[!quiet ? 'pushState' : 'replaceState']({
|
|
|
|
|
url: url + hash
|
|
|
|
|
}, url, RELATIVE_PATH + '/' + url + hash);
|
|
|
|
|
}
|
|
|
|
|
// Remove relative path and trailing slash
|
|
|
|
|
url = ajaxify.removeRelativePath(url.replace(/\/$/, ''));
|
|
|
|
|
|
|
|
|
|
translator.load(config.defaultLang, tpl_url);
|
|
|
|
|
$(window).trigger('action:ajaxify.start', {url: url});
|
|
|
|
|
|
|
|
|
|
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
|
|
|
|
|
var hash = '';
|
|
|
|
|
if(ajaxify.initialLoad) {
|
|
|
|
|
hash = window.location.hash ? window.location.hash : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var startTime = (new Date()).getTime();
|
|
|
|
|
ajaxify.currentPage = url;
|
|
|
|
|
|
|
|
|
|
ajaxify.variables.flush();
|
|
|
|
|
ajaxify.loadData(url, function(err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return onAjaxError(err, url, callback, quiet);
|
|
|
|
|
}
|
|
|
|
|
if (window.history && window.history.pushState) {
|
|
|
|
|
window.history[!quiet ? 'pushState' : 'replaceState']({
|
|
|
|
|
url: url + hash
|
|
|
|
|
}, url, RELATIVE_PATH + '/' + url + hash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderTemplate(url, tpl_url, data, startTime, callback);
|
|
|
|
|
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
|
|
|
|
|
|
|
|
|
|
require(['search'], function(search) {
|
|
|
|
|
search.topicDOM.end();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
var startTime = (new Date()).getTime();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
ajaxify.variables.flush();
|
|
|
|
|
ajaxify.loadData(url, function(err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return onAjaxError(err, url, callback, quiet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
app.template = data.template.name;
|
|
|
|
|
|
|
|
|
|
function renderTemplate(url, tpl_url, data, startTime, callback) {
|
|
|
|
|
var animationDuration = parseFloat($('#content').css('transition-duration')) || 0.2;
|
|
|
|
|
$(window).trigger('action:ajaxify.loadingTemplates', {});
|
|
|
|
|
translator.load(config.defaultLang, data.template.name);
|
|
|
|
|
|
|
|
|
|
templates.parse(tpl_url, data, function(template) {
|
|
|
|
|
translator.translate(template, function(translatedTemplate) {
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
$('#content').html(translatedTemplate);
|
|
|
|
|
renderTemplate(url, data.template.name, data, startTime, callback);
|
|
|
|
|
|
|
|
|
|
ajaxify.variables.parse();
|
|
|
|
|
require(['search'], function(search) {
|
|
|
|
|
search.topicDOM.end();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ajaxify.widgets.render(tpl_url, url, function() {
|
|
|
|
|
$(window).trigger('action:ajaxify.end', {url: url, tpl_url: tpl_url});
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$(window).trigger('action:ajaxify.contentLoaded', {url: url});
|
|
|
|
|
function onAjaxError(err, url, callback, quiet) {
|
|
|
|
|
var data = err.data,
|
|
|
|
|
textStatus = err.textStatus;
|
|
|
|
|
|
|
|
|
|
ajaxify.loadScript(tpl_url);
|
|
|
|
|
if (data) {
|
|
|
|
|
var status = parseInt(data.status, 10);
|
|
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.processPage();
|
|
|
|
|
function renderTemplate(url, tpl_url, data, startTime, callback) {
|
|
|
|
|
var animationDuration = parseFloat($('#content').css('transition-duration')) || 0.2;
|
|
|
|
|
$(window).trigger('action:ajaxify.loadingTemplates', {});
|
|
|
|
|
|
|
|
|
|
$('#content, #footer').removeClass('ajaxifying');
|
|
|
|
|
ajaxify.initialLoad = false;
|
|
|
|
|
templates.parse(tpl_url, data, function(template) {
|
|
|
|
|
translator.translate(template, function(translatedTemplate) {
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
$('#content').html(translatedTemplate);
|
|
|
|
|
|
|
|
|
|
app.refreshTitle(url);
|
|
|
|
|
}, animationDuration * 1000 - ((new Date()).getTime() - startTime));
|
|
|
|
|
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.removeRelativePath = function(url) {
|
|
|
|
|
if (url.indexOf(RELATIVE_PATH.slice(1)) === 0) {
|
|
|
|
|
url = url.slice(RELATIVE_PATH.length);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
ajaxify.loadScript(tpl_url);
|
|
|
|
|
|
|
|
|
|
ajaxify.refresh = function() {
|
|
|
|
|
ajaxify.go(ajaxify.currentPage);
|
|
|
|
|
};
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ajaxify.loadScript = function(tpl_url, callback) {
|
|
|
|
|
var location = !app.inAdmin ? 'forum/' : '';
|
|
|
|
|
app.processPage();
|
|
|
|
|
|
|
|
|
|
require([location + tpl_url], function(script) {
|
|
|
|
|
if (script && script.init) {
|
|
|
|
|
script.init();
|
|
|
|
|
}
|
|
|
|
|
$('#content, #footer').removeClass('ajaxifying');
|
|
|
|
|
ajaxify.initialLoad = false;
|
|
|
|
|
|
|
|
|
|
app.refreshTitle(url);
|
|
|
|
|
}, animationDuration * 1000 - ((new Date()).getTime() - startTime));
|
|
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ajaxify.isTemplateAvailable = function(tpl) {
|
|
|
|
|
return $.inArray(tpl + '.tpl', templatesModule.available) !== -1;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ajaxify.getTemplateMapping = function(url) {
|
|
|
|
|
var tpl_url = ajaxify.getCustomTemplateMapping(url.split('?')[0]);
|
|
|
|
|
ajaxify.removeRelativePath = function(url) {
|
|
|
|
|
if (url.indexOf(RELATIVE_PATH.slice(1)) === 0) {
|
|
|
|
|
url = url.slice(RELATIVE_PATH.length);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (tpl_url === false && !templates[url]) {
|
|
|
|
|
tpl_url = url.split('/');
|
|
|
|
|
ajaxify.refresh = function() {
|
|
|
|
|
ajaxify.go(ajaxify.currentPage);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
while(tpl_url.length) {
|
|
|
|
|
if (ajaxify.isTemplateAvailable(tpl_url.join('/'))) {
|
|
|
|
|
tpl_url = tpl_url.join('/');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tpl_url.pop();
|
|
|
|
|
}
|
|
|
|
|
ajaxify.loadScript = function(tpl_url, callback) {
|
|
|
|
|
var location = !app.inAdmin ? 'forum/' : '';
|
|
|
|
|
|
|
|
|
|
if (!tpl_url.length) {
|
|
|
|
|
tpl_url = url.split('/')[0].split('?')[0];
|
|
|
|
|
}
|
|
|
|
|
} else if (templates[url]) {
|
|
|
|
|
tpl_url = url;
|
|
|
|
|
require([location + tpl_url], function(script) {
|
|
|
|
|
if (script && script.init) {
|
|
|
|
|
script.init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
ajaxify.loadData = function(url, callback) {
|
|
|
|
|
url = ajaxify.removeRelativePath(url);
|
|
|
|
|
|
|
|
|
|
ajaxify.loadData = function(url, callback) {
|
|
|
|
|
url = ajaxify.removeRelativePath(url);
|
|
|
|
|
$(window).trigger('action:ajaxify.loadingData', {url: url});
|
|
|
|
|
|
|
|
|
|
$(window).trigger('action:ajaxify.loadingData', {url: url});
|
|
|
|
|
var location = document.location || window.location;
|
|
|
|
|
|
|
|
|
|
var location = document.location || window.location,
|
|
|
|
|
tpl_url = ajaxify.getCustomTemplateMapping(url.split('?')[0]);
|
|
|
|
|
apiXHR = $.ajax({
|
|
|
|
|
url: RELATIVE_PATH + '/api/' + url,
|
|
|
|
|
cache: false,
|
|
|
|
|
success: function(data) {
|
|
|
|
|
if (!data) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!tpl_url) {
|
|
|
|
|
tpl_url = ajaxify.getTemplateMapping(url);
|
|
|
|
|
}
|
|
|
|
|
data.relative_path = RELATIVE_PATH;
|
|
|
|
|
|
|
|
|
|
apiXHR = $.ajax({
|
|
|
|
|
url: RELATIVE_PATH + '/api/' + url,
|
|
|
|
|
cache: false,
|
|
|
|
|
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) {
|
|
|
|
|
if (!data) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.relative_path = RELATIVE_PATH;
|
|
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback(null, data);
|
|
|
|
|
}
|
|
|
|
|
callback(data.toString());
|
|
|
|
|
},
|
|
|
|
|
error: function(data, textStatus) {
|
|
|
|
|
callback({
|
|
|
|
|
data: data,
|
|
|
|
|
textStatus: textStatus
|
|
|
|
|
});
|
|
|
|
|
error: function(error) {
|
|
|
|
|
throw new Error("Unable to load template: " + template + " (" + error.statusText + ")");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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) === "#";
|
|
|
|
|
}
|
|
|
|
|
if (!window.history || !window.history.pushState) {
|
|
|
|
|
return; // no ajaxification for old browsers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
function hrefEmpty(href) {
|
|
|
|
|
return href === undefined || href === '' || href === 'javascript:;' || href === window.location.href + "#" || href.slice(0, 1) === "#";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!window.location.pathname.match(/\/(403|404)$/g)) {
|
|
|
|
|
app.previousUrl = window.location.href;
|
|
|
|
|
}
|
|
|
|
|
// 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 (!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.match(/\/(403|404)$/g)) {
|
|
|
|
|
app.previousUrl = window.location.href;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(window.location.pathname === this.pathname && this.hash) {
|
|
|
|
|
if (this.hash !== window.location.hash) {
|
|
|
|
|
window.location.hash = this.hash;
|
|
|
|
|
}
|
|
|
|
|
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 + '/', '');
|
|
|
|
|
|
|
|
|
|
ajaxify.loadScript(ajaxify.getTemplateMapping(url));
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
} else {
|
|
|
|
|
if (ajaxify.go(url)) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
if(window.location.pathname === this.pathname && this.hash) {
|
|
|
|
|
if (this.hash !== window.location.hash) {
|
|
|
|
|
window.location.hash = this.hash;
|
|
|
|
|
}
|
|
|
|
|
} 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();
|
|
|
|
|
} 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();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|