Add share option to answers

This commit is contained in:
Karina Kwiatek 2021-08-05 18:30:44 +02:00
parent 49c33486dd
commit a13322dcee
3 changed files with 28 additions and 0 deletions

View File

@ -61,4 +61,10 @@
}
}
}
}
body:not(.cap-web-share) {
.answerbox__action[name="ab-share"] {
display: none;
}
}

View File

@ -0,0 +1,20 @@
import $ from 'jquery';
export default (): void => {
document.addEventListener('turbolinks:load', function () {
if (navigator.share) {
document.body.classList.add('cap-web-share')
$(document).on('click', 'button[name=ab-share]', function () {
const card = $(this).closest('.card')
navigator.share({
url: card.find('.answerbox__answer-date a')[0].href
}).then(() => {
// do nothing, prevents exception from being thrown
}).catch(() => {
// do nothing, prevents exception from being thrown
})
})
}
})
}

View File

@ -16,6 +16,8 @@
%button.btn.btn-link.answerbox__action{ type: :button, name: 'ab-comments', data: { a_id: a.id, state: :hidden } }
%i.fa.fa-fw.fa-comments
%span{ id: "ab-comment-count-#{a.id}" }= a.comment_count
%button.btn.btn-link.answerbox__action{ type: :button, name: 'ab-share'}
%i.fa.fa-fw.fa-share-alt{ title: 'Share' }
- if user_signed_in?
.btn-group
%button.btn.btn-default.btn-sm.dropdown-toggle{ data: { toggle: :dropdown }, aria: { expanded: false } }