Skip to content

Commit

Permalink
BUG Respect CMS preview active state (related to #8089)
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Jan 25, 2013
1 parent 1ca15d0 commit 3457f43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions admin/javascript/LeftAndMain.Preview.js
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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)
);
});
}

Expand Down
6 changes: 3 additions & 3 deletions admin/templates/Includes/LeftAndMain_SilverStripeNavigator.ss
Expand Up @@ -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>
Expand All @@ -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 %>
Expand Down

0 comments on commit 3457f43

Please sign in to comment.