HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/Siyum_old/wp-content/themes/siyum-old/js/custom.js
jQuery(document).ready(function ($) {
    // Event listener for opening the modal
  $('#customModalVideo').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); // Button that triggered the modal
    var videoUrl = button.data('url');    // Extract video URL from data-url attribute
    var title = button.data('title');    
    var subtitle = button.data('subtitle'); 
    var description = button.data('description'); 
    var pdf = button.data('pdf');
    var count = button.data('count');

    var modal = $(this);
    var videoContainer = modal.find('#videoContainer'); 
    var modalTitle = modal.find('.modal-title'); 
    var modalSubtitle = modal.find('.subtitle');
    var next_btn = modal.find('.next-btn');
    var prev_btn = modal.find('.prev-btn');
    button.attr("data-pdf", pdf);
    const modal1 = document.getElementById('customModalVideo');
    const downloadButton = modal1.querySelector('.email');

    if (count <= 1) {
      next_btn.hide(); // Hide the next button
       
    } else {
        next_btn.show(); // Show the next button if count > 1
        
    }
    

    // Clear previous content before loading new video
    videoContainer.empty();

    // Set the modal title and subtitle
    modalTitle.text(title);
    modalSubtitle.text(subtitle);

    // Check if the URL is a Vimeo link
    if (videoUrl.includes('vimeo.com')) {
      // Extract Vimeo video ID from URL  + '?autoplay=1'
       var vimeoId = videoUrl.split('/').pop();
      // var vimeoId = videoUrl.match(/video\/(\d+)/)[1];
      var embedUrl = 'https://player.vimeo.com/video/' + vimeoId ;
      
      
      // Embed Vimeo iframe
      videoContainer.html('<iframe id="customVideoIframe" width="100%" height="600" src="' + embedUrl + '" frameborder="0"  fullscreen" allowfullscreen></iframe>');

    } else if (videoUrl.endsWith('.mp4')) {
    
      // Embed MP4 video
      videoContainer.html(`
        <video id="customVideo" poster="poster-image.png" width="100%" height="400" controls>
          <source src="${videoUrl}" type="video/mp4">
          Your browser does not support HTML5 video.
        </video>
        <div id="playButton" class="play-btn">
          <img src="${themeData.templateDirectory}/img/play-btn.svg" alt="Play">
        </div>
      `);
      
    }

    // Optional: Set description (if any)
    if (description) {
      var descriptionContainer = modal.find('.content');
      descriptionContainer.text(description);
    }
    if (pdf) {
      document.getElementById('email_pdf').value = pdf;
      // downloadButton.innerHTML = `
      //     <span class="ico">
      //         <img src="https://kedusha.spericorn.com/wp-content/themes/kedushas/img/mail-ico.svg" alt="PDF">
      //     </span> 
      //     <span><a href="${pdf}" target="_blank">Receive via email</a></span>
      // `;
      // downloadButton.setAttribute('href', pdf);
      // downloadButton.setAttribute('download', `${title || 'document'}.pdf`);
  } else {
      // downloadButton.innerHTML = 'PDF Not Available';
      // downloadButton.removeAttribute('href');
      // downloadButton.removeAttribute('download');
  }
  });

  // Play video on button click (for MP4 videos)
  $('#videoContainer').on('click', '#playButton', function() {
    var videoElement = $('#customVideo')[0];
    if (videoElement.paused) {
      videoElement.play();
      $('#playButton').css('display', 'none'); 
    } else {
      $('#playButton').css('display', 'block'); 
      videoElement.pause();
      
    }   
  });
//   $('#videoContainer').on('click', '#customVideo', function() {
//     var videoElement = $('#customVideo')[0]; // Get the video element
//     videoElement.pause();
//     console.log('Video is paused:', videoElement.paused);
    
//     if (!videoElement.paused) {
//         videoElement.pause(); // Pause the video if it's currently playing
//         $('#playButton').css('display', 'block'); // Show the play button
//     }
// });




//  // Attach a click event listener to the .btn-primary button within the modal
// $('#customModalVideo').on('click', '.btn-primary', function (e) {
//   e.preventDefault(); // Prevent default button behavior

//   // Fetch the PDF URL from the button's data attribute
//   var pdfUrl = $('#email_pdf').val(); // Retrieve value from the hidden input field
//   if (!pdfUrl) {
//       alert("No PDF URL available.");
//       return;
//   }

//   // Log or alert the PDF URL (for debugging purposes)
//   console.log("PDF URL:", pdfUrl);

//   // Define the AJAX URL from localized data (ensure `pdfData.ajax_url` is defined in your script)
//   var ajaxUrl = pdfData.ajax_url;
//   if (!ajaxUrl) {
//       alert("AJAX URL is not defined.");
//       return;
//   }

//   // Trigger AJAX request to send the email
//   $.ajax({
//       url: ajaxUrl,
//       method: "POST",
//       data: {
//           action: "send_pdf_email_with_attachment", // WordPress action hook
//           pdf_url: pdfUrl, // The PDF URL to send in the email
//       },
//       beforeSend: function () {
//           // Optional: Add a loading indicator or disable the button during the request
//           $('.btn-primary.email').prop('disabled', true).text('Sending...');
//       },
//       success: function (response) {
//           // Handle the response from the server
//           if (response.success) {
//               alert("Email sent successfully!");
//           } else {
//               alert("Failed to send email. Please try again.");
//           }
//       },
//       error: function (xhr, status, error) {
//           // Handle AJAX errors
//           console.error("AJAX Error:", status, error);
//           alert("An error occurred while sending the email.");
//       },
//       complete: function () {
//           // Re-enable the button and reset the text
//           $('.btn-primary.email').prop('disabled', false).html(`
//               <span class="ico"><img src="${pdfData.theme_url}/img/pdf.svg" alt="pdf"></span> 
//               <span>Receive via email</span>
//           `);
//       },
//   });
// });




});
function validateEmail() {
  const emailInput = document.getElementById("email-input");
  const email = emailInput.value.trim();
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Simple email regex pattern

  if (!emailRegex.test(email)) {
    $('#successAlert')
        .text('Please enter a valid email address.')
        .css('color', 'red') // Set the text color to red
        .show();
      setTimeout(function() {
        $('#successAlert').fadeOut(); // Use fadeOut for a smooth disappearance
    }, 2000);
   
    emailInput.focus();
    return false;
  }

  return true;
}

// jQuery(document).ready(function ($) {
// var videoButtons = document.querySelectorAll('.video-btn');
//     var currentIndex = 0;
//     var videos = [];

//     videoButtons.forEach(function(button, index) {
//         button.addEventListener('click', function() {
//             currentIndex = index;
//             loadVideoData(button);
//         });

//         // Store video data for navigation
//         videos.push({
//             title: button.getAttribute('data-title'),
//             subtitle: button.getAttribute('data-subtitle'),
//             url: button.getAttribute('data-url'),
//             pdf: button.getAttribute('data-pdf'),
//             description: button.getAttribute('data-description')
//         });
//     });



//     // Handle "Next" button click
//     document.querySelector('.next-btn').addEventListener('click', function() {
//         currentIndex = (currentIndex + 1) % videos.length;
//         var nextVideo = videos[currentIndex];
//         loadVideoDataFromObject(nextVideo);
//     });

//     function loadVideoDataFromObject(video) {
//         var modal = document.getElementById('customModalVideo');
//         modal.querySelector('.modal-title').textContent = video.title;
//         modal.querySelector('.subtitle').textContent = video.subtitle;
//         modal.querySelector('#videoContainer').innerHTML = `
//             <video controls id="customVideo">
//                 <source src="${video.url}" type="video/mp4">
//                 Your browser does not support the video tag.
//             </video>
//             <div id="playButton" class="play-btn" >
//                 <img src="${themeData.templateDirectory}/img/play-btn.svg" alt="Play" >
//               </div>
//         `;
//         modal.querySelector('.btn-primary').setAttribute('data-pdf', video.pdf);
//         modal.querySelector('.content').textContent = video.description;
//     }
// });

jQuery(document).ready(function ($) {
  var videoButtons = document.querySelectorAll('.video-btn');
    var videos = [];
    var currentPostId = null;
    var currentIndex = 0;

  // Initialize videos array and attach click events
  // videoButtons.forEach(function (button, index) {
  //     button.addEventListener('click', function () {
  //         currentIndex = index;
  //         currentPostId = button.getAttribute('data-post-id'); // Get the current post ID from the button
  //         loadVideoData(button);
  //     });

  //     // Store video data for navigation
  //     videos.push({
  //         postId: button.getAttribute('data-post-id'), // Store the post ID
  //         title: button.getAttribute('data-title'),
  //         subtitle: button.getAttribute('data-subtitle'),
  //         url: button.getAttribute('data-url'),
  //         pdf: button.getAttribute('data-pdf'),
  //         description: button.getAttribute('data-description')
  //     });
  // });

  videoButtons.forEach(function (button) {
    var postId = button.getAttribute('data-post-id');

    // Store video data for navigation
    videos.push({
        postId: postId,
        title: button.getAttribute('data-title'),
        subtitle: button.getAttribute('data-subtitle'),
        url: button.getAttribute('data-url'),
        pdf: button.getAttribute('data-pdf'),
        description: button.getAttribute('data-description')
    });

    // Click event for buttons
    button.addEventListener('click', function () {
        currentPostId = postId; // Set current post ID
        
        // Set correct index based on filtered videos
        var filteredVideos = videos.filter(v => v.postId === currentPostId);
        currentIndex = filteredVideos.findIndex(v => v.url === button.getAttribute('data-url'));

        loadVideoData(button);
    });
});

  // Handle "Next" button click
  // document.querySelector('#next-btn').addEventListener('click', function () {
  //     // Filter videos by the current post ID
     
  //     var filteredVideos = videos.filter(function (video) {
  //         return video.postId === currentPostId;
  //     });

  //     // Update the current index within the filtered list
  //     currentIndex = (currentIndex + 1) % filteredVideos.length;

  //     var nextVideo = filteredVideos[currentIndex];
  //     loadVideoDataFromObject(nextVideo);
  // });

  document.querySelector('#next-btn').addEventListener('click', function () {
    // Filter videos by the current post ID
    var filteredVideos = videos.filter(function (video) {
        return video.postId === currentPostId;
    });

    if (filteredVideos.length === 0) {
        console.warn("No videos found for post ID:", currentPostId);
        return; // Avoid errors if no videos match
    }

    // Ensure currentIndex is valid before use
    if (typeof currentIndex === 'undefined' || currentIndex < 0) {
        currentIndex = 0; // Initialize if not set
    } else {
        currentIndex = (currentIndex + 1) % filteredVideos.length;
    }
  
    console.log("Next Video Index:", currentIndex);

    var nextVideo = filteredVideos[currentIndex];
    console.log("Next Video Selected:", nextVideo);

    loadVideoDataFromObject(nextVideo);
});


  document.querySelector('#prev-btn').addEventListener('click', function () {
    // Filter videos by the current post ID
    var filteredVideos = videos.filter(function (video) {
        return video.postId === currentPostId;
    });

    // Update the current index within the filtered list (decrement to go to the previous video)
    currentIndex = (currentIndex - 1 + filteredVideos.length) % filteredVideos.length;

    var previousVideo = filteredVideos[currentIndex];
    loadVideoDataFromObject(previousVideo);
});

  function loadVideoDataFromObject(video) {
    var modal = document.getElementById('customModalVideo');
    modal.querySelector('.modal-title').textContent = video.title;
    modal.querySelector('.subtitle').textContent = video.subtitle;
console.log(video.url);
    // Check if the video URL contains ".vimeo"
    if (video.url.includes('vimeo.com')) {
      // var vimeoId = video.url.match(/video\/(\d+)/)[1];
      var vimeoId = video.url.split('/').pop();
      var embedUrl = 'https://player.vimeo.com/video/' + vimeoId ;
        modal.querySelector('#videoContainer').innerHTML = `
            <iframe 
                src="${embedUrl}" 
                frameborder="0" 
                allow="autoplay; fullscreen; picture-in-picture"                  
                style="width: 100%; height: 100%;"
            ></iframe>
        `;
    } else {
        modal.querySelector('#videoContainer').innerHTML = `
            <video controls id="customVideo" style="width: 100%; height: auto;">
                <source src="${video.url}" type="video/mp4">
                Your browser does not support the video tag.
            </video>
            <div id="playButton" class="play-btn">
                <img src="${themeData.templateDirectory}/img/play-btn.svg" alt="Play">
            </div>
        `;
    }

    modal.querySelector('.emailbtn').setAttribute('data-pdf', video.pdf);
    modal.querySelector('.content').textContent = video.description;

    // Set the PDF value in the hidden input field
    document.getElementById('email_pdf').value = video.pdf;
}

});


document.addEventListener('DOMContentLoaded', function() {
  // Select all buttons and the input element
  const buttons = document.querySelectorAll('.tab-btn');
  const emailInput = document.getElementById('email-pdf');
  
  // Add click event listener to each button
  buttons.forEach(button => {
      button.addEventListener('click', function() {
          // Get the data-pdf-url attribute of the clicked button
          const pdfUrl = this.getAttribute('data-pdf-url');
          
          // Update the input value with the PDF URL
          emailInput.value = pdfUrl;
      });
  });


 
});

document.addEventListener('DOMContentLoaded', function () {
  // Select the video and Lottie player elements
  // const video = document.querySelector('.banner-media');
  const lottiePlayer = document.getElementById('lottie-player');
  const video = document.getElementById("radio-stream");
  // video.autoplay = true;
  // video.muted = false;
  // Check if both elements exist before proceeding
  if (video && lottiePlayer) {
      // Add a click event listener to the Lottie player
      lottiePlayer.addEventListener('click', function () {
          // Toggle the muted property of the video
          video.muted = !video.muted;

          // Optionally, log the state
          if (video.muted) {
              console.log('Video is muted');
              lottiePlayer.stop();
              
          } else {
              console.log('Video is unmuted');
              lottiePlayer.play();
          }
      });
  } else {
      console.error('Video or Lottie player element not found');
  }
});



//--------------------Publication next--------------------------------
jQuery(document).ready(function ($) {
  var videoButtons = document.querySelectorAll('.publication-btn');
  var currentIndex = 0;
  var videos = [];
  var currentPostId = null;

  // Initialize videos array and attach click events
  videoButtons.forEach(function (button, index) {
      button.addEventListener('click', function () {
          currentIndex = index;
          currentPostId = button.getAttribute('data-post-id'); // Get the current post ID from the button
          // loadVideoData(button);
      });

      // Store video data for navigation
      videos.push({
          postId: button.getAttribute('data-post-id'), // Store the post ID
          title: button.getAttribute('data-title'),
          subtitle: button.getAttribute('data-subtitle'),
          url: button.getAttribute('data-url'),
          pdf: button.getAttribute('data-pdf'),
          description: button.getAttribute('data-description'),
          thumbnail: button.getAttribute('data-thumbnail')
      });
  });

  // Handle "Next" button click
  document.querySelector('.right-arw-dy').addEventListener('click', function () {
    
      // Filter videos by the current post ID
      var filteredVideos = videos.filter(function (video) {
          return video.postId === currentPostId;
      });

      // Update the current index within the filtered list
      currentIndex = (currentIndex + 1) % filteredVideos.length;

      var nextVideo = filteredVideos[currentIndex];
      loadVideoDataFromObject(nextVideo);
  });

  document.querySelector('.left-arw-dy').addEventListener('click', function () {
    // Filter videos by the current post ID
    var filteredVideos = videos.filter(function (video) {
        return video.postId === currentPostId;
    });

    // Update the current index within the filtered list (decrement to go to the previous video)
    currentIndex = (currentIndex - 1 + filteredVideos.length) % filteredVideos.length;

    var previousVideo = filteredVideos[currentIndex];
    loadVideoDataFromObject(previousVideo);
});


  function loadVideoDataFromObject(video) {
    var modal = document.getElementById('customModal');
    modal.querySelector('.modal-title').textContent = video.title;
    modal.querySelector('.subtitle').textContent = video.subtitle;
    // Check if the video URL contains ".vimeo"
    try {
      thumbnail = JSON.parse(video.thumbnail);
  } catch (error) {
      console.error("Error parsing JSON data:", error);
  }
  const imgSlider = modal.querySelector('.img-slider');
  const downloadButton = modal.querySelector('.btn-primary');
   // Clear existing images
   imgSlider.innerHTML = '';

   // Add new image to the slider
   if (thumbnail) {
       const imgDiv = document.createElement('div');
       imgDiv.classList.add('pdf-image');
       imgDiv.innerHTML = `<img src="${thumbnail}" alt="Thumbnail">`;
       imgSlider.appendChild(imgDiv);
   }

   if (video.pdf) {
    downloadButton.innerHTML = `
        <span class="ico">
            <img src="https://kedusha.spericorn.com/wp-content/themes/kedushas/img/pdf.svg" alt="PDF">
        </span> 
        <span><a href="${video.pdf}" target="_blank">Download PDF</a></span>
    `;
    downloadButton.setAttribute('href', video.pdf);
    downloadButton.setAttribute('download', `${video.title || 'document'}.pdf`);
} else {
    downloadButton.innerHTML = 'PDF Not Available';
    downloadButton.removeAttribute('href');
    downloadButton.removeAttribute('download');
}
    modal.querySelector('.content').textContent = video.description;
}

});