Make WordPress Core

Changeset 40107 for trunk


Ignore:
Timestamp:
02/24/2017 05:47:30 PM (8 years ago)
Author:
adamsilverstein
Message:

Themes: enable browser history support in add new theme screen.

Enable history support for the new theme screen, including navigating theme details and closing the details modal. Theme selection is now also bookmark-able, so linking to a URL like /wp-admin/theme-install.php?theme=twentyseventeen correctly opens the theme preview.

Props dd32.
Fixes #36613.

File:
1 edited

Legend:

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

    r40076 r40107  
    493493
    494494        // Construct a new Preview view.
    495         preview = new themes.view.Preview({
     495        themes.currentPreview = preview = new themes.view.Preview({
    496496            model: this.model
    497497        });
     
    572572        this.listenTo( preview, 'preview:close', function() {
    573573            self.current = self.model;
     574        });
     575
     576        // Listen for closepreview events, closing the preview.
     577        this.listenTo( preview, 'closepreview', function() {
     578            preview.close();
    574579        });
    575580    },
     
    886891        }
    887892
    888         themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.get( 'id' ) ), { replace: true } );
     893        themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.get( 'id' ) ), { replace: false } );
    889894
    890895        this.$el.fadeIn( 200, function() {
     
    19091914        // Queries the API for the passed theme slug
    19101915        themes.router.on( 'route:preview', function( slug ) {
    1911             request.theme = slug;
    1912             self.view.collection.query( request );
    1913             self.view.collection.once( 'update', function() {
     1916
     1917            // If the theme preview is active, set the current theme.
     1918            if ( self.view.view.theme && self.view.view.theme.preview ) {
     1919                self.view.view.theme.model = self.view.collection.findWhere( { 'slug': slug } );
    19141920                self.view.view.theme.preview();
    1915             });
     1921            } else {
     1922
     1923                // Select the theme by slug.
     1924                request.theme = slug;
     1925                self.view.collection.query( request );
     1926                self.view.collection.trigger( 'update' );
     1927
     1928                // Open the theme preview.
     1929                self.view.collection.once( 'query:success', function() {
     1930                    $( 'div[data-slug="' + slug + '"]' ).trigger( 'click' );
     1931                })
     1932
     1933            }
    19161934        });
    19171935
     
    19241942            }
    19251943            self.view.sort( sort );
    1926             self.view.trigger( 'theme:close' );
     1944
     1945            // Close the preview if open.
     1946            if ( themes.currentPreview ) {
     1947                themes.currentPreview.trigger( 'closepreview' );
     1948            }
    19271949        });
    19281950
Note: See TracChangeset for help on using the changeset viewer.