//New JS function getLocalStorageData(key) { var data = localStorage.getItem(key); return data ? JSON.parse(data) : null; } function setLocalStorageData(key, data) { localStorage.setItem(key, JSON.stringify(data)); } var preloadedData = getLocalStorageData('preloadedData') || {}; function preloadData($element) { var objectid = $element.attr('class'); var objectimg = $element.attr('data-img-url'); if (!preloadedData[objectid]) { jQuery.ajax({ url: '<?php echo admin_url('admin-ajax.php'); ?>', type: 'post', data: { action: 'data_fetch_salco', objectid: objectid, objectimg: objectimg }, success: function(data) { // Store the preloaded data in the object and local storage preloadedData[objectid] = data; setLocalStorageData('preloadedData', preloadedData); }, error: function() { console.log("Error preloading data"); } }); } } jQuery(document).on('mouseenter', '.popmak', function() { preloadData(jQuery(this)); }); jQuery(document).on('click', '.popmak', function(event) { event.preventDefault(); var $this = jQuery(this); var objectid = $this.attr('class'); var displayContent = function(data) { jQuery('.popup__content_dyn').html(data); document.querySelectorAll(".wpcf7 > form").forEach( function(e) { return wpcf7.init(e); } ); jQuery(".popup_custom").fadeIn(50).css('display', 'flex'); jQuery('#Realtor input[value="Realtor"]').attr('checked', 'checked'); }; if (preloadedData[objectid]) { displayContent(preloadedData[objectid]); } else { jQuery.ajax({ url: '<?php echo admin_url('admin-ajax.php'); ?>', type: 'post', data: { action: 'data_fetch_salco', objectid: objectid, objectimg: objectimg }, success: function(data) { preloadedData[objectid] = data; setLocalStorageData('preloadedData', preloadedData); displayContent(data); }, error: function() { console.log("Error loading data"); } }); } }); var observer = new IntersectionObserver(function(entries) { entries.forEach(function(entry) { if (entry.isIntersecting) { preloadData(jQuery(entry.target)); } }); }, { threshold: 0.0 }); jQuery('.popmak').each(function() { //observer.observe(this); }); jQuery(document).ready(function() { jQuery('.popmak').each(function() { preloadData(jQuery(this)); }); }); //New
Jagdish Sarma Asked question June 27, 2024