WordPress.org

Make WordPress Core

Changeset 28123


Ignore:
Timestamp:
04/14/2014 10:05:20 PM (4 years ago)
Author:
nacin
Message:

Theme installer: Improve route handling and make ?theme= work.

props matveb.
fixes #27708.

Location:
trunk/src/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/themes.css

    r28104 r28123  
    17141714    float: right;
    17151715}
     1716.wp-full-overlay.no-navigation .theme-navigation {
     1717    display: none;
     1718}
    17161719
    17171720/* Animations */
  • trunk/src/wp-admin/js/theme.js

    r28105 r28123  
    2323    // Map `id` to `slug` for shared code
    2424    initialize: function() {
    25         var install;
     25        var install, description;
    2626
    2727        // Install url for the theme
     
    4747            id: this.get( 'slug' ) || this.get( 'id' )
    4848        });
     49
     50        // Map `section.description` to `description`
     51        // as the API sometimes returns it differently
     52        if ( this.has( 'sections' ) ) {
     53            description = this.get( 'sections' ).description;
     54            this.set({ description: description });
     55        }
    4956    }
    5057});
     
    219226    // When we are missing a cache object we fire an apiCall()
    220227    // which triggers events of `query:success` or `query:fail`
    221     query: function( request ) {
     228    query: function( request, action ) {
    222229        /**
    223230         * @static
     
    248255        // Otherwise, send a new API call and add it to the cache.
    249256        if ( ! query && ! isPaginated ) {
    250             query = this.apiCall( request ).done( function( data ) {
     257            query = this.apiCall( request, action ).done( function( data ) {
     258
    251259                // Update the collection with the queried data.
    252                 self.reset( data.themes );
    253                 count = data.info.results;
     260                if ( data.themes ) {
     261                    self.reset( data.themes );
     262                    count = data.info.results;
     263                    // Store the results and the query request
     264                    queries.push( { themes: data.themes, request: request, total: count } );
     265
     266                } else if ( action ) {
     267                    self.reset( data );
     268                    count = 1;
     269                    self.trigger( 'query:theme' );
     270                }
    254271
    255272                // Trigger a collection refresh event
     
    258275                self.trigger( 'query:success', count );
    259276
    260                 if ( data.themes.length === 0 ) {
     277                if ( data.themes && data.themes.length === 0 ) {
    261278                    self.trigger( 'query:empty' );
    262279                }
    263280
    264                 // Store the results and the query request
    265                 queries.push( { themes: data.themes, request: request, total: count } );
    266281            }).fail( function() {
    267282                self.trigger( 'query:fail' );
     
    270285            // If it's a paginated request we need to fetch more themes...
    271286            if ( isPaginated ) {
    272                 return this.apiCall( request, isPaginated ).done( function( data ) {
     287                return this.apiCall( request, action, isPaginated ).done( function( data ) {
    273288                    // Add the new themes to the current collection
    274289                    // @todo update counter
     
    315330
    316331    // Send request to api.wordpress.org/themes
    317     apiCall: function( request, paginated ) {
     332    apiCall: function( request, action, paginated ) {
    318333
    319334        // Send tags (and fields) as comma-separated to keep the JSONP query string short.
    320335        if ( request.tag && _.isArray( request.tag ) ) {
    321336            request.tag = request.tag.join( ',' );
     337        }
     338
     339        // Set request action
     340        if ( ! action ) {
     341            action = 'query_themes'
    322342        }
    323343
     
    330350            // Request data
    331351            data: {
    332                 action: 'query_themes',
     352                action: action,
    333353                request: _.extend({
    334354                    per_page: 72,
     
    483503        preview.render();
    484504        this.setNavButtonsState();
     505
     506        // Hide previous/next navigation if there is only one theme
     507        if ( this.model.collection.length === 1 ) {
     508            preview.$el.addClass( 'no-navigation' );
     509        } else {
     510            preview.$el.removeClass( 'no-navigation' );
     511        }
     512
     513        // Apend preview
    485514        $( 'div.wrap' ).append( preview.el );
    486515
     
    781810        themes.router.navigate( themes.router.baseUrl( '' ) );
    782811        this.trigger( 'preview:close' );
     812        this.unbind();
    783813        return false;
    784814    },
     
    13061336    },
    13071337
    1308     // Handles all the rendering of the public theme directory
    1309     browse: function( section ) {
     1338    // Initial render method
     1339    render: function() {
    13101340        var self = this;
     1341
     1342        this.search();
     1343        this.uploader();
    13111344
    13121345        this.collection = new themes.Collection();
     
    13401373        });
    13411374
    1342         // Create a new collection with the proper theme data
    1343         // for each section
    1344         this.collection.query( { browse: section } );
    1345 
    13461375        if ( this.view ) {
    13471376            this.view.remove();
     
    13511380        this.view = new themes.view.Themes({
    13521381            collection: this.collection,
    1353             section: section,
    13541382            parent: this
    13551383        });
     
    13641392    },
    13651393
    1366     // Initial render method
    1367     render: function() {
    1368         this.search();
    1369         this.uploader();
    1370         return this.browse( this.options.section );
     1394    // Handles all the rendering of the public theme directory
     1395    browse: function( section ) {
     1396        // Create a new collection with the proper theme data
     1397        // for each section
     1398        this.collection.query( { browse: section } );
    13711399    },
    13721400
     
    15551583        'theme-install.php?upload': 'upload',
    15561584        'theme-install.php?search=:query': 'search',
    1557         '': 'sort'
     1585        'theme-install.php': 'sort'
    15581586    },
    15591587
     
    15971625
    15981626    routes: function() {
    1599         var self = this;
    1600         // Bind to our global thx object
    1601         // so that the object is available to sub-views
     1627        var self = this,
     1628            request = {};
     1629
     1630        // Bind to our global `wp.themes` object
     1631        // so that the router is available to sub-views
    16021632        themes.router = new themes.InstallerRouter();
    16031633
    1604         // Handles theme details route event
    1605         themes.router.on( 'route:theme', function( slug ) {
    1606             self.view.view.expand( slug );
    1607         });
    1608 
     1634        // Handles `theme` route event
     1635        // Queries the API for the passed theme slug
     1636        themes.router.on( 'route:preview', function( slug ) {
     1637            request.slug = slug;
     1638            self.view.collection.query( request, 'theme_information' );
     1639        });
     1640
     1641        // Handles sorting / browsing routes
     1642        // Also handles the root URL triggering a sort request
     1643        // for `featured`, the default view
    16091644        themes.router.on( 'route:sort', function( sort ) {
    16101645            if ( ! sort ) {
     
    16151650        });
    16161651
     1652        // Support the `upload` route by going straight to upload section
    16171653        themes.router.on( 'route:upload', function() {
    16181654            $( 'a.upload' ).trigger( 'click' );
    16191655        });
    16201656
    1621         // Handles search route event
     1657        // The `search` route event. The router populates the input field.
    16221658        themes.router.on( 'route:search', function() {
    16231659            $( '.theme-search' ).focus().trigger( 'keyup' );
  • trunk/src/wp-admin/theme-install.php

    r28105 r28123  
    123123    <div class="theme-navigation">
    124124        <span class="theme-count"></span>
    125         <a class="theme-section current" href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a>
     125        <a class="theme-section" href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a>
    126126        <a class="theme-section" href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a>
    127127        <a class="theme-section" href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a>
Note: See TracChangeset for help on using the changeset viewer.