File: /var/www/pausfood/wp-content/themes/frutin/assets/js/main.js
function frutin_content_load_scripts() {
var $ = jQuery;
"use strict";
/*---------- 03. Mobile Menu Active ----------*/
$.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); // Select menu
// Menu Show & Hide
function menuToggle() {
menu.toggleClass(opt.bodyToggleClass);
// collapse submenu on menu hide or show
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);
}
});
}
// Class Set Up for every submenu
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);
});
// Toggle Submenu
function toggleDropDown($element) {
if ($($element).next("ul").length > 0) {
$($element).parent().toggleClass(opt.subMenuParentToggle);
$($element).next("ul").slideToggle(opt.toggleSpeed);
$($element).next("ul").toggleClass(opt.subMenuToggleClass);
} else if ($($element).prev("ul").length > 0) {
$($element).parent().toggleClass(opt.subMenuParentToggle);
$($element).prev("ul").slideToggle(opt.toggleSpeed);
$($element).prev("ul").toggleClass(opt.subMenuToggleClass);
}
}
// Submenu toggle Button
var expandToggler = "." + opt.meanExpandClass;
$(expandToggler).each(function () {
$(this).on("click", function (e) {
e.preventDefault();
toggleDropDown($(this).parent());
});
});
// Menu Show & Hide On Toggle Btn click
$(opt.menuToggleBtn).each(function () {
$(this).on("click", function () {
menuToggle();
});
});
// Hide Menu On out side click
menu.on("click", function (e) {
e.stopPropagation();
menuToggle();
});
// Stop Hide full menu on menu click
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');
});
});
/*---------- 05. Scroll To Top ----------*/
// progressAvtivation
if ($('.scroll-top').length > 0) {
var scrollTopbtn = document.querySelector('.scroll-top');
var progressPath = document.querySelector('.scroll-top path');
var pathLength = progressPath.getTotalLength();
progressPath.style.transition = progressPath.style.WebkitTransition = 'none';
progressPath.style.strokeDasharray = pathLength + ' ' + pathLength;
progressPath.style.strokeDashoffset = pathLength;
progressPath.getBoundingClientRect();
progressPath.style.transition = progressPath.style.WebkitTransition = 'stroke-dashoffset 10ms linear';
var updateProgress = function () {
var scroll = $(window).scrollTop();
var height = $(document).height() - $(window).height();
var progress = pathLength - (scroll * pathLength / height);
progressPath.style.strokeDashoffset = progress;
}
updateProgress();
$(window).scroll(updateProgress);
var offset = 50;
var duration = 750;
jQuery(window).on('scroll', function() {
if (jQuery(this).scrollTop() > offset) {
jQuery(scrollTopbtn).addClass('show');
} else {
jQuery(scrollTopbtn).removeClass('show');
}
});
jQuery(scrollTopbtn).on('click', function(event) {
event.preventDefault();
jQuery('html, body').animate({scrollTop: 0}, duration);
return false;
})
}
/*---------- 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');
});
};
/*----------- 07. Global Slider ---------------------------------------------------------*/
$('.th-slider').each(function () {
var thSlider = $(this);
var settings = $(this).data('slider-options');
// Store references to the navigation Slider
var prevArrow = thSlider.find('.slider-prev');
var nextArrow = thSlider.find('.slider-next');
var paginationEl = thSlider.find('.slider-pagination');
var paginationType = settings['paginationType'] ? settings['paginationType'] : 'bullets';
var autoplayconditon = settings['autoplay'];
var sliderDefault = {
slidesPerView: 1,
spaceBetween: settings['spaceBetween'] ? settings['spaceBetween'] : 24,
loop: settings['loop'] == false ? false : true,
speed: settings['speed'] ? settings['speed'] : 1000,
autoplay: autoplayconditon ? autoplayconditon : {delay: 6000, disableOnInteraction: false},
navigation: {
nextEl: nextArrow.get(0),
prevEl: prevArrow.get(0),
},
pagination: {
el: paginationEl.get(0),
type: paginationType,
clickable: true,
renderBullet: function (index, className) {
return '<span class="' + className + '" aria-label="Go to Slide ' + (index + 1) + '"></span>';
},
formatFractionCurrent: function (number) {
return ('0' + number).slice(-2);
},
formatFractionTotal: function (number) {
return ('0' + number).slice(-2);
},
renderFraction: function (currentClass, totalClass) {
return '<span class="' + currentClass + '"></span>' +
' / ' +
'<span class="' + totalClass + '"></span>';
}
},
on: {
slideChange: function() {
setTimeout(function () {
swiper.params.mousewheel.releaseOnEdges = false;
}, 500);
},
reachEnd: function() {
setTimeout(function () {
swiper.params.mousewheel.releaseOnEdges = true;
}, 750);
}
}
};
var options = JSON.parse(thSlider.attr('data-slider-options'));
options = $.extend({}, sliderDefault, options);
var swiper = new Swiper(thSlider.get(0), options); // Assign the swiper variable
if ($('.slider-area').length > 0) {
$('.slider-area').closest(".container").parent().addClass("arrow-wrap");
}
});
// 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();
// Add click event handlers for external slider arrows based on data attributes
$('[data-slider-prev], [data-slider-next]').on('click', function () {
var sliderSelector = $(this).data('slider-prev') || $(this).data('slider-next');
var targetSlider = $(sliderSelector);
if (targetSlider.length) {
var swiper = targetSlider[0].swiper;
if (swiper) {
if ($(this).data('slider-prev')) {
swiper.slidePrev();
} else {
swiper.slideNext();
}
}
}
});
/* Slider End Here ------------------------------------------------------------------------*/
/*---------- 10. Search Box Popup ----------*/
function popupSarchBox($searchBox, $searchOpen, $searchCls, $toggleCls) {
$($searchOpen).on("click", function (e) {
e.preventDefault();
$($searchBox).addClass($toggleCls);
});
$($searchBox).on("click", function (e) {
e.stopPropagation();
$($searchBox).removeClass($toggleCls);
});
$($searchBox)
.find("form")
.on("click", function (e) {
e.stopPropagation();
$($searchBox).addClass($toggleCls);
});
$($searchCls).on("click", function (e) {
e.preventDefault();
e.stopPropagation();
$($searchBox).removeClass($toggleCls);
});
}
popupSarchBox( ".popup-search-box", ".searchBoxToggler", ".searchClose", "show" );
/*---------- 11. 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('.sidemenu-info', '.sideMenuInfo', '.sideMenuCls', 'show');
popupSideMenu('.sidemenu-cart', '.sideMenuCart', '.sideMenuCls', 'show');
/*----------- 14. Search Masonary ----------*/
$(".filter-active").imagesLoaded(function () {
var $filter = ".filter-active",
$filterItem = ".filter-item",
$filterMenu = ".filter-menu-active";
if ($($filter).length > 0) {
var $grid = $($filter).isotope({
itemSelector: $filterItem,
filter: "*",
percentPosition: true,
masonry: {
columnWidth: $filterItem,
},
});
// filter items on button click
$($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");
});
}
});
$('.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
// }
});
};
});
$(".masonary-active, .woocommerce-Reviews .comment-list").imagesLoaded(function () {
var $filter = ".masonary-active, .woocommerce-Reviews .comment-list",
$filterItem = ".filter-item, .woocommerce-Reviews .comment-list li";
if ($($filter).length > 0) {
$($filter).isotope({
itemSelector: $filterItem,
filter: "*",
masonry: {
// use outer width of grid-sizer for columnWidth
columnWidth: 1,
},
});
}
$('[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) {
$($filter).isotope({
filter: "*",
});
});
});
/*----------- 14. Counter Up ----------*/
$(".counter-number").counterUp({
delay: 10,
time: 1000,
});
$.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();
}
/*----------- 12. Magnific Popup ----------*/
/* 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,
});
$(".popup-content").on("click", function () {
$(".slick-slider").slick("refresh");
});
/*---------- 15. Image Zoom ----------*/
function magnify(imgSelector, zoom) {
$(imgSelector).each(function () {
var img = $(this);
var glass, w, h, bw;
/* Create magnifier glass: */
glass = $("<div class='img-magnifier-glass'></div>");
/* Insert magnifier glass: */
img.parent().prepend(glass);
/* Set background properties for the magnifier glass: */
glass.css({
backgroundImage: "url('" + img.attr("src") + "')",
backgroundRepeat: "no-repeat",
backgroundSize: img.width() * zoom + "px " + img.height() * zoom + "px",
});
bw = 3;
w = glass.width() / 2;
h = glass.height() / 2;
/* Execute a function when someone moves the magnifier glass over the image: */
glass.on("mousemove", moveMagnifier);
img.on("mousemove", moveMagnifier);
/* and also for touch screens: */
glass.on("touchmove", moveMagnifier);
img.on("touchmove", moveMagnifier);
function moveMagnifier(e) {
var pos, x, y;
/* Prevent any other actions that may occur when moving over the image */
e.preventDefault();
/* Get the cursor's x and y positions: */
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
/* Prevent the magnifier glass from being positioned outside the image: */
if (x > img.width() - (w / zoom)) {
x = img.width() - (w / zoom);
}
if (x < w / zoom) {
x = w / zoom;
}
if (y > img.height() - (h / zoom)) {
y = img.height() - (h / zoom);
}
if (y < h / zoom) {
y = h / zoom;
}
/* Set the position of the magnifier glass: */
glass.css({
left: (x - w) + "px",
top: (y - h) + "px",
backgroundPosition: "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px",
});
}
function getCursorPos(e) {
var a, x = 0, y = 0;
e = e || window.event;
/* Get the x and y positions of the image: */
a = img[0].getBoundingClientRect();
/* Calculate the cursor's x and y coordinates, relative to the image: */
x = e.pageX - a.left;
y = e.pageY - a.top;
/* Consider any page scrolling: */
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return { x: x, y: y };
}
});
}
magnify(".magnified img", 2);
/*---------- 14. Section Position ----------*/
// Interger Converter
function convertInteger(str) {
return parseInt(str, 10);
}
$.fn.sectionPosition = function (mainAttr, posAttr) {
$(this).each(function () {
var section = $(this);
function setPosition() {
var sectionHeight = Math.floor(section.height() / 2), // Main Height of section
posData = section.attr(mainAttr), // where to position
posFor = section.attr(posAttr), // On Which section is for positioning
topMark = "top-half", // Pos top
bottomMark = "bottom-half", // Pos Bottom
parentPT = convertInteger($(posFor).css("padding-top")), // Default Padding of parent
parentPB = convertInteger($(posFor).css("padding-bottom")); // Default Padding of parent
if (posData === topMark) {
$(posFor).css(
"padding-bottom",
parentPB + sectionHeight + "px"
);
section.css("margin-top", "-" + sectionHeight + "px");
} else if (posData === bottomMark) {
$(posFor).css(
"padding-top",
parentPT + sectionHeight + "px"
);
section.css("margin-bottom", "-" + sectionHeight + "px");
}
}
setPosition(); // Set Padding On Load
});
};
var postionHandler = "[data-sec-pos]";
if ($(postionHandler).length) {
$(postionHandler).imagesLoaded(function () {
$(postionHandler).sectionPosition("data-sec-pos", "data-pos-for");
});
}
/*----------- 16. Progress Bar Animation ----------*/
$('.progress-bar').waypoint(function() {
$('.progress-bar').css({
animation: "animate-positive 1.8s",
opacity: "1"
});
}, { offset: '75%' });
/*----------- 19. Countdown ----------*/
$.fn.countdown = function () {
$(this).each(function () {
var $counter = $(this),
countDownDate = new Date($counter.data("offer-date")).getTime(), // Set the date we're counting down toz
exprireCls = "expired";
// Finding Function
function s$(element) {
return $counter.find(element);
}
// Update the count down every 1 second
var counter = setInterval(function () {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor(
(distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
);
var minutes = Math.floor(
(distance % (1000 * 60 * 60)) / (1000 * 60)
);
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Check If value is lower than ten, so add zero before number
days < 10 ? (days = "0" + days) : null;
hours < 10 ? (hours = "0" + hours) : null;
minutes < 10 ? (minutes = "0" + minutes) : null;
seconds < 10 ? (seconds = "0" + seconds) : null;
// If the count down is over, write some text
if (distance < 0) {
clearInterval(counter);
$counter.addClass(exprireCls);
$counter.find(".message").css("display", "block");
} else {
// Output the result in elements
s$(".day").html(days);
s$(".hour").html(hours);
s$(".minute").html(minutes);
s$(".seconds").html(seconds);
}
}, 1000);
});
};
if ($(".counter-list").length) {
$(".counter-list").countdown();
}
/*---------- 14. Image to SVG Code ----------*/
const cache = {};
$.fn.inlineSvg = function fnInlineSvg() {
this.each(imgToSvg);
return this;
};
function imgToSvg() {
const $img = $(this);
const src = $img.attr("src");
// fill cache by src with promise
if (!cache[src]) {
const d = $.Deferred();
$.get(src, (data) => {
d.resolve($(data).find("svg"));
});
cache[src] = d.promise();
}
// replace img with svg when cached promise resolves
cache[src].then((svg) => {
const $svg = $(svg).clone();
if ($img.attr("id")) $svg.attr("id", $img.attr("id"));
if ($img.attr("class")) $svg.attr("class", $img.attr("class"));
if ($img.attr("style")) $svg.attr("style", $img.attr("style"));
if ($img.attr("width")) {
$svg.attr("width", $img.attr("width"));
if (!$img.attr("height")) $svg.removeAttr("height");
}
if ($img.attr("height")) {
$svg.attr("height", $img.attr("height"));
if (!$img.attr("width")) $svg.removeAttr("width");
}
$svg.insertAfter($img);
$img.trigger("svgInlined", $svg[0]);
$img.remove();
});
}
$(".svg-img").inlineSvg();
/*----------- 21. Price Slider ----------*/
$(".price_slider").slider({
range: true,
min: 10,
max: 100,
values: [10, 75],
slide: function (event, ui) {
$(".from").text("$" + ui.values[0]);
$(".to").text("$" + ui.values[1]);
}
});
$(".from").text("$" + $(".price_slider").slider("values", 0));
$(".to").text("$" + $(".price_slider").slider("values", 1));
/*----------- 00. Woocommerce Toggle ----------*/
// Ship To Different Address
$("#ship-to-different-address-checkbox").on("change", function () {
if ($(this).is(":checked")) {
$("#ship-to-different-address")
.next(".shipping_address")
.slideDown();
} else {
$("#ship-to-different-address").next(".shipping_address").slideUp();
}
});
// Woocommerce Payment Toggle
$('.wc_payment_methods input[type="radio"]:checked')
.siblings(".payment_box")
.show();
$('.wc_payment_methods input[type="radio"]').each(function () {
$(this).on("change", function () {
$(".payment_box").slideUp();
$(this).siblings(".payment_box").slideDown();
});
});
// Woocommerce Rating Toggle
$(".rating-select .stars a").each(function () {
$(this).on("click", function (e) {
e.preventDefault();
$(this).siblings().removeClass("active");
$(this).parent().parent().addClass("selected");
$(this).addClass("active");
});
});
// Quantity Plus Minus ---------------------------
/*---------- Quantity Added ----------*/
$(document).on('click', '.quantity-plus, .quantity-minus', function(e) {
e.preventDefault();
// Get current quantity values
var qty = $(this).closest('.quantity, .product-quantity').find('.qty-input');
var val = parseFloat(qty.val());
var max = parseFloat(qty.attr('max'));
var min = parseFloat(qty.attr('min'));
var step = parseFloat(qty.attr('step'));
// Change the value if plus or minus
if ($(this).is('.quantity-plus')) {
if (max && (max <= val)) {
qty.val(max);
} else {
qty.val(val + step);
}
} else {
if (min && (min >= val)) {
qty.val(min);
} else if (val > 0) {
qty.val(val - step);
}
}
$('.cart_table button[name="update_cart"]').prop('disabled', false);
});
}
(function ($) {
/*---------- 01. On Load Function ----------*/
$(window).on("load", function () {
$(".preloader").fadeOut();
});
/*---------- 02. Preloader ----------*/
if ($(".preloader").length > 0) {
$(".preloaderCls").each(function () {
$(this).on("click", function (e) {
e.preventDefault();
$(".preloader").css("display", "none");
});
});
}
/*---------- Sticky Footer ----------*/
function checkHeight() {
if ($('body').height() < $(window).height()) {
$('.footer-sitcky').addClass('sticky-footer');
} else {
$('.footer-sitcky').removeClass('sticky-footer');
}
}
$(window).on('load resize', function () {
checkHeight();
});
// Elementor Frontend Load
$(window).on('elementor/frontend/init', function () {
if (elementorFrontend.isEditMode()) {
elementorFrontend.hooks.addAction('frontend/element_ready/global', function () {
setTimeout(function () {
frutin_content_load_scripts();
}, 500);
});
}
});
// Window Load
$(window).on('load', function () {
frutin_content_load_scripts();
});
/*----------- 00. Right Click Disable ----------*/
// window.addEventListener('contextmenu', function (e) {
// // do something here...
// e.preventDefault();
// }, false);
/*----------- 00. Inspect Element Disable ----------*/
// document.onkeydown = function (e) {
// if (event.keyCode == 123) {
// return false;
// }
// if (e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {
// return false;
// }
// if (e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)) {
// return false;
// }
// if (e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {
// return false;
// }
// if (e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {
// return false;
// }
// }
})(jQuery);