Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions modules/search/class-jetpack-search-customize.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public function customize_register( $wp_customize ) {
$wp_customize->add_setting(
$id,
array(
'default' => 'light',
'type' => 'option',
'default' => 'light',
'transport' => 'postMessage',
'type' => 'option',
)
);
$wp_customize->add_control(
Expand All @@ -75,8 +76,9 @@ public function customize_register( $wp_customize ) {
$wp_customize->add_setting(
$id,
array(
'default' => 97,
'type' => 'option',
'default' => 97,
'transport' => 'postMessage',
'type' => 'option',
)
);
$wp_customize->add_control(
Expand All @@ -98,8 +100,9 @@ public function customize_register( $wp_customize ) {
$wp_customize->add_setting(
$id,
array(
'default' => '#BD3854',
'type' => 'option',
'default' => '#BD3854',
'transport' => 'postMessage',
'type' => 'option',
)
);
$wp_customize->add_control(
Expand All @@ -118,8 +121,9 @@ public function customize_register( $wp_customize ) {
$wp_customize->add_setting(
$id,
array(
'default' => '#FFC',
'type' => 'option',
'default' => '#FFC',
'transport' => 'postMessage',
'type' => 'option',
)
);
$wp_customize->add_control(
Expand All @@ -138,8 +142,9 @@ public function customize_register( $wp_customize ) {
$wp_customize->add_setting(
$id,
array(
'default' => true,
'type' => 'option',
'default' => true,
'transport' => 'postMessage',
'type' => 'option',
)
);
$wp_customize->add_control(
Expand All @@ -155,8 +160,9 @@ public function customize_register( $wp_customize ) {
$wp_customize->add_setting(
$id,
array(
'default' => true,
'type' => 'option',
'default' => true,
'transport' => 'postMessage',
'type' => 'option',
)
);

Expand All @@ -173,8 +179,9 @@ public function customize_register( $wp_customize ) {
$wp_customize->add_setting(
$id,
array(
'default' => true,
'type' => 'option',
'default' => true,
'transport' => 'postMessage',
'type' => 'option',
)
);
$wp_customize->add_control(
Expand Down
16 changes: 12 additions & 4 deletions modules/search/instant-search/components/search-app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getSortKeyFromSortOption,
getSortOptionFromSortKey,
} from '../lib/query-string';
import { bindCustomizerChanges } from '../lib/customize';

class SearchApp extends Component {
static defaultProps = {
Expand All @@ -39,6 +40,7 @@ class SearchApp extends Component {
this.state = {
hasError: false,
isLoading: false,
overlayOptions: { ...this.props.initialOverlayOptions },
requestId: 0,
response: {},
showResults: false,
Expand All @@ -63,6 +65,8 @@ class SearchApp extends Component {
}

addEventListeners() {
bindCustomizerChanges( this.handleOverlayOptionsUpdate );

window.addEventListener( 'popstate', this.onChangeQueryString );
window.addEventListener( 'queryStringChange', this.onChangeQueryString );

Expand Down Expand Up @@ -119,6 +123,10 @@ class SearchApp extends Component {
setSortQuery( getSortKeyFromSortOption( event.target.value ) );
};

handleOverlayOptionsUpdate = ( { key, value } ) => {
this.setState( { overlayOptions: { ...this.state.overlayOptions, [ key ]: value } } );
};

showResults = () => {
this.setState( { showResults: true } );
this.preventBodyScroll();
Expand Down Expand Up @@ -199,14 +207,14 @@ class SearchApp extends Component {
render() {
return createPortal(
<Overlay
closeColor={ this.props.overlayOptions.closeColor }
closeColor={ this.state.overlayOptions.closeColor }
closeOverlay={ this.hideResults }
colorTheme={ this.props.overlayOptions.colorTheme }
colorTheme={ this.state.overlayOptions.colorTheme }
isVisible={ this.state.showResults }
opacity={ this.props.overlayOptions.opacity }
opacity={ this.state.overlayOptions.opacity }
>
<SearchResults
enableLoadOnScroll={ this.props.overlayOptions.enableInfScroll }
enableLoadOnScroll={ this.state.overlayOptions.enableInfScroll }
hasError={ this.state.hasError }
hasNextPage={ this.hasNextPage() }
highlightColor={ this.props.options.highlightColor }
Expand Down
2 changes: 1 addition & 1 deletion modules/search/instant-search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const injectSearchApp = () => {
<SearchApp
aggregations={ buildFilterAggregations( window[ SERVER_OBJECT_NAME ].widgets ) }
initialHref={ window.location.href }
initialOverlayOptions={ window[ SERVER_OBJECT_NAME ].overlayOptions }
initialSort={ determineDefaultSort( window[ SERVER_OBJECT_NAME ].sort, getSearchQuery() ) }
isSearchPage={ getSearchQuery() !== '' }
options={ window[ SERVER_OBJECT_NAME ] }
overlayOptions={ window[ SERVER_OBJECT_NAME ].overlayOptions }
themeOptions={ getThemeOptions( window[ SERVER_OBJECT_NAME ] ) }
/>,
document.body
Expand Down
46 changes: 46 additions & 0 deletions modules/search/instant-search/lib/customize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const CUSTOMIZE_SETTINGS = [
'jetpack_search_close_color',
'jetpack_search_color_theme',
'jetpack_search_inf_scroll',
'jetpack_search_highlight_color',
'jetpack_search_opacity',
'jetpack_search_show_logo',
'jetpack_search_show_powered_by',
];

const SETTINGS_TO_STATE_MAP = new Map( [
[ 'jetpack_search_close_color', 'closeColor' ],
[ 'jetpack_search_color_theme', 'colorTheme' ],
[ 'jetpack_search_inf_scroll', 'enableInfScroll' ],
[ 'jetpack_search_highlight_color', 'highlightColor' ],
[ 'jetpack_search_opacity', 'opacity' ],
[ 'jetpack_search_show_logo', 'showLogo' ],
[ 'jetpack_search_show_powered_by', 'showPoweredBy' ],
] );

export function isInCustomizer() {
return Boolean(
'undefined' !== typeof window.wp &&
window.wp.customize &&
window.wp.customize.settings &&
window.wp.customize.settings.url &&
window.wp.customize.settings.url.self
);
}

export function bindCustomizerChanges( callback ) {
if ( ! isInCustomizer() ) {
return;
}

CUSTOMIZE_SETTINGS.forEach( setting => {
window.wp.customize( setting, value => {
value.bind( function( newValue ) {
callback( {
key: SETTINGS_TO_STATE_MAP.get( setting ),
value: newValue,
} );
} );
} );
} );
}