(function($){
'use strict';
const ContentSERP={
init: function(){
this.mobileMenu();
this.pricingToggle();
this.smoothScroll();
this.addToCart();
this.faqAccordion();
this.testimonialSlider();
console.log('✅ ContentSERP initialized');
},
mobileMenu: function(){
$('.mobile-menu-toggle').on('click', function(){
$(this).toggleClass('active');
$('.main-navigation').toggleClass('active');
$('body').toggleClass('menu-open');
});
$(document).on('click', function(e){
if(!$(e.target).closest('.header-content').length){
$('.mobile-menu-toggle').removeClass('active');
$('.main-navigation').removeClass('active');
$('body').removeClass('menu-open');
}});
$('.nav-menu a').on('click', function(){
$('.mobile-menu-toggle').removeClass('active');
$('.main-navigation').removeClass('active');
$('body').removeClass('menu-open');
});
},
pricingToggle: function(){
$('#pricingToggle').on('change', function(){
if($(this).is(':checked')){
$('#creditsPackages').fadeOut(300, function(){
$('#monthlyPlans').fadeIn(300);
});
}else{
$('#monthlyPlans').fadeOut(300, function(){
$('#creditsPackages').fadeIn(300);
});
}});
},
smoothScroll: function(){
$('a[href*="#"]:not([href="#"])').on('click', function(e){
if(location.pathname.replace(/^\//, '')===this.pathname.replace(/^\//, '') &&
location.hostname===this.hostname){
var target=$(this.hash);
target=target.length ? target:$('[name=' + this.hash.slice(1) + ']');
if(target.length){
e.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top - 100
}, 800);
}}
});
},
addToCart: function(){
$('.add-to-cart-btn').on('click', function(e){
e.preventDefault();
const $button=$(this);
const productId=$button.data('product-id');
const originalText=$button.text();
$button.prop('disabled', true).text('Adding...');
$.ajax({
url: wc_add_to_cart_params.ajax_url,
type: 'POST',
data: {
action: 'woocommerce_ajax_add_to_cart',
product_id: productId,
quantity: 1,
},
success: function(response){
if(response.error){
alert(response.error);
$button.prop('disabled', false).text(originalText);
}else{
$('.cart-count').text(response.cart_count);
ContentSERP.showNotification('✅ Added to cart!', 'success');
setTimeout(function(){
window.location.href=response.cart_url||wc_add_to_cart_params.cart_url;
}, 1000);
}},
error: function(){
alert('Error adding to cart. Please try again.');
$button.prop('disabled', false).text(originalText);
}});
});
},
faqAccordion: function(){
$('.faq-item h4').on('click', function(){
const $item=$(this).parent();
const $content=$item.find('p');
$item.toggleClass('active');
$content.slideToggle(300);
$('.faq-item').not($item).removeClass('active').find('p').slideUp(300);
});
},
testimonialSlider: function(){
if($('.testimonials-grid').length){
let currentSlide=0;
const $testimonials=$('.testimonial-card');
const totalSlides=$testimonials.length;
if(totalSlides > 3){
setInterval(function(){
currentSlide=(currentSlide + 1) % totalSlides;
}, 5000);
}}
},
showNotification: function(message, type='success'){
const bgColor=type==='success' ? '#28A745':'#DC3545';
const toast=$('<div class="toast-notification"></div>')
.text(message)
.css({
'position': 'fixed',
'top': '20px',
'right': '20px',
'background': bgColor,
'color': 'white',
'padding': '16px 24px',
'border-radius': '8px',
'box-shadow': '0 4px 12px rgba(0,0,0,0.2)',
'z-index': 9999,
'animation': 'slideIn 0.3s ease-out'
});
$('body').append(toast);
setTimeout(function(){
toast.fadeOut(300, function(){
$(this).remove();
});
}, 3000);
},
formatINR: function(amount){
return new Intl.NumberFormat('en-IN', {
style: 'currency',
currency: 'INR',
minimumFractionDigits: 0
}).format(amount);
},
copyToClipboard: function(text){
if(navigator.clipboard){
navigator.clipboard.writeText(text).then(function(){
ContentSERP.showNotification('Copied to clipboard!', 'success');
});
}else{
const $temp=$('<textarea>');
$('body').append($temp);
$temp.val(text).select();
document.execCommand ('copy');
$temp.remove();
ContentSERP.showNotification('Copied to clipboard!', 'success');
}}
};
$(document).ready(function(){
ContentSERP.init();
});
window.ContentSERP=ContentSERP;
})(jQuery);
const style=document.createElement('style');
style.textContent=`
@keyframes slideIn {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}}
`;
document.head.appendChild(style);