Make WordPress Core

Changeset 40824


Ignore:
Timestamp:
05/23/2017 08:32:00 PM (7 years ago)
Author:
adamsilverstein
Message:

Themes: improve browser history support on new themes page.

When closing the theme preview, restore the previously selected tab. Avoid an issue where duplicate entries in the history prevented navigation. When re-opening the preview, remove bound event handlers before re-adding them.

Props afercia.
Fixes #36613.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/theme.js

    r40586 r40824  
    493493
    494494        // Construct a new Preview view.
    495         themes.currentPreview = preview = new themes.view.Preview({
     495        themes.preview = preview = new themes.view.Preview({
    496496            model: this.model
    497497        });
     
    574574        });
    575575
    576         // Listen for closepreview events, closing the preview.
    577         this.listenTo( preview, 'closepreview', function() {
    578             preview.close();
    579         });
    580576    },
    581577
     
    917913        }).removeClass( 'iframe-ready' );
    918914
    919         themes.router.navigate( themes.router.baseUrl( '' ) );
     915        // Restore the previous browse tab if available.
     916        if ( themes.router.selectedTab ) {
     917            themes.router.navigate( themes.router.baseUrl( '?browse=' + themes.router.selectedTab ) );
     918            themes.router.selectedTab = false;
     919        } else {
     920            themes.router.navigate( themes.router.baseUrl( '' ) );
     921        }
    920922        this.trigger( 'preview:close' );
    921923        this.undelegateEvents();
     
    16521654        this.clearSearch();
    16531655
     1656        // Track sorting so we can restore the correct tab when closing preview.
     1657        themes.router.selectedTab = sort;
     1658
    16541659        $( '.filter-links li > a, .theme-filter' ).removeClass( this.activeClass );
    16551660        $( '[data-sort="' + sort + '"]' ).addClass( this.activeClass );
     
    19151920        themes.router.on( 'route:preview', function( slug ) {
    19161921
     1922            // Remove existing handlers.
     1923            if ( themes.preview ) {
     1924                themes.preview.undelegateEvents();
     1925                themes.preview.unbind();
     1926            }
     1927
    19171928            // If the theme preview is active, set the current theme.
    19181929            if ( self.view.view.theme && self.view.view.theme.preview ) {
     
    19401951            if ( ! sort ) {
    19411952                sort = 'featured';
     1953                themes.router.navigate( themes.router.baseUrl( '?browse=featured' ), { replace: true } );
    19421954            }
    19431955            self.view.sort( sort );
    19441956
    19451957            // Close the preview if open.
    1946             if ( themes.currentPreview ) {
    1947                 themes.currentPreview.trigger( 'closepreview' );
     1958            if ( themes.preview ) {
     1959                themes.preview.close();
    19481960            }
    19491961        });
Note: See TracChangeset for help on using the changeset viewer.