wp_back/wp-content/plugins/visual-portfolio/gutenberg/extensions/link-rel.js

24 lines
622 B
JavaScript
Raw Normal View History

2024-05-20 15:37:46 +03:00
import { addFilter } from '@wordpress/hooks';
const NOOPENER_DEFAULT = 'noopener noreferrer';
addFilter(
'vpf.editor.controls-on-change',
'vpf/editor/controls-on-change/link-rel',
(newAttributes, control, val, attributes) => {
if (control.name === 'items_click_action_url_target') {
if (val === '_blank' && !attributes.items_click_action_url_rel) {
newAttributes.items_click_action_url_rel = NOOPENER_DEFAULT;
}
if (
val !== '_blank' &&
NOOPENER_DEFAULT === attributes.items_click_action_url_rel
) {
newAttributes.items_click_action_url_rel = '';
}
}
return newAttributes;
}
);