(function ($) {
"use strict";
let DIRECTION = null;
function direction() {
if (DIRECTION === null) {
DIRECTION = getComputedStyle(document.body).direction;
}
return DIRECTION;
}
function isRTL() {
return direction() === 'rtl';
}
/*
// product tabs
*/
$(function () {
$('.product-tabs').each(function (i, element) {
$('.product-tabs__list', element).on('click', '.product-tabs__item', function (event) {
event.preventDefault();
const tab = $(this);
const content = $('.product-tabs__pane' + $(this).attr('href'), element);
if (content.length) {
$('.product-tabs__item').removeClass('product-tabs__item--active');
tab.addClass('product-tabs__item--active');
$('.product-tabs__pane').removeClass('product-tabs__pane--active');
content.addClass('product-tabs__pane--active');
}
});
const currentTab = $('.product-tabs__item--active', element);
const firstTab = $('.product-tabs__item:first', element);
if (currentTab.length) {
currentTab.trigger('click');
} else {
firstTab.trigger('click');
}
});
});
/*
// block slideshow
*/
$(function() {
$('.block-slideshow-dots-true .owl-carousel').owlCarousel({
autoplay:true,
autoplayTimeout:7000,
autoplayHoverPause:true,
items: 1,
nav: true,
navText: [
'',
''
],
dots: true,
loop: true,
rtl: isRTL()
});
});
/*
// block slideshow
*/
$(function() {
$('.block-slideshow-dots-false .owl-carousel').owlCarousel({
autoplay:true,
autoplayTimeout:7000,
autoplayHoverPause:true,
items: 1,
nav: true,
navText: [
'',
''
],
dots: false,
loop: true,
rtl: isRTL()
});
});
/*
// block products carousel static
*/
$(function() {
$('.block-products-carousel__slider .owl-carousel').owlCarousel({
nav: true,
navText: [
'',
''
],
dots: false,
loop: true,
rtl: isRTL(),
responsive: {
1200: {items: 5},
992: {items: 4},
768: {items: 3},
0: {items: 2}
}
});
});
/*
// block products carousel static
*/
$(function() {
$('.block-products-carousel__slider-no-loop .owl-carousel').owlCarousel({
nav: true,
navText: [
'',
''
],
dots: false,
loop: false,
rtl: isRTL(),
responsive: {
1200: {items: 5},
992: {items: 4},
768: {items: 3},
0: {items: 2}
}
});
});
/*
// block products carousel autoplay
*/
$(function() {
$('.block-products-carousel__slider-autoplay .owl-carousel').owlCarousel({
autoplay:true,
autoplayTimeout:2000,
autoplayHoverPause:true,
nav: true,
navText: [
'',
''
],
dots: false,
loop: true,
rtl: isRTL(),
responsive: {
1200: {items: 5},
992: {items: 4},
768: {items: 3},
0: {items: 2}
}
});
});
/*
// block products carousel without autoplay
*/
$(function() {
$('.block-products-carousel__slider-no-loop-autoplay .owl-carousel').owlCarousel({
autoplay:true,
autoplayTimeout:2000,
autoplayHoverPause:true,
nav: true,
navText: [
'',
''
],
dots: false,
loop: false,
rtl: isRTL(),
responsive: {
1200: {items: 5},
992: {items: 4},
768: {items: 3},
0: {items: 2}
}
});
});
/*
// block products carousel static without loop and nav
*/
$(function() {
$('.block-products-carousel__no-loop-no-nav .owl-carousel').owlCarousel({
nav: false,
dots: false,
loop: false,
rtl: isRTL(),
responsive: {
1200: {items: 5},
992: {items: 4},
768: {items: 3},
0: {items: 2}
}
});
});
/*
// block brands carousel
*/
$(function() {
$('.block-brands__slider-autoplay .owl-carousel').owlCarousel({
autoplay:true,
autoplayTimeout:2000,
autoplayHoverPause:true,
nav: true,
navText: [
'',
''
],
dots: false,
loop: true,
rtl: isRTL(),
responsive: {
1200: {items: 6},
992: {items: 5},
768: {items: 4},
576: {items: 3},
0: {items: 2}
}
});
});
/*
// block brands carousel
*/
$(function() {
$('.block-brands__slider .owl-carousel').owlCarousel({
nav: true,
navText: [
'',
''
],
dots: false,
loop: true,
rtl: isRTL(),
responsive: {
1200: {items: 6},
992: {items: 5},
768: {items: 4},
576: {items: 3},
0: {items: 2}
}
});
});
/*
// block posts carousel
*/
$(function() {
$('.block-posts').each(function() {
const layout = $(this).data('layout');
const options = {
margin: 30,
nav: false,
dots: false,
loop: true,
rtl: isRTL()
};
const layoutOptions = {
'grid-nl': {
responsive: {
992: {items: 3},
768: {items: 2},
0: {items: 1}
}
},
'list-sm': {
responsive: {
992: {items: 2},
0: {items: 1}
}
}
};
const owl = $('.block-posts__slider .owl-carousel');
owl.owlCarousel($.extend({}, options, layoutOptions[layout]));
$(this).find('.block-header__arrow--left').on('click', function() {
owl.trigger('prev.owl.carousel', [500]);
});
$(this).find('.block-header__arrow--right').on('click', function() {
owl.trigger('next.owl.carousel', [500]);
});
});
});
/*
// teammates
*/
$(function() {
$('.teammates .owl-carousel').owlCarousel({
nav: false,
dots: true,
rtl: isRTL(),
responsive: {
768: {items: 3, margin: 32},
380: {items: 2, margin: 24},
0: {items: 1}
}
});
});
/*
// quickview
*/
const quickview = {
cancelPreviousModal: function() {},
clickHandler: function() {
const modal = $('#quickview-modal');
const button = $(this);
const doubleClick = button.is('.product-card__quickview--preload');
quickview.cancelPreviousModal();
if (doubleClick) {
return;
}
button.addClass('product-card__quickview--preload');
let xhr = null;
// timeout ONLY_FOR_DEMO!
const timeout = setTimeout(function() {
xhr = $.ajax({
url: 'quickview.html',
success: function(data) {
quickview.cancelPreviousModal = function() {};
button.removeClass('product-card__quickview--preload');
modal.find('.modal-content').html(data);
modal.find('.quickview__close').on('click', function() {
modal.modal('hide');
});
modal.modal('show');
}
});
}, 1000);
quickview.cancelPreviousModal = function() {
button.removeClass('product-card__quickview--preload');
if (xhr) {
xhr.abort();
}
// timeout ONLY_FOR_DEMO!
clearTimeout(timeout);
};
}
};
$(function () {
const modal = $('#quickview-modal');
modal.on('shown.bs.modal', function() {
modal.find('.product').each(function () {
const gallery = $(this).find('.product-gallery');
if (gallery.length > 0) {
initProductGallery(gallery[0], $(this).data('layout'));
}
});
$('.input-number', modal).customNumber();
});
$('.product-card__quickview').on('click', function() {
quickview.clickHandler.apply(this, arguments);
});
});
/*
// products carousel
*/
$(function() {
$('.block-products-carousel').each(function() {
const layout = $(this).data('layout');
const options = {
items: 4,
margin: 14,
nav: false,
dots: false,
loop: true,
stagePadding: 1,
rtl: isRTL()
};
const layoutOptions = {
'grid-4': {
responsive: {
1200: {items: 4, margin: 14},
992: {items: 4, margin: 10},
768: {items: 3, margin: 10},
576: {items: 2, margin: 10},
475: {items: 2, margin: 10},
0: {items: 1}
}
},
'grid-4-sm': {
responsive: {
1200: {items: 4, margin: 14},
992: {items: 3, margin: 10},
768: {items: 3, margin: 10},
576: {items: 2, margin: 10},
475: {items: 2, margin: 10},
0: {items: 1}
}
},
'grid-5': {
responsive: {
1200: {items: 5, margin: 12},
992: {items: 4, margin: 10},
768: {items: 3, margin: 10},
576: {items: 2, margin: 10},
475: {items: 2, margin: 10},
0: {items: 1}
}
},
'horizontal': {
items: 3,
responsive: {
1200: {items: 3, margin: 14},
992: {items: 3, margin: 10},
768: {items: 2, margin: 10},
576: {items: 1},
475: {items: 1},
0: {items: 1}
}
},
};
const owl = $('.owl-carousel', this);
let cancelPreviousTabChange = function() {};
owl.owlCarousel($.extend({}, options, layoutOptions[layout]));
$(this).find('.block-header__group').on('click', function(event) {
const block = $(this).closest('.block-products-carousel');
event.preventDefault();
if ($(this).is('.block-header__group--active')) {
return;
}
cancelPreviousTabChange();
loading(true, true);
$(this).closest('.block-header__groups-list').find('.block-header__group--active').removeClass('block-header__group--active');
$(this).addClass('block-header__group--active');
$.ajax({
url: URL_SITE + 'components/products-carousel-column.php?id_component=' + $(this).attr('data-id-component') + '&tab=' + $(this).attr('data-tab'),
type: 'GET',
beforeSend: function beforeSend() {
},
success: function success(result) {
block.find('.owl-carousel').trigger('replace.owl.carousel', result).trigger('refresh.owl.carousel');
loading(false, true);
return;
}
});
cancelPreviousTabChange = function() {
cancelPreviousTabChange = function() {};
};
});
$(this).find('.block-header__arrow--left').on('click', function() {
owl.trigger('prev.owl.carousel', [500]);
});
$(this).find('.block-header__arrow--right').on('click', function() {
owl.trigger('next.owl.carousel', [500]);
});
});
});
/*
// product gallery
*/
const initProductGallery = function(element, layout) {
layout = layout !== undefined ? layout : 'standard';
const options = {
nav: true,
navText: [
'',
''
],
dots: false,
loop: false,
margin: 10,
rtl: isRTL()
};
const layoutOptions = {
standard: {
responsive: {
1200: {items: 5},
992: {items: 4},
768: {items: 3},
480: {items: 5},
380: {items: 4},
0: {items: 3}
}
},
sidebar: {
responsive: {
768: {items: 4},
480: {items: 5},
380: {items: 4},
0: {items: 3}
}
},
columnar: {
responsive: {
768: {items: 4},
480: {items: 5},
380: {items: 4},
0: {items: 3}
}
},
quickview: {
responsive: {
1200: {items: 5},
768: {items: 4},
480: {items: 5},
380: {items: 4},
0: {items: 3}
}
}
};
const gallery = $(element);
const image = gallery.find('.product-gallery__featured .owl-carousel');
const carousel = gallery.find('.product-gallery__carousel .owl-carousel');
image
.owlCarousel({items: 1, dots: false, rtl: isRTL()})
.on('changed.owl.carousel', syncPosition);
carousel
.on('initialized.owl.carousel', function () {
carousel.find('.product-gallery__carousel-item').eq(0).addClass('product-gallery__carousel-item--active');
})
.owlCarousel($.extend({}, options, layoutOptions[layout]));
carousel.on('click', '.owl-item', function(e){
e.preventDefault();
image.data('owl.carousel').to($(this).index(), 300, true);
});
gallery.find('.product-gallery__zoom').on('click', function() {
openPhotoSwipe(image.find('.owl-item.active').index());
});
image.on('click', '.owl-item a', function(event) {
event.preventDefault();
openPhotoSwipe($(this).closest('.owl-item').index());
});
function getIndexDependOnDir(index) {
// we need to invert index id direction === 'rtl' because photoswipe do not support rtl
if (isRTL()) {
return image.find('.owl-item img').length - 1 - index;
}
return index;
}
function openPhotoSwipe(index) {
const photoSwipeImages = image.find('.owl-item a').toArray().map(function(element) {
const img = $(element).find('img')[0];
const width = $(element).data('width') || img.naturalWidth;
const height = $(element).data('height') || img.naturalHeight;
return {
src: element.href,
msrc: element.href,
w: width,
h: height,
};
});
if (isRTL()) {
photoSwipeImages.reverse();
}
const photoSwipeOptions = {
getThumbBoundsFn: function(index) {
const imageElements = image.find('.owl-item img').toArray();
const dirDependentIndex = getIndexDependOnDir(index);
if (!imageElements[dirDependentIndex]) {
return null;
}
const imageElement = imageElements[dirDependentIndex];
const pageYScroll = window.pageYOffset || document.documentElement.scrollTop;
const rect = imageElement.getBoundingClientRect();
return {x: rect.left, y: rect.top + pageYScroll, w: rect.width};
},
index: getIndexDependOnDir(index),
bgOpacity: .9,
history: false
};
const photoSwipeGallery = new PhotoSwipe($('.pswp')[0], PhotoSwipeUI_Default, photoSwipeImages, photoSwipeOptions);
photoSwipeGallery.listen('beforeChange', function() {
image.data('owl.carousel').to(getIndexDependOnDir(photoSwipeGallery.getCurrentIndex()), 0, true);
});
photoSwipeGallery.init();
}
function syncPosition (el) {
let current = el.item.index;
carousel
.find('.product-gallery__carousel-item')
.removeClass('product-gallery__carousel-item--active')
.eq(current)
.addClass('product-gallery__carousel-item--active');
const onscreen = carousel.find('.owl-item.active').length - 1;
const start = carousel.find('.owl-item.active').first().index();
const end = carousel.find('.owl-item.active').last().index();
if (current > end) {
carousel.data('owl.carousel').to(current, 100, true);
}
if (current < start) {
carousel.data('owl.carousel').to(current - onscreen, 100, true);
}
}
};
$(function() {
$('.product').each(function () {
const gallery = $(this).find('.product-gallery');
if (gallery.length > 0) {
initProductGallery(gallery[0], $(this).data('layout'));
}
});
});
/*
// Checkout payment methods
*/
$(function () {
$('[name="id_forma_pagamento"]').on('change', function () {
const currentItem = $(this).closest('.payment-methods__item');
$(this).closest('.payment-methods__list').find('.payment-methods__item').each(function (i, element) {
const links = $(element);
const linksContent = links.find('.payment-methods__item-container');
if (element !== currentItem[0]) {
const startHeight = linksContent.height();
linksContent.css('height', startHeight + 'px');
links.removeClass('payment-methods__item--active');
linksContent.css('height', '');
} else {
const startHeight = linksContent.height();
links.addClass('payment-methods__item--active');
const endHeight = linksContent.height();
// linksContent.css('height', startHeight + 'px');
// linksContent.css('height', endHeight + 'px');
}
});
});
$('.payment-methods__item-container').on('transitionend', function (event) {
if (event.originalEvent.propertyName === 'height') {
$(this).css('height', '');
}
});
});
/*
// collapse
*/
$(function () {
$('[data-collapse]').each(function (i, element) {
const collapse = element;
const openedClass = $(element).data('collapse-opened-class');
$('[data-collapse-trigger]', collapse).on('click', function () {
const item = $(this).closest('[data-collapse-item]');
const content = item.children('[data-collapse-content]');
const itemParents = item.parents();
itemParents.slice(0, itemParents.index(collapse) + 1).filter('[data-collapse-item]').css('height', '');
if (item.is('.' + openedClass)) {
const startHeight = content.height();
content.css('height', startHeight + 'px');
item.removeClass(openedClass);
content.css('height', '');
} else {
const startHeight = content.height();
item.addClass(openedClass);
const endHeight = content.height();
content.css('height', startHeight + 'px');
content.css('height', endHeight + 'px');
}
});
$('[data-collapse-content]', collapse).on('transitionend', function (event) {
if (event.originalEvent.propertyName === 'height') {
$(this).css('height', '');
}
});
});
});
/*
// price filter
*/
$(function () {
$('.filter-price').each(function (i, element) {
const min = $(element).data('min');
const max = $(element).data('max');
const from = $(element).data('from');
const to = $(element).data('to');
const slider = element.querySelector('.filter-price__slider');
noUiSlider.create(slider, {
start: [from, to],
connect: true,
direction: isRTL() ? 'rtl' : 'ltr',
range: {
'min': min,
'max': max
}
});
const titleValues = [
$(element).find('.filter-price__min-value')[0],
$(element).find('.filter-price__max-value')[0]
];
slider.noUiSlider.on('update', function (values, handle) {
titleValues[handle].innerHTML = values[handle];
});
});
});
/*
// mobilemenu
*/
$(function () {
const body = $('body');
const mobilemenu = $('.mobilemenu');
if (mobilemenu.length) {
const open = function() {
const bodyWidth = body.width();
mobilemenu.addClass('mobilemenu--open');
};
const close = function() {
mobilemenu.removeClass('mobilemenu--open');
};
$('.mobile-header__menu-button').on('click', function() {
open();
});
$('.mobilemenu__backdrop, .mobilemenu__close').on('click', function() {
close();
});
}
});
/*
// tooltips
*/
$(function () {
$('[data-toggle="tooltip"]').tooltip({trigger: 'hover'});
});
/*
// layout switcher
*/
$(function () {
$('.layout-switcher__button').on('click', function() {
const layoutSwitcher = $(this).closest('.layout-switcher');
const productsView = $(this).closest('.products-view');
const productsList = productsView.find('.products-list');
layoutSwitcher.find('.layout-switcher__button').removeClass('layout-switcher__button--active');
$(this).addClass('layout-switcher__button--active');
// productsList.attr('data-layout', $(this).attr('data-layout'));
// productsList.attr('data-with-features', $(this).attr('data-with-features'));
if($(this).attr('data-layout') == 'list'){
$('.products-view__layout-grid').hide();
$('.products-view__layout-list').show();
if(isOnScreen($('.btn-fixo')) || isOnScreen($('.site-footer__logo'))){
$('.btn-flutuante').hide();
}
else{
$('.btn-flutuante').show();
}
}
else if($(this).attr('data-layout') == 'grid'){
$('.products-view__layout-grid').show();
$('.products-view__layout-list').hide();
}
$.ajax({
url: URL_SITE + 'controllers/api-controller.php?acao=layout&layout=' + $(this).attr('data-layout'),
type: 'GET',
success: function success(result) {
return true;
}
});
});
});
/*
// offcanvas filters
*/
$(function () {
const body = $('body');
const blockSidebar = $('.block-sidebar');
const mobileMedia = matchMedia('(max-width: 991px)');
if (blockSidebar.length) {
const open = function() {
if (blockSidebar.is('.block-sidebar--offcanvas--mobile') && !mobileMedia.matches) {
return;
}
const bodyWidth = body.width();
// body.css('overflow', 'hidden');
// body.css('paddingRight', (body.width() - bodyWidth) + 'px');
blockSidebar.addClass('block-sidebar--open');
};
const close = function() {
// body.css('overflow', 'auto');
// body.css('paddingRight', '');
blockSidebar.removeClass('block-sidebar--open');
};
const onChangeMedia = function() {
if (blockSidebar.is('.block-sidebar--open.block-sidebar--offcanvas--mobile') && !mobileMedia.matches) {
close();
}
};
$('.filters-button').on('click', function() {
open();
});
$('.block-sidebar__backdrop, .block-sidebar__close').on('click', function() {
close();
});
if (mobileMedia.addEventListener) {
mobileMedia.addEventListener('change', onChangeMedia);
} else {
mobileMedia.addListener(onChangeMedia);
}
}
});
})(jQuery);