Address review comments

This commit is contained in:
Karina Kwiatek 2021-08-10 15:50:17 +02:00
parent b4f87a288a
commit 016f369ba2
4 changed files with 20 additions and 21 deletions

View File

@ -3,5 +3,3 @@ import initAnswerbox from '../retrospring/features/answerbox/index';
start(); start();
document.addEventListener('turbolinks:load', initAnswerbox); document.addEventListener('turbolinks:load', initAnswerbox);
document.addEventListener('turbolinks:load', initAnswerbox);
document.addEventListener('turbolinks:load', initAnswerbox);

View File

@ -2,19 +2,17 @@ import registerEvents from "retrospring/utilities/registerEvents";
import {createShareEvent} from "./share"; import {createShareEvent} from "./share";
export default (): void => { export default (): void => {
if (!('share' in navigator)) { if ('share' in navigator) {
return; document.body.classList.add('cap-web-share');
const entries: NodeList = document.querySelectorAll('.answerbox:not(.js-initialized)');
entries.forEach((element: HTMLElement) => {
console.log(element)
registerEvents([
{ type: 'click', target: element.querySelector('[data-action=ab-share]'), handler: createShareEvent(element) }
]);
element.classList.add('js-initialized');
});
} }
}
document.body.classList.add('cap-web-share');
const entries: NodeList = document.querySelectorAll('.answerbox:not(.js-initialized)');
entries.forEach((element: HTMLElement) => {
console.log(element)
registerEvents([
{ type: 'click', target: element.querySelector('[data-action=ab-share]'), handler: createShareEvent(element) }
]);
element.classList.add('js-initialized');
});
}

View File

@ -1,11 +1,11 @@
import noop from 'retrospring/utilities/noop';
export function createShareEvent(answerbox: HTMLElement): () => void { export function createShareEvent(answerbox: HTMLElement): () => void {
return function (): void { return function (): void {
navigator.share({ navigator.share({
url: answerbox.querySelector<HTMLAnchorElement>('.answerbox__answer-date > a').href url: answerbox.querySelector<HTMLAnchorElement>('.answerbox__answer-date > a').href
}).then(() => {
// do nothing, prevents exce ption from being thrown
}).catch(() => {
// do nothing, prevents exception from being thrown
}) })
.then(noop)
.catch(noop)
} }
} }

View File

@ -0,0 +1,3 @@
export default () => void {
// do nothing
}