Skip to content
document.addEventListener('DOMContentLoaded', function () {
console.log('π Ebook Button Handler Loaded');
document.querySelectorAll('.open-book-popup').forEach(function (btn, i) {
btn.addEventListener('click', function (e) {
e.preventDefault();
console.log(`π© Clicked Ebook Button #${i + 1}`, btn);
const container = btn.closest('.elementor-container, .elementor-widget');
if (!container) return console.warn('β No container found for this button.');
const bookEl = container.querySelector('[data-book]');
const popupEl = container.querySelector('[data-popup-id]');
const bookTitle = bookEl?.getAttribute('data-book') || '';
const popupId = popupEl?.getAttribute('data-popup-id') || '';
const input = document.querySelector('input[name="book_title"]');
console.log('π Book Title:', bookTitle);
console.log('π Popup ID:', popupId);
console.log('π© Hidden Input:', input);
if (input && bookTitle) {
input.value = bookTitle;
console.log('β
Set hidden field to:', bookTitle);
} else {
console.warn('β οΈ Missing input or book title');
}
if (typeof JetPopup !== 'undefined' && popupId) {
console.log('π Triggering JetPopup ID:', popupId);
JetPopup.showPopup(parseInt(popupId));
} else {
console.warn('β JetPopup not available or popup ID missing');
}
});
});
});