/**
* Script for our theme
* Written By: ThemeMove
*/
var tmRobin;
var md = new MobileDetect( window.navigator.userAgent ); // Mobile Detect
(
function( $ ) {
'use strict';
tmRobin = (
function() {
var $window = $( window ),
$document = $( document ),
$body = $( 'body' );
return {
init: function() {
this.stickyHeader();
this.scrollToTop();
this.blog();
this.switcher();
this.siteMenu();
this.mobileMenu();
this.search();
this.wishlist();
this.miniCart();
this.shop();
this.quickView();
this.notification();
this.compare();
this.ajaxAddToCart();
this.ajaxLoadMore();
this.product();
this.crossSells();
this.swatches();
this.initQuantityFields();
this.imageCarousel();
this.testimonialCarousel();
this.countdown();
this.productCategoriesShortcode();
this.productsShortCode();
this.vcTabs();
this.vcRow();
this.cookie();
this.brand();
this.videoPopup();
},
// Fixed Header
stickyHeader: function() {
if ( !tmRobinConfigs.sticky_header ) {
return;
}
var $header = $( '.site-header' );
if ( !$header.length ) {
return;
}
var $topBar = $( '.topbar' ),
$logo = $header.find( '.site-logo' ),
$menu = $header.find( '.site-menu' ),
$tools = $header.find( '.header-tools' ),
startOffset = $header.outerHeight();
var stickyHeaderHTML = '
';
// create HTML for stickyHeader
$header.before( stickyHeaderHTML );
var $stickyHeader = $( '.sticky-header' );
if ( $logo.length ) {
var $img = $stickyHeader.find( '.site-logo img' );
if ( $img.length ) {
var o_logo = $img.attr( 'data-o_logo' );
if ( typeof o_logo !== 'undefined' ) {
$img.attr( 'src', o_logo );
}
}
}
if ( $topBar.length ) {
startOffset += $topBar.outerHeight() - 30;
}
if ( $( '#wpadminbar' ).length ) {
startOffset += $( '#wpadminbar' ).outerHeight();
}
$window.on( 'scroll', function() {
var currentScroll = $( this ).scrollTop(),
$realTools = $( '.site-header:not(.sticky-header)' ).find( '.header-tools' ),
$stickyTools = $stickyHeader.find( '.header-tools' );
if ( currentScroll > startOffset ) {
$stickyHeader.addClass( 'is-sticky' );
$header.addClass( 'real-header' );
$realTools.find( '>div' )
.appendTo( '.site-header.sticky-header > .container > .row > .header-tools' );
} else {
$stickyTools.find( '>div' )
.appendTo( '.site-header.real-header > .container > .row > .header-tools' );
$stickyHeader.removeClass( 'is-sticky' );
$header.removeClass( 'real-header' );
}
} );
// Trigger scroll
$window.trigger( 'scroll' );
},
scrollToTop: function() {
var $scrollToTop = $( '.scroll-to-top' );
$window.on( 'scroll', function() {
if ( $window.scrollTop() > 100 ) {
$scrollToTop.addClass( 'show' );
} else {
$scrollToTop.removeClass( 'show' );
}
} );
$scrollToTop.on( 'click', function( e ) {
e.preventDefault();
$( 'body, html' ).animate( { scrollTop: 0 }, 600 );
} );
},
fitVideo: function() {
$( '.container' ).fitVids();
},
thumbGallery: function() {
if ( $( '.post-gallery > .slider .single-image' ).length ) {
$( '.post-gallery > .slider' ).slick( {
slidesToShow: 1,
arrows: true,
dots: false,
infinite: true,
adaptiveHeight: true,
} );
$( '.single-image:not(.slick-cloned)' ).magnificPopup( {
delegate: 'a',
gallery: {
enabled: true,
},
type: 'image',
} );
}
},
blog: function() {
var blogMasonry = function() {
if ( typeof (
$.fn.isotope
) === 'undefined' || typeof (
$.fn.imagesLoaded
) === 'undefined' ) {
return;
}
var $container = $( '.masonry-container' );
// initialize Masonry after all images have loaded
$container.imagesLoaded( function() {
var isotopeOptions = {
gutter: 0,
itemSelector: '.post-teaser--masonry, .masonry-item',
}
if ( tmRobinConfigs.isRTL ) {
isotopeOptions.originLeft = false;
}
$container.isotope( isotopeOptions );
} );
};
var postsSlider = function() {
$( '.js-post-carousel' ).each( function() {
var $this = $( this ),
atts = JSON.parse( $this.attr( 'data-atts' ) );
if ( atts === null ) {
return;
}
if ( typeof atts.auto_play_speed === 'undefined' || isNaN( atts.auto_play_speed ) ) {
atts.auto_play_speed = 5;
}
var configs = {
slidesToShow: parseInt( atts.columns ),
slidesToScroll: parseInt( atts.columns ),
adaptiveHeight: true,
infinite: atts.loop === 'yes',
autoplay: atts.auto_play === 'yes',
autoplaySpeed: parseInt( atts.auto_play_speed ) * 1000,
prevArrow: '',
nextArrow: '',
responsive: [
{
breakpoint: 992,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
},
}, {
breakpoint: 769,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
},
}, {
breakpoint: 544,
settings: {
adaptiveHeight: true,
arrows: true,
dots: false,
centerMode: true,
centerPadding: '30px',
slidesToShow: 1,
slidesToScroll: 1,
},
},
],
};
if ( !atts.nav_type ) {
configs.arrows = false;
configs.dots = false;
} else {
if ( atts.nav_type == 'dots' ) {
configs.arrows = false;
configs.dots = true;
}
if ( atts.nav_type == 'both' ) {
configs.arrows = true;
configs.dots = true;
}
}
if ( tmRobinConfigs.isRTL ) {
configs.rtl = true;
}
$this.slick( configs );
setTimeout( function() {
var $thumbGallery = $this.find( '.post-gallery > .slider' );
$thumbGallery.each( function() {
if ( typeof $( this ).get( 0 ).slick != 'undefined' ) {
$( this ).get( 0 ).slick.setPosition();
}
} );
}, 1000 );
} );
};
var blogShortcode = function() {
var $posts = $( '.tm-robin-blog .posts' ),
masonryConfig = {
itemSelector: '.post-item',
transitionDuration: 400,
};
if ( $posts.hasClass( 'post-carousel-layout' ) ) {
return;
} else if ( $posts.hasClass( 'post-grid-layout' ) ) {
masonryConfig[ 'layoutMode' ] = 'fitRows';
}
if ( tmRobinConfigs.isRTL ) {
masonryConfig.originLeft = false;
}
$posts.isotope( masonryConfig ).imagesLoaded( function() {
$posts.isotope( 'layout' );
} );
};
tmRobin.fitVideo();
tmRobin.thumbGallery();
blogMasonry();
postsSlider();
blogShortcode();
},
// language & currency switchers
switcher: function() {
var $languageSwitcher = $( '.language-switcher select' ),
$currencySwitcher = $( '.currency-switcher select' ),
$WOOCSCurrencySwitcher = $( '.currency-switcher.woocs-switcher' ),
$WPMLCurrencySwitcher = $( '.currency-switcher.wcml-switcher' );
var loadCurrency = function( currency ) {
$.ajax( {
type: 'post',
url: tmShopieConfigs.ajax_url,
data: {
action: 'wcml_switch_currency',
currency: currency,
},
success: function() {
window.location = window.location.href;
},
error: function( error ) {
console.log( error );
},
} );
};
var WOOCSSwitcher = function() {
// WooCommerce Currency Switcher plugin
$( '.option', $WOOCSCurrencySwitcher ).on( 'click', function() {
$WPMLCurrencySwitcher.addClass( 'loading' );
var $this = $( this );
$( '.currency-switcher' ).addClass( 'loading' );
setTimeout( function() {
window.location = $this.attr( 'data-value' );
}, 500 );
} );
};
var wooWPMLSwitcher = function() {
// WooCommerce WPML Multilingual plugin
$( '.option', $WPMLCurrencySwitcher ).on( 'click', function() {
$WPMLCurrencySwitcher.addClass( 'loading' );
var currency = $( this ).find( '.option' ).attr( 'data-value' );
loadCurrency( currency );
} );
};
// Language switcher
if ( $( 'option', $languageSwitcher ).length ) {
$languageSwitcher.niceSelect();
var $niceSelect = $languageSwitcher.next( '.nice-select' ),
imgSrc = $languageSwitcher.find( ':selected' ).attr( 'data-imagesrc' );
// Add flag image to .current
if ( typeof imgSrc != 'undefined' ) {
$niceSelect.find( 'span.current' ).prepend( '
' );
}
// Add flag image to option
$languageSwitcher.find( 'option' ).each( function() {
imgSrc = $( this ).attr( 'data-imagesrc' );
var index = $( this ).index();
if ( typeof imgSrc !== 'undefined' ) {
$niceSelect.find( '.option' )
.eq( index )
.prepend( '
' );
}
} );
$body.on( 'click', '.language-switcher .nice-select .option', function() {
var $this = $( this );
$( '.language-switcher' ).addClass( 'loading' );
setTimeout( function() {
window.location = $this.attr( 'data-value' );
}, 500 );
} );
}
// Currency switcher
if ( $( 'option', $currencySwitcher ).length ) {
$currencySwitcher.niceSelect();
WOOCSSwitcher();
wooWPMLSwitcher();
}
},
siteMenu: function() {
var $siteMenu = $( '.site-header:not(.sticky-header)' ).find( '.site-menu' );
if ( $( '.site-header.sticky-header' ).hasClass( 'is-sticky' ) ) {
$siteMenu = $( '.site-header.sticky-header' ).find( '.site-menu' );
}
if ( !$siteMenu.length ) {
return;
}
var $defaultMegaMenu = $siteMenu.find( 'li.mega-menu-default' ),
$fullWidthMegaMenu = $siteMenu.find( 'li.mega-menu-full-width' ),
$customMegaMenu = $siteMenu.find( 'li.mega-menu-custom' ),
$normalMegaMenu = $siteMenu.find( 'li.menu-item:not(.mega-menu)' ),
pageContainerRect = $( '#page-container' )[ 0 ].getBoundingClientRect(),
screenWidth = $window.width(),
viewportWidth = $body.hasClass( 'body-boxed' ) ? pageContainerRect.right : screenWidth;
// Calculate position for the mega menu
var megaMenuOffsets = function() {
if ( md.mobile() || md.phone() || md.tablet() ) {
return;
}
$defaultMegaMenu.on( 'mouseenter', function() {
defaultMegaMenu( $( this ) );
} ).each( function() {
defaultMegaMenu( $( this ) );
} );
$fullWidthMegaMenu.on( 'mouseenter', function() {
fullWidthMegaMenu( $( this ) );
} ).each( function() {
fullWidthMegaMenu( $( this ) );
} );
$customMegaMenu.on( 'mouseenter', function() {
customMegaMenu( $( this ) );
} );
};
// default mega menu
var defaultMegaMenu = function( $li ) {
if ( $body.hasClass( 'error404' ) ) {
return;
}
if ( typeof $li == 'undefined' ) {
return;
}
$siteMenu = $li.closest( '.site-menu' );
if ( !$siteMenu.length ) {
return;
}
var mainContainerRect = $body.hasClass( 'single-product' ) ? $( '.site-content > .product > .container' )[ 0 ].getBoundingClientRect() : $( '.main-container > .container' )[ 0 ].getBoundingClientRect(),
menuContainerRect = $siteMenu[ 0 ].getBoundingClientRect(),
left = mainContainerRect.left - menuContainerRect.left + 15;
if ( $( '.site-header' ).hasClass( 'header-menu-left' ) ) {
left = 0;
}
if ( tmRobinConfigs.isRTL ) {
$li.find( '>.sub-menu' ).css( {
'width': mainContainerRect.width - 30,
'right': left
} );
} else {
$li.find( '>.sub-menu' ).css( {
'width': mainContainerRect.width - 30,
'left': left
} );
}
};
// fullwidth mega menu
var fullWidthMegaMenu = function( $li ) {
if ( $body.hasClass( 'error404' ) ) {
return;
}
if ( typeof $li == 'undefined' ) {
return;
}
$siteMenu = $li.closest( '.site-menu' );
if ( !$siteMenu.length ) {
return;
}
var pageContainerRect = $( '#page-container' )[ 0 ].getBoundingClientRect(),
left = $siteMenu[ 0 ].getBoundingClientRect().left,
w = $window.width();
if ( $body.hasClass( 'body-boxed' ) ) {
left = pageContainerRect.left - left;
w = pageContainerRect.width;
} else {
left = 0 - left;
}
$li.find( '>.sub-menu' ).css( {
'width': w,
'left': left,
} );
};
var normalMenuHoverBack = function() {
if ( md.mobile() || md.phone() || md.tablet() ) {
return;
}
$normalMegaMenu.on( 'mouseenter', function() {
hoverBack( $( this ) );
} ).each( function() {
hoverBack( $( this ) );
} );
};
var hoverBack = function( $li ) {
if ( isOutSide( $li ) ) {
var $subMenu = $( '>.sub-menu', $li );
if ( !$subMenu.hasClass( 'hover-back' ) ) {
$li.addClass( 'has-hover-back' );
$subMenu.addClass( 'hover-back' );
$( '.sub-menu', $subMenu ).addClass( 'hover-back' );
} else {
$li.removeClass( 'has-hover-back' );
$subMenu.removeClass( 'hover-back' );
$( '.sub-menu', $subMenu ).removeClass( 'hover-back' );
}
}
};
var isOutSide = function( $li ) {
var subMenu = $li.find( '>.sub-menu' );
if ( typeof subMenu[ 0 ] == 'undefined' ) {
return;
}
var subMenuRect = subMenu[ 0 ].getBoundingClientRect();
if ( tmRobinConfigs.isRTL ) {
return subMenuRect.left <= 0;
} else {
return subMenuRect.right >= viewportWidth;
}
};
var customMegaMenu = function( $li ) {
var $subMenu = $li.find( '>.sub-menu' ),
subMenuRect = $subMenu[ 0 ].getBoundingClientRect();
if ( isOutSide( $li ) ) {
var pageContainerRect = $( '#page-container' )[ 0 ].getBoundingClientRect();
if ( tmRobinConfigs.isRTL ) {
var sub = pageContainerRect.left - subMenuRect.left;
} else {
var sub = subMenuRect.right - pageContainerRect.right;
}
var left = 0 - sub - 15;
if ( tmRobinConfigs.isRTL ) {
$subMenu.css( 'right', left );
} else {
$subMenu.css( 'left', left );
}
}
};
megaMenuOffsets();
normalMenuHoverBack();
defaultMegaMenu();
fullWidthMegaMenu();
$window.on( 'resize', function() {
defaultMegaMenu();
fullWidthMegaMenu();
} );
},
setTopValue: function( $el ) {
var $adminBar = $( '#wpadminbar' ),
w = $window.width(),
h = $adminBar.height(),
top = h;
if ( $adminBar.length ) {
if ( $adminBar.css( 'position' ) == 'absolute' && w <= 600 ) {
var t = $adminBar[ 0 ].getBoundingClientRect().top;
// get the top value for mobile menu
// t always negative or equal 0
// E.g: t = -30px, h = 46px => top = 46 + (-30) = 46 - 30 = 13
top = (
t >= 0 - h
) ? h + t : 0;
}
}
if ( w >= 1200 ) {
return;
}
$el.css( 'top', top );
},
mobileMenu: function() {
var $mobileBtn = $( '.mobile-menu-btn' ),
$mobileMenu = $( '#site-mobile-menu' ),
$mobileMenuClz = $( '.site-mobile-menu' ),
$pageContainer = $( '#page-container' );
var caculateRealHeight = function( $ul ) {
var height = 0;
$ul.find( '>li' ).each( function() {
height += $( this ).outerHeight();
} );
return height;
};
var setUpOverflow = function( h1, h2 ) {
if ( h1 < h2 ) {
$mobileMenuClz.css( 'overflow-y', 'hidden' );
} else {
$mobileMenuClz.css( 'overflow-y', 'auto' );
}
};
var buildSlideOut = function() {
if ( typeof $mobileMenu !== 'undefined' && typeof $pageContainer !== 'undefined' ) {
$body.on( 'click', '.mobile-menu-btn', function() {
$( this ).toggleClass( 'is-active' );
$( this ).find( '> .hamburger' ).toggleClass( 'is-active' );
$body.toggleClass( 'mobile-menu-opened' );
tmRobin.setTopValue( $mobileMenuClz );
} );
// Close menu if click on the site
$pageContainer.on( 'click touchstart', function( e ) {
if ( !$( e.target ).closest( '.mobile-menu-btn' ).length ) {
if ( $body.hasClass( 'mobile-menu-opened' ) ) {
$body.removeClass( 'mobile-menu-opened' );
$mobileBtn.removeClass( 'is-active' );
$mobileBtn.find( '> .hamburger' ).removeClass( 'is-active' );
$mobileMenu.find( '#searchform input[type="text"]' ).trigger( 'blur' );
e.preventDefault();
}
}
} );
setUpOverflow( $mobileMenu.height(), $mobileMenuClz.height() );
}
};
var buildDrillDown = function() {
var level = 0,
opener = 'open',
height = $mobileMenuClz.height();
$mobileMenu.find( 'li:has(ul)' ).each( function() {
var $this = $( this ),
allLink = $this.find( '> a' ).clone();
if ( allLink.length ) {
$this.prepend( opener );
$this.find( '> ul' )
.prepend( '