(function($){
"use strict";
/* ---------------------------------------------- /*
* Preloader
/* ---------------------------------------------- */
$(window).load(function() {
$('.page-loader').delay(350).fadeOut('slow');
});
$(document).ready(function() {
var header = $('.header'),
moduleHero = $('.module-hero'),
mobileTest;
/* ---------------------------------------------- /*
* Mobile detect
/* ---------------------------------------------- */
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
mobileTest = true;
} else {
mobileTest = false;
}
/* ---------------------------------------------- /*
* Transparent navbar animation
/* ---------------------------------------------- */
function navbarAnimation() {
if ( $(window).scrollTop() > 10 ) {
header.addClass('header-small');
$('.header-fixed').removeClass('header-transparent');
} else {
header.removeClass('header-small');
$('.header-fixed').addClass('header-transparent');
}
}
navbarAnimation();
$(window).scroll(function() {
navbarAnimation();
});
$('.js-stick').stick_in_parent();
$('.nav-icon-toggle').on('click', function() {
$(this).toggleClass('open');
});
/* ---------------------------------------------- /*
* One Page Nav
/* ---------------------------------------------- */
$('.onepage-nav').singlePageNav({
currentClass: 'active'
});
/* ---------------------------------------------- /*
* Collapse navbar on click
/* ---------------------------------------------- */
$(document).on('click', '.main-nav.in', function(e) {
if ( $(e.target).is('a') && !$(e.target).parent().hasClass('has-submenu') ) {
$(this).collapse('hide');
$('.nav-icon-toggle').toggleClass('open');
}
});
/* ---------------------------------------------- /*
* FlexSlider
/* ---------------------------------------------- */
$('.flexslider').flexslider({
animation: "fade",
controlNav: false,
directionNav: false,
before: function(slider) {
$('.hero-caption').fadeOut().animate({top:'-80px'},{queue:false, easing: 'swing', duration: 700});
slider.slides.eq(slider.currentSlide).delay(500);
slider.slides.eq(slider.animatingTo).delay(500);
},
after: function(slider) {
$('.hero-caption').fadeIn().animate({top:'0'},{queue:false, easing: 'swing', duration: 700});
},
useCSS: true
});
/* ---------------------------------------------- /*
* Setting background of modules
/* ---------------------------------------------- */
var modules = $('.module-hero, .module, .module-sm, .module-xs, .background-side, .footer');
modules.each(function() {
if ($(this).attr('data-background')) {
$(this).css('background-image', 'url(' + $(this).attr('data-background') + ')');
}
});
/* ---------------------------------------------- /*
* Open & Close shop cart
/* ---------------------------------------------- */
$('#open-cart, #cart-toggle').on('click', function() {
$('body').toggleClass('off-canvas-cart-open');
return false;
});
$(document).on('click', function(e) {
var container = $('.off-canvas-cart');
if (!container.is(e.target) && container.has(e.target).length === 0) {
$('body').removeClass('off-canvas-cart-open');
}
});
function getScrollBarWidth() {
var inner = document.createElement('p');
inner.style.width = "100%";
inner.style.height = "200px";
var outer = document.createElement('div');
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
outer.style.width = "200px";
outer.style.height = "150px";
outer.style.overflow = "hidden";
outer.appendChild (inner);
document.body.appendChild (outer);
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
var w2 = inner.offsetWidth;
if (w1 == w2) w2 = outer.clientWidth;
document.body.removeChild (outer);
return (w1 - w2);
};
$('.off-canvas-cart-wrapper').css('margin-right', '-' + getScrollBarWidth() + 'px');
/* ---------------------------------------------- /*
* Open & Close header search
/* ---------------------------------------------- */
$('#modal-search, .form-close-btn').on('click', function() {
$('.header-search-form').toggleClass('opened');
return false;
});
/* ---------------------------------------------- /*
* Parallax
/* ---------------------------------------------- */
$('.parallax').jarallax({
speed: 0.7
});
/* ---------------------------------------------- /*
* Twitter
/* ---------------------------------------------- */
$('.twitter-feed').each(function (index) {
$(this).attr('id', 'twitter-' + index);
var twitterID = $(this).data('twitter');
var twitter_config = {
'id': twitterID,
'domId': 'twitter-' + index,
'maxTweets': 2,
'enableLinks': true,
'showPermalinks': false
};
twitterFetcher.fetch(twitter_config);
});
/* ---------------------------------------------- /*
* Shop Product Zoom
/* ---------------------------------------------- */
$('.product-slider .item').zoom();
/* ---------------------------------------------- /*
* Shop product carousel
/* ---------------------------------------------- */
var owl;
owl = $('.product-slider');
owl.owlCarousel({
navigation: false,
slideSpeed: 300,
paginationSpeed: 400,
singleItem: true,
afterInit: afterOWLinit,
afterUpdate: afterOWLinit,
touchDrag: false,
mouseDrag: false
});
function afterOWLinit() {
$('.owl-controls .owl-page').append('');
var pafinatorsLink = $('.owl-controls .item-link');
$.each(this.owl.userItems, function (i) {
$(pafinatorsLink[i]).css({
'background': 'url(' + $(this).find('img').attr('src') + ') center center no-repeat',
'-webkit-background-size': 'cover',
'-moz-background-size': 'cover',
'-o-background-size': 'cover',
'background-size': 'cover'
}).click(function () {
owl.trigger('owl.goTo', i);
return false;
});
});
}
/* ---------------------------------------------- /*
* Carousels & Sliders
/* ---------------------------------------------- */
$('.images-carousel').each(function () {
$(this).owlCarousel($.extend({
stopOnHover: true,
navigation: false,
pagination: true,
autoPlay: 3000,
items: 5,
navigationText: [
'',
''
],
}, $(this).data('carousel-options')));
});
$('.box-carousel').each(function () {
$(this).owlCarousel($.extend({
stopOnHover: true,
navigation: false,
pagination: true,
autoPlay: 3000,
items: 3,
navigationText: [
'',
''
],
}, $(this).data('carousel-options')));
});
$('.clients-carousel').each(function () {
$(this).owlCarousel($.extend({
nav: false,
pagination: false,
dots: false,
slideTransition: 'linear',
autoplay: true,
autoplayTimeout: 0,
autoplaySpeed:3000,
loop:true,
items: 6,
margin:10,
navText: [
'',
''
],
}, $(this).data('carousel-options')));
});
$('.image-slider').each(function () {
$(this).owlCarousel($.extend({
stopOnHover: true,
navigation: true,
pagination: true,
autoPlay: 3000,
singleItem: true,
items: 1,
navigationText: [
'',
''
],
}, $(this).data('carousel-options')));
});
$('.slider-testimonial').owlCarousel({
paginationSpeed: 400,
slideSpeed: 300,
navigation: true,
pagination: true,
singleItem: true,
transitionStyle : 'backSlide',
navigationText: [
'',
''
],
});
$('.video-carousel').owlCarousel({
items:1,
merge:true,
loop:true,
margin:10,
video:true,
lazyLoad:true,
center:true,
nav:true,
responsive:{
480:{
items:2
},
600:{
items:4
}
}
})
/* ---------------------------------------------- /*
* Lightbox, Gallery
/* ---------------------------------------------- */
$('.lightbox').magnificPopup({
type: 'image'
});
$('.gallery').each(function() {
$(this).magnificPopup({
delegate: 'a',
type: 'image',
gallery: {
enabled:true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
titleSrc: 'title',
tError: 'The image could not be loaded.',
},
zoom: {
enabled: true,
duration: 300
}
});
});
$(window).on('resize', function() {
$('.gallery').imagesLoaded(function() {
$('.gallery').isotope({
layoutMode: 'fitRows',
itemSelector: '.gallery-item',
});
});
}).resize();
$('.video-pop-up').magnificPopup({
type: 'iframe',
});
/* ---------------------------------------------- /*
* WOW Animation
/* ---------------------------------------------- */
var wow = new WOW({
mobile: false
});
wow.init();
/* ---------------------------------------------- /*
* Scroll Animation
/* ---------------------------------------------- */
$('.smoothscroll').on('click', function(e) {
var target = this.hash;
var $target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top - header.height()
}, 600, 'swing');
e.preventDefault();
});
/* ---------------------------------------------- /*
* Scroll top
/* ---------------------------------------------- */
$('a[href="#top"]').on('click', function() {
$('html, body').animate({ scrollTop: 0 }, 'slow');
return false;
});
/* ---------------------------------------------- /*
* Disable hover on scroll
/* ---------------------------------------------- */
var body = document.body,
timer;
window.addEventListener('scroll', function() {
clearTimeout(timer);
if (!body.classList.contains('disable-hover')) {
body.classList.add('disable-hover')
}
timer = setTimeout(function() {
body.classList.remove('disable-hover')
}, 100);
}, false);
});
})(jQuery);