diff --git a/admin/javascript/LeftAndMain.Layout.js b/admin/javascript/LeftAndMain.Layout.js index a4b8c261c..b35bd4199 100644 --- a/admin/javascript/LeftAndMain.Layout.js +++ b/admin/javascript/LeftAndMain.Layout.js @@ -104,9 +104,21 @@ } } + // Calculate what columns are already hidden pre-layout + var prehidden = { + content: spec.content.hasClass('column-hidden'), + preview: spec.preview.hasClass('column-hidden') + }; + + // Calculate what columns will be hidden (zero width) post-layout + var posthidden = { + content: contentWidth === 0, + preview: previewWidth === 0 + }; + // Apply classes for elements that might not be visible at all. - spec.content.toggleClass('column-hidden', contentWidth===0); - spec.preview.toggleClass('column-hidden', previewWidth===0); + spec.content.toggleClass('column-hidden', posthidden.content); + spec.preview.toggleClass('column-hidden', posthidden.preview); // Apply the widths to columns, and call subordinate layouts to arrange the children. menu.bounds({'x': left, 'y': top, 'height': bottom - top, 'width': menuWidth}); @@ -115,12 +127,15 @@ left += menuWidth; content.bounds({'x': left, 'y': top, 'height': bottom - top, 'width': contentWidth}); - content.doLayout(); + if (!posthidden.content) content.doLayout(); left += contentWidth; preview.bounds({'x': left, 'y': top, 'height': bottom - top, 'width': previewWidth}); - preview.doLayout(); + if (!posthidden.preview) preview.doLayout(); + + if (posthidden.content !== prehidden.content) spec.content.trigger('columnvisibilitychanged'); + if (posthidden.preview !== prehidden.preview) spec.preview.trigger('columnvisibilitychanged'); return container; }; diff --git a/admin/javascript/LeftAndMain.Preview.js b/admin/javascript/LeftAndMain.Preview.js index a607e0474..7856e9da5 100644 --- a/admin/javascript/LeftAndMain.Preview.js +++ b/admin/javascript/LeftAndMain.Preview.js @@ -198,6 +198,7 @@ * Caveat: the preview will be automatically enabled when ".cms-previewable" class is detected. */ disablePreview: function() { + this.setPendingURL(null); this._loadUrl('about:blank'); this._block(); this.changeMode('content', false); @@ -304,6 +305,18 @@ } }, + /** @var string A URL that should be displayed in this preview panel once it becomes visible */ + PendingURL: null, + + oncolumnvisibilitychanged: function() { + var url = this.getPendingURL(); + if (url && !this.is('.column-hidden')) { + this.setPendingURL(null); + this._loadUrl(url); + this._unblock(); + } + }, + /** * Update preview whenever a form is submitted. * This is an alternative to the LeftAndmMain::loadPanel functionality which we already @@ -369,20 +382,37 @@ }); } + var url = null; + if (currentState[0]) { // State is available on the newly loaded content. Get it. - this._loadUrl(currentState[0].url); - this._unblock(); + url = currentState[0].url; } else if (states.length) { // Fall back to the first available content state. this.setCurrentStateName(states[0].name); - this._loadUrl(states[0].url); - this._unblock(); + url = states[0].url; } else { // No state available at all. this.setCurrentStateName(null); + } + + // If this preview panel isn't visible at the moment, delay loading the URL until it (maybe) is later + if (this.is('.column-hidden')) { + this.setPendingURL(url); + this._loadUrl('about:blank'); this._block(); } + else { + this.setPendingURL(null); + + if (url) { + this._loadUrl(url); + this._unblock(); + } + else { + this._block(); + } + } return this; },