Make WordPress Core

Ticket #26543: 26543-theme-js.diff

File 26543-theme-js.diff, 2.0 KB (added by matveb, 12 years ago)
  • wp-admin/js/theme.js

     
    645645// Listens to [theme] and [search] params
    646646themes.routes = Backbone.Router.extend({
    647647
    648         initialize: function() {
    649                 this.routes = _.object([
    650                 ]);
     648        routes: {
     649                'themes.php?theme=:slug': 'theme',
     650                'themes.php?search=:query': 'search',
     651                'themes.php?s=:query': 'search'
    651652        },
    652653
    653654        baseUrl: function( url ) {
    654                 return themes.data.settings.root + url;
     655                return 'themes.php' + url;
     656        },
     657
     658        search: function( query ) {
     659                $( '.theme-search' ).val( query );
    655660        }
    656661});
    657662
     
    675680                this.view.render();
    676681                this.routes();
    677682
    678                 // Set the initial theme
    679                 if ( 'undefined' !== typeof themes.data.settings.theme && '' !== themes.data.settings.theme ){
    680                         this.view.view.theme.trigger( 'theme:expand', this.view.collection.findWhere( { id: themes.data.settings.theme } ) );
    681                 }
    682 
    683                 // Set the initial search
    684                 if ( 'undefined' !== typeof themes.data.settings.search && '' !== themes.data.settings.search ){
    685                         $( '.theme-search' ).val( themes.data.settings.search );
    686                         this.themes.doSearch( themes.data.settings.search );
    687                 }
    688 
    689                 // Start the router if browser supports History API
    690                 if ( window.history && window.history.pushState ) {
    691                         // Calls the routes functionality
    692                         Backbone.history.start({ pushState: true, silent: true });
    693                 }
     683                // Sets up Backbone.history
     684                Backbone.history.start({ root: themes.data.settings.root.replace( 'themes.php', '' ), pushState: true, queryUri: true });
    694685        },
    695686
    696687        routes: function() {
     688                var self = this;
    697689                // Bind to our global thx object
    698690                // so that the object is available to sub-views
    699691                themes.router = new themes.routes();
     692
     693                // Handles theme details route event
     694                themes.router.on( 'route:theme', function( slug ) {
     695                        self.view.view.expand( slug );
     696                });
     697
     698                // Handles search route event
     699                themes.router.on( 'route:search', function( query ) {
     700                        self.themes.doSearch( query );
     701                });
    700702        }
    701703};
    702704