Changeset 59130
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php
r59098 r59130 201 201 202 202 /** 203 * Set client-side interactivity-router data. 204 * 205 * Once in the browser, the state will be parsed and used to hydrate the client-side 206 * interactivity stores and the configuration will be available using a `getConfig` utility. 207 * 208 * @since 6.7.0 209 * 210 * @param array $data Data to filter. 211 * @return array Data for the Interactivity Router script module. 212 */ 213 public function filter_script_module_interactivity_router_data( array $data ): array { 214 if ( ! isset( $data['i18n'] ) ) { 215 $data['i18n'] = array(); 216 } 217 $data['i18n']['loading'] = __( 'Loading page, please wait.' ); 218 $data['i18n']['loaded'] = __( 'Page Loaded.' ); 219 return $data; 220 } 221 222 /** 203 223 * Set client-side interactivity data. 204 224 * … … 297 317 public function add_hooks() { 298 318 add_filter( 'script_module_data_@wordpress/interactivity', array( $this, 'filter_script_module_interactivity_data' ) ); 319 add_filter( 'script_module_data_@wordpress/interactivity-router', array( $this, 'filter_script_module_interactivity_router_data' ) ); 299 320 } 300 321 … … 974 995 975 996 /** 976 * Outputs the markup for the top loading indicator and the screen reader 977 * notifications during client-side navigations. 997 * Deprecated. 998 * 999 * @since 6.5.0 1000 * @deprecated 6.7.0 Use {@see WP_Interactivity_API::print_router_markup} instead. 1001 */ 1002 public function print_router_loading_and_screen_reader_markup() { 1003 _deprecated_function( __METHOD__, '6.7.0', 'WP_Interactivity_API::print_router_markup' ); 1004 1005 // Call the new method. 1006 $this->print_router_markup(); 1007 } 1008 1009 /** 1010 * Outputs markup for the @wordpress/interactivity-router script module. 978 1011 * 979 1012 * This method prints a div element representing a loading bar visible during 980 * navigation, as well as an aria-live region that can be read by screen 981 * readers to announce navigation status. 982 * 983 * @since 6.5.0 984 */ 985 public function print_router_loading_and_screen_reader_markup() { 1013 * navigation. 1014 * 1015 * @since 6.7.0 1016 */ 1017 public function print_router_markup() { 986 1018 echo <<<HTML 987 1019 <div … … 991 1023 data-wp-class--finish-animation="state.navigation.hasFinished" 992 1024 ></div> 993 <div994 class="screen-reader-text"995 aria-live="polite"996 data-wp-interactive="core/router"997 data-wp-text="state.navigation.message"998 ></div>999 1025 HTML; 1000 1026 } … … 1017 1043 $this->has_processed_router_region = true; 1018 1044 1019 // Initialize the `core/router` store. 1045 /* 1046 * Initialize the `core/router` store. 1047 * If the store is not initialized like this with minimal 1048 * navigation object, the interactivity-router script module 1049 * errors. 1050 */ 1020 1051 $this->state( 1021 1052 'core/router', 1022 1053 array( 1023 'navigation' => array( 1024 'texts' => array( 1025 'loading' => __( 'Loading page, please wait.' ), 1026 'loaded' => __( 'Page Loaded.' ), 1027 ), 1028 ), 1054 'navigation' => new stdClass(), 1029 1055 ) 1030 1056 ); … … 1036 1062 1037 1063 // Adds the necessary markup to the footer. 1038 add_action( 'wp_footer', array( $this, 'print_router_ loading_and_screen_reader_markup' ) );1064 add_action( 'wp_footer', array( $this, 'print_router_markup' ) ); 1039 1065 } 1040 1066 } -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php
r59098 r59130 103 103 * @covers ::process_directives 104 104 */ 105 public function test_wp_router_region_adds_loading_bar_ aria_live_region_only_once() {105 public function test_wp_router_region_adds_loading_bar_region_only_once() { 106 106 $html = ' 107 107 <div data-wp-router-region="region A">Interactive region</div> … … 126 126 $this->assertTrue( $p->next_tag( $query ) ); 127 127 $this->assertFalse( $p->next_tag( $query ) ); 128 $query = array( 'class_name' => 'screen-reader-text' );129 $p = new WP_HTML_Tag_Processor( $footer );130 $this->assertTrue( $p->next_tag( $query ) );131 $this->assertFalse( $p->next_tag( $query ) );132 128 } 133 129 }
Note: See TracChangeset
for help on using the changeset viewer.