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

React compatibility: Removing javascript: url usage #38783

Merged
merged 6 commits into from
Aug 12, 2024
Merged
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 @@ -18,6 +18,22 @@ import { isModuleFound } from 'state/search';

export const SearchableModules = withModuleSettingsFormHelpers(
class extends Component {
componentDidMount() {
document.addEventListener( 'click', this.handleAnchorClick );
}

componentWillUnmount() {
document.removeEventListener( 'click', this.handleAnchorClick );
}

handleAnchorClick = event => {
const anchor = event.target.closest( '.jp-searchable-banner a.dops-button[href="#"]' );

if ( anchor ) {
event.preventDefault();
}
};

handleBannerClick = module => {
return () => this.props.updateOptions( { [ module ]: true } );
};
Expand Down Expand Up @@ -68,7 +84,7 @@ export const SearchableModules = withModuleSettingsFormHelpers(
key={ slug }
callToAction={ __( 'Activate', 'jetpack' ) }
description={ moduleData.description }
href="javascript:void( 0 )"
href="#"
icon="cog"
onClick={ this.handleBannerClick( moduleData.module ) }
title={ moduleData.name }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Javascript: Cleaning up usage of javascript: in URLs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ domReady( function () {
const expireDays = parseInt( expiryDaysContainer.textContent );
const expireTimeDate = new Date( Date.now() + expireDays * millisInDay );
const cookieName = 'eucookielaw';

const button = container.querySelector( '.wp-block-button a' );
button.setAttribute( 'role', 'button' );
button.setAttribute( 'href', 'javascript:void(0)' );
button.setAttribute( 'href', '#' );
button.addEventListener( 'click', event => {
if ( button.closest( '.wp-block-jetpack-cookie-consent' ) ) {
// This simply prevents adding a # to the URL after the click.
event.preventDefault();
}
} );
/**
* Set cookie and trigger dismiss event
*/
Expand Down
Loading