Changeset 27268
- Timestamp:
- 02/25/2014 07:21:58 PM (12 years ago)
- Location:
- trunk/src/wp-admin
- Files:
-
- 2 edited
-
js/theme.js (modified) (9 diffs)
-
themes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/theme.js
r27248 r27268 67 67 } 68 68 69 view = new themes.view.Search({ collection: self.collection });69 view = new themes.view.Search({ collection: self.collection, parent: this }); 70 70 71 71 // Render and append after screen title … … 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 … … 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 ) { … … 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' … … 660 666 className: 'theme-search', 661 667 id: 'theme-search-input', 668 searching: false, 662 669 663 670 attributes: { … … 670 677 'keyup': 'search', 671 678 'change': 'search', 672 'search': 'search' 679 'search': 'search', 680 'blur': 'pushState' 681 }, 682 683 initialize: function( options ) { 684 685 this.parent = options.parent; 686 687 this.listenTo( this.parent, 'theme:close', function() { 688 this.searching = false; 689 } ); 690 673 691 }, 674 692 675 693 // Runs a search on the theme collection. 676 694 search: function( event ) { 695 var options = {}; 696 677 697 // Clear on escape. 678 698 if ( event.type === 'keyup' && event.which === 27 ) { … … 682 702 this.collection.doSearch( event.target.value ); 683 703 704 // if search is initiated and key is not return 705 if ( this.searching && event.which !== 13 ) { 706 options.replace = true; 707 } else { 708 this.searching = true; 709 } 710 684 711 // Update the URL hash 685 712 if ( event.target.value ) { 686 themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), { replace: true });713 themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), options ); 687 714 } else { 688 themes.router.navigate( themes.router.baseUrl( '' ), { replace: true } ); 689 } 715 themes.router.navigate( themes.router.baseUrl( '' ) ); 716 } 717 }, 718 719 pushState: function( event ) { 720 var url = themes.router.baseUrl( '' ); 721 722 if ( event.target.value ) { 723 url = themes.router.baseUrl( '?search=' + event.target.value ); 724 } 725 726 this.searching = false; 727 themes.router.navigate( url ); 728 690 729 } 691 730 }); … … 695 734 themes.routes = Backbone.Router.extend({ 696 735 697 initialize: function() { 698 this.routes = _.object([ 699 ]); 736 routes: { 737 'themes.php?theme=:slug': 'theme', 738 'themes.php?search=:query': 'search', 739 'themes.php?s=:query': 'search', 740 'themes.php': 'themes', 741 '': 'themes' 700 742 }, 701 743 702 744 baseUrl: function( url ) { 703 return themes.data.settings.root + url; 745 return 'themes.php' + url; 746 }, 747 748 search: function( query ) { 749 $( '.theme-search' ).val( query ); 750 }, 751 752 themes: function() { 753 $( '.theme-search' ).val( '' ); 704 754 } 755 705 756 }); 706 757 … … 721 772 722 773 render: function() { 774 723 775 // Render results 724 776 this.view.render(); 725 777 this.routes(); 726 778 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 739 if ( window.history && window.history.pushState ) { 740 // Calls the routes functionality 741 Backbone.history.start({ pushState: true, silent: true }); 742 } 779 Backbone.history.start({ 780 root: themes.data.settings.adminUrl, 781 pushState: true, 782 hashChange: false 783 }); 743 784 }, 744 785 745 786 routes: function() { 787 var self = this; 746 788 // Bind to our global thx object 747 789 // so that the object is available to sub-views 748 790 themes.router = new themes.routes(); 791 792 // Handles theme details route event 793 themes.router.on( 'route:theme', function( slug ) { 794 self.view.view.expand( slug ); 795 }); 796 797 themes.router.on( 'route:themes', function() { 798 self.themes.doSearch( '' ); 799 self.view.trigger( 'theme:close' ); 800 }); 801 802 // Handles search route event 803 themes.router.on( 'route:search', function( query ) { 804 self.view.trigger( 'theme:close' ); 805 self.themes.doSearch( query ); 806 }); 749 807 } 750 808 }; -
trunk/src/wp-admin/themes.php
r27119 r27268 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 'root' => parse_url( admin_url( 'themes.php' ), PHP_URL_PATH ), 103 'theme' => esc_html( $theme ), 104 'search' => esc_html( $search ), 105 102 'adminUrl' => parse_url( admin_url(), PHP_URL_PATH ), 106 103 ), 107 104 'l10n' => array(
Note: See TracChangeset
for help on using the changeset viewer.