Ticket #25963: 25963.10.diff
File 25963.10.diff, 6.8 KB (added by , 11 years ago) |
---|
-
src/wp-admin/js/theme.js
291 291 scroll = document.body.scrollTop; 292 292 293 293 // Clean the url structure 294 themes.router.navigate( '');294 themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); 295 295 296 296 // Restore scroll position 297 297 document.body.scrollTop = scroll; … … 299 299 } 300 300 }, 301 301 302 // Handles arrow keys navigation for the overlay 303 // Triggers theme:next and theme:previous events 302 // Handles .disabled classes for next/previous buttons 304 303 navigation: function() { 305 var self = this;306 304 307 $( 'body' ).on( 'keyup', function( event ) {308 309 // Pressing the right arrow key fires a theme:next event310 if ( event.keyCode === 39 ) {311 self.trigger( 'theme:next', self.model.cid );312 }313 314 // Pressing the left arrow key fires a theme:previous event315 if ( event.keyCode === 37 ) {316 self.trigger( 'theme:previous', self.model.cid );317 }318 319 // Pressing the escape key closes the theme details panel320 if ( event.keyCode === 27 ) {321 self.collapse();322 }323 });324 325 305 // Disable Left/Right when at the start or end of the collection 326 306 if ( this.model.cid === this.model.collection.at(0).cid ) { 327 307 this.$el.find( '.left' ).addClass( 'disabled' ); … … 379 359 themes.view.Themes = wp.Backbone.View.extend({ 380 360 381 361 className: 'themes', 362 $overlay: $( 'div.theme-overlay' ), 382 363 383 364 // Number to keep track of scroll position 384 365 // while in theme-overlay mode … … 409 390 this.listenTo( this.parent, 'theme:scroll', function() { 410 391 self.renderThemes( self.parent.page ); 411 392 }); 393 394 // Bind keyboard events. 395 $('body').on( 'keyup', function( event ) { 396 // Pressing the right arrow key fires a theme:next event 397 if ( event.keyCode === 39 ) { 398 self.overlay.nextTheme(); 399 } 400 401 // Pressing the left arrow key fires a theme:previous event 402 if ( event.keyCode === 37 ) { 403 self.overlay.previousTheme(); 404 } 405 406 // Pressing the escape key fires a theme:collapse event 407 if ( event.keyCode === 27 ) { 408 self.overlay.collapse( event ); 409 } 410 }); 412 411 }, 413 412 414 413 // Manages rendering of theme pages … … 510 509 this.model = self.collection.get( id ); 511 510 512 511 // Trigger a route update for the current model 513 themes.router.navigate( 'theme/' + this.model.id);512 themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ), { replace: true } ); 514 513 515 514 // Sets this.view to 'detail' 516 515 this.setView( 'detail' ); … … 522 521 }); 523 522 524 523 this.overlay.render(); 525 this.$ el.append( this.overlay.el );524 this.$overlay.html( this.overlay.el ); 526 525 527 526 this.overlay.screenshotGallery(); 528 527 … … 564 563 this.overlay.closeOverlay(); 565 564 566 565 // Trigger a route update for the current model 567 // that renders the new theme's overlay568 themes.router.navigate( 'theme/' + nextModel.id, { trigger: true } ); 566 self.theme.trigger( 'theme:expand', nextModel.cid ); 567 569 568 } 570 569 }, 571 570 … … 588 587 this.overlay.closeOverlay(); 589 588 590 589 // Trigger a route update for the current model 591 // that renders the new theme's overlay592 themes.router.navigate( 'theme/' + previousModel.id, { trigger: true } ); 590 self.theme.trigger( 'theme:expand', previousModel.cid ); 591 593 592 } 594 593 } 595 594 }); … … 623 622 624 623 // Update the URL hash 625 624 if ( event.target.value ) { 626 themes.router.navigate( 'search/' + event.target.value, { replace: true } );625 themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), { replace: true } ); 627 626 } else { 628 themes.router.navigate( '');627 themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); 629 628 } 630 629 } 631 630 }); … … 634 633 // Listens to [theme] and [search] params 635 634 themes.routes = Backbone.Router.extend({ 636 635 637 routes:{638 'search/*query': 'search',639 'theme/*slug': 'theme'636 initialize: function() { 637 this.routes = _.object([ 638 ]); 640 639 }, 641 640 641 baseUrl: function( url ) { 642 return themes.data.settings.root + url; 643 }, 644 642 645 // Set the search input value based on url 643 646 search: function( query ) { 644 647 $( '.theme-search' ).val( query ); 648 self.themes.doSearch( query ); 645 649 } 646 650 }); 647 651 … … 666 670 render: function() { 667 671 // Render results 668 672 this.view.render(); 669 670 // Calls the routes functionality671 673 this.routes(); 672 674 673 // Set ups history with pushState and our root 674 Backbone.history.start({ root: themes.data.settings.root }); 675 // Set the initial theme 676 if ( 'undefined' !== typeof themes.data.settings.theme && '' !== themes.data.settings.theme ){ 677 this.view.view.theme.trigger( 'theme:expand', this.view.collection.findWhere( { id: themes.data.settings.theme } ) ); 678 } 679 680 // Set the initial search 681 if ( 'undefined' !== typeof themes.data.settings.search && '' !== themes.data.settings.search ){ 682 $( '.theme-search' ).val( themes.data.settings.search ); 683 this.themes.doSearch( themes.data.settings.search ); 684 } 685 686 // Start the router if browser supports History API 687 if ( window.history && window.history.pushState ) { 688 // Calls the routes functionality 689 Backbone.history.start({ pushState: true, silent: true }); 690 } 675 691 }, 676 692 677 693 routes: function() { … … 679 695 // Bind to our global thx object 680 696 // so that the object is available to sub-views 681 697 themes.router = new themes.routes(); 682 683 // Handles theme details route event684 themes.router.on( 'route:theme', function( slug ) {685 self.view.view.expand( slug );686 });687 688 // Handles search route event689 themes.router.on( 'route:search', function( query ) {690 self.themes.doSearch( query );691 });692 698 } 693 699 }; 694 700 -
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.