mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Moved X-ControllerURL handling into global ajax response handlers to avoid code duplication
This commit is contained in:
parent
0414e42bbc
commit
c2b741642e
@ -32,8 +32,16 @@ jQuery.noConflict();
|
|||||||
|
|
||||||
$(window).bind('resize', positionLoadingSpinner).trigger('resize');
|
$(window).bind('resize', positionLoadingSpinner).trigger('resize');
|
||||||
|
|
||||||
// global ajax error handlers
|
// global ajax handlers
|
||||||
$.ajaxSetup({
|
$.ajaxSetup({
|
||||||
|
complete: function(xhr) {
|
||||||
|
// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it.
|
||||||
|
// Causes non-pushState browser to re-request the URL, so ignore for those.
|
||||||
|
if(window.History.enabled && !History.emulated.pushState) {
|
||||||
|
var url = xmlhttp.getResponseHeader('X-ControllerURL');
|
||||||
|
if(url) window.History.replaceState({}, '', url);
|
||||||
|
}
|
||||||
|
},
|
||||||
error: function(xmlhttp, status, error) {
|
error: function(xmlhttp, status, error) {
|
||||||
if(xmlhttp.status < 200 || xmlhttp.status > 399) {
|
if(xmlhttp.status < 200 || xmlhttp.status > 399) {
|
||||||
var msg = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.statusText;
|
var msg = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.statusText;
|
||||||
@ -87,13 +95,6 @@ jQuery.noConflict();
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('.cms-edit-form').live('reloadeditform', function(e, data) {
|
$('.cms-edit-form').live('reloadeditform', function(e, data) {
|
||||||
// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
|
|
||||||
// Causes non-pushState browser to re-request the URL, so ignore for those.
|
|
||||||
if(window.History.enabled && !History.emulated.pushState) {
|
|
||||||
var url = data.xmlhttp.getResponseHeader('X-ControllerURL');
|
|
||||||
if(url) window.history.replaceState({}, '', url);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.redraw();
|
self.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -251,13 +252,6 @@ jQuery.noConflict();
|
|||||||
newContentEl.css('visibility', 'visible');
|
newContentEl.css('visibility', 'visible');
|
||||||
newContentEl.removeClass('loading');
|
newContentEl.removeClass('loading');
|
||||||
|
|
||||||
// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it.
|
|
||||||
// Causes non-pushState browser to re-request the URL, so ignore for those.
|
|
||||||
if(window.History.enabled && !History.emulated.pushState) {
|
|
||||||
var url = xhr.getResponseHeader('X-ControllerURL');
|
|
||||||
if(url) window.History.replaceState({}, '', url);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: newContentEl});
|
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: newContentEl});
|
||||||
},
|
},
|
||||||
error: function(xhr, status, e) {
|
error: function(xhr, status, e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user