jQuery(document).ready(function() { // Load notification count when the page loads wppm_loadNotifications(); // Refresh every 30 seconds setInterval(function () { if (!document.hidden) { wppm_loadNotifications(); } }, 60000); }); jQuery(document).on('click', function (e) { if ( !jQuery(e.target).closest('#wppm_notification_bell').length && !jQuery(e.target).closest('#wppm-notification-container').length ) { jQuery('#wppm-notification-container').hide(); } }); function wppm_loadNotifications() { jQuery.ajax({ url: wppm_notification.ajax_url, type: "POST", data: { action: "wppm_get_notifications" }, dataType: "json", success: function(response) { if(response.length > 0){ jQuery("#wppm_notification_bell").addClass("wppm-has-notification"); jQuery(".wppm-badge").text(response.length).show(); }else{ jQuery("#wppm_notification_bell").removeClass("wppm-has-notification"); jQuery(".wppm-badge").text("0").show(); } var html = ""; if(response.length > 0){ jQuery.each(response, function(i, notification){ html += '