Themes: After [36546] restore theme search functionality.

* Correct several incorrect uses of `_.union`. Since Underscore 1.7.0 `_.union` supports only arrays and not variadic args.
* Use a namespaced event `themes:update`. Backbone 1.2 added a built in `update` event that triggers after any amount of models are added or removed from a collection.

Props adamsilverstein.
See #34350.
Built from https://develop.svn.wordpress.org/trunk@36580


git-svn-id: http://core.svn.wordpress.org/trunk@36547 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2016-02-18 21:21:26 +00:00
parent 284f88e35a
commit 6f2a56bf3e
3 changed files with 10 additions and 10 deletions

View File

@ -158,8 +158,8 @@ themes.Collection = Backbone.Collection.extend({
$( 'body' ).removeClass( 'no-results' ); $( 'body' ).removeClass( 'no-results' );
} }
// Trigger an 'update' event // Trigger a 'themes:update' event
this.trigger( 'update' ); this.trigger( 'themes:update' );
}, },
// Performs a search within the collection // Performs a search within the collection
@ -185,7 +185,7 @@ themes.Collection = Backbone.Collection.extend({
description = data.get( 'description' ).replace( /(<([^>]+)>)/ig, '' ); description = data.get( 'description' ).replace( /(<([^>]+)>)/ig, '' );
author = data.get( 'author' ).replace( /(<([^>]+)>)/ig, '' ); author = data.get( 'author' ).replace( /(<([^>]+)>)/ig, '' );
haystack = _.union( name, data.get( 'id' ), description, author, data.get( 'tags' ) ); haystack = _.union( [ name, data.get( 'id' ), description, author, data.get( 'tags' ) ] );
if ( match.test( data.get( 'author' ) ) && term.length > 2 ) { if ( match.test( data.get( 'author' ) ) && term.length > 2 ) {
data.set( 'displayAuthor', true ); data.set( 'displayAuthor', true );
@ -264,7 +264,7 @@ themes.Collection = Backbone.Collection.extend({
// Trigger a collection refresh event // Trigger a collection refresh event
// and a `query:success` event with a `count` argument. // and a `query:success` event with a `count` argument.
self.trigger( 'update' ); self.trigger( 'themes:update' );
self.trigger( 'query:success', count ); self.trigger( 'query:success', count );
if ( data.themes && data.themes.length === 0 ) { if ( data.themes && data.themes.length === 0 ) {
@ -308,7 +308,7 @@ themes.Collection = Backbone.Collection.extend({
this.count = this.length; this.count = this.length;
} }
this.trigger( 'update' ); this.trigger( 'themes:update' );
this.trigger( 'query:success', this.count ); this.trigger( 'query:success', this.count );
} }
}, },
@ -863,11 +863,11 @@ themes.view.Themes = wp.Backbone.View.extend({
self.currentTheme(); self.currentTheme();
// When the collection is updated by user input... // When the collection is updated by user input...
this.listenTo( self.collection, 'update', function() { this.listenTo( self.collection, 'themes:update', function() {
self.parent.page = 0; self.parent.page = 0;
self.currentTheme(); self.currentTheme();
self.render( this ); self.render( this );
}); } );
// Update theme count to full result set when available. // Update theme count to full result set when available.
this.listenTo( self.collection, 'query:success', function( count ) { this.listenTo( self.collection, 'query:success', function( count ) {
@ -1478,7 +1478,7 @@ themes.view.Installer = themes.view.Appearance.extend({
// Construct the filter request // Construct the filter request
// using the default values // using the default values
filter = _.union( filter, this.filtersChecked() ); filter = _.union( [ filter, this.filtersChecked() ] );
request = { tag: [ filter ] }; request = { tag: [ filter ] };
// Get the themes by sending Ajax POST request to api.wordpress.org/themes // Get the themes by sending Ajax POST request to api.wordpress.org/themes

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.5-alpha-36579'; $wp_version = '4.5-alpha-36580';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.