mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #1288 from chillu/pulls/tab-state-overrides
Tab state overrides
This commit is contained in:
commit
b2552f885b
@ -437,8 +437,8 @@ jQuery.noConflict();
|
|||||||
contentEls.removeClass('loading');
|
contentEls.removeClass('loading');
|
||||||
},
|
},
|
||||||
success: function(data, status, xhr) {
|
success: function(data, status, xhr) {
|
||||||
var els = self.handleAjaxResponse(data, status, xhr);
|
var els = self.handleAjaxResponse(data, status, xhr, state);
|
||||||
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: els});
|
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: els, state: state});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -449,8 +449,14 @@ jQuery.noConflict();
|
|||||||
* Handles ajax responses containing plain HTML, or mulitple
|
* Handles ajax responses containing plain HTML, or mulitple
|
||||||
* PJAX fragments wrapped in JSON (see PjaxResponseNegotiator PHP class).
|
* PJAX fragments wrapped in JSON (see PjaxResponseNegotiator PHP class).
|
||||||
* Can be hooked into an ajax 'success' callback.
|
* Can be hooked into an ajax 'success' callback.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* (Object) data
|
||||||
|
* (String) status
|
||||||
|
* (XMLHTTPRequest) xhr
|
||||||
|
* (Object) state The original history state which the request was initiated with
|
||||||
*/
|
*/
|
||||||
handleAjaxResponse: function(data, status, xhr) {
|
handleAjaxResponse: function(data, status, xhr, state) {
|
||||||
var self = this, url, selectedTabs, guessFragment;
|
var self = this, url, selectedTabs, guessFragment;
|
||||||
|
|
||||||
// Support a full reload
|
// Support a full reload
|
||||||
@ -545,7 +551,7 @@ jQuery.noConflict();
|
|||||||
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
|
|
||||||
this.restoreTabState();
|
this.restoreTabState(state.data.tabState !== 'undefined' ? state.data.tabState : null);
|
||||||
|
|
||||||
return newContentEls;
|
return newContentEls;
|
||||||
},
|
},
|
||||||
@ -620,20 +626,35 @@ jQuery.noConflict();
|
|||||||
/**
|
/**
|
||||||
* Re-select previously saved tabs.
|
* Re-select previously saved tabs.
|
||||||
* Requires HTML5 sessionStorage support.
|
* Requires HTML5 sessionStorage support.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* (Object) Map of tab container selectors to tab selectors.
|
||||||
|
* Used to mark a specific tab as active regardless of the previously saved options.
|
||||||
*/
|
*/
|
||||||
restoreTabState: function() {
|
restoreTabState: function(overrideStates) {
|
||||||
if(typeof(window.sessionStorage)=="undefined" || window.sessionStorage === null) return;
|
|
||||||
|
|
||||||
var self = this, url = this._tabStateUrl(),
|
var self = this, url = this._tabStateUrl(),
|
||||||
data = window.sessionStorage.getItem('tabs-' + url),
|
hasSessionStorage = (typeof(window.sessionStorage)!=="undefined" && window.sessionStorage),
|
||||||
selectedTabs = data ? JSON.parse(data) : false;
|
sessionData = hasSessionStorage ? window.sessionStorage.getItem('tabs-' + url) : null,
|
||||||
if(selectedTabs) {
|
sessionStates = sessionData ? JSON.parse(sessionData) : false;
|
||||||
$.each(selectedTabs, function(i, selectedTab) {
|
|
||||||
var el = self.find('#' + selectedTab.id);
|
this.find('.cms-tabset').each(function() {
|
||||||
if(!el.data('tabs')) return; // don't act on uninit'ed controls
|
var index, tabset = $(this), tabsetId = tabset.attr('id'), tab,
|
||||||
el.tabs('select', selectedTab.selected);
|
forcedTab = tabset.find('.ss-tabs-force-active');
|
||||||
|
|
||||||
|
if(!tabset.data('tabs')) return; // don't act on uninit'ed controls
|
||||||
|
|
||||||
|
if(forcedTab.length) {
|
||||||
|
index = forcedTab.index();
|
||||||
|
} else if(overrideStates && overrideStates[tabsetId]) {
|
||||||
|
tab = tabset.find(overrideStates[tabsetId].tabSelector);
|
||||||
|
if(tab.length) index = tab.index();
|
||||||
|
} else if(sessionStates) {
|
||||||
|
$.each(sessionStates, function(i, sessionState) {
|
||||||
|
if(tabset.is('#' + sessionState.id)) index = sessionState.selected;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if(index !== null) tabset.tabs('select', index);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user