Make WordPress Core

Ticket #27521: 27521.16.diff

File 27521.16.diff, 2.8 KB (added by kirasong, 11 years ago)

Refreshed, Cleaned up, and Combined 13 & 15.

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

    diff --git src/wp-admin/js/theme.js src/wp-admin/js/theme.js
    index edb9bb6..fbcd0d2 100644
    themes.view.Theme = wp.Backbone.View.extend({ 
    443443                this.touchDrag = true;
    444444        },
    445445
     446        // Handles .disabled classes for previous/next buttons in theme installer preview
     447        setNavButtonsState: function() {
     448                var $themeInstaller = $( '#theme-installer' ),
     449                        current = _.isUndefined( this.current ) ? this.model : this.current;
     450
     451                // Disable previous at the zero position
     452                if ( 0 === this.model.collection.indexOf( current ) ) {
     453                        $themeInstaller.find( '.previous-theme' ).addClass( 'disabled' );
     454                }
     455
     456                // Disable next if the next model is undefined
     457                if ( _.isUndefined( this.model.collection.at( this.model.collection.indexOf( current ) + 1 ) ) ) {
     458                        $themeInstaller.find( '.next-theme' ).addClass( 'disabled' );
     459                }
     460        },
     461
    446462        preview: function( event ) {
    447463                var self = this,
    448464                        current, preview;
    themes.view.Theme = wp.Backbone.View.extend({ 
    511527
    512528                        // Render and append.
    513529                        preview.render();
     530                        this.setNavButtonsState();
    514531                        $( 'div.wrap' ).append( preview.el );
    515532                        $( '.next-theme' ).focus();
    516533                })
    themes.view.Theme = wp.Backbone.View.extend({ 
    539556
    540557                        // Render and append.
    541558                        preview.render();
     559                        this.setNavButtonsState();
    542560                        $( 'div.wrap' ).append( preview.el );
    543561                        $( '.previous-theme' ).focus();
    544562                });
     563                self.setNavButtonsState();
    545564        }
    546565});
    547566
    themes.view.Details = wp.Backbone.View.extend({ 
    676695                this.trigger( 'theme:collapse' );
    677696        },
    678697
    679         // Confirmation dialoge for deleting a theme
     698        // Confirmation dialog for deleting a theme
    680699        deleteTheme: function() {
    681700                return confirm( themes.data.settings.confirmDelete );
    682701        },
    themes.view.Preview = themes.view.Details.extend({ 
    725744        html: themes.template( 'theme-preview' ),
    726745
    727746        render: function() {
    728                 var data = this.model.toJSON();
     747                var data = this.model.toJSON(),
     748                        self = this;
    729749                this.$el.html( this.html( data ) );
    730750
    731751                themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.get( 'id' ) ), { replace: true } );
    732752
    733753                this.$el.fadeIn( 200, function() {
    734                         $( 'body' ).addClass( 'theme-installer-active full-overlay-active' );
     754                        $( 'body' )
     755                                .addClass( 'theme-installer-active full-overlay-active' )
     756                                .on( 'keyup', function( event ) {
     757                                        // Pressing the escape key closes the preview
     758                                        if ( event.keyCode === 27 ) {
     759                                                self.close();
     760                                        }
     761                                });
    735762                        $( '.close-full-overlay' ).focus();
    736763                });
    737764        },
    738765
    739766        close: function() {
    740767                this.$el.fadeOut( 200, function() {
    741                         $( 'body' ).removeClass( 'theme-installer-active full-overlay-active' );
     768                        $( 'body' ).removeClass( 'theme-installer-active full-overlay-active' ).unbind( 'keyup' );
    742769
    743770                        // Return focus to the theme div
    744771                        if ( themes.focusedTheme ) {