From d15347ae523ee413df991cb3a1adc48ac8cba32e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 19 Oct 2017 17:41:05 +0000 Subject: [PATCH] Customize: Prevent drawing attention to save button if status unchanged from publish; account for changes to status/date when alerting about unsaved changes. Also fix malformed ESLint directive from [41933]. Amends [41932]. See #39896, #42211. git-svn-id: https://develop.svn.wordpress.org/trunk@41947 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 30 +++++++++++++++++++++++- src/wp-admin/js/widgets/media-widgets.js | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 7b275b4d60..22fc84e683 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -6986,12 +6986,21 @@ } ); section.expanded.bind( function( isExpanded ) { + var defaultChangesetStatus; publishSettingsBtn.attr( 'aria-expanded', String( isExpanded ) ); publishSettingsBtn.toggleClass( 'active', isExpanded ); if ( isExpanded ) { cancelHighlightScheduleButton(); - } else if ( api.state( 'selectedChangesetStatus' ).get() !== api.state( 'changesetStatus' ).get() ) { + return; + } + + defaultChangesetStatus = api.state( 'changesetStatus' ).get(); + if ( '' === defaultChangesetStatus || 'auto-draft' === defaultChangesetStatus ) { + defaultChangesetStatus = 'publish'; + } + + if ( api.state( 'selectedChangesetStatus' ).get() !== defaultChangesetStatus ) { highlightScheduleButton(); } else if ( 'future' === api.state( 'selectedChangesetStatus' ).get() && api.state( 'selectedChangesetDate' ).get() !== api.state( 'changesetDate' ).get() ) { highlightScheduleButton(); @@ -8479,6 +8488,7 @@ var isInsideIframe = false; function isCleanState() { + var defaultChangesetStatus; /* * Handle special case of previewing theme switch since some settings (for nav menus and widgets) @@ -8488,6 +8498,20 @@ return 0 === api._latestRevision; } + // Dirty if the changeset status has been changed but not saved yet. + defaultChangesetStatus = api.state( 'changesetStatus' ).get(); + if ( '' === defaultChangesetStatus || 'auto-draft' === defaultChangesetStatus ) { + defaultChangesetStatus = 'publish'; + } + if ( api.state( 'selectedChangesetStatus' ).get() !== defaultChangesetStatus ) { + return false; + } + + // Dirty if scheduled but the changeset date hasn't been saved yet. + if ( 'future' === api.state( 'selectedChangesetStatus' ).get() && api.state( 'selectedChangesetDate' ).get() !== api.state( 'changesetDate' ).get() ) { + return false; + } + return api.state( 'saved' ).get() && 'auto-draft' !== api.state( 'changesetStatus' ).get(); } @@ -8501,6 +8525,8 @@ function startPromptingBeforeUnload() { api.unbind( 'change', startPromptingBeforeUnload ); + api.state( 'selectedChangesetStatus' ).unbind( startPromptingBeforeUnload ); + api.state( 'selectedChangesetDate' ).unbind( startPromptingBeforeUnload ); // Prompt user with AYS dialog if leaving the Customizer with unsaved changes $( window ).on( 'beforeunload.customize-confirm', function() { @@ -8513,6 +8539,8 @@ }); } api.bind( 'change', startPromptingBeforeUnload ); + api.state( 'selectedChangesetStatus' ).bind( startPromptingBeforeUnload ); + api.state( 'selectedChangesetDate' ).bind( startPromptingBeforeUnload ); function requestClose() { var clearedToClose = $.Deferred(), dismissAutoSave = false, dismissLock = false; diff --git a/src/wp-admin/js/widgets/media-widgets.js b/src/wp-admin/js/widgets/media-widgets.js index b8e8d5dc65..6d994add2b 100644 --- a/src/wp-admin/js/widgets/media-widgets.js +++ b/src/wp-admin/js/widgets/media-widgets.js @@ -93,7 +93,7 @@ wp.mediaWidgets = ( function( $ ) { * @returns {void} */ initialize: function( options ) { - var view = this, embedController; // eslint-disable-line consistent-thi + var view = this, embedController; // eslint-disable-line consistent-this wp.media.view.Embed.prototype.initialize.call( view, options ); if ( 'image' !== view.controller.options.mimeType ) { embedController = view.controller.states.get( 'embed' );