Make WordPress Core

Ticket #50291: 50291.1.diff

File 50291.1.diff, 2.3 KB (added by pbiron, 4 years ago)

same as 50291.diff, but uses a yoda condition in the wp-auto-update-setting-changed callback

  • src/js/_enqueues/wp/theme.js

    From 6f920cd6a4c0460d8870c1431213258040b6ed17 Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Mon, 1 Jun 2020 12:09:10 -0600
    Subject: [PATCH] same as 50291.diff, but uses a yoda condition in the
     `wp-auto-update-setting-changed` callback
    
    ---
     src/js/_enqueues/wp/theme.js   | 20 +++++++++++++++++++-
     src/js/_enqueues/wp/updates.js |  2 ++
     2 files changed, 21 insertions(+), 1 deletion(-)
    
    diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js
    index 7f7f0ce1fb..d5618c4028 100644
    a b themes.view.Details = wp.Backbone.View.extend({ 
    666666                'click .delete-theme': 'deleteTheme',
    667667                'click .left': 'previousTheme',
    668668                'click .right': 'nextTheme',
    669                 'click #update-theme': 'updateTheme'
     669                'click #update-theme': 'updateTheme',
     670                'click .toggle-auto-update': 'autoupdateState'
    670671        },
    671672
    672673        // The HTML template for the theme overlay.
    themes.view.Details = wp.Backbone.View.extend({ 
    787788                this.trigger( 'theme:collapse' );
    788789        },
    789790
     791        // Set state of the auto-update settings link after it has been changed and saved.
     792        autoupdateState: function() {
     793                var callback,
     794                        _this = this;
     795
     796                // Support concurrent clicks in different Theme Details overlays.
     797                callback = function( event, data ) {
     798                        if ( _this.model.get( 'id' ) === data.asset ) {
     799                                _this.model.set( { autoupdate: 'enable' === data.state } );
     800                                $( document ).off( 'wp-auto-update-setting-changed', callback );
     801                        }
     802                }
     803
     804                // Triggered in updates.js
     805                $( document ).on( 'wp-auto-update-setting-changed', callback );
     806        },
     807
    790808        updateTheme: function( event ) {
    791809                var _this = this;
    792810                event.preventDefault();
  • src/js/_enqueues/wp/updates.js

    diff --git a/src/js/_enqueues/wp/updates.js b/src/js/_enqueues/wp/updates.js
    index 8b52bfcdd6..222809500a 100644
    a b  
    25992599                                                $parent.find( '.auto-update-time' ).addClass( 'hidden' );
    26002600                                                wp.a11y.speak( wp.updates.l10n.autoUpdatesDisabled, 'polite' );
    26012601                                        }
     2602
     2603                                        $document.trigger( 'wp-auto-update-setting-changed', { state: action, type: type, asset: asset } );
    26022604                                } )
    26032605                                .fail( function() {
    26042606                                        $parent.find( '.notice.error' ).removeClass( 'hidden' ).find( 'p' ).text( wp.updates.l10n.autoUpdatesError );