{ if (listofcategory.subscribe_status === 1) { if (!listOfSubscribed.includes(listofcategory._id)) { listOfSubscribed.push(listofcategory._id); } if (!idstosubscribed.includes(listofcategory.news_cp_category_row_id)) { idstosubscribed.push(listofcategory.news_cp_category_row_id); } } }); idstosubscribed.forEach(id => { var subscribeButton = document.getElementById(`subscribe_` + id); var unsubscribeButton = document.getElementById(`unsubscribe_` + id); if (subscribeButton && unsubscribeButton) { subscribeButton.style.display = `none`; unsubscribeButton.style.display = `block`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `block`; } } }); } }, error: function(xhr, status, error) { console.error(`Error:`, error); } }); } function subscribe_unsubscribe_status(getcategoryId) { var elementTounsubscribe = document.getElementById(`unsubscribe_` + getcategoryId); var elementTosubscribe = document.getElementById(`subscribe_` + getcategoryId); jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `POST`, data: { action: `subscribe_api_ajax_request`, apiurl: `/app/email_newsletter/list?category_row_id=` + getcategoryId, }, success: function(response) { var result = JSON.parse(response.message); if (result.status === true) { jQuery(`.skeliton-loader-block`).hide(); var hasSubscribeStatusOne = false; result.message.forEach(subscribeStatus => { if (listOfSubscribed.includes(subscribeStatus._id) && subscribeStatus.subscribe_status === 1) { hasSubscribeStatusOne = true; } if (subscribeStatus.notification_type === 3) { document.getElementById(`monthlySelected_` + getcategoryId).style.display = `block`; document.getElementById(`monthly_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`monthly_` + getcategoryId).checked = true; } } else if (subscribeStatus.notification_type === 2) { document.getElementById(`weeklySelected_` + getcategoryId).style.display = `block`; document.getElementById(`weekly_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`weekly_` + getcategoryId).checked = true; } } else if (subscribeStatus.notification_type === 1) { document.getElementById(`dailySelected_` + getcategoryId).style.display = `block`; document.getElementById(`daily_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`daily_` + getcategoryId).checked = true; } } if (subscribeStatus.subscribe_status === 1) { listOfSubscribed.push(subscribeStatus._id); } }); if (hasSubscribeStatusOne) { elementTosubscribe.style.display = `none`; elementTounsubscribe.style.display = `block`; } else { elementTosubscribe.style.display = `block`; elementTounsubscribe.style.display = `none`; } } }, error: function(xhr, status, error) { console.error(`Error:`, error); } }); } function logSelectedSubscriptions(categoryid) { var unsubscribemodal = document.querySelector(`.unsubscribed-popup-modal .modal`); var subscribedmodal = document.querySelector(`.subscribed-popup-modal .modal`); unsubscribemodal.innerHTML=``; subscribedmodal.innerHTML=``; var selectedSubscriptions = []; var storeCheckedId = []; var checkboxes = document.querySelectorAll(`#subscription-options-` + categoryid + ` input[type="checkbox"]`); var errorMessage = document.getElementById(`error-message-select`); // Use a Set to handle unique data-ids var uniqueSubscribedIds = new Set(listOfSubscribed); checkboxes.forEach(function(checkbox) { var dataId = parseInt(checkbox.getAttribute(`data-id`)); if (checkbox.checked) { selectedSubscriptions.push(checkbox.id); storeCheckedId.push(dataId); } else { uniqueSubscribedIds.delete(dataId); // Remove unchecked data-id } }); // Update listOfSubscribed with unique values listOfSubscribed = Array.from(uniqueSubscribedIds); var selectedSubscriptionsString = selectedSubscriptions.join(`, `); var concatinateSubscribeId = [...new Set(storeCheckedId.concat(listOfSubscribed))]; var categoryData = { `subscribed_categories`: concatinateSubscribeId }; var requestSubscriberData = { action: `handle_dynamic_api_request_with_headers`, security: `c265685f77`, endpoint: `/app/email_newsletter/update_categories`, token: ``, data: categoryData }; jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `POST`, data: requestSubscriberData, beforeSend: function(xhr) { xhr.setRequestHeader(`X-Requested-With`, `XMLHttpRequest`); }, success: function(response) { try { response = response.data; if (storeCheckedId.length === 0) { var unsubcribedPopUpmodal = ` You’ve Unsubscribed Successfully We`re sorry to see you go! Your subscription has been canceled. If you change your mind, you can re-subscribe anytime. Thank you for being part of our community! `; unsubscribemodal.innerHTML = unsubcribedPopUpmodal; document.querySelector(`#subscribe-modal-design .modal`).style.display = `none`; unsubscribemodal.style.display = `block`; unsubscribemodal.classList.remove(`hide`); unsubscribemodal.classList.add(`show`); document.getElementById(`subscribe_` + categoryid).style.display = `block`; document.getElementById(`unsubscribe_` + categoryid).style.display = `none`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `none`; } } else { var subscribedPopupModal = ` Thank you for subscribing! Thank you for subscribing to our crypto and blockchain newsletter! You’ll now receive the latest news, insights, and updates straight to your inbox. Welcome to our community! `; let selectedSubscriptionsArray = selectedSubscriptionsString.split(`,`); let subscribedCategories = selectedSubscriptionsArray.map(subscription => subscription.split(`_`)[0]); let subscribedCategoriesString = subscribedCategories.join(`, `); subscribedmodal.innerHTML = subscribedPopupModal; if (document.getElementById(`selectidname`)) { document.getElementById(`selectidname`).textContent = subscribedCategoriesString; } document.querySelector(`#subscribe-modal-design .modal`).style.display = `none`; subscribedmodal.style.display = `block`; subscribedmodal.classList.remove(`hide`); subscribedmodal.classList.add(`show`); document.getElementById(`subscribe_` + categoryid).style.display = `none`; document.getElementById(`unsubscribe_` + categoryid).style.display = `block`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `block`; } } } catch (e) { console.error(`Error parsing response:`, e); } }, }); } function closeModal(template_id) { var modalId = template_id; var modal = document.querySelector(`#` + modalId); // Using querySelector to find the modal if (modal) { modal.classList.add(`hide`); modal.classList.remove(`show`); setTimeout(function() { modal.style.display = `none`; }, 500); } else { console.warn(`Modal not found:`, modalId); } } function closeunsubscribemodal() { var unsubscribemodal = document.querySelector(`.unsubscribed-popup-modal .modal`); if (unsubscribemodal) { unsubscribemodal.classList.add(`hide`); unsubscribemodal.classList.remove(`show`); } setTimeout(function() { unsubscribemodal.style.display = `none`; }, 500); } function closesubscribemodal() { var subscribedmodal = document.querySelector(`.subscribed-popup-modal .modal`); setTimeout(function() { subscribedmodal.style.display = `none`; }, 500); if (subscribedmodal) { subscribedmodal.classList.add(`hide`); subscribedmodal.classList.remove(`show`); } } function withoutLoginClicked(withoutlogin_id) { localStorage.setItem(`subscribe_without_Login`, `true`); localStorage.setItem(`subscribe_clicked_id`, withoutlogin_id); } document.addEventListener(`DOMContentLoaded`, function() { var templateId = `6`; getAllSubscriberCategoryList([templateId]); jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `GET`, data: { action: `subscribe_api_ajax_request`, apiurl: `/app/email_newsletter/list`, }, success: function(response) { var resultonload = JSON.parse(response.message); var storeallcategory = resultonload.message; if (Array.isArray(storeallcategory)) { // Collect all `news_cp_category_row_id` values and remove duplicates var allCategoryIds = storeallcategory.map(function(item) { return String(item.news_cp_category_row_id); // Convert IDs to strings }); var uniqueCategoryIds = Array.from(new Set(allCategoryIds)); // Get unique IDs // Convert templateId to a string for comparison var templateIdStr = String(templateId); // Check if the templateId is NOT found in the unique category IDs if (!uniqueCategoryIds.includes(templateIdStr)) { var idNotMatchTounsubscribe = document.getElementById(`unsubscribe_` + templateIdStr); var idNotMatchTosubscribe = document.getElementById(`subscribe_` + templateIdStr); // Check if elements exist before applying display changes if (idNotMatchTounsubscribe) { idNotMatchTounsubscribe.style.display = "none"; } if (idNotMatchTosubscribe) { idNotMatchTosubscribe.style.display = "none"; } } } else { console.log("storeallcategory is not an array."); } }, error: function(xhr, status, error) { console.error("AJAX request failed:", status, error); } }); const subscribewithoutData = localStorage.getItem(`subscribe_without_Login`); const subscribe_clicked_cat_id = localStorage.getItem(`subscribe_clicked_id`); // Function to get cookies function getCookie(name) { let value = "; " + document.cookie; let parts = value.split("; " + name + "="); if (parts.length == 2) return parts.pop().split(";").shift(); } // Get user token from cookies const userToken = getCookie(`user_token`); if (subscribewithoutData === `true` && userToken) { // Call the modal function with the category ID subscribed_popupmodal(subscribe_clicked_cat_id); // Remove the flag and category ID from localStorage localStorage.removeItem(`subscribe_without_Login`); localStorage.removeItem(`subscribe_clicked_id`); } }); /************************** update susbcriber content **************************** */ function initializeSubscriptionButton() { var initialListItems = document.querySelectorAll(`.subscription-options input[type="checkbox"]`); initialListItems.forEach(function(item) { console.log(item.checked, `Initial Checkbox checked status`); }); var listItems = document.querySelectorAll(`.subscription-options li`); if (listItems.length === 0) return; var anyActive = false; listItems.forEach(function(item) { var checkbox = item.querySelector(`input[type="checkbox"]`); if (checkbox) { if (checkbox.checked) { item.classList.add(`active`); anyActive = true; // Set anyActive to true } else { item.classList.remove(`active`); // Remove `active` class if checkbox is unchecked } } }); } function updateButtonText(anyActive) { var subscribeButtonSpan = document.querySelector(`.subscribe-submit .changeBtnText`); if (subscribeButtonSpan) { if (anyActive) { subscribeButtonSpan.textContent = `Subscribe Now`; } else { subscribeButtonSpan.textContent = `Unsubscribe`; } } } function updateSubscriptionButton() { var listItems = document.querySelectorAll(`.subscription-options li`); if (listItems.length === 0) return; var anyActive = false; listItems.forEach(function(item) { var checkbox = item.querySelector(`input[type="checkbox"]`); if (checkbox) { if (checkbox.checked) { item.classList.add(`active`); anyActive = true; // Set anyActive to true } else { item.classList.remove(`active`); // Remove `active` class if checkbox is unchecked } } }); // Update the button text based on whether any list item has the `active` class updateButtonText(anyActive); } document.addEventListener(`click`, function(event) { var clickedItem = event.target.closest(`.subscription-options li`); if (clickedItem) { var checkbox = clickedItem.querySelector(`input[type="checkbox"]`); if (checkbox) { checkbox.checked = !checkbox.checked; updateSubscriptionButton(); } } });" /> { if (listofcategory.subscribe_status === 1) { if (!listOfSubscribed.includes(listofcategory._id)) { listOfSubscribed.push(listofcategory._id); } if (!idstosubscribed.includes(listofcategory.news_cp_category_row_id)) { idstosubscribed.push(listofcategory.news_cp_category_row_id); } } }); idstosubscribed.forEach(id => { var subscribeButton = document.getElementById(`subscribe_` + id); var unsubscribeButton = document.getElementById(`unsubscribe_` + id); if (subscribeButton && unsubscribeButton) { subscribeButton.style.display = `none`; unsubscribeButton.style.display = `block`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `block`; } } }); } }, error: function(xhr, status, error) { console.error(`Error:`, error); } }); } function subscribe_unsubscribe_status(getcategoryId) { var elementTounsubscribe = document.getElementById(`unsubscribe_` + getcategoryId); var elementTosubscribe = document.getElementById(`subscribe_` + getcategoryId); jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `POST`, data: { action: `subscribe_api_ajax_request`, apiurl: `/app/email_newsletter/list?category_row_id=` + getcategoryId, }, success: function(response) { var result = JSON.parse(response.message); if (result.status === true) { jQuery(`.skeliton-loader-block`).hide(); var hasSubscribeStatusOne = false; result.message.forEach(subscribeStatus => { if (listOfSubscribed.includes(subscribeStatus._id) && subscribeStatus.subscribe_status === 1) { hasSubscribeStatusOne = true; } if (subscribeStatus.notification_type === 3) { document.getElementById(`monthlySelected_` + getcategoryId).style.display = `block`; document.getElementById(`monthly_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`monthly_` + getcategoryId).checked = true; } } else if (subscribeStatus.notification_type === 2) { document.getElementById(`weeklySelected_` + getcategoryId).style.display = `block`; document.getElementById(`weekly_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`weekly_` + getcategoryId).checked = true; } } else if (subscribeStatus.notification_type === 1) { document.getElementById(`dailySelected_` + getcategoryId).style.display = `block`; document.getElementById(`daily_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`daily_` + getcategoryId).checked = true; } } if (subscribeStatus.subscribe_status === 1) { listOfSubscribed.push(subscribeStatus._id); } }); if (hasSubscribeStatusOne) { elementTosubscribe.style.display = `none`; elementTounsubscribe.style.display = `block`; } else { elementTosubscribe.style.display = `block`; elementTounsubscribe.style.display = `none`; } } }, error: function(xhr, status, error) { console.error(`Error:`, error); } }); } function logSelectedSubscriptions(categoryid) { var unsubscribemodal = document.querySelector(`.unsubscribed-popup-modal .modal`); var subscribedmodal = document.querySelector(`.subscribed-popup-modal .modal`); unsubscribemodal.innerHTML=``; subscribedmodal.innerHTML=``; var selectedSubscriptions = []; var storeCheckedId = []; var checkboxes = document.querySelectorAll(`#subscription-options-` + categoryid + ` input[type="checkbox"]`); var errorMessage = document.getElementById(`error-message-select`); // Use a Set to handle unique data-ids var uniqueSubscribedIds = new Set(listOfSubscribed); checkboxes.forEach(function(checkbox) { var dataId = parseInt(checkbox.getAttribute(`data-id`)); if (checkbox.checked) { selectedSubscriptions.push(checkbox.id); storeCheckedId.push(dataId); } else { uniqueSubscribedIds.delete(dataId); // Remove unchecked data-id } }); // Update listOfSubscribed with unique values listOfSubscribed = Array.from(uniqueSubscribedIds); var selectedSubscriptionsString = selectedSubscriptions.join(`, `); var concatinateSubscribeId = [...new Set(storeCheckedId.concat(listOfSubscribed))]; var categoryData = { `subscribed_categories`: concatinateSubscribeId }; var requestSubscriberData = { action: `handle_dynamic_api_request_with_headers`, security: `c265685f77`, endpoint: `/app/email_newsletter/update_categories`, token: ``, data: categoryData }; jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `POST`, data: requestSubscriberData, beforeSend: function(xhr) { xhr.setRequestHeader(`X-Requested-With`, `XMLHttpRequest`); }, success: function(response) { try { response = response.data; if (storeCheckedId.length === 0) { var unsubcribedPopUpmodal = ` You’ve Unsubscribed Successfully We`re sorry to see you go! Your subscription has been canceled. If you change your mind, you can re-subscribe anytime. Thank you for being part of our community! `; unsubscribemodal.innerHTML = unsubcribedPopUpmodal; document.querySelector(`#subscribe-modal-design .modal`).style.display = `none`; unsubscribemodal.style.display = `block`; unsubscribemodal.classList.remove(`hide`); unsubscribemodal.classList.add(`show`); document.getElementById(`subscribe_` + categoryid).style.display = `block`; document.getElementById(`unsubscribe_` + categoryid).style.display = `none`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `none`; } } else { var subscribedPopupModal = ` Thank you for subscribing! Thank you for subscribing to our crypto and blockchain newsletter! You’ll now receive the latest news, insights, and updates straight to your inbox. Welcome to our community! `; let selectedSubscriptionsArray = selectedSubscriptionsString.split(`,`); let subscribedCategories = selectedSubscriptionsArray.map(subscription => subscription.split(`_`)[0]); let subscribedCategoriesString = subscribedCategories.join(`, `); subscribedmodal.innerHTML = subscribedPopupModal; if (document.getElementById(`selectidname`)) { document.getElementById(`selectidname`).textContent = subscribedCategoriesString; } document.querySelector(`#subscribe-modal-design .modal`).style.display = `none`; subscribedmodal.style.display = `block`; subscribedmodal.classList.remove(`hide`); subscribedmodal.classList.add(`show`); document.getElementById(`subscribe_` + categoryid).style.display = `none`; document.getElementById(`unsubscribe_` + categoryid).style.display = `block`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `block`; } } } catch (e) { console.error(`Error parsing response:`, e); } }, }); } function closeModal(template_id) { var modalId = template_id; var modal = document.querySelector(`#` + modalId); // Using querySelector to find the modal if (modal) { modal.classList.add(`hide`); modal.classList.remove(`show`); setTimeout(function() { modal.style.display = `none`; }, 500); } else { console.warn(`Modal not found:`, modalId); } } function closeunsubscribemodal() { var unsubscribemodal = document.querySelector(`.unsubscribed-popup-modal .modal`); if (unsubscribemodal) { unsubscribemodal.classList.add(`hide`); unsubscribemodal.classList.remove(`show`); } setTimeout(function() { unsubscribemodal.style.display = `none`; }, 500); } function closesubscribemodal() { var subscribedmodal = document.querySelector(`.subscribed-popup-modal .modal`); setTimeout(function() { subscribedmodal.style.display = `none`; }, 500); if (subscribedmodal) { subscribedmodal.classList.add(`hide`); subscribedmodal.classList.remove(`show`); } } function withoutLoginClicked(withoutlogin_id) { localStorage.setItem(`subscribe_without_Login`, `true`); localStorage.setItem(`subscribe_clicked_id`, withoutlogin_id); } document.addEventListener(`DOMContentLoaded`, function() { var templateId = `6`; getAllSubscriberCategoryList([templateId]); jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `GET`, data: { action: `subscribe_api_ajax_request`, apiurl: `/app/email_newsletter/list`, }, success: function(response) { var resultonload = JSON.parse(response.message); var storeallcategory = resultonload.message; if (Array.isArray(storeallcategory)) { // Collect all `news_cp_category_row_id` values and remove duplicates var allCategoryIds = storeallcategory.map(function(item) { return String(item.news_cp_category_row_id); // Convert IDs to strings }); var uniqueCategoryIds = Array.from(new Set(allCategoryIds)); // Get unique IDs // Convert templateId to a string for comparison var templateIdStr = String(templateId); // Check if the templateId is NOT found in the unique category IDs if (!uniqueCategoryIds.includes(templateIdStr)) { var idNotMatchTounsubscribe = document.getElementById(`unsubscribe_` + templateIdStr); var idNotMatchTosubscribe = document.getElementById(`subscribe_` + templateIdStr); // Check if elements exist before applying display changes if (idNotMatchTounsubscribe) { idNotMatchTounsubscribe.style.display = "none"; } if (idNotMatchTosubscribe) { idNotMatchTosubscribe.style.display = "none"; } } } else { console.log("storeallcategory is not an array."); } }, error: function(xhr, status, error) { console.error("AJAX request failed:", status, error); } }); const subscribewithoutData = localStorage.getItem(`subscribe_without_Login`); const subscribe_clicked_cat_id = localStorage.getItem(`subscribe_clicked_id`); // Function to get cookies function getCookie(name) { let value = "; " + document.cookie; let parts = value.split("; " + name + "="); if (parts.length == 2) return parts.pop().split(";").shift(); } // Get user token from cookies const userToken = getCookie(`user_token`); if (subscribewithoutData === `true` && userToken) { // Call the modal function with the category ID subscribed_popupmodal(subscribe_clicked_cat_id); // Remove the flag and category ID from localStorage localStorage.removeItem(`subscribe_without_Login`); localStorage.removeItem(`subscribe_clicked_id`); } }); /************************** update susbcriber content **************************** */ function initializeSubscriptionButton() { var initialListItems = document.querySelectorAll(`.subscription-options input[type="checkbox"]`); initialListItems.forEach(function(item) { console.log(item.checked, `Initial Checkbox checked status`); }); var listItems = document.querySelectorAll(`.subscription-options li`); if (listItems.length === 0) return; var anyActive = false; listItems.forEach(function(item) { var checkbox = item.querySelector(`input[type="checkbox"]`); if (checkbox) { if (checkbox.checked) { item.classList.add(`active`); anyActive = true; // Set anyActive to true } else { item.classList.remove(`active`); // Remove `active` class if checkbox is unchecked } } }); } function updateButtonText(anyActive) { var subscribeButtonSpan = document.querySelector(`.subscribe-submit .changeBtnText`); if (subscribeButtonSpan) { if (anyActive) { subscribeButtonSpan.textContent = `Subscribe Now`; } else { subscribeButtonSpan.textContent = `Unsubscribe`; } } } function updateSubscriptionButton() { var listItems = document.querySelectorAll(`.subscription-options li`); if (listItems.length === 0) return; var anyActive = false; listItems.forEach(function(item) { var checkbox = item.querySelector(`input[type="checkbox"]`); if (checkbox) { if (checkbox.checked) { item.classList.add(`active`); anyActive = true; // Set anyActive to true } else { item.classList.remove(`active`); // Remove `active` class if checkbox is unchecked } } }); // Update the button text based on whether any list item has the `active` class updateButtonText(anyActive); } document.addEventListener(`click`, function(event) { var clickedItem = event.target.closest(`.subscription-options li`); if (clickedItem) { var checkbox = clickedItem.querySelector(`input[type="checkbox"]`); if (checkbox) { checkbox.checked = !checkbox.checked; updateSubscriptionButton(); } } });" /> { if (listofcategory.subscribe_status === 1) { if (!listOfSubscribed.includes(listofcategory._id)) { listOfSubscribed.push(listofcategory._id); } if (!idstosubscribed.includes(listofcategory.news_cp_category_row_id)) { idstosubscribed.push(listofcategory.news_cp_category_row_id); } } }); idstosubscribed.forEach(id => { var subscribeButton = document.getElementById(`subscribe_` + id); var unsubscribeButton = document.getElementById(`unsubscribe_` + id); if (subscribeButton && unsubscribeButton) { subscribeButton.style.display = `none`; unsubscribeButton.style.display = `block`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `block`; } } }); } }, error: function(xhr, status, error) { console.error(`Error:`, error); } }); } function subscribe_unsubscribe_status(getcategoryId) { var elementTounsubscribe = document.getElementById(`unsubscribe_` + getcategoryId); var elementTosubscribe = document.getElementById(`subscribe_` + getcategoryId); jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `POST`, data: { action: `subscribe_api_ajax_request`, apiurl: `/app/email_newsletter/list?category_row_id=` + getcategoryId, }, success: function(response) { var result = JSON.parse(response.message); if (result.status === true) { jQuery(`.skeliton-loader-block`).hide(); var hasSubscribeStatusOne = false; result.message.forEach(subscribeStatus => { if (listOfSubscribed.includes(subscribeStatus._id) && subscribeStatus.subscribe_status === 1) { hasSubscribeStatusOne = true; } if (subscribeStatus.notification_type === 3) { document.getElementById(`monthlySelected_` + getcategoryId).style.display = `block`; document.getElementById(`monthly_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`monthly_` + getcategoryId).checked = true; } } else if (subscribeStatus.notification_type === 2) { document.getElementById(`weeklySelected_` + getcategoryId).style.display = `block`; document.getElementById(`weekly_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`weekly_` + getcategoryId).checked = true; } } else if (subscribeStatus.notification_type === 1) { document.getElementById(`dailySelected_` + getcategoryId).style.display = `block`; document.getElementById(`daily_` + getcategoryId).setAttribute(`data-id`, subscribeStatus._id); if (subscribeStatus.subscribe_status === 1) { document.getElementById(`daily_` + getcategoryId).checked = true; } } if (subscribeStatus.subscribe_status === 1) { listOfSubscribed.push(subscribeStatus._id); } }); if (hasSubscribeStatusOne) { elementTosubscribe.style.display = `none`; elementTounsubscribe.style.display = `block`; } else { elementTosubscribe.style.display = `block`; elementTounsubscribe.style.display = `none`; } } }, error: function(xhr, status, error) { console.error(`Error:`, error); } }); } function logSelectedSubscriptions(categoryid) { var unsubscribemodal = document.querySelector(`.unsubscribed-popup-modal .modal`); var subscribedmodal = document.querySelector(`.subscribed-popup-modal .modal`); unsubscribemodal.innerHTML=``; subscribedmodal.innerHTML=``; var selectedSubscriptions = []; var storeCheckedId = []; var checkboxes = document.querySelectorAll(`#subscription-options-` + categoryid + ` input[type="checkbox"]`); var errorMessage = document.getElementById(`error-message-select`); // Use a Set to handle unique data-ids var uniqueSubscribedIds = new Set(listOfSubscribed); checkboxes.forEach(function(checkbox) { var dataId = parseInt(checkbox.getAttribute(`data-id`)); if (checkbox.checked) { selectedSubscriptions.push(checkbox.id); storeCheckedId.push(dataId); } else { uniqueSubscribedIds.delete(dataId); // Remove unchecked data-id } }); // Update listOfSubscribed with unique values listOfSubscribed = Array.from(uniqueSubscribedIds); var selectedSubscriptionsString = selectedSubscriptions.join(`, `); var concatinateSubscribeId = [...new Set(storeCheckedId.concat(listOfSubscribed))]; var categoryData = { `subscribed_categories`: concatinateSubscribeId }; var requestSubscriberData = { action: `handle_dynamic_api_request_with_headers`, security: `c265685f77`, endpoint: `/app/email_newsletter/update_categories`, token: ``, data: categoryData }; jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `POST`, data: requestSubscriberData, beforeSend: function(xhr) { xhr.setRequestHeader(`X-Requested-With`, `XMLHttpRequest`); }, success: function(response) { try { response = response.data; if (storeCheckedId.length === 0) { var unsubcribedPopUpmodal = ` You’ve Unsubscribed Successfully We`re sorry to see you go! Your subscription has been canceled. If you change your mind, you can re-subscribe anytime. Thank you for being part of our community! `; unsubscribemodal.innerHTML = unsubcribedPopUpmodal; document.querySelector(`#subscribe-modal-design .modal`).style.display = `none`; unsubscribemodal.style.display = `block`; unsubscribemodal.classList.remove(`hide`); unsubscribemodal.classList.add(`show`); document.getElementById(`subscribe_` + categoryid).style.display = `block`; document.getElementById(`unsubscribe_` + categoryid).style.display = `none`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `none`; } } else { var subscribedPopupModal = ` Thank you for subscribing! Thank you for subscribing to our crypto and blockchain newsletter! You’ll now receive the latest news, insights, and updates straight to your inbox. Welcome to our community! `; let selectedSubscriptionsArray = selectedSubscriptionsString.split(`,`); let subscribedCategories = selectedSubscriptionsArray.map(subscription => subscription.split(`_`)[0]); let subscribedCategoriesString = subscribedCategories.join(`, `); subscribedmodal.innerHTML = subscribedPopupModal; if (document.getElementById(`selectidname`)) { document.getElementById(`selectidname`).textContent = subscribedCategoriesString; } document.querySelector(`#subscribe-modal-design .modal`).style.display = `none`; subscribedmodal.style.display = `block`; subscribedmodal.classList.remove(`hide`); subscribedmodal.classList.add(`show`); document.getElementById(`subscribe_` + categoryid).style.display = `none`; document.getElementById(`unsubscribe_` + categoryid).style.display = `block`; var showDownloadReport = document.getElementById(`download_report`); if (showDownloadReport) { showDownloadReport.style.display = `block`; } } } catch (e) { console.error(`Error parsing response:`, e); } }, }); } function closeModal(template_id) { var modalId = template_id; var modal = document.querySelector(`#` + modalId); // Using querySelector to find the modal if (modal) { modal.classList.add(`hide`); modal.classList.remove(`show`); setTimeout(function() { modal.style.display = `none`; }, 500); } else { console.warn(`Modal not found:`, modalId); } } function closeunsubscribemodal() { var unsubscribemodal = document.querySelector(`.unsubscribed-popup-modal .modal`); if (unsubscribemodal) { unsubscribemodal.classList.add(`hide`); unsubscribemodal.classList.remove(`show`); } setTimeout(function() { unsubscribemodal.style.display = `none`; }, 500); } function closesubscribemodal() { var subscribedmodal = document.querySelector(`.subscribed-popup-modal .modal`); setTimeout(function() { subscribedmodal.style.display = `none`; }, 500); if (subscribedmodal) { subscribedmodal.classList.add(`hide`); subscribedmodal.classList.remove(`show`); } } function withoutLoginClicked(withoutlogin_id) { localStorage.setItem(`subscribe_without_Login`, `true`); localStorage.setItem(`subscribe_clicked_id`, withoutlogin_id); } document.addEventListener(`DOMContentLoaded`, function() { var templateId = `6`; getAllSubscriberCategoryList([templateId]); jQuery.ajax({ url: `https://coinpedia.org/wp-admin/admin-ajax.php`, type: `GET`, data: { action: `subscribe_api_ajax_request`, apiurl: `/app/email_newsletter/list`, }, success: function(response) { var resultonload = JSON.parse(response.message); var storeallcategory = resultonload.message; if (Array.isArray(storeallcategory)) { // Collect all `news_cp_category_row_id` values and remove duplicates var allCategoryIds = storeallcategory.map(function(item) { return String(item.news_cp_category_row_id); // Convert IDs to strings }); var uniqueCategoryIds = Array.from(new Set(allCategoryIds)); // Get unique IDs // Convert templateId to a string for comparison var templateIdStr = String(templateId); // Check if the templateId is NOT found in the unique category IDs if (!uniqueCategoryIds.includes(templateIdStr)) { var idNotMatchTounsubscribe = document.getElementById(`unsubscribe_` + templateIdStr); var idNotMatchTosubscribe = document.getElementById(`subscribe_` + templateIdStr); // Check if elements exist before applying display changes if (idNotMatchTounsubscribe) { idNotMatchTounsubscribe.style.display = "none"; } if (idNotMatchTosubscribe) { idNotMatchTosubscribe.style.display = "none"; } } } else { console.log("storeallcategory is not an array."); } }, error: function(xhr, status, error) { console.error("AJAX request failed:", status, error); } }); const subscribewithoutData = localStorage.getItem(`subscribe_without_Login`); const subscribe_clicked_cat_id = localStorage.getItem(`subscribe_clicked_id`); // Function to get cookies function getCookie(name) { let value = "; " + document.cookie; let parts = value.split("; " + name + "="); if (parts.length == 2) return parts.pop().split(";").shift(); } // Get user token from cookies const userToken = getCookie(`user_token`); if (subscribewithoutData === `true` && userToken) { // Call the modal function with the category ID subscribed_popupmodal(subscribe_clicked_cat_id); // Remove the flag and category ID from localStorage localStorage.removeItem(`subscribe_without_Login`); localStorage.removeItem(`subscribe_clicked_id`); } }); /************************** update susbcriber content **************************** */ function initializeSubscriptionButton() { var initialListItems = document.querySelectorAll(`.subscription-options input[type="checkbox"]`); initialListItems.forEach(function(item) { console.log(item.checked, `Initial Checkbox checked status`); }); var listItems = document.querySelectorAll(`.subscription-options li`); if (listItems.length === 0) return; var anyActive = false; listItems.forEach(function(item) { var checkbox = item.querySelector(`input[type="checkbox"]`); if (checkbox) { if (checkbox.checked) { item.classList.add(`active`); anyActive = true; // Set anyActive to true } else { item.classList.remove(`active`); // Remove `active` class if checkbox is unchecked } } }); } function updateButtonText(anyActive) { var subscribeButtonSpan = document.querySelector(`.subscribe-submit .changeBtnText`); if (subscribeButtonSpan) { if (anyActive) { subscribeButtonSpan.textContent = `Subscribe Now`; } else { subscribeButtonSpan.textContent = `Unsubscribe`; } } } function updateSubscriptionButton() { var listItems = document.querySelectorAll(`.subscription-options li`); if (listItems.length === 0) return; var anyActive = false; listItems.forEach(function(item) { var checkbox = item.querySelector(`input[type="checkbox"]`); if (checkbox) { if (checkbox.checked) { item.classList.add(`active`); anyActive = true; // Set anyActive to true } else { item.classList.remove(`active`); // Remove `active` class if checkbox is unchecked } } }); // Update the button text based on whether any list item has the `active` class updateButtonText(anyActive); } document.addEventListener(`click`, function(event) { var clickedItem = event.target.closest(`.subscription-options li`); if (clickedItem) { var checkbox = clickedItem.querySelector(`input[type="checkbox"]`); if (checkbox) { checkbox.checked = !checkbox.checked; updateSubscriptionButton(); } } });" />