(function($) {
"use strict";
/*------------------------------------------
= FUNCTIONS
-------------------------------------------*/
// Check ie and version
function isIE () {
var myNav = navigator.userAgent.toLowerCase();
return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1], 10) : false;
}
// Toggle mobile navigation
function toggleMobileNavigation() {
var navbar = $(".navigation-holder");
var openBtn = $(".navbar-header .open-btn");
var closeBtn = $(".navigation-holder .close-navbar");
var navLinks = $(".navigation-holder > ul > li > a[href^='#']");
openBtn.on("click", function() {
if (!navbar.hasClass("slideInn")) {
navbar.addClass("slideInn");
}
return false;
})
closeBtn.on("click", function() {
if (navbar.hasClass("slideInn")) {
navbar.removeClass("slideInn");
}
return false;
})
navLinks.on("click", function() {
if (navbar.hasClass("slideInn")) {
navbar.removeClass("slideInn");
}
return false;
})
}
toggleMobileNavigation();
// Function for toggle a class for small menu
function toggleClassForSmallNav() {
var windowWidth = window.innerWidth;
var mainNav = $("#navbar > ul");
if (windowWidth <= 991) {
mainNav.addClass("small-nav");
} else {
mainNav.removeClass("small-nav");
}
}
toggleClassForSmallNav();
// Function for small menu
function smallNavFunctionality() {
var windowWidth = window.innerWidth;
var mainNav = $(".navigation-holder");
var smallNav = $(".navigation-holder > .small-nav");
var subMenu = smallNav.find(".sub-menu");
var megamenu = smallNav.find(".mega-menu");
var menuItemWidthSubMenu = smallNav.find(".menu-item-has-children > a");
if (windowWidth <= 991) {
subMenu.hide();
megamenu.hide();
menuItemWidthSubMenu.on("click", function(e) {
var $this = $(this);
$this.siblings().slideToggle();
e.preventDefault();
e.stopImmediatePropagation();
})
} else if (windowWidth > 991) {
mainNav.find(".sub-menu").show();
mainNav.find(".mega-menu").show();
}
}
smallNavFunctionality();
//ACTIVE CURRENT MENU WHILE SCROLLING
// function for active menuitem
function activeMenuItem($links) {
var cur_pos = $(window).scrollTop() + 2,
bottomPosition = $(document).height() - $(window).height() - $(window).scrollTop(),
sections = $("section"),
nav = $links,
nav_height = nav.outerHeight(),
home = nav.find(" > ul > li:first");
sections.each(function() {
var top = $(this).offset().top - nav_height,
bottom = top + $(this).outerHeight();
if (cur_pos >= top && cur_pos <= bottom) {
nav.find("> ul > li > a").parent().removeClass("current-menu-item");
nav.find("a[href='#" + $(this).attr('id') + "']").parent().addClass("current-menu-item");
} else if (cur_pos === 2) {
nav.find("> ul > li > a").parent().removeClass("current-menu-item");
home.addClass("current-menu-item");
}
});
}
// smooth-scrolling
function smoothScrolling($links, $topGap) {
var links = $links;
var topGap = $topGap;
links.on("click", function() {
if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
var target = $(this.hash);
target = target.length ? target : $("[name=" + this.hash.slice(1) +"]");
if (target.length) {
$("html, body").animate({
scrollTop: target.offset().top - topGap
}, 1000, "easeInOutExpo");
return false;
}
}
return false;
});
}
// Parallax background
function bgParallax() {
if ($(".parallax").length) {
$(".parallax").each(function() {
var height = $(this).position().top;
var resize = height - $(window).scrollTop();
var doParallax = -(resize/5);
var positionValue = doParallax + "px";
var img = $(this).data("bg-image");
$(this).css({
backgroundImage: "url(" + img + ")",
backgroundPosition: "50%" + positionValue,
backgroundSize: "cover"
});
});
}
}
// Hero slider background setting
function sliderBgSetting() {
if ($(".hero-slider .slide").length) {
$(".hero-slider .slide").each(function() {
var $this = $(this);
var img = ($this.find(".slider-bg").attr("src")) ? $this.find(".slider-bg").attr("src") : null ;
if(img != null) {
$this.css({
backgroundImage: "url("+ img +")",
backgroundSize: "cover",
backgroundPosition: "center center"
})
}
});
}
}
//Setting hero slider
function heroSlider() {
if ($(".hero-slider").length) {
$(".hero-slider").slick({
arrows: true,
prevArrow: '',
nextArrow: '',
dots: true,
fade: true,
cssEase: 'linear'
});
}
}
// Animated scroll specific section
if ($("#scroll").length) {
$('#scroll').on('click', function(e){
e.preventDefault();
$('html,body').animate({scrollTop:$(this.hash).offset().top}, 1000, "easeInOutExpo");
return false;
});
}
/*------------------------------------------
= HIDE PRELOADER
-------------------------------------------*/
function preloader() {
if($('.preloader').length) {
$('.preloader').delay(100).fadeOut(500, function() {
//active wow
wow.init();
//Active heor slider
heroSlider();
});
}
}
/*------------------------------------------
= WOW ANIMATION SETTING
-------------------------------------------*/
var wow = new WOW({
boxClass: 'wow', // default
animateClass: 'animated', // default
offset: 0, // default
mobile: true, // default
live: true // default
});
/*------------------------------------------
= ACTIVE POPUP IMAGE
-------------------------------------------*/
if ($(".fancybox").length) {
$(".fancybox").fancybox({
openEffect : "elastic",
closeEffect : "elastic",
wrapCSS : "project-fancybox-title-style"
});
}
/*------------------------------------------
= POPUP VIDEO
-------------------------------------------*/
if ($(".video-btn").length) {
$(".video-btn").on("click", function(){
$.fancybox({
href: this.href,
type: $(this).data("type"),
'title' : this.title,
helpers : {
title : { type : 'inside' },
media : {}
},
beforeShow : function(){
$(".fancybox-wrap").addClass("gallery-fancybox");
}
});
return false
});
}
/*------------------------------------------
= ACTIVE GALLERY POPUP IMAGE
-------------------------------------------*/
if ($(".popup-gallery").length) {
$('.popup-gallery').magnificPopup({
delegate: 'a',
type: 'image',
gallery: {
enabled: true
},
zoom: {
enabled: true,
duration: 300,
easing: 'ease-in-out',
opener: function(openerElement) {
return openerElement.is('img') ? openerElement : openerElement.find('img');
}
}
});
}
/*------------------------------------------
= FUNCTION FORM SORTING GALLERY
-------------------------------------------*/
function sortingGallery() {
if ($(".sortable-gallery").length) {
var $container = $('.gallery-container');
var $columnWidth = (window.innerWidth >= 768) ? 1 : ".grid-item" ;
$container.isotope({
itemSelector: '.grid-item',
percentPosition: true,
masonry: {
columnWidth: $columnWidth
},
filter:'*',
animationOptions: {
duration: 750,
easing: 'ease',
queue: false,
}
});
$container.imagesLoaded(function () {
$container.isotope("layout");
});
$(".gallery-filters li a").on("click", function() {
$('.gallery-filters li .current').removeClass('current');
$(this).addClass('current');
var selector = $(this).attr('data-filter');
$container.isotope({
filter:selector,
animationOptions: {
duration: 750,
easing: 'linear',
queue: false,
}
});
return false;
});
}
}
sortingGallery();
/*------------------------------------------
= MASONRY GALLERY SETTING
-------------------------------------------*/
function masonryGridSetting() {
if ($('.masonry-gallery').length) {
var $grid = $('.masonry-gallery').masonry({
itemSelector: '.grid-item',
columnWidth: '.grid-item',
percentPosition: true
});
$grid.imagesLoaded().progress( function() {
$grid.masonry('layout');
});
}
}
//masonryGridSetting();
/*------------------------------------------
= STICKY HEADER
-------------------------------------------*/
// Function for clone an element for sticky menu
function cloneNavForSticyMenu($ele, $newElmClass) {
$ele.addClass('original').clone().insertAfter($ele).addClass($newElmClass).removeClass('original');
}
// clone home style 1 navigation for sticky menu
if ($('.site-header .navigation').length) {
cloneNavForSticyMenu($('.site-header .navigation'), "sticky-header");
}
// Function for sticky menu
function stickIt($stickyClass, $toggleClass) {
if ($(window).scrollTop() >= 300) {
var orgElement = $(".original");
var coordsOrgElement = orgElement.offset();
var leftOrgElement = coordsOrgElement.left;
var widthOrgElement = orgElement.css("width");
$stickyClass.addClass($toggleClass);
$stickyClass.css({
"width": widthOrgElement
}).show();
$(".original").css({
"visibility": "hidden"
});
} else {
$(".original").css({
"visibility": "visible"
});
$stickyClass.removeClass($toggleClass);
}
}
/*------------------------------------------
= PROGRESS BAR
-------------------------------------------*/
function progressBar() {
if ($(".progress-bar").length) {
var $progress_bar = $('.progress-bar');
$progress_bar.appear();
$(document.body).on('appear', '.progress-bar', function() {
var current_item = $(this);
if (!current_item.hasClass('appeared')) {
var percent = current_item.data('percent');
current_item.css('width', percent + '%').addClass('appeared').parent().append('' + percent + '%' + '');
}
});
};
}
progressBar();
/*------------------------------------------
= TESTIMONIALS SLIDER
-------------------------------------------*/
if($(".testimonials-slider".length)) {
$(".testimonials-slider").owlCarousel({
items: 1,
mouseDrag: false,
smartSpeed: 300,
loop:true,
autoplayHoverPause:true,
nav: true,
navText: ['',''],
});
}
/*------------------------------------------
= TESTIMONIALS S2 SLIDER
-------------------------------------------*/
if($(".testimonials-slider-s2".length)) {
$(".testimonials-slider-s2").owlCarousel({
items: 1,
mouseDrag: false,
smartSpeed: 600,
loop:true,
autoplayHoverPause:true,
nav: true,
navText: ['',''],
});
}
/*------------------------------------------
= PARTNERS SLIDER
-------------------------------------------*/
if ($(".partners-slider").length) {
$(".partners-slider").owlCarousel({
autoplay:true,
smartSpeed: 300,
margin: 30,
loop:true,
autoplayHoverPause:true,
dots: false,
responsive: {
0 : {
items: 2
},
400 : {
items: 3
},
550 : {
items: 4
},
992 : {
items: 5
}
}
});
}
/*------------------------------------------
= APP LANDING SCREENSHOT SLIDER
-------------------------------------------*/
if ($(".screenshot-slider").length) {
$(".screenshot-slider").owlCarousel({
loop:true,
margin:50,
items: 1,
smartSpeed: 700,
autoplay: true,
autoplayTimeout: 2000,
dots: false,
nav:true,
navText: [ '', '' ],
});
}
/*------------------------------------------
= TESTIMONIALS SLIDER
-------------------------------------------*/
if ($(".testimonials-slider-s3").length) {
$(".testimonials-slider-s3").owlCarousel({
autoplay:true,
smartSpeed: 300,
margin: 15,
loop:true,
autoplayHoverPause:true,
dots: false,
nav:true,
navText: [ '', '' ],
responsive: {
0 : {
items: 1
},
992 : {
items: 2
}
}
});
}
/*------------------------------------------
= RELATED POST SLIDER
-------------------------------------------*/
if($(".related-posts-slider".length)) {
$(".related-posts-slider").owlCarousel({
mouseDrag: false,
smartSpeed: 300,
loop:true,
autoplayHoverPause:true,
responsive: {
0 : {
items: 1,
},
600: {
items: 2,
}
}
});
}
/*------------------------------------------
= CONTACT FORM SUBMISSION
-------------------------------------------*/
if ($("#contact-form").length) {
$("#contact-form").validate({
rules: {
name: {
required: true,
minlength: 2
},
email: "required",
subject: "required",
phone: "required",
},
messages: {
name: "Please enter your name",
email: "Please enter your email",
phone: "Please enter your phone",
subject: "Please enter your subject"
},
submitHandler: function (form) {
$.ajax({
type: "POST",
url: "mail.php",
data: $(form).serialize(),
success: function () {
$( "#loader").hide();
$( "#success").slideDown( "slow" );
setTimeout(function() {
$( "#success").slideUp( "slow" );
}, 3000);
form.reset();
},
error: function() {
$( "#loader").hide();
$( "#error").slideDown( "slow" );
setTimeout(function() {
$( "#error").slideUp( "slow" );
}, 3000);
}
});
return false; // required to block normal submit since you used ajax
}
});
}
if ($("#contact-form-s2").length) {
$("#contact-form-s2").validate({
rules: {
name: {
required: true,
minlength: 2
},
email: "required",
phone: "required",
},
messages: {
name: "Please enter your name",
email: "Please enter your email",
phone: "Please enter your phone",
},
submitHandler: function (form) {
$.ajax({
type: "POST",
url: "mail2.php",
data: $(form).serialize(),
success: function () {
$( "#loader").hide();
$( "#success").slideDown( "slow" );
setTimeout(function() {
$( "#success").slideUp( "slow" );
}, 3000);
form.reset();
},
error: function() {
$( "#loader").hide();
$( "#error").slideDown( "slow" );
setTimeout(function() {
$( "#error").slideUp( "slow" );
}, 3000);
}
});
return false; // required to block normal submit since you used ajax
}
});
}
/*==========================================================================
WHEN DOCUMENT LOADING
==========================================================================*/
$(window).on('load', function() {
preloader();
sliderBgSetting();
toggleMobileNavigation();
smallNavFunctionality();
//smoothScrolling($("#navbar > ul > li > a[href^='#']"), $(".site-header .navigation").innerHeight());
if($(".header-style-2").length) {
smoothScrolling($("#navbar > ul > li > a[href^='#']"), 88);
} else if(($(".header-style-1").length) || $(".header-style-3").length) {
smoothScrolling($("#navbar > ul > li > a[href^='#']"), $(".site-header .navigation").innerHeight());
}
// masonryGridSetting();
sortingGallery();
});
/*==========================================================================
WHEN WINDOW SCROLL
==========================================================================*/
$(window).on("scroll", function() {
if ($(".site-header").length) {
stickIt($(".sticky-header"), "sticky-on");
}
activeMenuItem($(".navigation-holder"));
});
/*==========================================================================
WHEN WINDOW RESIZE
==========================================================================*/
$(window).on("resize", function() {
toggleClassForSmallNav();
clearTimeout($.data(this, 'resizeTimer'));
$.data(this, 'resizeTimer', setTimeout(function() {
smallNavFunctionality();
}, 200));
});
})(window.jQuery);