Ticket #25963: 25963.9.diff
File 25963.9.diff, 6.8 KB (added by , 11 years ago) |
---|
-
src/wp-admin/js/theme.js
292 292 scroll = document.body.scrollTop; 293 293 294 294 // Clean the url structure 295 themes.router.navigate( '');295 themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); 296 296 297 297 // Restore scroll position 298 298 document.body.scrollTop = scroll; … … 300 300 } 301 301 }, 302 302 303 // Handles arrow keys navigation for the overlay 304 // Triggers theme:next and theme:previous events 303 // Handles .disabled classes for next/previous buttons 305 304 navigation: function() { 306 var self = this;307 305 308 $( 'body' ).on( 'keyup', function( event ) {309 310 // Pressing the right arrow key fires a theme:next event311 if ( event.keyCode === 39 ) {312 self.trigger( 'theme:next', self.model.cid );313 }314 315 // Pressing the left arrow key fires a theme:previous event316 if ( event.keyCode === 37 ) {317 self.trigger( 'theme:previous', self.model.cid );318 }319 320 // Pressing the escape key closes the theme details panel321 if ( event.keyCode === 27 ) {322 self.collapse();323 }324 });325 326 306 // Disable Left/Right when at the start or end of the collection 327 307 if ( this.model.cid === this.model.collection.at(0).cid ) { 328 308 this.$el.find( '.left' ).addClass( 'disabled' ); … … 380 360 themes.view.Themes = wp.Backbone.View.extend({ 381 361 382 362 className: 'themes', 363 $overlay: $( 'div.theme-overlay' ), 383 364 384 365 // Number to keep track of scroll position 385 366 // while in theme-overlay mode … … 410 391 this.listenTo( this.parent, 'theme:scroll', function() { 411 392 self.renderThemes( self.parent.page ); 412 393 }); 394 395 // Bind keyboard events. 396 $('body').on( 'keyup', function( event ) { 397 // Pressing the right arrow key fires a theme:next event 398 if ( event.keyCode === 39 ) { 399 self.overlay.nextTheme(); 400 } 401 402 // Pressing the left arrow key fires a theme:previous event 403 if ( event.keyCode === 37 ) { 404 self.overlay.previousTheme(); 405 } 406 407 // Pressing the escape key fires a theme:collapse event 408 if ( event.keyCode === 27 ) { 409 self.overlay.collapse( event ); 410 } 411 }); 413 412 }, 414 413 415 414 // Manages rendering of theme pages … … 511 510 this.model = self.collection.get( id ); 512 511 513 512 // Trigger a route update for the current model 514 themes.router.navigate( 'theme/' + this.model.id);513 themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ), { replace: true } ); 515 514 516 515 // Sets this.view to 'detail' 517 516 this.setView( 'detail' ); … … 523 522 }); 524 523 525 524 this.overlay.render(); 526 this.$ el.append( this.overlay.el );525 this.$overlay.html( this.overlay.el ); 527 526 528 527 this.overlay.screenshotGallery(); 529 528 … … 565 564 this.overlay.closeOverlay(); 566 565 567 566 // Trigger a route update for the current model 568 // that renders the new theme's overlay569 themes.router.navigate( 'theme/' + nextModel.id, { trigger: true } ); 567 self.theme.trigger( 'theme:expand', nextModel.cid ); 568 570 569 } 571 570 }, 572 571 … … 589 588 this.overlay.closeOverlay(); 590 589 591 590 // Trigger a route update for the current model 592 // that renders the new theme's overlay593 themes.router.navigate( 'theme/' + previousModel.id, { trigger: true } ); 591 self.theme.trigger( 'theme:expand', previousModel.cid ); 592 594 593 } 595 594 } 596 595 }); … … 624 623 625 624 // Update the URL hash 626 625 if ( event.target.value ) { 627 themes.router.navigate( 'search/' + event.target.value, { replace: true } );626 themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), { replace: true } ); 628 627 } else { 629 themes.router.navigate( '');628 themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); 630 629 } 631 630 } 632 631 }); … … 635 634 // Listens to [theme] and [search] params 636 635 themes.routes = Backbone.Router.extend({ 637 636 638 routes:{639 'search/*query': 'search',640 'theme/*slug': 'theme'637 initialize: function() { 638 this.routes = _.object([ 639 ]); 641 640 }, 642 641 642 baseUrl: function( url ) { 643 return themes.data.settings.root + url; 644 }, 645 643 646 // Set the search input value based on url 644 647 search: function( query ) { 645 648 $( '.theme-search' ).val( query ); 649 _.debounce( self.themes.doSearch( query ), 200 ); 646 650 } 647 651 }); 648 652 … … 667 671 render: function() { 668 672 // Render results 669 673 this.view.render(); 670 671 // Calls the routes functionality672 674 this.routes(); 673 675 674 // Set ups history with pushState and our root 675 Backbone.history.start({ root: themes.data.settings.root }); 676 // Set the initial theme 677 if ( 'undefined' !== typeof themes.data.settings.theme && '' !== themes.data.settings.theme ){ 678 this.view.view.theme.trigger( 'theme:expand', this.view.collection.findWhere( { id: themes.data.settings.theme } ) ); 679 } 680 681 // Set the initial search 682 if ( 'undefined' !== typeof themes.data.settings.search && '' !== themes.data.settings.search ){ 683 $( '.theme-search' ).val( themes.data.settings.search ); 684 this.themes.doSearch( themes.data.settings.search ); 685 } 686 687 // Start the router if browser supports History API 688 if ( window.history && window.history.pushState ) { 689 // Calls the routes functionality 690 Backbone.history.start({ pushState: true, silent: true }); 691 } 676 692 }, 677 693 678 694 routes: function() { … … 680 696 // Bind to our global thx object 681 697 // so that the object is available to sub-views 682 698 themes.router = new themes.routes(); 683 684 // Handles theme details route event685 themes.router.on( 'route:theme', function( slug ) {686 self.view.view.expand( slug );687 });688 689 // Handles search route event690 themes.router.on( 'route:search', function( query ) {691 self.themes.doSearch( query );692 });693 699 } 694 700 }; 695 701 -
src/wp-admin/themes.php
91 91 } else { 92 92 $themes = wp_prepare_themes_for_js( array( wp_get_theme() ) ); 93 93 } 94 wp_reset_vars( array( 'theme', 'search' ) ); 94 95 95 96 wp_localize_script( 'theme', '_wpThemeSettings', array( 96 97 'themes' => $themes, … … 98 99 'canInstall' => ( ! is_multisite() && current_user_can( 'install_themes' ) ), 99 100 'installURI' => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null, 100 101 'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ), 101 'root' => admin_url( 'themes.php'),102 'root' => parse_url( admin_url( 'themes.php' ), PHP_URL_PATH ), 102 103 'extraRoutes' => '', 104 'theme' => esc_html( $theme ), 105 'search' => esc_html( $search ), 106 103 107 ), 104 108 'l10n' => array( 105 109 'addNew' => __( 'Add New Theme' ), … … 180 184 ?> 181 185 182 186 <div class="theme-browser"></div> 187 <div class="theme-overlay"></div> 183 188 184 189 <?php 185 190 // List broken themes, if any.