Skip to content

Commit

Permalink
Only add legacy handling for closing the editor when it's needed (#44389
Browse files Browse the repository at this point in the history
)
  • Loading branch information
p-jackson authored Jul 24, 2020
1 parent 60922eb commit 0872f07
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -595,12 +595,18 @@ function handleCloseEditor( calypsoPort ) {
// The close button is generally overridden using the <MainDashboardButton> slot API
// which was introduced in Gutenberg 8.2. In older editors we still need to override
// the click handler so that the link will open in the parent frame instead of the
// iframe. If this happens to be a newer version of the editor the <MainDashboardButton>
// in `handleCloseEditor()` will end up overriding these chanages.
// iframe. We try not to add the click handler if <MainDashboardButton> has been used.
function handleCloseInLegacyEditors( handleClose ) {
const legacySelector = '.edit-post-fullscreen-mode-close__toolbar a'; // support for Gutenberg plugin < v7.7
const selector = '.edit-post-header .edit-post-fullscreen-mode-close';
// Selects close buttons in Gutenberg plugin < v7.7
const legacySelector = '.edit-post-fullscreen-mode-close__toolbar a';

// Selects the close button in modern Gutenberg versions, unless it itself is a close button override
const wpcomCloseSelector = '.wpcom-block-editor__close-button';
const navSidebarCloseSelector = '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button';
const selector = `.edit-post-header .edit-post-fullscreen-mode-close:not(${ wpcomCloseSelector }):not(${ navSidebarCloseSelector })`;

const siteEditorSelector = '.edit-site-header .edit-site-fullscreen-mode-close';

$( '#editor' ).on( 'click', `${ legacySelector }, ${ selector }`, handleClose );
$( '#edit-site-editor' ).on( 'click', `${ siteEditorSelector }`, handleClose );
}
Expand Down

0 comments on commit 0872f07

Please sign in to comment.