wp/wp-admin/js/theme.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
   116 		self.SearchView = view;
   116 		self.SearchView = view;
   117 
   117 
   118 		// Render and append after screen title.
   118 		// Render and append after screen title.
   119 		view.render();
   119 		view.render();
   120 		this.searchContainer
   120 		this.searchContainer
   121 			.append( $.parseHTML( '<label class="screen-reader-text" for="wp-filter-search-input">' + l10n.search + '</label>' ) )
   121 			.find( '.search-box' )
   122 			.append( view.el )
   122 			.append( $.parseHTML( '<label for="wp-filter-search-input">' + l10n.search + '</label>' ) )
   123 			.on( 'submit', function( event ) {
   123 			.append( view.el );
   124 				event.preventDefault();
   124 
   125 			});
   125 		this.searchContainer.on( 'submit', function( event ) {
       
   126 			event.preventDefault();
       
   127 		});
   126 	},
   128 	},
   127 
   129 
   128 	// Checks when the user gets close to the bottom
   130 	// Checks when the user gets close to the bottom
   129 	// of the mage and triggers a theme:scroll event.
   131 	// of the mage and triggers a theme:scroll event.
   130 	scroller: function() {
   132 	scroller: function() {
   924 
   926 
   925 		this.$el.removeClass( 'iframe-ready' ).html( this.html( data ) );
   927 		this.$el.removeClass( 'iframe-ready' ).html( this.html( data ) );
   926 
   928 
   927 		currentPreviewDevice = this.$el.data( 'current-preview-device' );
   929 		currentPreviewDevice = this.$el.data( 'current-preview-device' );
   928 		if ( currentPreviewDevice ) {
   930 		if ( currentPreviewDevice ) {
   929 			self.tooglePreviewDeviceButtons( currentPreviewDevice );
   931 			self.togglePreviewDeviceButtons( currentPreviewDevice );
   930 		}
   932 		}
   931 
   933 
   932 		themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.get( 'id' ) ), { replace: false } );
   934 		themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.get( 'id' ) ), { replace: false } );
   933 
   935 
   934 		this.$el.fadeIn( 200, function() {
   936 		this.$el.fadeIn( 200, function() {
   986 		this.$el
   988 		this.$el
   987 			.removeClass( 'preview-desktop preview-tablet preview-mobile' )
   989 			.removeClass( 'preview-desktop preview-tablet preview-mobile' )
   988 			.addClass( 'preview-' + device )
   990 			.addClass( 'preview-' + device )
   989 			.data( 'current-preview-device', device );
   991 			.data( 'current-preview-device', device );
   990 
   992 
   991 		this.tooglePreviewDeviceButtons( device );
   993 		this.togglePreviewDeviceButtons( device );
   992 	},
   994 	},
   993 
   995 
   994 	tooglePreviewDeviceButtons: function( newDevice ) {
   996 	togglePreviewDeviceButtons: function( newDevice ) {
   995 		var $devices = $( '.wp-full-overlay-footer .devices' );
   997 		var $devices = $( '.wp-full-overlay-footer .devices' );
   996 
   998 
   997 		$devices.find( 'button' )
   999 		$devices.find( 'button' )
   998 			.removeClass( 'active' )
  1000 			.removeClass( 'active' )
   999 			.attr( 'aria-pressed', false );
  1001 			.attr( 'aria-pressed', false );
  1298 		// Get the current theme.
  1300 		// Get the current theme.
  1299 		model = self.collection.get( args[0] );
  1301 		model = self.collection.get( args[0] );
  1300 		// Find the next model within the collection.
  1302 		// Find the next model within the collection.
  1301 		nextModel = self.collection.at( self.collection.indexOf( model ) + 1 );
  1303 		nextModel = self.collection.at( self.collection.indexOf( model ) + 1 );
  1302 
  1304 
  1303 		// Sanity check which also serves as a boundary test.
  1305 		// Confidence check which also serves as a boundary test.
  1304 		if ( nextModel !== undefined ) {
  1306 		if ( nextModel !== undefined ) {
  1305 
  1307 
  1306 			// We have a new theme...
  1308 			// We have a new theme...
  1307 			// Close the overlay.
  1309 			// Close the overlay.
  1308 			this.overlay.closeOverlay();
  1310 			this.overlay.closeOverlay();
  1357 	className: 'wp-filter-search',
  1359 	className: 'wp-filter-search',
  1358 	id: 'wp-filter-search-input',
  1360 	id: 'wp-filter-search-input',
  1359 	searching: false,
  1361 	searching: false,
  1360 
  1362 
  1361 	attributes: {
  1363 	attributes: {
  1362 		placeholder: l10n.searchPlaceholder,
       
  1363 		type: 'search',
  1364 		type: 'search',
  1364 		'aria-describedby': 'live-search-desc'
  1365 		'aria-describedby': 'live-search-desc'
  1365 	},
  1366 	},
  1366 
  1367 
  1367 	events: {
  1368 	events: {
  1692 
  1693 
  1693 	// Handles all the rendering of the public theme directory.
  1694 	// Handles all the rendering of the public theme directory.
  1694 	browse: function( section ) {
  1695 	browse: function( section ) {
  1695 		// Create a new collection with the proper theme data
  1696 		// Create a new collection with the proper theme data
  1696 		// for each section.
  1697 		// for each section.
  1697 		this.collection.query( { browse: section } );
  1698 		if ( 'block-themes' === section ) {
       
  1699 			// Get the themes by sending Ajax POST request to api.wordpress.org/themes
       
  1700 			// or searching the local cache.
       
  1701 			this.collection.query( { tag: 'full-site-editing' } );
       
  1702 		} else {
       
  1703 			this.collection.query( { browse: section } );
       
  1704 		}
  1698 	},
  1705 	},
  1699 
  1706 
  1700 	// Sorting navigation.
  1707 	// Sorting navigation.
  1701 	onSort: function( event ) {
  1708 	onSort: function( event ) {
  1702 		var $el = $( event.target ),
  1709 		var $el = $( event.target ),