diff --git src/wp-admin/js/theme.js src/wp-admin/js/theme.js
index aba7d9b..9f2e3a2 100644
|
|
themes.view.Details = wp.Backbone.View.extend({ |
350 | 350 | scroll = document.body.scrollTop; |
351 | 351 | |
352 | 352 | // Clean the url structure |
353 | | themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); |
| 353 | themes.router.navigate( themes.router.baseUrl( '' ) ); |
354 | 354 | |
355 | 355 | // Restore scroll position |
356 | 356 | document.body.scrollTop = scroll; |
… |
… |
themes.view.Themes = wp.Backbone.View.extend({ |
451 | 451 | self.renderThemes( self.parent.page ); |
452 | 452 | }); |
453 | 453 | |
| 454 | this.listenTo( this.parent, 'theme:close', function() { |
| 455 | if ( self.overlay ) { |
| 456 | self.overlay.closeOverlay(); |
| 457 | } |
| 458 | } ); |
| 459 | |
454 | 460 | // Bind keyboard events. |
455 | 461 | $('body').on( 'keyup', function( event ) { |
456 | 462 | if ( ! self.overlay ) { |
… |
… |
themes.view.Themes = wp.Backbone.View.extend({ |
573 | 579 | this.model = self.collection.get( id ); |
574 | 580 | |
575 | 581 | // Trigger a route update for the current model |
576 | | themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ), { replace: true } ); |
| 582 | themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ) ); |
577 | 583 | |
578 | 584 | // Sets this.view to 'detail' |
579 | 585 | this.setView( 'detail' ); |
… |
… |
themes.view.Search = wp.Backbone.View.extend({ |
659 | 665 | tagName: 'input', |
660 | 666 | className: 'theme-search', |
661 | 667 | id: 'theme-search-input', |
| 668 | searching: false, |
662 | 669 | |
663 | 670 | attributes: { |
664 | 671 | placeholder: l10n.searchPlaceholder, |
… |
… |
themes.view.Search = wp.Backbone.View.extend({ |
669 | 676 | 'input': 'search', |
670 | 677 | 'keyup': 'search', |
671 | 678 | 'change': 'search', |
672 | | 'search': 'search' |
| 679 | 'search': 'search', |
| 680 | 'blur': 'pushState' |
673 | 681 | }, |
674 | 682 | |
675 | 683 | // Runs a search on the theme collection. |
676 | 684 | search: function( event ) { |
| 685 | var options = {}; |
| 686 | |
677 | 687 | // Clear on escape. |
678 | 688 | if ( event.type === 'keyup' && event.which === 27 ) { |
679 | 689 | event.target.value = ''; |
… |
… |
themes.view.Search = wp.Backbone.View.extend({ |
681 | 691 | |
682 | 692 | this.collection.doSearch( event.target.value ); |
683 | 693 | |
| 694 | if ( this.searching && event.which !== 15) { |
| 695 | options.replace = true; |
| 696 | } else { |
| 697 | this.searching = true; |
| 698 | } |
| 699 | |
684 | 700 | // Update the URL hash |
685 | 701 | if ( event.target.value ) { |
686 | | themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), { replace: true } ); |
| 702 | themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), options ); |
687 | 703 | } else { |
688 | 704 | themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); |
689 | 705 | } |
| 706 | }, |
| 707 | |
| 708 | pushState: function( event ) { |
| 709 | var url = themes.router.baseUrl( '' ); |
| 710 | |
| 711 | if ( event.target.value ) { |
| 712 | url = themes.router.baseUrl( '?search=' + event.target.value ); |
| 713 | } |
| 714 | |
| 715 | themes.router.navigate( url ); |
| 716 | |
690 | 717 | } |
691 | 718 | }); |
692 | 719 | |
… |
… |
themes.view.Search = wp.Backbone.View.extend({ |
694 | 721 | // Listens to [theme] and [search] params |
695 | 722 | themes.routes = Backbone.Router.extend({ |
696 | 723 | |
697 | | initialize: function() { |
698 | | this.routes = _.object([ |
699 | | ]); |
| 724 | routes: { |
| 725 | 'themes.php?theme=:slug': 'theme', |
| 726 | 'themes.php?search=:query': 'search', |
| 727 | 'themes.php?s=:query': 'search', |
| 728 | 'themes.php': 'themes', |
| 729 | '': 'themes' |
700 | 730 | }, |
701 | 731 | |
702 | 732 | baseUrl: function( url ) { |
703 | | return themes.data.settings.root + url; |
| 733 | return 'themes.php' + url; |
| 734 | }, |
| 735 | |
| 736 | search: function( query ) { |
| 737 | $( '.theme-search' ).val( query ); |
| 738 | }, |
| 739 | |
| 740 | themes: function() { |
| 741 | $( '.theme-search' ).val(''); |
704 | 742 | } |
| 743 | |
705 | 744 | }); |
706 | 745 | |
707 | 746 | // Execute and setup the application |
… |
… |
themes.Run = { |
720 | 759 | }, |
721 | 760 | |
722 | 761 | render: function() { |
| 762 | var root; |
| 763 | |
723 | 764 | // Render results |
724 | 765 | this.view.render(); |
725 | 766 | this.routes(); |
726 | 767 | |
727 | | // Set the initial theme |
728 | | if ( 'undefined' !== typeof themes.data.settings.theme && '' !== themes.data.settings.theme ){ |
729 | | this.view.view.theme.trigger( 'theme:expand', this.view.collection.findWhere( { id: themes.data.settings.theme } ) ); |
730 | | } |
731 | | |
732 | | // Set the initial search |
733 | | if ( 'undefined' !== typeof themes.data.settings.search && '' !== themes.data.settings.search ){ |
734 | | $( '.theme-search' ).val( themes.data.settings.search ); |
735 | | this.themes.doSearch( themes.data.settings.search ); |
736 | | } |
737 | | |
738 | | // Start the router if browser supports History API |
| 768 | // Sets up Backbone.history |
| 769 | // Only change root if we have a pushState enabled browser - |
| 770 | // fixes redirect to /wp-admin/#themes.php bug in IE8 |
739 | 771 | if ( window.history && window.history.pushState ) { |
740 | | // Calls the routes functionality |
741 | | Backbone.history.start({ pushState: true, silent: true }); |
| 772 | root = themes.data.settings.root.replace( 'themes.php', '' ); |
| 773 | } else { |
| 774 | root = themes.data.settings.root; |
742 | 775 | } |
| 776 | |
| 777 | Backbone.history.start({ root: root, pushState: true }); |
743 | 778 | }, |
744 | 779 | |
745 | 780 | routes: function() { |
| 781 | var self = this; |
746 | 782 | // Bind to our global thx object |
747 | 783 | // so that the object is available to sub-views |
748 | 784 | themes.router = new themes.routes(); |
| 785 | |
| 786 | // Handles theme details route event |
| 787 | themes.router.on( 'route:theme', function( slug ) { |
| 788 | self.view.view.expand( slug ); |
| 789 | }); |
| 790 | |
| 791 | themes.router.on( 'route:themes', function() { |
| 792 | self.themes.doSearch( '' ); |
| 793 | self.view.trigger( 'theme:close' ); |
| 794 | }); |
| 795 | |
| 796 | // Handles search route event |
| 797 | themes.router.on( 'route:search', function( query ) { |
| 798 | self.view.trigger( 'theme:close' ); |
| 799 | self.themes.doSearch( query ); |
| 800 | }); |
749 | 801 | } |
750 | 802 | }; |
751 | 803 | |
diff --git src/wp-admin/themes.php src/wp-admin/themes.php
index db0e1e5..7578b7d 100644
|
|
wp_localize_script( 'theme', '_wpThemeSettings', array( |
100 | 100 | 'installURI' => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null, |
101 | 101 | 'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ), |
102 | 102 | 'root' => parse_url( admin_url( 'themes.php' ), PHP_URL_PATH ), |
103 | | 'theme' => esc_html( $theme ), |
104 | | 'search' => esc_html( $search ), |
105 | | |
106 | 103 | ), |
107 | 104 | 'l10n' => array( |
108 | 105 | 'addNew' => __( 'Add New Theme' ), |