// Render and append
this.view.render();
- this.$el.empty().append( this.view.el ).addClass('rendered');
+ this.$el.empty().append( this.view.el ).addClass( 'rendered' );
this.$el.append( '<br class="clear"/>' );
},
// Useful for resetting the views when you clean the input
if ( this.terms === '' ) {
this.reset( themes.data.themes );
+ $( 'body' ).removeClass( 'no-results' );
}
// Trigger an 'update' event
// Performs a search within the collection
// @uses RegExp
search: function( term ) {
- var match, results, haystack;
+ var match, results, haystack, name, description, author;
// Start with a full collection
this.reset( themes.data.themes, { silent: true } );
// Find results
// _.filter and .test
results = this.filter( function( data ) {
- haystack = _.union( data.get( 'name' ), data.get( 'id' ), data.get( 'description' ), data.get( 'author' ), data.get( 'tags' ) );
+ name = data.get( 'name' ).replace( /(<([^>]+)>)/ig, '' );
+ description = data.get( 'description' ).replace( /(<([^>]+)>)/ig, '' );
+ author = data.get( 'author' ).replace( /(<([^>]+)>)/ig, '' );
+
+ haystack = _.union( name, data.get( 'id' ), description, author, data.get( 'tags' ) );
if ( match.test( data.get( 'author' ) ) && term.length > 2 ) {
data.set( 'displayAuthor', true );
index: 0,
// The theme count element
- count: $( '.wp-filter .theme-count' ),
+ count: $( '.wp-core-ui .theme-count' ),
+
+ // The live themes count
+ liveThemeCount: 0,
initialize: function( options ) {
var self = this;
this.listenTo( self.collection, 'query:success', function( count ) {
if ( _.isNumber( count ) ) {
self.count.text( count );
+ self.announceSearchResults( count );
} else {
self.count.text( self.collection.length );
+ self.announceSearchResults( self.collection.length );
}
});
// and keeping theme count in sync
render: function() {
// Clear the DOM, please
- this.$el.html( '' );
+ this.$el.empty();
// If the user doesn't have switch capabilities
// or there is only one theme in the collection
}
// Display a live theme count for the collection
- this.count.text( this.collection.count ? this.collection.count : this.collection.length );
+ this.liveThemeCount = this.collection.count ? this.collection.count : this.collection.length;
+ this.count.text( this.liveThemeCount );
+
+ this.announceSearchResults( this.liveThemeCount );
},
// Iterates through each instance of the collection
self.theme.trigger( 'theme:expand', previousModel.cid );
}
+ },
+
+ // Dispatch audible search results feedback message
+ announceSearchResults: function( count ) {
+ if ( 0 === count ) {
+ wp.a11y.speak( l10n.noThemesFound );
+ } else {
+ wp.a11y.speak( l10n.themesFound.replace( '%d', count ) );
+ }
}
});
attributes: {
placeholder: l10n.searchPlaceholder,
- type: 'search'
+ type: 'search',
+ 'aria-describedby': 'live-search-desc'
},
events: {
- 'input': 'search',
- 'keyup': 'search',
- 'change': 'search',
- 'search': 'search',
- 'blur': 'pushState'
+ 'input': 'search',
+ 'keyup': 'search',
+ 'blur': 'pushState'
},
initialize: function( options ) {
},
- // Runs a search on the theme collection.
search: function( event ) {
- var options = {};
-
// Clear on escape.
if ( event.type === 'keyup' && event.which === 27 ) {
event.target.value = '';
}
- // Lose input focus when pressing enter
- if ( event.which === 13 ) {
- this.$el.trigger( 'blur' );
- }
+ /**
+ * Since doSearch is debounced, it will only run when user input comes to a rest
+ */
+ this.doSearch( event );
+ },
+
+ // Runs a search on the theme collection.
+ doSearch: _.debounce( function( event ) {
+ var options = {};
this.collection.doSearch( event.target.value );
} else {
themes.router.navigate( themes.router.baseUrl( '' ) );
}
- },
+ }, 500 ),
pushState: function( event ) {
var url = themes.router.baseUrl( '' );
themes.view.InstallerSearch = themes.view.Search.extend({
events: {
+ 'input': 'search',
'keyup': 'search'
},
event.target.value = '';
}
- _.debounce( _.bind( this.doSearch, this ), 300 )( event.target.value );
+ this.doSearch( event.target.value );
},
doSearch: _.debounce( function( value ) {
// Set route
themes.router.navigate( themes.router.baseUrl( themes.router.searchPath + value ), { replace: true } );
- }, 300 )
+ }, 500 )
});
themes.view.Installer = themes.view.Appearance.extend({