Skip to content

Commit

Permalink
test share functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Jadit19 committed Nov 23, 2023
1 parent 4a1e56d commit 00deeca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _includes/footer_custom.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% if site.socials %}

<div class="footer-icons">
<a style="margin-right: 24px">
<i class="fa-solid fa-share-nodes fa-xl" onclick="shareFunction()"></i>
</a>
{% if site.socials.email %}
<a href="mailto:{{ site.socials.email }}" target="_blank">
<i class="fa-solid fa-envelope fa-xl"></i>
Expand Down
29 changes: 29 additions & 0 deletions _includes/header_custom.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,32 @@
'<img src="/wiki/assets/images/astroclubiitk_navbar_logo.png" alt="logo" style="height: 80%; max-height: 45px" />'
})
</script>

<script>
const shareFunction = async () => {
if (navigator.canShare) {
try {
navigator.share({
title: document.title,
url: window.location.href
})
} catch (err) {
console.error('[ERROR]: ', err)
}
} else {
alert("Your browser doesn't support Web Share API")
}
}

document.addEventListener('DOMContentLoaded', () => {
const shareElement = document.createElement('i')
shareElement.classList.add('fa-solid')
shareElement.classList.add('fa-share')
shareElement.classList.add('fa-sm')
shareElement.style.cssText =
'float: right; cursor: pointer; margin-top: 4px;'
shareElement.onclick = shareFunction

document.querySelector('h2').appendChild(shareElement)
})
</script>

0 comments on commit 00deeca

Please sign in to comment.