Make WordPress Core

Changeset 28044


Ignore:
Timestamp:
04/08/2014 08:11:33 AM (12 years ago)
Author:
ocean90
Message:

Widget Customizer: Fix widget filtering.

props westonruter.
fixes #27451.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-widgets.js

    r28034 r28044  
    3737                params: [],
    3838                width: null,
    39                 height: null
     39                height: null,
     40                search_matched: true
    4041        });
    4142
     
    7273                        // Useful for resetting the views when you clean the input
    7374                        if ( this.terms === '' ) {
    74                                 this.reset( api.Widgets.data.availableWidgets );
    75                         }
    76 
    77                         // Trigger an 'update' event
    78                         this.trigger( 'update' );
     75                                this.each( function ( widget ) {
     76                                        widget.set( 'search_matched', true );
     77                                } );
     78                        }
    7979                },
    8080
     
    8282                // @uses RegExp
    8383                search: function( term ) {
    84                         var match, results, haystack;
    85 
    86                         // Start with a full collection
    87                         this.reset( api.Widgets.data.availableWidgets, { silent: true } );
     84                        var match, haystack;
    8885
    8986                        // Escape the term string for RegExp meta characters
     
    9592                        match = new RegExp( '^(?=.*' + term + ').+', 'i' );
    9693
    97                         results = this.filter( function( data ) {
    98                                 haystack = _.union( data.get( 'name' ), data.get( 'id' ), data.get( 'description' ) );
    99 
    100                                 return match.test( haystack );
    101                         });
    102 
    103                         this.reset( results );
     94                        this.each( function ( data ) {
     95                                haystack = [ data.get( 'name' ), data.get( 'id' ), data.get( 'description' ) ].join( ' ' );
     96                                data.set( 'search_matched', match.test( haystack ) );
     97                        } );
    10498                }
    10599        });
     
    177171                        _.bindAll( this, 'close' );
    178172
    179                         this.listenTo( this.collection, 'update', this.updateList );
    180173                        this.listenTo( this.collection, 'change', this.updateList );
    181174
     
    223216                },
    224217
    225                 // Changes visibilty of available widgets
     218                // Changes visibility of available widgets
    226219                updateList: function() {
    227                         // First hide all widgets...
    228                         this.$el.find( '.widget-tpl' ).hide();
    229 
    230                         // ..and then show only available widgets which could be filtered
    231220                        this.collection.each( function( widget ) {
    232221                                var widgetTpl = $( '#widget-tpl-' + widget.id );
    233                                 widgetTpl.toggle( ! widget.get( 'is_disabled' ) );
     222                                widgetTpl.toggle( widget.get( 'search_matched' ) && ! widget.get( 'is_disabled' ) );
    234223                                if ( widget.get( 'is_disabled' ) && widgetTpl.is( this.selected ) ) {
    235224                                        this.selected = null;
     
    238227                },
    239228
    240                 // Hightlights a widget
     229                // Highlights a widget
    241230                select: function( widgetTpl ) {
    242231                        this.selected = $( widgetTpl );
     
    245234                },
    246235
    247                 // Hightlights a widget on focus
     236                // Highlights a widget on focus
    248237                focus: function( event ) {
    249238                        this.select( $( event.currentTarget ) );
     
    16021591                /**
    16031592                 * @param {string} widgetId or an id_base for adding a previously non-existing widget
    1604                  * @returns {object} widget_form control instance
     1593                 * @returns {object|false} widget_form control instance, or false on error
    16051594                 */
    16061595                addWidget: function( widgetId ) {
     
    16131602
    16141603                        if ( ! widget ) {
    1615                                 return;
     1604                                return false;
    16161605                        }
    16171606
    16181607                        if ( widgetNumber && ! widget.get( 'is_multi' ) ) {
    1619                                 return;
     1608                                return false;
    16201609                        }
    16211610
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r27985 r28044  
    11511151                if ( ! empty( $_POST['sanitized_widget_setting'] ) ) {
    11521152                        $sanitized_widget_setting = json_decode( $this->get_post_value( 'sanitized_widget_setting' ), true );
    1153                         if ( empty( $sanitized_widget_setting ) ) {
     1153                        if ( false === $sanitized_widget_setting ) {
    11541154                                $this->stop_capturing_option_updates();
    11551155                                return new WP_Error( 'widget_setting_malformed' );
Note: See TracChangeset for help on using the changeset viewer.