Make WordPress Core

Ticket #27521: 27521.11.diff

File 27521.11.diff, 1.5 KB (added by adamsilverstein, 9 years ago)

Theme install preview - Disable next/prev buttons when you reach an dead end.

  • src/wp-admin/js/theme.js

     
    442442                this.touchDrag = true;
    443443        },
    444444
     445        // Handles .disabled classes for next/previous buttons in theme installer preview
     446        setNavButtonsState: function() {
     447                var $themeInstaller = $( '#theme-installer' ),
     448                        current = _.isUndefined( this.current ) ? this.model : this.current;
     449
     450                // Disable Left at the zero position
     451                if ( 0 === this.model.collection.indexOf( current ) ) {
     452                        $themeInstaller.find( '.previous-theme' ).addClass( 'disabled' );
     453                }
     454
     455                // Disable next if the next model is undefined
     456                if ( _.isUndefined( this.model.collection.at( this.model.collection.indexOf( current ) + 1 ) ) ) {
     457                        $themeInstaller.find( '.next-theme' ).addClass( 'disabled' );
     458                }
     459        },
     460
     461
    445462        preview: function( event ) {
    446463                var self = this,
    447464                        current, preview;
     
    494511
    495512                        // If we have no more themes, bail.
    496513                        if ( _.isUndefined( self.current ) ) {
     514                                self.options.parent.parent.trigger( 'theme:end' );
    497515                                return self.current = current;
    498516                        }
    499517
     
    504522
    505523                        // Render and append.
    506524                        preview.render();
     525                        this.setNavButtonsState();
    507526                        $( 'div.wrap' ).append( preview.el );
    508527                })
    509528                .listenTo( preview, 'theme:previous', function() {
     
    531550
    532551                        // Render and append.
    533552                        preview.render();
     553                        this.setNavButtonsState();
    534554                        $( 'div.wrap' ).append( preview.el );
    535555                });
     556                self.setNavButtonsState();
    536557        }
    537558});
    538559