"use strict";
//Wrapping all JavaScript code into a IIFE function for prevent global variables creation
(function ($) {
var $body = $('body');
var $window = $(window);
//hidding menu elements that do not fit in menu width
//processing center logo
function menuHideExtraElements() {
//cleaneng changed elements
$('.sf-more-li, .sf-logo-li').remove();
var windowWidth = $('body').innerWidth();
$('.sf-menu').each(function () {
var $thisMenu = $(this);
var $menuWraper = $thisMenu.closest('.top-nav');
$menuWraper.attr('style', '');
if (windowWidth > 1199) {
//grab all main menu first level items
var $menuLis = $menuWraper.find('.sf-menu > li');
$menuLis.removeClass('sf-xl-hidden');
var $headerLogoCenter = $thisMenu.closest('.header_logo_center');
var logoWidth = 0;
var summaryLiWidth = 0;
if ($headerLogoCenter.length) {
var $logo = $headerLogoCenter.find('.logo');
// 30/2 - left and right margins
logoWidth = $logo.outerWidth(true) + 70;
}
// var wrapperWidth = $('.sf-menu').width();
var wrapperWidth = $menuWraper.outerWidth(true);
$menuLis.each(function (index) {
//4 - 4px additional width for inline-block LI element
var elementWidth = $(this).outerWidth() + 4;
summaryLiWidth += elementWidth;
if (summaryLiWidth >= (wrapperWidth - logoWidth)) {
var $newLi = $('
');
$($menuLis[index - 1]).before($newLi);
var newLiWidth = $($newLi).outerWidth(true);
var $extraLiElements = $menuLis.filter(':gt(' + (index - 2) + ')');
$extraLiElements.clone().appendTo($newLi.find('ul'));
$extraLiElements.addClass('sf-xl-hidden');
return false;
}
});
//processing center logo
if ($headerLogoCenter.length) {
var $menuLisVisible = $headerLogoCenter.find('.sf-menu > li:not(.sf-xl-hidden)');
var menuLength = $menuLisVisible.length;
var summaryLiVisibleWidth = 0;
$menuLisVisible.each(function () {
summaryLiVisibleWidth += $(this).outerWidth();
});
var centerLi = Math.floor(menuLength / 2);
if ((menuLength % 2 === 0)) {
centerLi--;
}
var $liLeftFromLogo = $menuLisVisible.eq(centerLi);
$liLeftFromLogo.after('
');
$headerLogoCenter.find('.sf-logo-li').width(logoWidth);
var liLeftRightDotX = $liLeftFromLogo.offset().left + $liLeftFromLogo.outerWidth();
var logoLeftDotX = windowWidth / 2 - logoWidth / 2;
var menuLeftOffset = liLeftRightDotX - logoLeftDotX;
$menuWraper.css({'left': -menuLeftOffset})
}
}// > 991
}); //sf-menu each
} //menuHideExtraElements
function initMegaMenu(timeOut) {
var $megaMenu = $('.top-nav .mega-menu');
if ($megaMenu.length) {
setTimeout(function () {
var windowWidth = $('body').innerWidth();
if (windowWidth > 991) {
$megaMenu.each(function () {
var $thisMegaMenu = $(this);
//temporary showing mega menu to proper size calc
$thisMegaMenu.css({'display': 'block', 'left': 'auto'});
//checking for sticked side header
var stickedSideHeaderWidth = 0;
var $stickedSideHeader = $('.header_side_sticked');
if ($stickedSideHeader.length && $stickedSideHeader.hasClass('active-slide-side-header')) {
stickedSideHeaderWidth = $stickedSideHeader.outerWidth(true);
if ($stickedSideHeader.hasClass('header_side_right')) {
stickedSideHeaderWidth = -stickedSideHeaderWidth;
}
windowWidth = windowWidth - stickedSideHeaderWidth;
}
var thisWidth = $thisMegaMenu.outerWidth();
var thisOffset = $thisMegaMenu.offset().left - stickedSideHeaderWidth;
var thisLeft = (thisOffset + (thisWidth / 2)) - windowWidth / 2;
$thisMegaMenu.css({'left': -thisLeft, 'display': 'none'});
if (!$thisMegaMenu.closest('ul').hasClass('nav')) {
$thisMegaMenu.css('left', '');
}
});
}
}, timeOut);
}
}
//NOTE: affixed sidebar works bad with side headers
function initAffixSidebar() {
var $affixAside = $('.affix-aside');
if ($affixAside.length) {
$window = $(window);
//on stick and unstick event
$affixAside.on('affix.bs.affix', function (e) {
var affixWidth = $affixAside.width() - 1;
var affixLeft = $affixAside.offset().left;
$affixAside
.width(affixWidth)
.css("left", affixLeft);
}).on('affix-bottom.bs.affix', function (e) {
var affixWidth = $affixAside.width() - 1;
//if sticked left header
var stickedSideHeaderWidth = 0;
var $stickedSideHeader = $('.header_side_sticked');
if ($stickedSideHeader.length && $stickedSideHeader.hasClass('active-slide-side-header') && !$stickedSideHeader.hasClass('header_side_right')) {
stickedSideHeaderWidth = $stickedSideHeader.outerWidth(true);
}
var affixLeft = $affixAside.offset().left - stickedSideHeaderWidth - $('#box_wrapper').offset().left;
;
$affixAside
.width(affixWidth)
.css("left", affixLeft);
}).on('affix-top.bs.affix', function (e) {
$affixAside.css({"width": "", "left": ""});
});
//counting offset
var offsetTopAdd = 10;
var offsetBottomAdd = 150;
var offsetTop = $affixAside.offset().top - $('.page_header').height();
//note that page_footer and page_copyright sections must exists - else this will cause error in last jQuery versions
var offsetBottom = $('.page_footer').outerHeight(true) + $('.page_copyright').outerHeight(true);
$affixAside.affix({
offset: {
top: offsetTop - offsetTopAdd,
bottom: offsetBottom + offsetBottomAdd
},
});
$window.on('resize', function () {
//returning sidebar in top position if it is sticked because of unexpected behavior
$affixAside.removeClass("affix affix-bottom").addClass("affix-top").trigger('affix-top.bs.affix');
var offsetTopSectionsArray = [
'.page_topline',
'.page_toplogo',
'.page_header',
'.page_title',
'.blog_slider',
'.blog-featured-posts'
];
var offsetTop = 0;
offsetTopSectionsArray.map(function (val) {
offsetTop += $(val).outerHeight(true) || 0;
});
//note that page_footer and page_copyright sections must exists - else this will cause error in last jQuery versions
var offsetBottom = $('.page_footer').outerHeight(true)
+ $('.page_copyright').outerHeight(true);
$affixAside.data('bs.affix').options.offset.top = offsetTop - offsetTopAdd;
$affixAside.data('bs.affix').options.offset.bottom = offsetBottom + offsetBottomAdd;
$affixAside.affix('checkPosition');
});
$affixAside.affix('checkPosition');
}//eof checking of affix sidebar existing
}
//photoSwipe gallery plugin
function initPhotoSwipe() {
if (typeof PhotoSwipe !== 'undefined') {
//adding prettyPhoto for backward compatibility. Deprecated.
//will leave only .photoswipe-link later
var gallerySelectors = '.photoswipe-link, a[data-gal^="prettyPhoto"], [data-thumb] a';
var $galleryLinks = $(gallerySelectors);
if ($galleryLinks.length) {
//adding photoswipe gallery markup
if (!($('.pswp').length)) {
$body.append('
');
//if function already was called - return (all listeners was setted and .pswp gallery container was added)
} else {
return;
}
//adding prettyPhoto for backward compatibility. Deprecated.
$('body').on('click', gallerySelectors, function (e) {
e.preventDefault();
var $link = $(this);
var $linksParentContainer = $link.closest('.photoswipe-container, .isotope-wrapper, .owl-carousel, .flickr_ul, .images');
var $links = $linksParentContainer.find(gallerySelectors);
//for cloned owl-carousel items - continue to prevent duplicating - moved to EACH loop
//start index does not work with owl-carousel loop enabled
// if ($linksParentContainer.is('.owl-carousel')) {
// $links = $links.filter(function (index) {
// return !($(this).closest('.cloned').length);
// });
// }
//if no container only adding this link
if (!$links.length) {
$links.push($link);
}
var items = [];
var options = {
bgOpacity: 0.7,
showHideOpacity: true,
history: false,
shareEl: false,
//data index is set in owl carousel init
index: $link.data('index') ? $link.data('index') : 0
};
var gallery = $('.pswp')[0];
//building items array
$links.each(function (i) {
var $this = $(this);
//if cloned element (owl or flexslider thumbs) - continue
if ($this.closest('.clone, .cloned').length) {
return;
}
//TODO think about hide items that are not showing after filtering and renew indexes for them
// if ($linksParentContainer.hasClass('isotope-wrapper') && !$this.is(':visible')) {
// return;
// }
var item = {};
//if not owl carousel
if (($link[0] === $this[0]) && !($link.data('index'))) {
//start from 0
if ($linksParentContainer.hasClass('owl-carousel') || $linksParentContainer.hasClass('images')) {
options.index = i - 1;
} else {
options.index = i;
}
}
//video or image
if ($this.data('iframe')) {
//for wordpress - iframe tag is escaped
//item.html = $this.data('iframe').replace(/&/g, '&').replace(/$lt;/g, '<').replace(/>/g, '>').replace(/$quot;/g, '"');
//for html - building iframe manually
//autoplay only if 1 iframe in gallery
var autoplay = ( $links.length > 1 ) ? '' : '&autoplay=1';
item.html = '
';
}
geocoder.geocode({
address: $marker.find('.marker-address').text()
}, function(data){
var iconSrc = $marker.find('.marker-icon').attr('src');
var lat = data[0].geometry.location.lat();
var lng = data[0].geometry.location.lng();
var center = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: center,
title: markerTitle,
map: map,
icon: iconSrc
});
var infowindow = new google.maps.InfoWindow({
content: markerDescription
});
infoWindows.push(infowindow);
google.maps.event.addListener(marker, 'click', function() {
for (var i=0;i');
$thisMenu.find('.sf-menu-item-mobile-toggler').on('click', function (e) {
var $parentLi = $(this).parent();
if ($parentLi.hasClass('sfHover')) {
$parentLi.superfish('hide');
} else {
$parentLi.superfish('show');
}
});
}
});
$('ul.sf-menu-side').superfish({
popUpSelector: 'ul:not(.mega-menu ul), .mega-menu ',
delay: 500,
animation: {opacity: 'show', height: 100 + '%'},
animationOut: {opacity: 'hide', height: 0},
speed: 400,
speedOut: 300,
disableHI: false,
cssArrows: true,
autoArrows: true
});
}
$('.header-special .close-wrapper a').on('click', function () {
$(this).closest('.header-special').removeClass('active-slide-side-header');
$('.toggle_menu_side_special').removeClass('active');
});
//toggle mobile menu
$('.page_header .toggle_menu:not(.toggle_menu_side_special), .page_toplogo .toggle_menu').on('click', function () {
$(this)
.toggleClass('mobile-active')
.closest('.page_header')
.toggleClass('mobile-active')
.end()
.closest('.page_toplogo')
.next()
.find('.page_header')
.toggleClass('mobile-active');
$('.page_topline').toggleClass('index');
});
$('.sf-menu a').on('click', function () {
var $this = $(this);
//If this is a local link or item with sumbenu - not toggling menu
if (($this.hasClass('sf-with-ul')) || !($this.attr('href').charAt(0) === '#')) {
return;
}
$this
.closest('.page_header')
.toggleClass('mobile-active')
.find('.toggle_menu')
.toggleClass('mobile-active');
});
//side header processing
var $sideHeader = $('.page_header_side');
// toggle sub-menus visibility on menu-click
$('ul.menu-click').find('li').each(function () {
var $thisLi = $(this);
//toggle submenu only for menu items with submenu
if ($thisLi.find('ul').length) {
$thisLi
.append('')
//adding anchor
.find('.toggle_submenu, > a')
.on('click', function (e) {
var $thisSpanOrA = $(this);
//if this is a link and it is already opened - going to link
if (($thisSpanOrA.attr('href') === '#') || !($thisSpanOrA.parent().hasClass('active-submenu'))) {
e.preventDefault();
}
if ($thisSpanOrA.parent().hasClass('active-submenu')) {
$thisSpanOrA.parent().removeClass('active-submenu');
return;
}
$thisLi.addClass('active-submenu').siblings().removeClass('active-submenu');
});
} //eof sumbenu check
});
if ($sideHeader.length) {
$('.toggle_menu_side').on('click', function () {
var $thisToggler = $(this);
$thisToggler.toggleClass('active');
if ($thisToggler.hasClass('header-slide')) {
$sideHeader.toggleClass('active-slide-side-header');
} else {
if ($thisToggler.parent().hasClass('header_side_right')) {
$body.toggleClass('active-side-header slide-right');
} else {
$body.toggleClass('active-side-header');
}
$body.parent().toggleClass('html-active-push-header');
}
//fixing mega menu and aside affix on toggling side sticked header
if ($thisToggler.closest('.header_side_sticked').length) {
initMegaMenu(600);
var $affixAside = $('.affix-aside');
if ($affixAside.length) {
$affixAside.removeClass("affix affix-bottom").addClass("affix-top").css({
"width": "",
"left": ""
}).trigger('affix-top.bs.affix');
setTimeout(function () {
$affixAside.removeClass("affix affix-bottom").addClass("affix-top").css({
"width": "",
"left": ""
}).trigger('affix-top.bs.affix');
}, 10);
}
}
});
//hidding side header on click outside header
$body.on('mousedown touchstart', function (e) {
if (!($(e.target).closest('.page_header_side').length) && !($sideHeader.hasClass('header_side_sticked'))) {
$sideHeader.removeClass('active-slide-side-header');
$body.removeClass('active-side-header slide-right');
$body.parent().removeClass('html-active-push-header');
var $toggler = $('.toggle_menu_side');
if (($toggler).hasClass('active')) {
$toggler.removeClass('active');
}
}
});
} //sideHeader check
//1 and 2/3/4th level offscreen fix
var MainWindowWidth = $window.width();
$window.on('resize', function () {
MainWindowWidth = $(window).width();
});
//2/3/4 levels
$('.top-nav .sf-menu').on('mouseover', 'ul li', function () {
// $('.mainmenu').on('mouseover', 'ul li', function(){
if (MainWindowWidth > 991) {
var $this = $(this);
// checks if third level menu exist
var subMenuExist = $this.find('ul').length;
if (subMenuExist > 0) {
var subMenuWidth = $this.find('ul, div').first().width();
var subMenuOffset = $this.find('ul, div').first().parent().offset().left + subMenuWidth;
// if sub menu is off screen, give new position
if ((subMenuOffset + subMenuWidth) > MainWindowWidth) {
var newSubMenuPosition = subMenuWidth + 0;
$this.find('ul, div').first().css({
left: -newSubMenuPosition,
});
} else {
$this.find('ul, div').first().css({
left: '100%',
});
}
}
}
//1st level
}).on('mouseover', '> li', function () {
if (MainWindowWidth > 991) {
var $this = $(this);
var subMenuExist = $this.find('ul').length;
if (subMenuExist > 0) {
var subMenuWidth = $this.find('ul').width();
var subMenuOffset = $this.find('ul').parent().offset().left;
// if sub menu is off screen, give new position
if ((subMenuOffset + subMenuWidth) > MainWindowWidth) {
var newSubMenuPosition = MainWindowWidth - (subMenuOffset + subMenuWidth);
$this.find('ul').first().css({
left: newSubMenuPosition,
});
}
}
}
});
/////////////////////////////////////////
//single page localscroll and scrollspy//
/////////////////////////////////////////
var navHeight = $('.page_header').outerHeight(true);
//if sidebar nav exists - binding to it. Else - to main horizontal nav
if ($('.mainmenu_side_wrapper').length) {
$body.scrollspy({
target: '.mainmenu_side_wrapper',
offset: navHeight ? navHeight : 50
});
} else if ($('.top-nav').length) {
$body.scrollspy({
target: '.top-nav',
offset: navHeight
})
}
if ($().localScroll) {
$('.top-nav > ul, .mainmenu_side_wrapper > ul, #land, .comments-link, .mouse_down').localScroll({
duration: 900,
easing: 'easeInOutQuart',
offset: -navHeight + 40
});
}
//background image teaser and sections with half image bg
//put this before prettyPhoto init because image may be wrapped in prettyPhoto link
$(".bg_teaser, .cover-image").each(function () {
var $element = $(this);
var $image = $element.find("img").first();
if (!$image.length) {
$image = $element.parent().find("img").first();
}
if (!$image.length) {
return;
}
var imagePath = $image.attr("src");
$element.css("background-image", "url(" + imagePath + ")");
var $imageParent = $image.parent();
//if image inside link - adding this link, removing gallery to preserve duplicating gallery items
if ($imageParent.is('a')) {
$element.prepend($image.parent().clone().html(''));
$imageParent.attr('data-gal', '');
}
});
//video images preview - from WP
$('.embed-placeholder').each(function(){
$(this).on('click', function(e) {
var $thisLink = $(this);
// if prettyPhoto popup with YouTube - return
if ($thisLink.attr('data-gal')) {
return;
}
e.preventDefault();
if ($thisLink.attr('href') === '' || $thisLink.attr('href') === '#') {
$thisLink.replaceWith($thisLink.data('iframe').replace(/&/g, '&').replace(/$lt;/g, '<').replace(/>/g, '>').replace(/$quot;/g, '"')).trigger('click');
} else {
$thisLink.replaceWith('');
}
});
});
//toTop
if ($().UItoTop) {
$().UItoTop({easingType: 'easeInOutQuart'});
}
//parallax
if ($().parallax) {
$('.s-parallax').parallax("50%", 0.01);
}
//prettyPhoto
if ($().prettyPhoto) {
$("a[data-gal^='prettyPhoto']").prettyPhoto({
hook: 'data-gal',
theme: 'facebook' /* light_rounded / dark_rounded / light_square / dark_square / facebook / pp_default*/
});
}
initPhotoSwipe();
////////////////////////////////////////
//init Bootstrap JS components//
////////////////////////////////////////
//adding .form-control class for search widgets
$('[type="search"]').addClass('form-control');
//bootstrap carousel
if ($().carousel) {
$('.carousel').carousel();
}
//bootstrap tab - show first tab
$('.nav-tabs').each(function () {
$(this).find('a').first().tab('show');
});
//video in bootstrap tabs
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var iframe = $(e.relatedTarget.hash).find('iframe');
var src = iframe.attr('src');
iframe.attr('src', '');
iframe.attr('src', src);
});
$('.tab-content').each(function () {
$(this).find('.tab-pane').first().addClass('fade in');
});
//bootstrap collapse - show first tab
$('.panel-group').each(function () {
$(this).find('a').first().filter('.collapsed').trigger('click');
});
//tooltip
if ($().tooltip) {
$('[data-toggle="tooltip"]').tooltip();
}
//comingsoon counter
if ($().countdown) {
var $counter = $('#comingsoon-countdown, #comingsoon-countdown2');
//today date plus month for demo purpose
var date = ($counter.data('date') !== 'undefined') ? $counter.data('date') : false;
if (date) {
date = new Date(date);
} else {
date = new Date();
date.setMonth(date.getMonth() + 1);
}
$counter.countdown({until: date});
}
/////////////////////////////////////////////////
//PHP widgets - contact form, search, MailChimp//
/////////////////////////////////////////////////
//contact form processing
$('form.contact-form').on('submit', function (e) {
e.preventDefault();
var $form = $(this);
$($form).find('.contact-form-respond').remove();
//checking on empty values
$($form).find('[aria-required="true"], [required]').each(function (index) {
var $thisRequired = $(this);
if (!$thisRequired.val().length) {
$thisRequired
.addClass('invalid')
.on('focus', function () {
$thisRequired
.removeClass('invalid');
});
}
});
//if one of form fields is empty - exit
if ($form.find('[aria-required="true"], [required]').hasClass('invalid')) {
return;
}
//sending form data to PHP server if fields are not empty
var request = $form.serialize();
var ajax = jQuery.post("contact-form.php", request)
.done(function (data) {
$($form).find('[type="submit"]').attr('disabled', false).parent().append('
' + data + '
');
//cleaning form
var $formErrors = $form.find('.form-errors');
if (!$formErrors.length) {
$form[0].reset();
}
})
.fail(function (data) {
$($form).find('[type="submit"]').attr('disabled', false).blur().parent().append('
Mail cannot be sent. You need PHP server to send mail.
');
})
});
//search modal
$(".search_modal_button").on('click', function (e) {
e.preventDefault();
$('#search_modal').modal('show').find('input').first().focus();
});
//search form processing - not need in WP
$('form.searchform, form.search-form').on('submit', function (e) {
e.preventDefault();
var $form = $(this);
var $searchModal = $('#search_modal');
$searchModal.find('div.searchform-respond').remove();
//checking on empty values
$($form).find('[type="text"], [type="search"]').each(function (index) {
var $thisField = $(this);
if (!$thisField.val().length) {
$thisField
.addClass('invalid')
.on('focus', function () {
$thisField.removeClass('invalid')
});
}
});
//if one of form fields is empty - exit
if ($form.find('[type="text"]').hasClass('invalid')) {
return;
}
$searchModal.modal('show');
//sending form data to PHP server if fields are not empty
var request = $form.serialize();
var ajax = jQuery.post("search.php", request)
.done(function (data) {
$searchModal.append('