templates/_partials/courses/_share.html.twig line 1

Open in your IDE?
  1. {% if app.user %}
  2. <span class="curso-compartir" data-actividad-id="{{ actividad.id }}" data-actividad-tipo="{{ tipo }}"></span>
  3. <div id="sharePopup" class="share-popup">
  4. <div class="share-popup-content">
  5. <span class="share-close">&times;</span>
  6. <h3>Compartir curso</h3>
  7. <div class="share-buttons">
  8. <a href="#" class="share-button share-whatsapp" data-share="whatsapp">
  9. <i class="fab fa-whatsapp"></i>
  10. </a>
  11. <a href="#" class="share-button share-telegram" data-share="telegram">
  12. <i class="fab fa-telegram"></i>
  13. </a>
  14. <a href="#" class="share-button share-facebook" data-share="facebook">
  15. <i class="fab fa-facebook"></i>
  16. </a>
  17. <a href="#" class="share-button share-twitter" data-share="twitter">
  18. <i class="fab fa-twitter"></i>
  19. </a>
  20. <a href="#" class="share-button share-linkedin" data-share="linkedin">
  21. <i class="fab fa-linkedin"></i>
  22. </a>
  23. <a href="#" class="share-button share-email" data-share="email">
  24. <i class="fas fa-envelope"></i>
  25. </a>
  26. <a href="#" class="share-button share-copy" data-share="copy">
  27. <i class="fas fa-copy"></i>
  28. </a>
  29. </div>
  30. </div>
  31. </div>
  32. <script>
  33. document.addEventListener('DOMContentLoaded', function() {
  34. // Inicializar botón de compartir
  35. const compartirBtn = document.querySelector('.curso-compartir[data-actividad-id="{{ actividad.id }}"][data-actividad-tipo="{{ tipo }}"]');
  36. const sharePopup = document.getElementById('sharePopup');
  37. const closeBtn = document.querySelector('.share-close');
  38. if (compartirBtn) {
  39. compartirBtn.addEventListener('click', function(e) {
  40. e.preventDefault();
  41. sharePopup.style.display = 'block';
  42. });
  43. }
  44. // Cerrar el popup al hacer clic en la X
  45. if (closeBtn) {
  46. closeBtn.addEventListener('click', function() {
  47. sharePopup.style.display = 'none';
  48. });
  49. }
  50. // Cerrar el popup al hacer clic fuera del contenido
  51. window.addEventListener('click', function(event) {
  52. if (event.target === sharePopup) {
  53. sharePopup.style.display = 'none';
  54. }
  55. });
  56. // Funcionalidad de compartir
  57. const shareButtons = document.querySelectorAll('.share-button');
  58. const pageUrl = window.location.href;
  59. const pageTitle = document.getElementById('course_name').innerText;
  60. shareButtons.forEach(button => {
  61. button.addEventListener('click', function(e) {
  62. e.preventDefault();
  63. const shareType = this.getAttribute('data-share');
  64. switch(shareType) {
  65. case 'whatsapp':
  66. window.open(`https://api.whatsapp.com/send?text=${encodeURIComponent(pageTitle + ' ' + pageUrl)}`, '_blank');
  67. break;
  68. case 'telegram':
  69. window.open(`https://t.me/share/url?url=${encodeURIComponent(pageUrl)}&text=${encodeURIComponent(pageTitle)}`, '_blank');
  70. break;
  71. case 'facebook':
  72. window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(pageUrl)}`, '_blank');
  73. break;
  74. case 'twitter':
  75. window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(pageUrl)}&text=${encodeURIComponent(pageTitle)}`, '_blank');
  76. break;
  77. case 'linkedin':
  78. window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(pageUrl)}`, '_blank');
  79. break;
  80. case 'email':
  81. window.location.href = `mailto:?subject=${encodeURIComponent(pageTitle)}&body=${encodeURIComponent(pageUrl)}`;
  82. break;
  83. case 'copy':
  84. navigator.clipboard.writeText(pageUrl).then(() => {
  85. // Mostrar mensaje de éxito
  86. const copyButton = document.querySelector('.share-copy');
  87. const originalIcon = copyButton.innerHTML;
  88. copyButton.innerHTML = '<i class="fas fa-check"></i>';
  89. setTimeout(() => {
  90. copyButton.innerHTML = originalIcon;
  91. }, 2000);
  92. });
  93. break;
  94. }
  95. });
  96. });
  97. });
  98. </script>
  99. {% endif %}