From 316041fe919fb439694e11d95c590f9056d52935 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 17 Jun 2020 17:04:59 -0300 Subject: [PATCH] =?UTF-8?q?Usar=20el=20caj=C3=B3n=20de=20compartir=20del?= =?UTF-8?q?=20sistema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _layouts/default.html | 1 + assets/js/script.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 assets/js/script.js diff --git a/_layouts/default.html b/_layouts/default.html index 7755094..a533fac 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -9,6 +9,7 @@ + {% seo %} {% feed_meta %} diff --git a/assets/js/script.js b/assets/js/script.js new file mode 100644 index 0000000..61cd8fa --- /dev/null +++ b/assets/js/script.js @@ -0,0 +1,31 @@ +--- +--- + +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(); + }); + }); +});