Make WordPress Core

Ticket #27198: 27198-02.patch

File 27198-02.patch, 5.8 KB (added by gcorne, 10 years ago)
  • src/wp-admin/js/theme.js

    diff --git src/wp-admin/js/theme.js src/wp-admin/js/theme.js
    index aba7d9b..9f2e3a2 100644
    themes.view.Details = wp.Backbone.View.extend({ 
    350350                                scroll = document.body.scrollTop;
    351351
    352352                                // Clean the url structure
    353                                 themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } );
     353                                themes.router.navigate( themes.router.baseUrl( '' ) );
    354354
    355355                                // Restore scroll position
    356356                                document.body.scrollTop = scroll;
    themes.view.Themes = wp.Backbone.View.extend({ 
    451451                        self.renderThemes( self.parent.page );
    452452                });
    453453
     454                this.listenTo( this.parent, 'theme:close', function() {
     455                        if ( self.overlay ) {
     456                                self.overlay.closeOverlay();
     457                        }
     458                } );
     459
    454460                // Bind keyboard events.
    455461                $('body').on( 'keyup', function( event ) {
    456462                        if ( ! self.overlay ) {
    themes.view.Themes = wp.Backbone.View.extend({ 
    573579                this.model = self.collection.get( id );
    574580
    575581                // Trigger a route update for the current model
    576                 themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ), { replace: true } );
     582                themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ) );
    577583
    578584                // Sets this.view to 'detail'
    579585                this.setView( 'detail' );
    themes.view.Search = wp.Backbone.View.extend({ 
    659665        tagName: 'input',
    660666        className: 'theme-search',
    661667        id: 'theme-search-input',
     668        searching: false,
    662669
    663670        attributes: {
    664671                placeholder: l10n.searchPlaceholder,
    themes.view.Search = wp.Backbone.View.extend({ 
    669676                'input':  'search',
    670677                'keyup':  'search',
    671678                'change': 'search',
    672                 'search': 'search'
     679                'search': 'search',
     680                'blur': 'pushState'
    673681        },
    674682
    675683        // Runs a search on the theme collection.
    676684        search: function( event ) {
     685                var options = {};
     686
    677687                // Clear on escape.
    678688                if ( event.type === 'keyup' && event.which === 27 ) {
    679689                        event.target.value = '';
    themes.view.Search = wp.Backbone.View.extend({ 
    681691
    682692                this.collection.doSearch( event.target.value );
    683693
     694                if ( this.searching && event.which !== 15) {
     695                        options.replace = true;
     696                } else {
     697                        this.searching = true;
     698                }
     699
    684700                // Update the URL hash
    685701                if ( event.target.value ) {
    686                         themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), { replace: true } );
     702                        themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), options );
    687703                } else {
    688704                        themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } );
    689705                }
     706        },
     707
     708        pushState: function( event ) {
     709                var url = themes.router.baseUrl( '' );
     710
     711                if ( event.target.value ) {
     712                        url = themes.router.baseUrl( '?search=' + event.target.value );
     713                }
     714
     715                themes.router.navigate( url );
     716
    690717        }
    691718});
    692719
    themes.view.Search = wp.Backbone.View.extend({ 
    694721// Listens to [theme] and [search] params
    695722themes.routes = Backbone.Router.extend({
    696723
    697         initialize: function() {
    698                 this.routes = _.object([
    699                 ]);
     724        routes: {
     725                'themes.php?theme=:slug': 'theme',
     726                'themes.php?search=:query': 'search',
     727                'themes.php?s=:query': 'search',
     728                'themes.php': 'themes',
     729                '': 'themes'
    700730        },
    701731
    702732        baseUrl: function( url ) {
    703                 return themes.data.settings.root + url;
     733                return 'themes.php' + url;
     734        },
     735
     736        search: function( query ) {
     737                $( '.theme-search' ).val( query );
     738        },
     739
     740        themes: function() {
     741                $( '.theme-search' ).val('');
    704742        }
     743
    705744});
    706745
    707746// Execute and setup the application
    themes.Run = { 
    720759        },
    721760
    722761        render: function() {
     762                var root;
     763
    723764                // Render results
    724765                this.view.render();
    725766                this.routes();
    726767
    727                 // Set the initial theme
    728                 if ( 'undefined' !== typeof themes.data.settings.theme && '' !== themes.data.settings.theme ){
    729                         this.view.view.theme.trigger( 'theme:expand', this.view.collection.findWhere( { id: themes.data.settings.theme } ) );
    730                 }
    731 
    732                 // Set the initial search
    733                 if ( 'undefined' !== typeof themes.data.settings.search && '' !== themes.data.settings.search ){
    734                         $( '.theme-search' ).val( themes.data.settings.search );
    735                         this.themes.doSearch( themes.data.settings.search );
    736                 }
    737 
    738                 // Start the router if browser supports History API
     768                // Sets up Backbone.history
     769                // Only change root if we have a pushState enabled browser -
     770                // fixes redirect to /wp-admin/#themes.php bug in IE8
    739771                if ( window.history && window.history.pushState ) {
    740                         // Calls the routes functionality
    741                         Backbone.history.start({ pushState: true, silent: true });
     772                        root = themes.data.settings.root.replace( 'themes.php', '' );
     773                } else {
     774                        root = themes.data.settings.root;
    742775                }
     776
     777                Backbone.history.start({ root: root, pushState: true });
    743778        },
    744779
    745780        routes: function() {
     781                var self = this;
    746782                // Bind to our global thx object
    747783                // so that the object is available to sub-views
    748784                themes.router = new themes.routes();
     785
     786                // Handles theme details route event
     787                themes.router.on( 'route:theme', function( slug ) {
     788                        self.view.view.expand( slug );
     789                });
     790
     791                themes.router.on( 'route:themes', function() {
     792                        self.themes.doSearch( '' );
     793                        self.view.trigger( 'theme:close' );
     794                });
     795
     796                // Handles search route event
     797                themes.router.on( 'route:search', function( query ) {
     798                        self.view.trigger( 'theme:close' );
     799                        self.themes.doSearch( query );
     800                });
    749801        }
    750802};
    751803
  • src/wp-admin/themes.php

    diff --git src/wp-admin/themes.php src/wp-admin/themes.php
    index db0e1e5..7578b7d 100644
    wp_localize_script( 'theme', '_wpThemeSettings', array( 
    100100                'installURI'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
    101101                'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
    102102                'root'          => parse_url( admin_url( 'themes.php' ), PHP_URL_PATH ),
    103                 'theme'         => esc_html( $theme ),
    104                 'search'        => esc_html( $search ),
    105 
    106103        ),
    107104        'l10n' => array(
    108105                'addNew' => __( 'Add New Theme' ),