Skip to content

Commit

Permalink
Upgrade fragment-style links to query param
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Jul 24, 2024
1 parent b33aa49 commit 4ee4665
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
);

?>
<div id="content-area" <?php body_class( 'dashicons-page' ); ?> data-wp-interactive="wporg/dashicons-page">
<div id="content-area" <?php body_class( 'dashicons-page' ); ?> data-wp-interactive="wporg/dashicons-page" data-wp-init="init">
<style data-wp-text="state.style"></style>
<main id="main" <?php post_class( 'site-main' ); ?> role="main">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ const { state } = IAPI.store( 'wporg/dashicons-page', {
state.filter = event.target.value;
},

/**
* A previous implementation used #icon-slug to pick an ico.
* Respect those links, but replace the URL with our query-based version.
*/
init: () => {
const url = new URL( document.location.href );
const iconFromQuery = url.searchParams.get( 'icon' );

// Prefer an icon from query, but if a hash (legacy link) includes it, fall-back to that.
if ( ! Object.hasOwn( config.icons, iconFromQuery ) && url.hash ) {
const iconFromHash = `dashicons-${ url.hash.substring( 1 ) }`;
console.log( iconFromQuery, iconFromHash );

Check failure on line 59 in source/wp-content/themes/wporg-developer-2023/src/dashicons-page/view.js

View workflow job for this annotation

GitHub Actions / Lint everything

Unexpected console statement
if ( Object.hasOwn( config.icons, iconFromHash ) ) {
url.hash = '';
state.selectedIcon = [ iconFromHash ];
url.searchParams.set( 'icon', iconFromHash );
window.history.replaceState( undefined, undefined, url );
}
}
},

copyClickHandlers: {
css: makeCopyHandler( 'css' ),
html: makeCopyHandler( 'html' ),
Expand Down

0 comments on commit 4ee4665

Please sign in to comment.