Skip to content

Commit

Permalink
add share script component
Browse files Browse the repository at this point in the history
  • Loading branch information
Imadnajam committed Jan 13, 2024
1 parent fbf14ab commit 68b026c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 82 deletions.
59 changes: 4 additions & 55 deletions resources/views/components/indexMD.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{ $movie['original_title'] }}</title>
<script>
const movieData = @json($movie);
</script>
<!--
- favicon
-->
Expand Down Expand Up @@ -397,65 +400,11 @@

</div>
</div>



</footer>





<!--
- #GO TO TOP
-->

<a href="#top" class="go-top" data-go-top>
<ion-icon name="chevron-up"></ion-icon>
</a>






<script>
document.addEventListener('DOMContentLoaded', function() {
// Get the WhatsApp and Facebook share buttons
const whatsappShareButton = document.getElementById('whatsappShare');
const facebookShareButton = document.getElementById('facebookShare');
// Retrieve movie data from data-movie attribute
const movieData = JSON.parse(document.body.getAttribute('data-movie'));
// Add a click event listener to the WhatsApp share button
whatsappShareButton.addEventListener('click', function() {
// Generate the sharing message based on the movie details
const shareMessage =
`${movieData.original_title} - ${movieData.overview}\n${window.location.href}`;
// Open the WhatsApp sharing link with the message
const whatsappLink = `https://wa.me/?text=${encodeURIComponent(shareMessage)}`;
window.open(whatsappLink, '_blank');
});
// Add a click event listener to the Facebook share button
facebookShareButton.addEventListener('click', function() {
// Generate the sharing link based on the movie details
const shareLink = window.location.href; // You can customize this based on your requirements
// Open the Facebook sharing link
const facebookLink =
`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(shareLink)}`;
window.open(facebookLink, '_blank');
});
});
</script>


<!--
- ionicon link
-->
@include('frontend.components.sharescript')
<script type="module" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.js"></script>

Expand Down
4 changes: 4 additions & 0 deletions resources/views/components/seriesDetaile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{$tvSeriesData['name']}}</title>
<!-- Inside the head tag or somewhere before the JavaScript code -->
<script>
const movieData = @json($tvSeriesData);
</script>

<!--
- favicon
Expand Down
64 changes: 37 additions & 27 deletions resources/views/frontend/components/sharescript.blade.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
// Get the WhatsApp and Facebook share buttons
const whatsappShareButton = document.getElementById('whatsappShare');
const facebookShareButton = document.getElementById('facebookShare');
// Add a click event listener to the WhatsApp share button
whatsappShareButton.addEventListener('click', function() {
// Generate the sharing message based on your movie details
const shareMessage = `${$movie['original_title']} - ${$movie['overview']}\n${window.location.href}`;
// Open the WhatsApp sharing link with the message
const whatsappLink = `https://wa.me/?text=${encodeURIComponent(shareMessage)}`;
window.open(whatsappLink, '_blank');
});
// Add a click event listener to the Facebook share button
facebookShareButton.addEventListener('click', function() {
// Generate the sharing link based on your movie details
const shareLink = window.location.href; // You can customize this based on your requirements
// Open the Facebook sharing link
const facebookLink =
`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(shareLink)}`;
window.open(facebookLink, '_blank');
});
});
</script>
// Get the WhatsApp and Facebook share buttons
const whatsappShareButton = document.getElementById('whatsappShare');
const facebookShareButton = document.getElementById('facebookShare');
// Check if the WhatsApp share button exists
if (whatsappShareButton) {
// Add a click event listener to the WhatsApp share button
whatsappShareButton.addEventListener('click', function() {
// Generate the sharing message based on movie details
const shareMessage = `${movieData['original_title']} - ${movieData['overview']}\n${window.location.href}`;
// Open the WhatsApp sharing link with the message
const whatsappLink = `https://wa.me/?text=${encodeURIComponent(shareMessage)}`;
// Open the link in a new window
window.open(whatsappLink, '_blank');
});
} else {
console.error('WhatsApp share button not found.');
}
// Check if the Facebook share button exists
if (facebookShareButton) {
// Add a click event listener to the Facebook share button
facebookShareButton.addEventListener('click', function() {
// Generate the sharing link based on your movie details
const shareLink = window.location.href;
// Open the Facebook sharing link in a new window
const facebookLink = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(shareLink)}`;
window.open(facebookLink, '_blank');
});
} else {
console.error('Facebook share button not found.');
}
});
</script>

0 comments on commit 68b026c

Please sign in to comment.