// 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"/>' );
},
// Render and append after screen title
view.render();
this.searchContainer
- .append( $.parseHTML( '<label class="screen-reader-text" for="theme-search-input">' + l10n.search + '</label>' ) )
+ .append( $.parseHTML( '<label class="screen-reader-text" for="wp-filter-search-input">' + l10n.search + '</label>' ) )
.append( view.el );
},
// 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 );
return match.test( haystack );
});
+ if ( results.length === 0 ) {
+ this.trigger( 'query:empty' );
+ } else {
+ $( 'body' ).removeClass( 'no-results' );
+ }
+
this.reset( results );
},
beforeSend: function() {
if ( ! paginated ) {
// Spin it
- $( 'body' ).addClass( 'loading-themes' ).removeClass( 'no-results' );
+ $( 'body' ).addClass( 'loading-content' ).removeClass( 'no-results' );
}
}
});
events: {
'click': themes.isInstall ? 'preview': 'expand',
- 'click .preview': 'preview',
'keydown': themes.isInstall ? 'preview': 'expand',
'touchend': themes.isInstall ? 'preview': 'expand',
'keyup': 'addFocus',
preview.$el.removeClass( 'no-navigation' );
}
- // Apend preview
+ // Append preview
$( 'div.wrap' ).append( preview.el );
// Listen to our preview object
current = self.current;
}
- // Get previous theme model.
+ // Get next theme model.
self.current = self.model.collection.at( self.model.collection.indexOf( current ) + 1 );
// If we have no more themes, bail.
return self.current = current;
}
- // Construct a new Preview view.
- preview = new themes.view.Preview({
- model: self.current
- });
+ preview.model = self.current;
// Render and append.
preview.render();
this.setNavButtonsState();
- $( 'div.wrap' ).append( preview.el );
$( '.next-theme' ).focus();
})
.listenTo( preview, 'theme:previous', function() {
return;
}
- // Construct a new Preview view.
- preview = new themes.view.Preview({
- model: self.current
- });
+ preview.model = self.current;
// Render and append.
preview.render();
this.setNavButtonsState();
- $( 'div.wrap' ).append( preview.el );
$( '.previous-theme' ).focus();
});
// Performs the actions to effectively close
// the theme details overlay
closeOverlay: function() {
- $( 'body' ).removeClass( 'theme-overlay-open' );
+ $( 'body' ).removeClass( 'modal-open' );
this.remove();
this.unbind();
this.trigger( 'theme:collapse' );
this.$el.html( this.html( data ) );
- themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.get( 'id' ) ), { replace: true } );
+ themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.get( 'id' ) ), { replace: true } );
this.$el.fadeIn( 200, function() {
$( 'body' ).addClass( 'theme-installer-active full-overlay-active' );
themes.router.navigate( themes.router.baseUrl( '' ) );
this.trigger( 'preview:close' );
+ this.undelegateEvents();
this.unbind();
return false;
},
index: 0,
// The theme count element
- count: $( '.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
this.model = self.collection.get( id );
// Trigger a route update for the current model
- themes.router.navigate( themes.router.baseUrl( '?theme=' + this.model.id ) );
+ themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.id ) );
// Sets this.view to 'detail'
this.setView( 'detail' );
- $( 'body' ).addClass( 'theme-overlay-open' );
+ $( 'body' ).addClass( 'modal-open' );
// Set up the theme details view
this.overlay = new themes.view.Details({
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 ) );
+ }
}
});
themes.view.Search = wp.Backbone.View.extend({
tagName: 'input',
- className: 'theme-search',
- id: 'theme-search-input',
+ className: 'wp-filter-search',
+ id: 'wp-filter-search-input',
searching: false,
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 );
// Update the URL hash
if ( event.target.value ) {
- themes.router.navigate( themes.router.baseUrl( '?search=' + event.target.value ), options );
+ themes.router.navigate( themes.router.baseUrl( themes.router.searchPath + event.target.value ), options );
} else {
themes.router.navigate( themes.router.baseUrl( '' ) );
}
- },
+ }, 500 ),
pushState: function( event ) {
var url = themes.router.baseUrl( '' );
if ( event.target.value ) {
- url = themes.router.baseUrl( '?search=' + event.target.value );
+ url = themes.router.baseUrl( themes.router.searchPath + event.target.value );
}
this.searching = false;
return 'themes.php' + url;
},
+ themePath: '?theme=',
+ searchPath: '?search=',
+
search: function( query ) {
- $( '.theme-search' ).val( query );
+ $( '.wp-filter-search' ).val( query );
},
themes: function() {
- $( '.theme-search' ).val( '' );
+ $( '.wp-filter-search' ).val( '' );
},
navigate: function() {
// Handles search route event
themes.router.on( 'route:search', function() {
- $( '.theme-search' ).trigger( 'keyup' );
+ $( '.wp-filter-search' ).trigger( 'keyup' );
});
this.extraRoutes();
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 ) {
request.tag = [ value.slice( 4 ) ];
}
- $( '.theme-section.current' ).removeClass( 'current' );
- $( 'body' ).removeClass( 'more-filters-opened filters-applied' );
+ $( '.filter-links li > a.current' ).removeClass( 'current' );
+ $( 'body' ).removeClass( 'show-filters filters-applied' );
// Get the themes by sending Ajax POST request to api.wordpress.org/themes
// or searching the local cache
this.collection.query( request );
// Set route
- themes.router.navigate( themes.router.baseUrl( '?search=' + value ), { replace: true } );
- }, 300 )
+ themes.router.navigate( themes.router.baseUrl( themes.router.searchPath + value ), { replace: true } );
+ }, 500 )
});
themes.view.Installer = themes.view.Appearance.extend({
// Register events for sorting and filters in theme-navigation
events: {
- 'click .theme-section': 'onSort',
+ 'click .filter-links li > a': 'onSort',
'click .theme-filter': 'onFilter',
- 'click .more-filters': 'moreFilters',
- 'click .apply-filters': 'applyFilters',
- 'click [type="checkbox"]': 'addFilter',
- 'click .clear-filters': 'clearFilters',
- 'click .feature-name': 'filterSection',
- 'click .filtering-by a': 'backToFilters'
+ 'click .drawer-toggle': 'moreFilters',
+ 'click .filter-drawer .apply-filters': 'applyFilters',
+ 'click .filter-group [type="checkbox"]': 'addFilter',
+ 'click .filter-drawer .clear-filters': 'clearFilters',
+ 'click .filtered-by': 'backToFilters'
},
// Initial render method
});
this.listenTo( this.collection, 'query:success', function() {
- $( 'body' ).removeClass( 'loading-themes' );
+ $( 'body' ).removeClass( 'loading-content' );
$( '.theme-browser' ).find( 'div.error' ).remove();
});
this.listenTo( this.collection, 'query:fail', function() {
- $( 'body' ).removeClass( 'loading-themes' );
+ $( 'body' ).removeClass( 'loading-content' );
$( '.theme-browser' ).find( 'div.error' ).remove();
$( '.theme-browser' ).find( 'div.themes' ).before( '<div class="error"><p>' + l10n.error + '</p></div>' );
});
event.preventDefault();
- $( 'body' ).removeClass( 'filters-applied more-filters-opened' );
+ $( 'body' ).removeClass( 'filters-applied show-filters' );
// Bail if this is already active
if ( $el.hasClass( this.activeClass ) ) {
this.sort( sort );
// Trigger a router.naviagte update
- themes.router.navigate( themes.router.baseUrl( '?browse=' + sort ) );
+ themes.router.navigate( themes.router.baseUrl( themes.router.browsePath + sort ) );
},
sort: function( sort ) {
this.clearSearch();
- $( '.theme-section, .theme-filter' ).removeClass( this.activeClass );
+ $( '.filter-links li > a, .theme-filter' ).removeClass( this.activeClass );
$( '[data-sort="' + sort + '"]' ).addClass( this.activeClass );
this.browse( sort );
return;
}
- $( '.theme-filter, .theme-section' ).removeClass( this.activeClass );
+ $( '.filter-links li > a, .theme-section' ).removeClass( this.activeClass );
$el.addClass( this.activeClass );
if ( ! filter ) {
var name,
tags = this.filtersChecked(),
request = { tag: tags },
- filteringBy = $( '.filtering-by .tags' );
+ filteringBy = $( '.filtered-by .tags' );
if ( event ) {
event.preventDefault();
}
$( 'body' ).addClass( 'filters-applied' );
- $( '.theme-section.current' ).removeClass( 'current' );
+ $( '.filter-links li > a.current' ).removeClass( 'current' );
filteringBy.empty();
_.each( tags, function( tag ) {
- name = $( 'label[for="feature-id-' + tag + '"]' ).text();
+ name = $( 'label[for="filter-id-' + tag + '"]' ).text();
filteringBy.append( '<span class="tag">' + name + '</span>' );
});
// Get the checked filters
// @return {array} of tags or false
filtersChecked: function() {
- var items = $( '.feature-group' ).find( ':checkbox' ),
+ var items = $( '.filter-group' ).find( ':checkbox' ),
tags = [];
_.each( items.filter( ':checked' ), function( item ) {
// When no filters are checked, restore initial state and return
if ( tags.length === 0 ) {
- $( '.apply-filters' ).find( 'span' ).text( '' );
- $( '.clear-filters' ).hide();
+ $( '.filter-drawer .apply-filters' ).find( 'span' ).text( '' );
+ $( '.filter-drawer .clear-filters' ).hide();
$( 'body' ).removeClass( 'filters-applied' );
return false;
}
- $( '.apply-filters' ).find( 'span' ).text( tags.length );
- $( '.clear-filters' ).css( 'display', 'inline-block' );
+ $( '.filter-drawer .apply-filters' ).find( 'span' ).text( tags.length );
+ $( '.filter-drawer .clear-filters' ).css( 'display', 'inline-block' );
return tags;
},
// Overwrite search container class to append search
// in new location
- searchContainer: $( '.theme-navigation' ),
+ searchContainer: $( '.wp-filter .search-form' ),
uploader: function() {
$( 'a.upload' ).on( 'click', function( event ) {
// If the filters section is opened and filters are checked
// run the relevant query collapsing to filtered-by state
- if ( $( 'body' ).hasClass( 'more-filters-opened' ) && this.filtersChecked() ) {
+ if ( $( 'body' ).hasClass( 'show-filters' ) && this.filtersChecked() ) {
return this.addFilter();
}
this.clearSearch();
themes.router.navigate( themes.router.baseUrl( '' ) );
- $( 'body' ).toggleClass( 'more-filters-opened' );
- },
-
- // Expand/collapse each individual filter section
- filterSection: function() {
- $( event.target ).parent().toggleClass( 'open' );
+ $( 'body' ).toggleClass( 'show-filters' );
},
// Clears all the checked filters
// @uses filtersChecked()
clearFilters: function( event ) {
- var items = $( '.feature-group' ).find( ':checkbox' ),
+ var items = $( '.filter-group' ).find( ':checkbox' ),
self = this;
event.preventDefault();
},
clearSearch: function() {
- $( '#theme-search-input').val( '' );
+ $( '#wp-filter-search-input').val( '' );
}
});
return 'theme-install.php' + url;
},
+ themePath: '?theme=',
+ browsePath: '?browse=',
+ searchPath: '?search=',
+
search: function( query ) {
- $( '.theme-search' ).val( query );
+ $( '.wp-filter-search' ).val( query );
},
navigate: function() {
// The `search` route event. The router populates the input field.
themes.router.on( 'route:search', function() {
- $( '.theme-search' ).focus().trigger( 'keyup' );
+ $( '.wp-filter-search' ).focus().trigger( 'keyup' );
});
this.extraRoutes();
} else {
themes.Run.init();
}
+
+ $( '.broken-themes .delete-theme' ).on( 'click', function() {
+ return confirm( _wpThemeSettings.settings.confirmDelete );
+ });
});
})( jQuery );