Ticket #25963: 25963.11.diff
File 25963.11.diff, 7.4 KB (added by , 11 years ago) |
---|
-
Gruntfile.js
36 36 src: [ 37 37 '**', 38 38 '!**/.{svn,git}/**', // Ignore version control directories. 39 '!wp-includes/version.php' // Exclude version.php 39 '!wp-includes/version.php', // Exclude version.php 40 '!wp-content/themes/wpcom-themes/**' 40 41 ], 41 42 dest: BUILD_DIR 42 43 }, -
src/wp-admin/js/theme.js
293 293 scroll = document.body.scrollTop; 294 294 295 295 // Clean the url structure 296 themes.router.navigate( '');296 themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); 297 297 298 298 // Restore scroll position 299 299 document.body.scrollTop = scroll; … … 301 301 } 302 302 }, 303 303 304 // Handles arrow keys navigation for the overlay 305 // Triggers theme:next and theme:previous events 304 // Handles .disabled classes for next/previous buttons 306 305 navigation: function() { 307 var self = this;308 306 309 $( 'body' ).on( 'keyup', function( event ) {310 311 // Pressing the right arrow key fires a theme:next event312 if ( event.keyCode === 39 ) {313 self.trigger( 'theme:next', self.model.cid );314 }315 316 // Pressing the left arrow key fires a theme:previous event317 if ( event.keyCode === 37 ) {318 self.trigger( 'theme:previous', self.model.cid );319 }320 321 // Pressing the escape key closes the theme details panel322 if ( event.keyCode === 27 ) {323 self.collapse();324 }325 });326 327 307 // Disable Left/Right when at the start or end of the collection 328 308 if ( this.model.cid === this.model.collection.at(0).cid ) { 329 309 this.$el.find( '.left' ).addClass( 'disabled' ); … … 377 357 themes.view.Themes = wp.Backbone.View.extend({ 378 358 379 359 className: 'themes', 360 $overlay: $( 'div.theme-overlay' ), 380 361 381 362 // Number to keep track of scroll position 382 363 // while in theme-overlay mode … … 407 388 this.listenTo( this.parent, 'theme:scroll', function() { 408 389 self.renderThemes( self.parent.page ); 409 390 }); 391 392 // Bind keyboard events. 393 $('body').on( 'keyup', function( event ) { 394 // Pressing the right arrow key fires a theme:next event 395 if ( event.keyCode === 39 ) { 396 self.overlay.nextTheme(); 397 } 398 399 // Pressing the left arrow key fires a theme:previous event 400 if ( event.keyCode === 37 ) { 401 self.overlay.previousTheme(); 402 } 403 404 // Pressing the escape key fires a theme:collapse event 405 if ( event.keyCode === 27 ) { 406 self.overlay.collapse( event ); 407 } 408 }); 410 409 }, 411 410 412 411 // Manages rendering of theme pages … … 508 507 this.model = self.collection.get( id ); 509 508 510 509 // Trigger a route update for the current model 511 themes.router.navigate( 'theme/' + this.model.id);510 themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ), { replace: true } ); 512 511 513 512 // Sets this.view to 'detail' 514 513 this.setView( 'detail' ); … … 520 519 }); 521 520 522 521 this.overlay.render(); 523 this.$ el.append( this.overlay.el );522 this.$overlay.html( this.overlay.el ); 524 523 525 524 // Bind to theme:next and theme:previous 526 525 // triggered by the arrow keys … … 558 557 this.overlay.closeOverlay(); 559 558 560 559 // Trigger a route update for the current model 561 // that renders the new theme's overlay562 themes.router.navigate( 'theme/' + nextModel.id, { trigger: true } ); 560 self.theme.trigger( 'theme:expand', nextModel.cid ); 561 563 562 } 564 563 }, 565 564 … … 582 581 this.overlay.closeOverlay(); 583 582 584 583 // Trigger a route update for the current model 585 // that renders the new theme's overlay586 themes.router.navigate( 'theme/' + previousModel.id, { trigger: true } ); 584 self.theme.trigger( 'theme:expand', previousModel.cid ); 585 587 586 } 588 587 } 589 588 }); … … 617 616 618 617 // Update the URL hash 619 618 if ( event.target.value ) { 620 themes.router.navigate( 'search/' + event.target.value, { replace: true } );619 themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), { replace: true } ); 621 620 } else { 622 themes.router.navigate( '');621 themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); 623 622 } 624 623 } 625 624 }); … … 628 627 // Listens to [theme] and [search] params 629 628 themes.routes = Backbone.Router.extend({ 630 629 631 routes:{632 'search/*query': 'search',633 'theme/*slug': 'theme'630 initialize: function() { 631 this.routes = _.object([ 632 ]); 634 633 }, 635 634 635 baseUrl: function( url ) { 636 return themes.data.settings.root + url; 637 }, 638 636 639 // Set the search input value based on url 637 640 search: function( query ) { 638 641 $( '.theme-search' ).val( query ); 642 self.themes.doSearch( query ); 639 643 } 640 644 }); 641 645 642 // Make routes easily extendable643 _.extend( themes.routes, themes.data.settings.extraRoutes );644 645 646 // Execute and setup the application 646 647 themes.Run = { 647 648 init: function() { … … 660 661 render: function() { 661 662 // Render results 662 663 this.view.render(); 663 664 // Calls the routes functionality665 664 this.routes(); 666 665 667 // Set ups history with pushState and our root 668 Backbone.history.start({ root: themes.data.settings.root }); 666 // Set the initial theme 667 if ( 'undefined' !== typeof themes.data.settings.theme && '' !== themes.data.settings.theme ){ 668 this.view.view.theme.trigger( 'theme:expand', this.view.collection.findWhere( { id: themes.data.settings.theme } ) ); 669 } 670 671 // Set the initial search 672 if ( 'undefined' !== typeof themes.data.settings.search && '' !== themes.data.settings.search ){ 673 $( '.theme-search' ).val( themes.data.settings.search ); 674 this.themes.doSearch( themes.data.settings.search ); 675 } 676 677 // Start the router if browser supports History API 678 if ( window.history && window.history.pushState ) { 679 // Calls the routes functionality 680 Backbone.history.start({ pushState: true, silent: true }); 681 } 669 682 }, 670 683 671 684 routes: function() { … … 673 686 // Bind to our global thx object 674 687 // so that the object is available to sub-views 675 688 themes.router = new themes.routes(); 676 677 // Handles theme details route event678 themes.router.on( 'route:theme', function( slug ) {679 self.view.view.expand( slug );680 });681 682 // Handles search route event683 themes.router.on( 'route:search', function( query ) {684 self.themes.doSearch( query );685 });686 689 } 687 690 }; 688 691 -
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 'extraRoutes' => '', 102 'root' => parse_url( admin_url( 'themes.php' ), PHP_URL_PATH ), 103 'theme' => esc_html( $theme ), 104 'search' => esc_html( $search ), 105 103 106 ), 104 107 'l10n' => array( 105 108 'addNew' => __( 'Add New Theme' ), … … 227 230 <br class="clear" /> 228 231 </div> 229 232 </div> 233 <div class="theme-overlay"></div> 230 234 231 235 <?php 232 236 // List broken themes, if any.