sutty-base-jekyll-theme/assets/js/script.js

32 lines
846 B
JavaScript
Raw Normal View History

---
---
document.addEventListener('{%- if site.turbolinks.enabled -%}turbolinks:load{%- else -%}DOMContentLoaded{%- endif -%}', () => {
document.querySelectorAll('.share').forEach(share => {
share.addEventListener('click', event => {
if (!Navigator.share) return;
event.preventDefault();
event.stopPropagation();
const title = document.querySelector('title').text;
try {
const text = document.querySelector('meta[property="og:description"]').content;
} catch {
const text = '';
}
try {
const url = document.querySelector('link[rel=canonical]').href;
} catch {
const url = document.location.href;
}
const data = { title: title, text: text, url: url };
if (Navigator.canShare(data)) Navigator.share(data).then();
});
});
});