Skip to content
This repository
Browse code

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

Comes with a wrapper for easy reloading of the current panel.
  • Loading branch information...
commit 70eaa270e4326ab3c46951a0401b12ea73925757 1 parent a58cb37
Mateusz U authored July 16, 2012 chillu committed August 16, 2012

Showing 1 changed file with 16 additions and 2 deletions. Show diff stats Hide diff stats

  1. 18  admin/javascript/LeftAndMain.js
18  admin/javascript/LeftAndMain.js
@@ -162,8 +162,9 @@ jQuery.noConflict();
162 162
 			 *  - {String} url
163 163
 			 *  - {String} title New window title
164 164
 			 *  - {Object} data Any additional data passed through to History.pushState()
  165
+			 *  - {boolean} forceReload Forces the replacement of the current history state, even if the URL is the same, i.e. allows reloading.
165 166
 			 */
166  
-			loadPanel: function(url, title, data) {
  167
+			loadPanel: function(url, title, data, forceReload) {
167 168
 				if(!data) data = {};
168 169
 				if(!title) title = "";
169 170
 
@@ -187,13 +188,26 @@ jQuery.noConflict();
187 188
 				if(window.History.enabled) {
188 189
 					// Active menu item is set based on X-Controller ajax header,
189 190
 					// which matches one class on the menu
190  
-					window.History.pushState(data, title, url);
  191
+					if(forceReload) {
  192
+						// Add a parameter to make sure the page gets reloaded even if the URL is the same.
  193
+						$.extend(data, {__forceReload: Math.random()});
  194
+						window.History.replaceState(data, title, url);
  195
+					} else {
  196
+						window.History.pushState(data, title, url);
  197
+					}
191 198
 				} else {
192 199
 					window.location = $.path.makeUrlAbsolute(url, $('base').attr('href'));
193 200
 				}
194 201
 			},
195 202
 
196 203
 			/**
  204
+			 * Nice wrapper for reloading current history state.
  205
+			 */
  206
+			reloadCurrentPanel: function() {
  207
+				this.loadPanel(window.History.getState().url, null, null, true);
  208
+			},
  209
+
  210
+			/**
197 211
 			 * Function: submitForm
198 212
 			 * 
199 213
 			 * Parameters:

0 notes on commit 70eaa27

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