Skip to content
Closed
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
18 changes: 17 additions & 1 deletion lib/interactivity-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,21 @@ function gutenberg_reregister_interactivity_script_modules() {
$default_version
);
}

add_action( 'init', 'gutenberg_reregister_interactivity_script_modules' );

function gutenberg_register_interactivity_script_module_data_hooks() {
if ( ! has_filter( 'script_module_data_@wordpress/interactivity-router', array( wp_interactivity(), 'filter_script_module_interactivity_router_data' ) ) ) {
add_filter(
'script_module_data_@wordpress/interactivity-router',
function ( $data ) {
if ( ! isset( $data['i18n'] ) ) {
$data['i18n'] = array();
}
$data['i18n']['loading'] = __( 'Loading page, please wait.', 'gutenberg' );
$data['i18n']['loaded'] = __( 'Page Loaded.', 'gutenberg' );
return $data;
}
);
}
}
add_action( 'after_setup_theme', 'gutenberg_register_interactivity_script_module_data_hooks', 20 );
29 changes: 22 additions & 7 deletions packages/interactivity-router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,31 @@ const isValidEvent = ( event: MouseEvent ) =>
// Variable to store the current navigation.
let navigatingTo = '';

const navigationTexts = {
loading: 'Loading page, please wait.',
loaded: 'Page Loaded.',
};
try {
const content = document.getElementById(
'wp-script-module-data-@wordpress/interactivity-router'
)?.textContent;
if ( content ) {
const parsed = JSON.parse( content );
if ( typeof parsed?.i18n?.loading === 'string' ) {
navigationTexts.loading = parsed.i18n.loading;
}
if ( typeof parsed?.i18n?.loaded === 'string' ) {
navigationTexts.loaded = parsed.i18n.loaded;
}
}
} catch {}

export const { state, actions } = store( 'core/router', {
state: {
url: window.location.href,
navigation: {
hasStarted: false,
hasFinished: false,
texts: {
loading: '',
loaded: '',
},
message: '',
},
},
Expand Down Expand Up @@ -275,7 +290,7 @@ export const { state, actions } = store( 'core/router', {
navigation.hasFinished = false;
}
if ( screenReaderAnnouncement ) {
navigation.message = navigation.texts.loading;
navigation.message = navigationTexts.loading;
}
}, 400 );

Expand Down Expand Up @@ -319,8 +334,8 @@ export const { state, actions } = store( 'core/router', {
// same, we use a no-break space similar to the @wordpress/a11y
// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
navigation.message =
navigation.texts.loaded +
( navigation.message === navigation.texts.loaded
navigationTexts.loaded +
( navigation.message === navigationTexts.loaded
? '\u00A0'
: '' );
}
Expand Down