Files
profen/public/wp-content/themes/rakar/assets/js/main.js
2026-07-14 20:19:21 +00:00

479 lines
15 KiB
JavaScript

function rakar_content_load_scripts() {
var $ = jQuery;
"use strict";
/*=================================
JS Index Here
==================================*/
/*
01. On Load Function
02. Preloader
03. Mobile Menu
04. Sticky fix
05. Scroll To Top
06. Set Background Image Color & Mask
07. Global Slider
08. Ajax Contact Form
09. Search Box Popup
10. Popup Sidemenu
11. Magnific Popup
12. Section Position
13. Filter
14. Counter Up
15. Shape Mockup
16. Progress Bar Animation
17. Countdown
18. Image to SVG Code
00. Woocommerce Toggle
00. Right Click Disable
*/
/*=================================
JS Index End
==================================*/
/*
/*---------- 03. Mobile Menu ----------*/
$.fn.thmobilemenu = function (options) {
var opt = $.extend(
{
menuToggleBtn: ".th-menu-toggle",
bodyToggleClass: "th-body-visible",
subMenuClass: "th-submenu",
subMenuParent: "th-item-has-children",
subMenuParentToggle: "th-active",
meanExpandClass: "th-mean-expand",
appendElement: '<span class="th-mean-expand"></span>',
subMenuToggleClass: "th-open",
toggleSpeed: 400,
},
options
);
return this.each(function () {
var menu = $(this);
function menuToggle() {
menu.toggleClass(opt.bodyToggleClass);
var subMenu = "." + opt.subMenuClass;
$(subMenu).each(function () {
if ($(this).hasClass(opt.subMenuToggleClass)) {
$(this).removeClass(opt.subMenuToggleClass);
$(this).css("display", "none");
$(this).parent().removeClass(opt.subMenuParentToggle);
}
});
}
menu.find("li").each(function () {
var submenu = $(this).find("ul");
submenu.addClass(opt.subMenuClass);
submenu.css("display", "none");
submenu.parent().addClass(opt.subMenuParent);
submenu.prev("a").append(opt.appendElement);
submenu.next("a").append(opt.appendElement);
});
function toggleDropDown($element) {
var $parent = $($element).parent();
var $siblings = $parent.siblings();
$siblings.removeClass(opt.subMenuParentToggle);
$siblings.find("ul").slideUp(opt.toggleSpeed).removeClass(opt.subMenuToggleClass);
$parent.toggleClass(opt.subMenuParentToggle);
$($element).next("ul").slideToggle(opt.toggleSpeed).toggleClass(opt.subMenuToggleClass);
}
var expandToggler = "." + opt.meanExpandClass;
$(expandToggler).each(function () {
$(this).on("click", function (e) {
e.preventDefault();
toggleDropDown($(this).parent());
});
});
$(opt.menuToggleBtn).each(function () {
$(this).on("click", function () {
menuToggle();
});
});
menu.on("click", function (e) {
e.stopPropagation();
menuToggle();
});
menu.find("div").on("click", function (e) {
e.stopPropagation();
});
});
};
$(".th-menu-wrapper").thmobilemenu();
/*---------- 04. Sticky fix ----------*/
$(window).scroll(function () {
var topPos = $(this).scrollTop();
if (topPos > 500) {
$('.sticky-wrapper').addClass('sticky');
$('.category-menu').addClass('close-category');
} else {
$('.sticky-wrapper').removeClass('sticky')
$('.category-menu').removeClass('close-category');
}
})
$(".menu-expand").each(function () {
$(this).on("click", function (e) {
e.preventDefault();
$('.category-menu').toggleClass('open-category');
});
});
/*---------- 06. Set Background Image Color & Mask ----------*/
if ($("[data-bg-src]").length > 0) {
$("[data-bg-src]").each(function () {
var src = $(this).attr("data-bg-src");
$(this).css("background-image", "url(" + src + ")");
$(this).removeAttr("data-bg-src").addClass("background-image");
});
}
if ($('[data-bg-color]').length > 0) {
$('[data-bg-color]').each(function () {
var color = $(this).attr('data-bg-color');
$(this).css('background-color', color);
$(this).removeAttr('data-bg-color');
});
};
$('[data-border]').each(function() {
var borderColor = $(this).data('border');
$(this).css('--th-border-color', borderColor);
});
if ($('[data-mask-src]').length > 0) {
$('[data-mask-src]').each(function () {
var mask = $(this).attr('data-mask-src');
$(this).css({
'mask-image': 'url(' + mask + ')',
'-webkit-mask-image': 'url(' + mask + ')'
});
$(this).addClass('bg-mask');
$(this).removeAttr('data-mask-src');
});
};
// Function to add animation classes
function animationProperties() {
$('[data-ani]').each(function () {
var animationName = $(this).data('ani');
$(this).addClass(animationName);
});
$('[data-ani-delay]').each(function () {
var delayTime = $(this).data('ani-delay');
$(this).css('animation-delay', delayTime);
});
}
animationProperties();
/*----------- 09. Ajax Contact Form ----------*/
/*---------- 10. Popup Sidemenu ----------*/
function popupSideMenu($sideMenu, $sideMunuOpen, $sideMenuCls, $toggleCls) {
// Sidebar Popup
$($sideMunuOpen).on('click', function (e) {
e.preventDefault();
$($sideMenu).addClass($toggleCls);
});
// $($sideMenu).on('click', function (e) {
// e.stopPropagation();
// $($sideMenu).removeClass($toggleCls)
// });
var sideMenuChild = $sideMenu + ' > div';
$(sideMenuChild).on('click', function (e) {
e.stopPropagation();
$($sideMenu).addClass($toggleCls)
});
$($sideMenuCls).on('click', function (e) {
e.preventDefault();
e.stopPropagation();
$($sideMenu).removeClass($toggleCls);
});
};
popupSideMenu( ".popup-search-box", ".searchBoxToggler", ".searchClose", "show" );
popupSideMenu('.sidemenu-cart', '.sideMenuToggler', '.sideMenuCls', 'show');
popupSideMenu('.sidemenu-info', '.sideMenuInfo', '.sideMenuCls', 'show');
/*----------- 11. Magnific Popup ----------*/
if ($.fn.magnificPopup) {
/* magnificPopup img view */
$(".popup-image").magnificPopup({
type: "image",
mainClass: 'mfp-zoom-in',
removalDelay: 260,
gallery: {
enabled: true,
},
});
/* magnificPopup video view */
$(".popup-video").magnificPopup({
type: "iframe",
});
/* magnificPopup video view */
$(".popup-content").magnificPopup({
type: "inline",
midClick: true,
});
}
/*----------- 13. Filter ----------*/
if ($.fn.imagesLoaded) {
$(".filter-active").imagesLoaded(function () {
var $filter = ".filter-active",
$filterItem = ".filter-item",
$filterMenu = ".filter-menu-active";
if ($($filter).length > 0) {
var $grid = typeof $.fn.isotope === 'function' ? $($filter).isotope({
itemSelector: $filterItem,
filter: "*",
masonry: {
columnWidth: $filterItem,
},
}) : null;
// filter items on button click
if ($grid) {
$($filterMenu).on("click", "button", function () {
var filterValue = $(this).attr("data-filter");
$grid.isotope({
filter: filterValue,
});
});
}
// Menu Active Class
$($filterMenu).on("click", "button", function (event) {
event.preventDefault();
$(this).addClass("active");
$(this).siblings(".active").removeClass("active");
});
}
$('.load-more-btn').on('click', function() {
var $icon = $(this).find('i');
$icon.addClass('fa-spin-pulse');
setTimeout(function() {
$icon.removeClass('fa-spin-pulse');
}, 1000);
var $button = $(this);
setTimeout(function() {
var $closestLoadMoreActive = $button.prev('.load-more-active');
if ($closestLoadMoreActive.length === 0) {
$closestLoadMoreActive = $button.closest('.container').find('.load-more-active');
}
$closestLoadMoreActive.find('.filter-item.d-none, .accordion-card.d-none').removeClass('d-none');
if ($grid) {
$grid.isotope({
filter: "*",
});
}
}, 700);
});
});
}
/*----------- 14. Counter Up ----------*/
if ($.fn.counterUp) {
$(".counter-number").counterUp({
delay: 10,
time: 1000,
});
}
/*----------- 16. Shape Mockup ----------*/
$.fn.shapeMockup = function () {
var $shape = $(this);
$shape.each(function() {
var $currentShape = $(this),
shapeTop = $currentShape.data('top'),
shapeRight = $currentShape.data('right'),
shapeBottom = $currentShape.data('bottom'),
shapeLeft = $currentShape.data('left');
$currentShape.css({
top: shapeTop,
right: shapeRight,
bottom: shapeBottom,
left: shapeLeft,
}).removeAttr('data-top')
.removeAttr('data-right')
.removeAttr('data-bottom')
.removeAttr('data-left')
.closest('.elementor-widget').css('position', 'static')
.closest('.e-parent').addClass('shape-mockup-wrap');
});
};
if ($('.shape-mockup')) {
$('.shape-mockup').shapeMockup();
}
/*----------- 22. Indicator ----------*/
// Indicator
$.fn.indicator = function () {
// Loop through each .indicator-active element
$(this).each(function () {
var $menu = $(this),
$linkBtn = $menu.find("a"),
$btn = $menu.find("button");
// Append indicator
$menu.append('<span class="indicator"></span>');
var $line = $menu.find(".indicator");
// Check which type button is Available
var $currentBtn;
if ($linkBtn.length) {
$currentBtn = $linkBtn;
} else if ($btn.length) {
$currentBtn = $btn;
}
// On Click Button Class Remove
$currentBtn.on("click", function (e) {
e.preventDefault();
$(this).addClass("active");
$(this).siblings(".active").removeClass("active");
linePos();
});
// Indicator Position
function linePos() {
var $btnActive = $menu.find(".active"),
$height = $btnActive.css("height"),
$width = $btnActive.css("width"),
$top = $btnActive.position().top + "px",
$left = $btnActive.position().left + "px";
$(window).on('resize', function () {
$top = $btnActive.position().top + "px",
$left = $btnActive.position().left + "px";
});
$line.get(0).style.setProperty("--height-set", $height);
$line.get(0).style.setProperty("--width-set", $width);
$line.get(0).style.setProperty("--pos-y", $top);
$line.get(0).style.setProperty("--pos-x", $left);
}
linePos();
$(window).on('resize', function () {
linePos();
});
});
};
if ($(".indicator-active").length) {
$(".indicator-active").indicator();
}
/*----------- Search Masonary ----------*/
if ($.fn.imagesLoaded && $.fn.isotope) {
$('.search-active').imagesLoaded(function () {
var $filter = '.search-active',
$filterItem = '.filter-item';
if ($($filter).length > 0) {
var $grid = $($filter).isotope({
itemSelector: $filterItem,
filter: '*',
// masonry: {
// // use outer width of grid-sizer for columnWidth
// columnWidth: 1
// }
});
};
});
}
}
(function ($) {
/*---------- 01. On Load Function ----------*/
$(window).on("load", function () {
$(".preloader").fadeOut();
$(".th-slider").addClass('fade-ani');
});
/*---------- 02. Preloader ----------*/
if ($(".preloader").length > 0) {
$(".preloaderCls").each(function () {
$(this).on("click", function (e) {
e.preventDefault();
$(".preloader").css("display", "none");
});
});
}
$(document).ready(function () {
setTimeout(function () {
$('#loader').addClass('loaded');
// Once the container has finished, the scroll appears
if ($('#loader').hasClass('loaded')) {
// It is so that once the container is gone, the entire preloader section is deleted
$('#preloader').delay(9000).queue(function () {
$(this).remove();
});
}
}, 3000);
});
// Elementor Frontend Load
$(window).on('elementor/frontend/init', function () {
if (elementorFrontend.isEditMode()) {
elementorFrontend.hooks.addAction('frontend/element_ready/global', function () {
setTimeout(function () {
rakar_content_load_scripts();
$(".th-slider").addClass('fade-ani');
}, 500);
});
}
});
// Window Load
$(window).on('load', function () {
rakar_content_load_scripts();
});
})(jQuery);