mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
a58cb37f96
commit
70eaa270e4
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user