Address review comments
This commit is contained in:
parent
b4f87a288a
commit
016f369ba2
|
@ -3,5 +3,3 @@ import initAnswerbox from '../retrospring/features/answerbox/index';
|
|||
|
||||
start();
|
||||
document.addEventListener('turbolinks:load', initAnswerbox);
|
||||
document.addEventListener('turbolinks:load', initAnswerbox);
|
||||
document.addEventListener('turbolinks:load', initAnswerbox);
|
|
@ -2,19 +2,17 @@ import registerEvents from "retrospring/utilities/registerEvents";
|
|||
import {createShareEvent} from "./share";
|
||||
|
||||
export default (): void => {
|
||||
if (!('share' in navigator)) {
|
||||
return;
|
||||
if ('share' in navigator) {
|
||||
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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import noop from 'retrospring/utilities/noop';
|
||||
|
||||
export function createShareEvent(answerbox: HTMLElement): () => void {
|
||||
return function (): void {
|
||||
navigator.share({
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export default () => void {
|
||||
// do nothing
|
||||
}
|
Loading…
Reference in New Issue