WordPress.org

Make WordPress Core

Changeset 28025


Ignore:
Timestamp:
04/07/2014 11:03:05 PM (5 years ago)
Author:
nacin
Message:

Theme Installer: Handle currently installed themes, add search route, let prev/next refresh collections.

props matveb.
see #27055. fixes #27695.

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

Legend:

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

    r27959 r28025  
    217217 * when an update is available.
    218218 */
    219 .theme-browser .theme .theme-update {
     219.theme-browser .theme .theme-update,
     220.theme-browser .theme .theme-installed {
    220221    background: #d54e21;
    221222    background: rgba(213, 78, 33, 0.95);
     
    235236}
    236237
    237 .theme-browser .theme .theme-update:before {
     238.theme-browser .theme .theme-update:before,
     239.theme-browser .theme .theme-installed:before {
    238240    content: '\f463';
    239241    display: inline-block;
     
    10741076  16.2 - Install Themes
    10751077------------------------------------------------------------------------------*/
     1078
     1079/* Already installed theme */
     1080.theme-browser .theme.is-installed {
     1081    cursor: default;
     1082}
     1083.theme-browser .theme .theme-installed {
     1084    background: #0074a2;
     1085}
     1086.theme-browser .theme .theme-installed:before {
     1087    content: '\f147';
     1088}
     1089.theme-browser .theme.is-installed .theme-actions,
     1090.theme-browser.rendered .theme.is-installed .more-details {
     1091    display: none !important;
     1092}
     1093.theme-browser.rendered .theme.is-installed:hover .theme-screenshot img,
     1094.theme-browser.rendered .theme.is-installed:focus .theme-screenshot img {
     1095    opacity: 1 !important;
     1096}
    10761097
    10771098.theme-navigation {
  • trunk/src/wp-admin/js/theme.js

    r27963 r28025  
    2323    // Map `id` to `slug` for shared code
    2424    initialize: function() {
    25         var install, preview;
     25        var install, installed;
    2626
    2727        // Install url for the theme
     
    3636        install = themes.data.settings.updateURI + '?' + $.param( install );
    3737
    38         // Preview url for the theme
    39         preview = {
    40             tab: 'theme-information',
    41             theme: this.get( 'slug' )
    42         };
    43 
    44         preview = themes.data.settings.installURI + '?' + $.param( preview );
     38        // If theme is already installed, set an attribute.
     39        if ( _.indexOf( themes.data.installedThemes, this.get( 'slug' ) ) !== -1 ) {
     40            this.set({ installed: true });
     41        }
    4542
    4643        // Set the attributes
    4744        this.set({
    48             installURI: install,
    49             previewURI: preview,
     45            installURI: ( this.get( 'slug' ) ) ? install : false,
    5046            // slug is for installation, id is for existing.
    5147            id: this.get( 'slug' ) || this.get( 'id' )
     
    392388            this.$el.addClass( 'display-author' );
    393389        }
     390
     391        if ( this.model.get( 'installed' ) ) {
     392            this.$el.addClass( 'is-installed' );
     393            this.$el.unbind();
     394        }
    394395    },
    395396
     
    452453        }
    453454
     455        // Allow direct link path to installing a theme.
     456        if ( $( event.target ).hasClass( 'button-primary' ) ) {
     457            return;
     458        }
     459
    454460        // 'enter' and 'space' keys expand the details view when a theme is :focused
    455461        if ( event.type === 'keydown' && ( event.which !== 13 && event.which !== 32 ) ) {
     
    495501            // If we have no more themes, bail.
    496502            if ( _.isUndefined( self.current ) ) {
     503                self.options.parent.parent.trigger( 'theme:end' );
    497504                return self.current = current;
    498505            }
     
    506513            preview.render();
    507514            $( 'div.wrap' ).append( preview.el );
     515            $( '.next-theme' ).focus();
    508516        })
    509517        .listenTo( preview, 'theme:previous', function() {
     
    533541            preview.render();
    534542            $( 'div.wrap' ).append( preview.el );
     543            $( '.previous-theme' ).focus();
    535544        });
    536545    }
     
    883892        self.instance.each( function( theme ) {
    884893            self.theme = new themes.view.Theme({
    885                 model: theme
     894                model: theme,
     895                parent: self
    886896            });
    887897
     
    11591169        // Handles search route event
    11601170        themes.router.on( 'route:search', function( query ) {
    1161             self.view.trigger( 'theme:close' );
    1162             self.themes.doSearch( query );
     1171            $( '.theme-search' ).trigger( 'keyup' );
    11631172        });
    11641173
     
    12251234        // or searching the local cache
    12261235        this.collection.query( request );
     1236
     1237        // Set route
     1238        themes.router.navigate( themes.router.baseUrl( '?search=' + value ), { replace: true } );
    12271239    }, 300 )
    12281240});
     
    13301342
    13311343    sort: function( sort ) {
    1332         $( '#theme-search-input' ).val( '' );
     1344        this.clearSearch();
    13331345
    13341346        $( '.theme-section, .theme-filter' ).removeClass( this.activeClass );
     
    14511463        }
    14521464
     1465        this.clearSearch();
     1466
     1467        themes.router.navigate( themes.router.baseUrl( '' ) );
    14531468        $( 'body' ).toggleClass( 'more-filters-opened' );
    14541469    },
     
    14751490    backToFilters: function() {
    14761491        $( 'body' ).removeClass( 'filters-applied' );
     1492    },
     1493
     1494    clearSearch: function() {
     1495        $( '#theme-search-input').val( '' );
    14771496    }
    14781497});
     
    14831502        'theme-install.php?sort=:sort': 'sort',
    14841503        'theme-install.php?upload': 'upload',
     1504        'theme-install.php?search=:query': 'search',
    14851505        '': 'sort'
    14861506    },
     
    14881508    baseUrl: function( url ) {
    14891509        return 'theme-install.php' + url;
    1490     }
     1510    },
     1511
     1512    search: function( query ) {
     1513        $( '.theme-search' ).val( query );
     1514    },
    14911515});
    14921516
     
    15411565        themes.router.on( 'route:upload', function() {
    15421566            $( 'a.upload' ).trigger( 'click' );
     1567        });
     1568
     1569        // Handles search route event
     1570        themes.router.on( 'route:search', function( query ) {
     1571            $( '.theme-search' ).focus().trigger( 'keyup' );
    15431572        });
    15441573
  • trunk/src/wp-admin/theme-install.php

    r27962 r28025  
    3333    'new'      => __( 'Newest Themes' ),
    3434);
     35
     36$installed_themes = search_theme_directories();
     37foreach ( $installed_themes as $k => $v ) {
     38    if ( false !== strpos( $k, '/' ) ) {
     39        unset( $installed_themes[ $k ] );
     40    }
     41}
    3542
    3643wp_localize_script( 'theme', '_wpThemeSettings', array(
     
    5259        'error'  => ( 'There was a problem trying to load the themes. Please, try again.' ), // @todo improve
    5360    ),
     61    'installedThemes' => array_keys( $installed_themes ),
    5462    'browse' => array(
    5563        'sections' => $sections,
     
    191199        <a class="button button-secondary preview install-theme-preview" href="#"><?php esc_html_e( 'Preview' ); ?></a>
    192200    </div>
     201
     202    <# if ( data.installed ) { #>
     203        <div class="theme-installed"><?php _e( 'Already Installed' ); ?></div>
     204    <# } #>
    193205</script>
    194206
     
    197209        <div class="wp-full-overlay-header">
    198210            <a href="#" class="close-full-overlay button-secondary"><?php _e( 'Close' ); ?></a>
     211        <# if ( data.installed ) { #>
     212            <a href="#" class="button button-primary theme-install disabled"><?php _e( 'Installed' ); ?></a>
     213        <# } else { #>
    199214            <a href="{{ data.installURI }}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a>
     215        <# } #>
    200216        </div>
    201217        <div class="wp-full-overlay-sidebar-content">
Note: See TracChangeset for help on using the changeset viewer.