Permalink
Browse files

ENHANCEMENT Support for fake "redirects" in ajax responses via Histor…

…y.replaceState() (used e.g. for an add form loading the record for editing afterwards, under its own URL)
  • Loading branch information...
1 parent 068fcb2 commit ac963755dda5c583767b908be01ab90f0fd07922 @chillu chillu committed Dec 20, 2011
Showing with 23 additions and 6 deletions.
  1. +10 −5 admin/javascript/LeftAndMain.Menu.js
  2. +13 −1 admin/javascript/LeftAndMain.js
@@ -57,15 +57,20 @@
editPageItem[editPageItem.is('.current') ? 'show' : 'hide']();
- // update the menu links to reflect the page ID if the page has changed the URL.
+ // Update the menu links to reflect the page ID if the page has changed the URL.
var currentID = $('.cms-content input[name=ID]').val();
-
- // only handling the sub menu as the other items are global in context
+ var itemsWithPageContext = [
+ '#Menu-CMSPageAddController',
+ '#Menu-CMSPageSettingsController',
+ '#Menu-CMSPageHistoryController',
+ '#Menu-CMSPageEditController'
+ ];
if(currentID) {
- $(this).find("ul a").each(function(i, elem) {
+ var links = $(this).find(itemsWithPageContext.join(',')).find('a');
+ links.each(function(i, elem) {
var href = $(elem).attr("href").split('/');
href[href.length -1] = currentID;
-
+ // Assumes that current ID will always be the last URL segment (and not a query parameter)
$(elem).attr('href', href.join('/'));
});
}
@@ -70,7 +70,13 @@
self.redraw();
});
- $('.cms-edit-form').live('reloadeditform', function() {
+ $('.cms-edit-form').live('reloadeditform', function(e, data) {
+ // Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
+ if(window.History.enabled) {
+ var url = data.xmlhttp.getResponseHeader('X-ControllerURL');
+ if(url) window.history.replaceState({}, '', url);
+ }
+
self.redraw()
});
@@ -222,6 +228,12 @@
self.redraw();
newContentEl.css('visibility', 'visible');
newContentEl.removeClass('loading');
+
+ // Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
+ if(window.History.enabled) {
+ var url = xhr.getResponseHeader('X-ControllerURL');
+ if(url) window.history.replaceState({}, '', url);
+ }
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: newContentEl});
},

0 comments on commit ac96375

Please sign in to comment.