Skip to content

Commit

Permalink
FIX Collapse the preview panel by default if no preview is available.
Browse files Browse the repository at this point in the history
This makes the editor experience more streamlined for DataObjects that
_can_ have a preview (and therefore the preview panel is present) but do
not have a preview in the current context (e.g. an elemental block owned
by a non-previewable DataObject).
  • Loading branch information
GuySartorelli committed May 4, 2022
1 parent cad5f67 commit 40ef7a1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion client/src/legacy/LeftAndMain.Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ $.entwine('ss.preview', function($){
*/
$('.cms-preview').entwine({

/**
* Whether the preview panel has been initialised after the edit form was added.
*/
AlreadyInitialised: false,

/**
* List of SilverStripeNavigator states (SilverStripeNavigatorItem classes) to search for.
* The order is significant - if the state is not available, preview will start searching the list
Expand Down Expand Up @@ -300,6 +305,7 @@ $.entwine('ss.preview', function($){
} else {
mode = this.loadState('mode');
size = this.loadState('size');
let save = true;

this._moveNavigator();
if(!mode || mode != 'content') {
Expand All @@ -308,11 +314,21 @@ $.entwine('ss.preview', function($){
}
this.redraw();

// If the DataObject has no preview URL, collapse the preview panel by default.
// Don't save the state - when the user navigates to a DataObject that has a preview URL their saved
// mode will kick in.
const currentPreviewURL = this.find('iframe').attr('src');
if (!this.getPendingURL() && (!currentPreviewURL || currentPreviewURL === 'about:blank')) {
mode = 'content';
save = false;
}

// now check the cookie to see if we have any preview settings that have been
// retained for this page from the last visit
if(mode) this.changeMode(mode);
if(mode) this.changeMode(mode, save);
if(size) this.changeSize(size);
}
this.setAlreadyInitialised(true);
return this;
},

Expand Down Expand Up @@ -542,6 +558,7 @@ $.entwine('ss.preview', function($){
$('.cms-edit-form').entwine({
onadd: function() {
this._super();
$('.cms-preview').setAlreadyInitialised(false)
$('.cms-preview')._initialiseFromContent();
}
});
Expand Down

0 comments on commit 40ef7a1

Please sign in to comment.