Ticket #25963: 25963.5.diff
File 25963.5.diff, 6.3 KB (added by , 11 years ago) |
---|
-
src/wp-admin/js/theme.js
260 260 this.$el.toggleClass( 'active', this.model.get( 'active' ) ); 261 261 }, 262 262 263 baseUrl: function( url ) { 264 return themes.data.settings.root + url; 265 }, 266 263 267 // Single theme overlay screen 264 268 // It's shown when clicking a theme 265 269 collapse: function( event ) { … … 292 296 scroll = document.body.scrollTop; 293 297 294 298 // Clean the url structure 295 themes.router.navigate( '');299 themes.router.navigate( themes.data.settings.root ); 296 300 297 301 // Restore scroll position 298 302 document.body.scrollTop = scroll; … … 380 384 themes.view.Themes = wp.Backbone.View.extend({ 381 385 382 386 className: 'themes', 387 $overlay: $( 'div.theme-overlay' ), 383 388 384 389 // Number to keep track of scroll position 385 390 // while in theme-overlay mode … … 502 507 return view; 503 508 }, 504 509 510 baseUrl: function( url ) { 511 return themes.data.settings.root + url; 512 }, 513 514 505 515 // Renders the overlay with the ThemeDetails view 506 516 // Uses the current model data 507 517 expand: function( id ) { … … 511 521 this.model = self.collection.get( id ); 512 522 513 523 // Trigger a route update for the current model 514 themes.router.navigate( 'theme/' + this.model.id);524 themes.router.navigate( this.baseUrl( '?theme=' + this.model.id ) ); 515 525 516 526 // Sets this.view to 'detail' 517 527 this.setView( 'detail' ); … … 523 533 }); 524 534 525 535 this.overlay.render(); 526 this.$ el.append( this.overlay.el );536 this.$overlay.html( this.overlay.el ); 527 537 528 538 this.overlay.screenshotGallery(); 529 539 … … 566 576 567 577 // Trigger a route update for the current model 568 578 // that renders the new theme's overlay 569 themes.router.navigate( 'theme/' + nextModel.id, { trigger: true } ); 579 //themes.router.navigate( this.baseUrl( '?theme=' + nextModel.id ) ); 580 self.theme.trigger( 'theme:expand', nextModel.cid ); 581 570 582 } 571 583 }, 572 584 … … 590 602 591 603 // Trigger a route update for the current model 592 604 // that renders the new theme's overlay 593 themes.router.navigate( 'theme/' + previousModel.id, { trigger: true } ); 605 //themes.router.navigate( baseUrl( '?theme=' + previousModel.id ) ); 606 self.theme.trigger( 'theme:expand', previousModel.cid ); 607 594 608 } 595 609 } 596 610 }); … … 615 629 616 630 // Runs a search on the theme collection. 617 631 search: function( event ) { 632 var self = this; 633 618 634 // Clear on escape. 619 635 if ( event.type === 'keyup' && event.which === 27 ) { 620 636 event.target.value = ''; 621 637 } 622 638 623 this.collection.doSearch( event.target.value );639 self.collection.doSearch( event.target.value ); 624 640 625 641 // Update the URL hash 626 642 if ( event.target.value ) { 627 themes.router.navigate( 'search/' + event.target.value, { replace: true } );643 themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), { replace: true } ); 628 644 } else { 629 themes.router.navigate( '');645 themes.router.navigate( themes.router.baseUrl( '' ) ); 630 646 } 631 647 } 632 648 }); … … 635 651 // Listens to [theme] and [search] params 636 652 themes.routes = Backbone.Router.extend({ 637 653 638 routes: { 639 'search/*query': 'search', 640 'theme/*slug': 'theme' 654 initialize: function() { 655 this.routes = _.object([ 656 [ this.baseUrl( '?theme=:theme' ), 'showTheme' ], 657 [ this.baseUrl( '?theme=:theme' ), 'showTheme' ], 658 [ this.baseUrl( '?search=:search' ), 'search' ], 659 [ this.baseUrl( '?search=:search' ), 'search' ] 660 ]); 641 661 }, 642 662 663 showTheme: function( theme ) { 664 alert( theme ); 665 }, 666 667 baseUrl: function( url ) { 668 return themes.data.settings.root + url; 669 }, 670 643 671 // Set the search input value based on url 644 672 search: function( query ) { 645 673 $( '.theme-search' ).val( query ); 674 _.debounce( self.themes.doSearch( query ), 200 ); 646 675 } 647 676 }); 648 677 … … 667 696 render: function() { 668 697 // Render results 669 698 this.view.render(); 670 671 // Calls the routes functionality672 699 this.routes(); 673 700 674 // Set ups history with pushState and our root 675 Backbone.history.start({ root: themes.data.settings.root }); 701 // Set the initial theme 702 if ( 'undefined' !== typeof themes.data.settings.theme && '' !== themes.data.settings.theme ){ 703 this.view.view.theme.trigger( 'theme:expand', this.view.collection.findWhere( { id: themes.data.settings.theme } ) ); 704 } 705 706 // Set the initial search 707 if ( 'undefined' !== typeof themes.data.settings.search && '' !== themes.data.settings.search ){ 708 $( '.theme-search' ).val( themes.data.settings.search ); 709 this.themes.doSearch( themes.data.settings.search ); 710 } 711 712 // Start the router if browser supports History API 713 if ( window.history && window.history.pushState ) { 714 // Calls the routes functionality 715 Backbone.history.start({ pushState: true }); 716 } 676 717 }, 677 718 678 719 routes: function() { … … 680 721 // Bind to our global thx object 681 722 // so that the object is available to sub-views 682 723 themes.router = new themes.routes(); 683 724 console.log(themes.router); 684 725 // Handles theme details route event 685 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 726 } 694 727 }; 695 728 -
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.