Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG Respect CMS preview active state (related to #8089)

  • Loading branch information...
commit 3457f438397d31dde2f6352f7f3b87dab48a823e 1 parent 1ca15d0
@chillu chillu authored
View
17 admin/javascript/LeftAndMain.Preview.js
@@ -17,7 +17,7 @@
* The order is significant - if the state is not available, preview will start searching the list
* from the beginning.
*/
- AllowedStates: ['StageLink', 'LiveLink'],
+ AllowedStates: ['StageLink', 'LiveLink','ArchiveLink'],
/**
* API
@@ -240,7 +240,15 @@
// Walk through available states and get the URLs.
var urlMap = $.map(this.getAllowedStates(), function(name) {
var stateLink = $('.cms-preview-states .state-name[data-name=' + name + ']');
- return stateLink.length ? {name: name, url: stateLink.attr('data-link')} : null;
+ if(stateLink.length) {
+ return {
+ name: name,
+ url: stateLink.attr('data-link'),
+ active: stateLink.is(':radio') ? stateLink.is(':checked') : stateLink.is(':selected')
+ };
+ } else {
+ return null;
+ }
});
return urlMap;
@@ -263,7 +271,10 @@
// Find current state within currently available states.
if (states) {
currentState = $.grep(states, function(state, index) {
- return currentStateName===state.name;
+ return (
+ currentStateName === state.name ||
+ (!currentStateName && state.active)
+ );
});
}
View
6 admin/templates/Includes/LeftAndMain_SilverStripeNavigator.ss
@@ -24,8 +24,8 @@
<fieldset id="preview-states" class="cms-preview-states switch-states size_{$Items.Count}">
<div class="switch">
<% loop Items %>
- <input id="$Title" data-name="$Name" class="state-name $FirstLast" data-link="$Link" name="view" type="radio" <% if First %>checked<% end_if %>>
- <label for="$Title"<% if First %> class="active"<% end_if %>><span>$Title</span></label>
+ <input id="$Title" data-name="$Name" class="state-name $FirstLast" data-link="$Link" name="view" type="radio" <% if isActive %>checked<% end_if %>>
+ <label for="$Title"<% if isActive %> class="active"<% end_if %>><span>$Title</span></label>
<% end_loop %>
<span class="slide-button"></span>
</div>
@@ -34,7 +34,7 @@
<span id="preview-state-dropdown" class="cms-preview-states field dropdown">
<select title="<% _t('SilverStripeNavigator.PreviewState', 'Preview State') %>" id="preview-states" class="preview-state dropdown nolabel" autocomplete="off" name="preview-state">
<% loop Items %>
- <option name="$Name" data-name="$Name" data-link="$Link" class="state-name $FirstLast" value="$Link" >
+ <option name="$Name" data-name="$Name" data-link="$Link" class="state-name $FirstLast" value="$Link" <% if isActive %>selected<% end_if %>>
$Title
</option>
<% end_loop %>
Please sign in to comment.
Something went wrong with that request. Please try again.