Make WordPress Core

Ticket #30583: 30583.diff

File 30583.diff, 4.2 KB (added by wonderboymusic, 9 years ago)
  • src/wp-admin/upload.php

     
    2525        wp_enqueue_script( 'media-grid' );
    2626        wp_enqueue_script( 'media' );
    2727
    28         $vars = wp_edit_attachments_query_vars();
     28        $q = $_GET;
     29        // let JS handle this
     30        unset( $q['s'] );
     31        $vars = wp_edit_attachments_query_vars( $q );
    2932        $ignore = array( 'mode', 'post_type', 'post_status', 'posts_per_page' );
    3033        foreach ( $vars as $key => $value ) {
    3134                if ( ! $value || in_array( $key, $ignore ) ) {
     
    6770
    6871        require_once( ABSPATH . 'wp-admin/admin-header.php' );
    6972        ?>
    70         <div class="wrap" id="wp-media-grid">
     73        <div class="wrap" id="wp-media-grid" data-search="<?php _admin_search_query() ?>">
    7174                <h2>
    7275                <?php
    7376                echo esc_html( $title );
  • src/wp-includes/js/media/grid.js

     
    682682                this.createStates();
    683683                this.bindRegionModeHandlers();
    684684                this.render();
     685                this.bindSearchHandler();
     686        },
    685687
     688        /**
     689         * The views must interact with form controls that are not part of a frame
     690         */
     691        bindSearchHandler: function() {
     692                var search = this.$( '#media-search-input' ),
     693                        currentSearch = this.options.container.data( 'search' ),
     694                        searchView = this.browserView.toolbar.get( 'search' ).$el,
     695                        listMode = this.$( '.view-list' ),
     696
     697                        input  = _.debounce( function (e) {
     698                                var val = $( e.currentTarget ).val(),
     699                                        url = '';
     700
     701                                if ( val ) {
     702                                        url += '?search=' + val;
     703                                }
     704                                this.gridRouter.navigate( this.gridRouter.baseUrl( url ) );
     705                        }, 1000 );
     706
    686707                // Update the URL when entering search string (at most once per second)
    687                 $( '#media-search-input' ).on( 'input', _.debounce( function(e) {
    688                         var val = $( e.currentTarget ).val(), url = '';
    689                         if ( val ) {
    690                                 url += '?search=' + val;
     708                search.on( 'input', _.bind( input, this ) );
     709                searchView.val( currentSearch ).trigger( 'input' );
     710
     711                this.gridRouter.on( 'route:search', function () {
     712                        var href = window.location.href;
     713                        if ( href.indexOf( 'mode=' ) > -1 ) {
     714                                href = href.replace( /mode=[^&]+/g, 'mode=list' );
     715                        } else {
     716                                href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list';
    691717                        }
    692                         self.gridRouter.navigate( self.gridRouter.baseUrl( url ) );
    693                 }, 1000 ) );
     718                        href = href.replace( 'search=', 's=' );
     719                        listMode.prop( 'href', href );
     720                } );
    694721        },
    695722
    696723        /**
  • src/wp-includes/js/media/views/frame/manage.js

     
    8383                this.createStates();
    8484                this.bindRegionModeHandlers();
    8585                this.render();
     86                this.bindSearchHandler();
     87        },
    8688
     89        /**
     90         * The views must interact with form controls that are not part of a frame
     91         */
     92        bindSearchHandler: function() {
     93                var search = this.$( '#media-search-input' ),
     94                        currentSearch = this.options.container.data( 'search' ),
     95                        searchView = this.browserView.toolbar.get( 'search' ).$el,
     96                        listMode = this.$( '.view-list' ),
     97
     98                        input  = _.debounce( function (e) {
     99                                var val = $( e.currentTarget ).val(),
     100                                        url = '';
     101
     102                                if ( val ) {
     103                                        url += '?search=' + val;
     104                                }
     105                                this.gridRouter.navigate( this.gridRouter.baseUrl( url ) );
     106                        }, 1000 );
     107
    87108                // Update the URL when entering search string (at most once per second)
    88                 $( '#media-search-input' ).on( 'input', _.debounce( function(e) {
    89                         var val = $( e.currentTarget ).val(), url = '';
    90                         if ( val ) {
    91                                 url += '?search=' + val;
     109                search.on( 'input', _.bind( input, this ) );
     110                searchView.val( currentSearch ).trigger( 'input' );
     111
     112                this.gridRouter.on( 'route:search', function () {
     113                        var href = window.location.href;
     114                        if ( href.indexOf( 'mode=' ) > -1 ) {
     115                                href = href.replace( /mode=[^&]+/g, 'mode=list' );
     116                        } else {
     117                                href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list';
    92118                        }
    93                         self.gridRouter.navigate( self.gridRouter.baseUrl( url ) );
    94                 }, 1000 ) );
     119                        href = href.replace( 'search=', 's=' );
     120                        listMode.prop( 'href', href );
     121                } );
    95122        },
    96123
    97124        /**