API Allow to force URL reload, while replacing the history state

Comes with a wrapper for easy reloading of the current panel.
This commit is contained in:
Mateusz Uzdowski 2012-07-16 11:54:10 +12:00 committed by Ingo Schommer
parent a58cb37f96
commit 70eaa270e4

View File

@ -162,8 +162,9 @@ jQuery.noConflict();
* - {String} url
* - {String} title New window title
* - {Object} data Any additional data passed through to History.pushState()
* - {boolean} forceReload Forces the replacement of the current history state, even if the URL is the same, i.e. allows reloading.
*/
loadPanel: function(url, title, data) {
loadPanel: function(url, title, data, forceReload) {
if(!data) data = {};
if(!title) title = "";
@ -187,12 +188,25 @@ jQuery.noConflict();
if(window.History.enabled) {
// Active menu item is set based on X-Controller ajax header,
// which matches one class on the menu
window.History.pushState(data, title, url);
if(forceReload) {
// Add a parameter to make sure the page gets reloaded even if the URL is the same.
$.extend(data, {__forceReload: Math.random()});
window.History.replaceState(data, title, url);
} else {
window.History.pushState(data, title, url);
}
} else {
window.location = $.path.makeUrlAbsolute(url, $('base').attr('href'));
}
},
/**
* Nice wrapper for reloading current history state.
*/
reloadCurrentPanel: function() {
this.loadPanel(window.History.getState().url, null, null, true);
},
/**
* Function: submitForm
*