wp/wp-includes/blocks/search.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    29 		)
    29 		)
    30 	);
    30 	);
    31 
    31 
    32 	$input_id            = wp_unique_id( 'wp-block-search__input-' );
    32 	$input_id            = wp_unique_id( 'wp-block-search__input-' );
    33 	$classnames          = classnames_for_block_core_search( $attributes );
    33 	$classnames          = classnames_for_block_core_search( $attributes );
    34 	$show_label          = ( ! empty( $attributes['showLabel'] ) ) ? true : false;
    34 	$show_label          = ! empty( $attributes['showLabel'] );
    35 	$use_icon_button     = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false;
    35 	$use_icon_button     = ! empty( $attributes['buttonUseIcon'] );
    36 	$show_button         = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
    36 	$show_button         = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
    37 	$button_position     = $show_button ? $attributes['buttonPosition'] : null;
    37 	$button_position     = $show_button ? $attributes['buttonPosition'] : null;
    38 	$query_params        = ( ! empty( $attributes['query'] ) ) ? $attributes['query'] : array();
    38 	$query_params        = ( ! empty( $attributes['query'] ) ) ? $attributes['query'] : array();
    39 	$button              = '';
    39 	$button              = '';
    40 	$query_params_markup = '';
    40 	$query_params_markup = '';
    78 		$input->set_attribute( 'placeholder', $attributes['placeholder'] );
    78 		$input->set_attribute( 'placeholder', $attributes['placeholder'] );
    79 
    79 
    80 		// If it's interactive, enqueue the script module and add the directives.
    80 		// If it's interactive, enqueue the script module and add the directives.
    81 		$is_expandable_searchfield = 'button-only' === $button_position;
    81 		$is_expandable_searchfield = 'button-only' === $button_position;
    82 		if ( $is_expandable_searchfield ) {
    82 		if ( $is_expandable_searchfield ) {
    83 			$suffix = wp_scripts_get_suffix();
    83 			wp_enqueue_script_module( '@wordpress/block-library/search/view' );
    84 			if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
       
    85 				$module_url = gutenberg_url( '/build/interactivity/search.min.js' );
       
    86 			}
       
    87 
       
    88 			wp_register_script_module(
       
    89 				'@wordpress/block-library/search',
       
    90 				isset( $module_url ) ? $module_url : includes_url( "blocks/search/view{$suffix}.js" ),
       
    91 				array( '@wordpress/interactivity' ),
       
    92 				defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
       
    93 			);
       
    94 			wp_enqueue_script_module( '@wordpress/block-library/search' );
       
    95 
    84 
    96 			$input->set_attribute( 'data-wp-bind--aria-hidden', '!context.isSearchInputVisible' );
    85 			$input->set_attribute( 'data-wp-bind--aria-hidden', '!context.isSearchInputVisible' );
    97 			$input->set_attribute( 'data-wp-bind--tabindex', 'state.tabindex' );
    86 			$input->set_attribute( 'data-wp-bind--tabindex', 'state.tabindex' );
    98 
    87 
    99 			// Adding these attributes manually is needed until the Interactivity API
    88 			// Adding these attributes manually is needed until the Interactivity API
   186 				'ariaLabelExpanded'    => $aria_label_expanded,
   175 				'ariaLabelExpanded'    => $aria_label_expanded,
   187 				'ariaLabelCollapsed'   => $aria_label_collapsed,
   176 				'ariaLabelCollapsed'   => $aria_label_collapsed,
   188 			)
   177 			)
   189 		);
   178 		);
   190 		$form_directives      = '
   179 		$form_directives      = '
   191 		 data-wp-interactive="core/search"'
   180 		 data-wp-interactive="core/search"
   192 		. $form_context .
   181 		 ' . $form_context . '
   193 		'data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible"
   182 		 data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible"
   194 		 data-wp-on-async--keydown="actions.handleSearchKeydown"
   183 		 data-wp-on-async--keydown="actions.handleSearchKeydown"
   195 		 data-wp-on-async--focusout="actions.handleSearchFocusout"
   184 		 data-wp-on-async--focusout="actions.handleSearchFocusout"
   196 		';
   185 		';
   197 	}
   186 	}
   198 
   187