v1.18.x
barisusakli 10 years ago
parent 63a6702285
commit 289474edf7

@ -11,7 +11,7 @@ $(document).ready(function() {
apiXHR = null; 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.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);
@ -19,10 +19,8 @@ $(document).ready(function() {
}; };
ajaxify.currentPage = null; ajaxify.currentPage = null;
ajaxify.initialLoad = false;
ajaxify.go = function (url, callback, quiet) { ajaxify.go = function (url, callback, quiet) {
// "quiet": If set to true, will not call pushState
app.enterRoom(''); app.enterRoom('');
$(window).off('scroll'); $(window).off('scroll');
@ -31,23 +29,7 @@ $(document).ready(function() {
apiXHR.abort(); apiXHR.abort();
} }
// Remove relative path and trailing slash url = ajaxify.start(url, quiet);
url = ajaxify.removeRelativePath(url.replace(/\/$/, ''));
$(window).trigger('action:ajaxify.start', {url: url});
var hash = '';
if(ajaxify.initialLoad) {
hash = window.location.hash ? window.location.hash : '';
}
ajaxify.currentPage = url;
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'); $('#footer, #content').removeClass('hide').addClass('ajaxifying');
@ -73,6 +55,23 @@ $(document).ready(function() {
return true; return true;
}; };
ajaxify.start = function(url, quiet) {
url = ajaxify.removeRelativePath(url.replace(/\/$/, ''));
var hash = window.location.hash;
var search = window.location.search;
ajaxify.currentPage = url;
$(window).trigger('action:ajaxify.start', {url: url});
if (window.history && window.history.pushState) {
window.history[!quiet ? 'pushState' : 'replaceState']({
url: url + search + hash
}, url, RELATIVE_PATH + '/' + url + search + hash);
}
return url;
};
function onAjaxError(err, url, callback, quiet) { function onAjaxError(err, url, callback, quiet) {
var data = err.data, var data = err.data,
textStatus = err.textStatus; textStatus = err.textStatus;
@ -110,24 +109,13 @@ $(document).ready(function() {
setTimeout(function() { setTimeout(function() {
$('#content').html(translatedTemplate); $('#content').html(translatedTemplate);
ajaxify.variables.parse(); ajaxify.end(url, tpl_url);
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') { if (typeof callback === 'function') {
callback(); callback();
} }
app.processPage();
$('#content, #footer').removeClass('ajaxifying'); $('#content, #footer').removeClass('ajaxifying');
ajaxify.initialLoad = false;
app.refreshTitle(url); app.refreshTitle(url);
}, animationDuration * 1000 - ((new Date()).getTime() - startTime)); }, animationDuration * 1000 - ((new Date()).getTime() - startTime));
@ -135,6 +123,20 @@ $(document).ready(function() {
}); });
} }
ajaxify.end = function(url, tpl_url) {
ajaxify.variables.parse();
ajaxify.loadScript(tpl_url);
ajaxify.widgets.render(tpl_url, url, function() {
$(window).trigger('action:ajaxify.end', {url: url});
});
$(window).trigger('action:ajaxify.contentLoaded', {url: url});
app.processPage();
};
ajaxify.removeRelativePath = function(url) { ajaxify.removeRelativePath = function(url) {
if (url.indexOf(RELATIVE_PATH.slice(1)) === 0) { if (url.indexOf(RELATIVE_PATH.slice(1)) === 0) {
url = url.slice(RELATIVE_PATH.length); url = url.slice(RELATIVE_PATH.length);

@ -481,13 +481,8 @@ 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.start(window.location.pathname.slice(1), true);
tpl_url = app.template, ajaxify.end(url, app.template);
search = window.location.search,
hash = window.location.hash,
$window = $(window);
$window.trigger('action:ajaxify.start', {url: url});
collapseNavigationOnClick(); collapseNavigationOnClick();
@ -511,28 +506,6 @@ app.cacheBuster = null;
createHeaderTooltips(); createHeaderTooltips();
showEmailConfirmWarning(); showEmailConfirmWarning();
ajaxify.variables.parse();
ajaxify.currentPage = url;
$window.trigger('action:ajaxify.contentLoaded', {
url: url
});
if (window.history && window.history.replaceState) {
window.history.replaceState({
url: url + search + hash
}, url, RELATIVE_PATH + '/' + url + search + hash);
}
ajaxify.loadScript(tpl_url, function() {
ajaxify.widgets.render(tpl_url, url, function() {
app.processPage();
$window.trigger('action:ajaxify.end', {
url: url
});
});
});
socket.removeAllListeners('event:nodebb.ready'); socket.removeAllListeners('event:nodebb.ready');
socket.on('event:nodebb.ready', function(cacheBusters) { socket.on('event:nodebb.ready', function(cacheBusters) {
if ( if (

Loading…
Cancel
Save