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

【2人目確認待ち】[ 投稿リスト ]編集画面では投稿のリンクをクリックしても飛ばないようにしました #2212

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ e.g.

== Changelog ==

[ Specification change ][ Post List (Pro) ] Disable link on edit screen.
[ Bug fix ][ Breadcrumb (Pro) ] Fixed an issue where the separator setting in the Breadcrumb block was not being loaded correctly (now loaded from view.js).
[ Add function ][ Core Table ] Add scroll hint for horizontal scrolling.

Expand Down
42 changes: 42 additions & 0 deletions src/blocks/_pro/post-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ import { DisplayItemsControl } from '@vkblocks/components/display-items-control'
import { ColumnLayoutControl } from '@vkblocks/components/column-layout-control';
import { AdvancedCheckboxControl } from '@vkblocks/components/advanced-checkbox-control';

// リンクを無効化
const disableLinks = () => {
const links = document.querySelectorAll('.vk_post_imgOuter a, .vk_post .vk_post_title a, .postListText_title a, .card-intext .card-intext-inner');
links.forEach((link) => {
link.addEventListener('click', (event) => {
event.preventDefault();
});
link.style.cursor = 'default';
link.style.boxShadow = 'unset';

// ホバー効果を無効化
link.style.color = 'inherit';
link.style.textDecorationColor = 'inherit';
});

// クリック無効化のみ
const singleTermLinks = document.querySelectorAll('.postListText_singleTermLabel_inner, .vk_post_btnOuter a');
singleTermLinks.forEach((link) => {
link.addEventListener('click', (event) => {
event.preventDefault();
});
link.style.cursor = 'default';
link.style.boxShadow = 'unset';
});
};

export default function PostListEdit(props) {
const { attributes, setAttributes, name, clientId } = props;
const {
Expand Down Expand Up @@ -268,6 +294,21 @@ export default function PostListEdit(props) {
});
}, [isCheckedPostTypeData, isCheckedTermsData]);

useEffect(() => {
// 初回およびattributesの変更時にリンクを無効化
setTimeout(disableLinks, 1000); // DOM の更新を待つためにタイムアウトを利用

// クリーンアップ関数
return () => {
const links = document.querySelectorAll('.vk_post_imgOuter a, .vk_post .vk_post_title a, .postListText_title a, .card-intext .card-intext-inner, .postListText_singleTermLabel_inner, .vk_post_btnOuter a');
links.forEach((link) => {
link.removeEventListener('click', (event) => {
event.preventDefault();
});
});
};
}, [attributes]);

return (
<>
<InspectorControls>
Expand Down Expand Up @@ -455,6 +496,7 @@ export default function PostListEdit(props) {
<ServerSideRender
block="vk-blocks/post-list"
attributes={attributes}
onRendered={disableLinks}
/>
</div>
</>
Expand Down