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

fix(author-box): don't use click handler for links #697

Merged
merged 2 commits into from
Dec 18, 2024
Merged
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
16 changes: 10 additions & 6 deletions blocks/author-box/author-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function openPopup(e) {
window.open(
href,
type,
'popup,top=233,left=233,width=700,height=467',
);
}

Expand All @@ -18,10 +17,14 @@ async function buildSharing(id, type = 'github') {
const sharing = document.createElement('div');
sharing.classList.add('sharing-details');
const scriptUrl = new URL(import.meta.url);
let href;
let iconsPath;
if (type === 'github') {
// support github id or url
href = id.startsWith('https://github.com/') ? id : `https://github.com/${id}`;
iconsPath = new URL('../../icons/icon-github.svg', scriptUrl).href;
} else if (type === 'linkedin') {
href = id;
iconsPath = new URL('../../icons/icon-linkedin.svg', scriptUrl).href;
}
// Fetch SVG content
Expand All @@ -48,21 +51,21 @@ async function buildSharing(id, type = 'github') {
} = profiles[type] || profiles.github;

sharing.innerHTML = `<span>
<a data-type="${dataType}" data-href="${id}" alt="${altText}" aria-label="${ariaLabel}" title="${titleText}">
<a data-type="${dataType}" data-href="${href}" alt="${altText}" aria-label="${ariaLabel}" title="${titleText}">
${svgContent}
</a>
</span>`;
sharing.querySelectorAll('[data-href]').forEach((link) => {
link.addEventListener('click', openPopup);
});
return sharing;
}

async function addProfileLinkToImage(authorImage, profileId, type = 'github') {
const authorLink = document.createElement('a');
authorLink.classList.add('blog-author-link');
if (type === 'github') {
authorLink.setAttribute('data-href', `https://github.com/${profileId}`);
authorLink.setAttribute(
'data-href',
profileId.startsWith('https://github.com/') ? profileId : `https://github.com/${profileId}`,
);
} else if (type === 'linkedin') {
authorLink.setAttribute('data-href', profileId);
}
Expand Down Expand Up @@ -127,6 +130,7 @@ export default async function decorateAuthorBox(blockEl) {
shareBlock = await buildSharing(linkedinLink, 'linkedin');
}
if (shareBlock) {
shareBlock.addEventListener('click', openPopup);
bylineContainer.append(shareBlock);
}
}
Loading