Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme previewer: Update back button to navigate all the way back to the theme details page. #114

Closed
wants to merge 2 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@

$content = $html->get_updated_html();

// Recreate the processor to grab the back button.
// See https://developer.wordpress.org/reference/classes/wp_html_tag_processor/#finding-tags
$html = new WP_HTML_Tag_Processor( $content );
while ( $html->next_tag( [ 'class_name' => 'wporg-theme-preview__back' ] ) ) {
$html->next_tag( 'a' );
$html->set_attribute( 'data-wp-on--click', 'wporg/themes/preview::actions.goBack' );
}

$content = $html->get_updated_html();

$markup = sprintf( $markup, $content, esc_url_raw( $url ) );

?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
*/
import { getContext, getElement, store } from '@wordpress/interactivity';

store( 'wporg/themes/preview', {
const { state } = store( 'wporg/themes/preview', {
state: {
get isLoaded() {
const context = getContext();
return context.isLoaded;
},
initialHistory: window.history.length,
},
actions: {
onLoad() {
const context = getContext();
context.isLoaded = true;
},
goBack( event ) {
if ( state.initialHistory > 2 ) {
event.preventDefault();
window.history.go( state.initialHistory - window.history.length - 1 );
}
},
navigateIframe( event ) {
event.preventDefault();
const context = getContext();
Expand Down