Skip to content
This repository
Browse code

MINOR Moved X-ControllerURL handling into global ajax response handle…

…rs to avoid code duplication
  • Loading branch information...
commit c2b741642e832d68c082a2949d85a811234aebd0 1 parent 0414e42
Ingo Schommer authored March 30, 2012

Showing 1 changed file with 9 additions and 15 deletions. Show diff stats Hide diff stats

  1. 24  admin/javascript/LeftAndMain.js
24  admin/javascript/LeftAndMain.js
@@ -32,8 +32,16 @@ jQuery.noConflict();
32 32
 		
33 33
 		$(window).bind('resize', positionLoadingSpinner).trigger('resize');
34 34
 
35  
-		// global ajax error handlers
  35
+		// global ajax handlers
36 36
 		$.ajaxSetup({
  37
+			complete: function(xhr) {
  38
+				// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it.
  39
+				// Causes non-pushState browser to re-request the URL, so ignore for those.
  40
+				if(window.History.enabled && !History.emulated.pushState) {
  41
+					var url = xmlhttp.getResponseHeader('X-ControllerURL');
  42
+					if(url) window.History.replaceState({}, '', url);
  43
+				}
  44
+			},
37 45
 			error: function(xmlhttp, status, error) {
38 46
 				if(xmlhttp.status < 200 || xmlhttp.status > 399) {
39 47
 					var msg = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.statusText;
@@ -87,13 +95,6 @@ jQuery.noConflict();
87 95
 				});
88 96
 				
89 97
 				$('.cms-edit-form').live('reloadeditform', function(e, data) {
90  
-					// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
91  
-					// Causes non-pushState browser to re-request the URL, so ignore for those.
92  
-					if(window.History.enabled && !History.emulated.pushState) {
93  
-						var url = data.xmlhttp.getResponseHeader('X-ControllerURL');
94  
-						if(url) window.history.replaceState({}, '', url);
95  
-					}
96  
-					
97 98
 					self.redraw();
98 99
 				});
99 100
 				
@@ -251,13 +252,6 @@ jQuery.noConflict();
251 252
 						newContentEl.css('visibility', 'visible');
252 253
 						newContentEl.removeClass('loading');
253 254
 
254  
-						// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it.
255  
-						// Causes non-pushState browser to re-request the URL, so ignore for those.
256  
-						if(window.History.enabled && !History.emulated.pushState) {
257  
-							var url = xhr.getResponseHeader('X-ControllerURL');
258  
-							if(url) window.History.replaceState({}, '', url);
259  
-						}
260  
-
261 255
 						self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: newContentEl});
262 256
 					},
263 257
 					error: function(xhr, status, e) {

0 notes on commit c2b7416

Please sign in to comment.
Something went wrong with that request. Please try again.