Current File : /home/kjohakhy/https:/airworldmechanical.net/sms/whatsappchatpro//chatpro.js
(function($) {
const widgetPosition = 'right';
const enableGDPR = true;
const buttonEffect = 'ripple';
var wa_time_out, wa_time_in;
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
$(document).on('click', '.wa__popup_content_item a', function(e) {
e.preventDefault();
const phone = $(this).data('phone');
const text = $(this).data('text');
if (!phone) {
console.error("WhatsApp phone number is not defined. Please check the 'data-phone' attribute.");
return;
}
const encodedText = encodeURIComponent(text || '');
const baseDomain = isMobile() ? 'api.whatsapp.com' : 'web.whatsapp.com';
const fullUrl = `https://${baseDomain}/send?phone=${phone}&text=${encodedText}`;
window.open(fullUrl, '_blank');
});
function enableButtonEffect() {
const $icon = $('.wa__btn_popup_icon');
// Clear any existing effects
$icon.removeClass('pulse ripple');
// Add the selected effect
if (buttonEffect === 'pulse') {
$icon.addClass('pulse');
} else if (buttonEffect === 'ripple') {
$icon.addClass('ripple');
}
// If buttonEffect is 'none', nothing is added
}
function disableButtonEffect() {
// Clear all effects
$('.wa__btn_popup_icon').removeClass('pulse ripple');
}
$(document).ready(function() {
if (widgetPosition === 'left') {
$('.wa__btn_popup, .wa__popup_chat_box').addClass('wa-widget-position--left');
} else {
$('.wa__btn_popup, .wa__popup_chat_box').addClass('wa-widget-position--right');
}
// --- Availability Check ---
function updateAvailability() {
let anyOnline = false;
$('.wa__popup_content_item a').each(function() {
const $link = $(this);
const timezone = $link.data('timezone');
const [workStart, workEnd] = $link.data('hours').split('-').map(Number);
const [dayStart, dayEnd] = ($link.data('days') || '1-7').split('-').map(Number);
const now = new Date();
const hourOptions = { timeZone: timezone, hour12: false, hour: 'numeric' };
const currentHour = parseInt(now.toLocaleString('en-US', hourOptions), 10);
const dayOptions = { timeZone: timezone, weekday: 'long' };
const currentDayName = now.toLocaleString('en-US', dayOptions);
const dayMap = { "Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4, "Friday": 5, "Saturday": 6, "Sunday": 7 };
const currentDay = dayMap[currentDayName];
const isWithinHours = currentHour >= workStart && currentHour < workEnd;
const isWithinDays = currentDay >= dayStart && currentDay <= dayEnd;
const isAvailable = isWithinHours && isWithinDays;
$link.toggleClass('wa__stt_online', isAvailable).toggleClass('wa__stt_offline', !isAvailable);
$link.toggleClass('pointer-disable', !isAvailable);
if(isAvailable) {
anyOnline = true;
$link.find('.wa__member_status').text('🟢 I am online now');
} else {
$link.find('.wa__member_status').text(`⏰ Available at ${workStart}:00`);
}
});
anyOnline ? enableButtonEffect() : disableButtonEffect();
}
updateAvailability();
setInterval(updateAvailability, 60000);
$('.wa__popup_content_list').on('click', '.pointer-disable', function(e) {
e.preventDefault();
return false;
});
// --- Popup Toggle with original animation logic ---
$(".wa__btn_popup").on("click", function() {
if ($(".wa__popup_chat_box").hasClass("wa__active")) {
$(".wa__popup_chat_box").removeClass("wa__active");
$(".wa__btn_popup").removeClass("wa__active");
clearTimeout(wa_time_in);
if ($(".wa__popup_chat_box").hasClass("wa__lauch")) {
wa_time_out = setTimeout(function() {
$(".wa__popup_chat_box").removeClass("wa__pending");
$(".wa__popup_chat_box").removeClass("wa__lauch");
}, 400);
}
} else {
$(".wa__popup_chat_box").addClass("wa__pending");
$(".wa__popup_chat_box").addClass("wa__active");
$(".wa__btn_popup").addClass("wa__active");
clearTimeout(wa_time_out);
if (!$(".wa__popup_chat_box").hasClass("wa__lauch")) {
wa_time_in = setTimeout(function() {
$(".wa__popup_chat_box").addClass("wa__lauch");
}, 100);
}
}
});
// --- GDPR and Cookie Functions ---
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function deleteCookie(cname) {
document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
// GDPR Consent Handler
function handleGDPRConsent() {
const gdprCheckbox = $("#nta-wa-gdpr");
const gdprContainer = $('.nta-wa-gdpr');
if (!enableGDPR) {
gdprContainer.hide(); // Hide the GDPR box
$('.wa__popup_content_item').removeClass('pointer-disable'); // Ensure chat items are clickable
$('.wa__popup_content_list').off('click.gdpr'); // Remove the click blocker
return; // Stop processing the rest of the GDPR logic
}
// Handle checkbox change
gdprCheckbox.on('change', function() {
if (this.checked) {
setCookie("nta-wa-gdpr", "accept", 30);
$('.nta-wa-gdpr').slideUp(300, function() {
$('.wa__popup_content_item').removeClass('pointer-disable');
$('.wa__popup_content_list').off('click.gdpr');
});
} else {
deleteCookie("nta-wa-gdpr");
// You might want to re-add the 'pointer-disable' class if unchecked
// $('.wa__popup_content_item').addClass('pointer-disable');
// And re-attach the 'click.gdpr' handler
}
});
// Check existing consent
if (getCookie("nta-wa-gdpr") === "accept") {
gdprContainer.hide();
$('.wa__popup_content_item').removeClass('pointer-disable');
} else {
// Initially disable user items if GDPR is not accepted
$('.wa__popup_content_item').addClass('pointer-disable');
// Add visual feedback when trying to click disabled items
$('.wa__popup_content_list').on('click.gdpr', '.pointer-disable', function(e){
e.preventDefault();
e.stopPropagation();
// Add highlight effect to GDPR section
gdprContainer.addClass('nta-wa-gdpr-highlight');
setTimeout(function() {
gdprContainer.removeClass('nta-wa-gdpr-highlight');
}, 1000);
return false;
});
}
}
// Initialize GDPR handling
handleGDPRConsent();
});
})(jQuery);