MINOR Disable 'preview' button if not applicable

This commit is contained in:
Ingo Schommer 2012-01-03 14:42:26 +01:00
parent a24675c6be
commit c0c073e03f

View File

@ -44,6 +44,8 @@
}); });
var updateAfterXhr = function() { var updateAfterXhr = function() {
$('.cms-preview-toggle-link')[self.canPreview() ? 'show' : 'hide']();
// Only load when panel is visible (see details in iframe load event handler). // Only load when panel is visible (see details in iframe load event handler).
if(self.is('.is-collapsed')) return; if(self.is('.is-collapsed')) return;
@ -80,6 +82,7 @@
// Preview might not be available in all admin interfaces - block/disable when necessary // Preview might not be available in all admin interfaces - block/disable when necessary
this.append('<div class="cms-preview-overlay ui-widget-overlay-light"></div>'); this.append('<div class="cms-preview-overlay ui-widget-overlay-light"></div>');
this.find('.cms-preview-overlay-light').hide(); this.find('.cms-preview-overlay-light').hide();
$('.cms-preview-toggle-link')[this.canPreview() ? 'show' : 'hide']();
self._fixIframeLinks(); self._fixIframeLinks();
@ -95,13 +98,9 @@
* based on metadata sent along with this document. * based on metadata sent along with this document.
*/ */
loadCurrentPage: function() { loadCurrentPage: function() {
var doc = this.find('iframe')[0].contentDocument, var doc = this.find('iframe')[0].contentDocument, containerEl = this.getLayoutContainer();
containerEl = this.getLayoutContainer(),
contentEl = containerEl.find('.cms-content');
// Only load if we're in the "edit page" view if(!this.canPreview()) return;
var blockedClasses = ['CMSPagesController', 'CMSSettingsController', 'CMSPageHistoryController'];
if(contentEl.is('.' + blockedClasses.join(',.'))) return;
// Load this page in the admin interface if appropriate // Load this page in the admin interface if appropriate
var id = $(doc).find('meta[name=x-page-id]').attr('content'); var id = $(doc).find('meta[name=x-page-id]').attr('content');
@ -115,6 +114,18 @@
$('.cms-container').loadPanel(editLink); $('.cms-container').loadPanel(editLink);
} }
}, },
/**
* Determines if the current interface is capable of previewing its managed record.
*
* Returns: {boolean}
*/
canPreview: function() {
var contentEl = this.getLayoutContainer().find('.cms-content');
// Only load if we're in the "edit page" view
var blockedClasses = ['CMSPagesController', 'CMSSettingsController', 'CMSPageHistoryController'];
return !(contentEl.is('.' + blockedClasses.join(',.')));
},
_fixIframeLinks: function() { _fixIframeLinks: function() {
var doc = this.find('iframe')[0].contentDocument; var doc = this.find('iframe')[0].contentDocument;