File: //proc/3421/cwd/public_html/javascript/main.js
/**
* isMobile
* responsiveMenu
* headerFixed
* onepage_nav
* ajaxContactForm
* alertBox
* blogSlider
* widgetSlider
* gallerySlider
* flatClients
* flatTestimonial
* detectViewport
* flatCounter
* flatSearch
* googleMap
* popupGallery
* flatFilterPrice
* flatAccordion
* portfolioIsotope
* flatTabs
* shopTabs
* goTop
* retinaLogos
* parallax
* removePreloader
*/
;(function($) {
'use strict'
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
var responsiveMenu = function() {
var menuType = 'desktop';
$(window).on('load resize', function() {
var currMenuType = 'desktop';
if ( matchMedia( 'only screen and (max-width: 991px)' ).matches ) {
currMenuType = 'mobile';
}
if ( currMenuType !== menuType ) {
menuType = currMenuType;
if ( currMenuType === 'mobile' ) {
var $mobileMenu = $('#mainnav').attr('id', 'mainnav-mobi').hide();
var hasChildMenu = $('#mainnav-mobi').find('li:has(ul)');
$('#header').after($mobileMenu);
hasChildMenu.children('ul').hide();
hasChildMenu.children('a').after('<span class="btn-submenu"></span>');
$('.btn-menu').removeClass('active');
} else {
var $desktopMenu = $('#mainnav-mobi').attr('id', 'mainnav').removeAttr('style');
$desktopMenu.find('.submenu').removeAttr('style');
$('#header').find('.nav-wrap').append($desktopMenu);
$('.btn-submenu').remove();
}
}
});
$('.btn-menu').on('click', function() {
$('#mainnav-mobi').slideToggle(300);
$(this).toggleClass('active');
});
$(document).on('click', '#mainnav-mobi li .btn-submenu', function(e) {
$(this).toggleClass('active').next('ul').slideToggle(300);
e.stopImmediatePropagation()
});
}
var headerFixed = function() {
if ( $('body').hasClass('header-sticky') ) {
var hd_height = $('#header').height();
$(window).on('load scroll', function(){
if ( $(window).scrollTop() > hd_height + 30 ) {
$('#header').addClass('downscrolled');
} else {
$('#header').removeClass('downscrolled');
}
if( $(window).scrollTop() > 145 ) {
$('#header').addClass('upscrolled');
} else {
$('#header').removeClass('upscrolled');
}
})
}
}
var onepage_nav = function () {
$('.page-template-front-page .mainnav > ul > li > a').on('click',function() {
var anchor = $(this).attr('href').split('#')[1];
var largeScreen = matchMedia('only screen and (min-width: 992px)').matches;
var headerHeight = 0;
headerHeight = $('.header').height();
if ( anchor ) {
if ( $('#'+anchor).length > 0 ) {
if ( $('.header-sticky').length > 0 && largeScreen ) {
headerHeight = headerHeight;
} else {
headerHeight = 0;
}
var target = $('#'+anchor).offset().top - headerHeight;
$('html,body').animate({scrollTop: target}, 1000, 'easeInOutExpo');
}
}
return false;
})
$('.mainnav ul > li > a').on( 'click', function() {
$( this ).addClass('active').parent().siblings().children().removeClass('active');
});
}
var ajaxContactForm = function() {
$('#contactform').each(function() {
$(this).validate({
submitHandler: function( form ) {
var $form = $(form),
str = $form.serialize(),
loading = $('<div />', { 'class': 'loading' });
$.ajax({
type: "POST",
url: $form.attr('action'),
data: str,
beforeSend: function () {
$form.find('.submit-wrap').append(loading);
},
success: function( msg ) {
var result, cls;
if ( msg == 'Success' ) {
result = 'Message Sent Successfully To Email Administrator. ( You can change the email management a very easy way to get the message of customers in the user manual )';
cls = 'msg-success';
} else {
result = 'Error sending email.';
cls = 'msg-error';
}
$form.prepend(
$('<div />', {
'class': 'flat-alert ' + cls,
'text' : result
}).append(
$('<a class="close" href="#"><i class="fa fa-close"></i></a>')
)
);
$form.find(':input').not('.submit').val('');
},
complete: function (xhr, status, error_thrown) {
$form.find('.loading').remove();
}
});
}
});
}); // each contactform
};
var alertBox = function() {
$(document).on('click', '.close', function(e) {
$(this).closest('.flat-alert').remove();
e.preventDefault();
})
}
var blogSlider = function() {
if ( $().flexslider ) {
$('.blog-slider').each(function() {
var $this = $(this)
$this.find('.flexslider').flexslider({
animation : "slide",
direction : "horizontal", // vertical
pauseOnHover : true,
useCSS : false,
easing : "swing",
animationSpeed : 500,
slideshowSpeed : 5000,
controlNav : true,
directionNav : true,
slideshow : true,
prevText : '<i class="fa fa-angle-left"></i>',
nextText : '<i class="fa fa-angle-right"></i>',
smoothHeight : true
}); // flexslider
}); // blog-sider
}
};
var widgetSlider = function() {
if ( $().flexslider ) {
$('.widget-slider').each(function() {
var $this = $(this)
$this.find('.flexslider').flexslider({
animation : "slide",
direction : "horizontal", // vertical
pauseOnHover : true,
useCSS : false,
easing : "swing",
animationSpeed : 500,
slideshowSpeed : 5000,
controlNav : true,
directionNav : false,
slideshow : true,
smoothHeight : true
}); // flexslider
}); // blog-sider
}
};
var gallerySlider = function() {
if ( $().flexslider ) {
$('.project-gallery-slider').each(function() {
var $this = $(this)
$this.find('.flexslider').flexslider({
animation : "slide",
direction : "horizontal", // vertical
pauseOnHover : true,
useCSS : false,
easing : "swing",
animationSpeed : 500,
slideshowSpeed : 5000,
controlNav : true,
directionNav : true,
slideshow : true,
prevText : '<i class="fa fa-angle-left"></i>',
nextText : '<i class="fa fa-angle-right"></i>',
smoothHeight : true
}); // flexslider
}); // blog-sider
}
};
var flatClients = function() {
$('.flat-row').each(function() {
if ( $().owlCarousel ) {
$(this).find('.flat-clients').owlCarousel({
loop: true,
margin: 30,
nav: false,
dots: false,
autoplay: true,
responsive:{
0:{
items: 1
},
480:{
items: 3
},
767:{
items: 3
},
991:{
items: 3
},
1200: {
items: 4
}
}
});
}
});
};
var flatTestimonial = function() {
$('.flat-row').each(function() {
if ( $().owlCarousel ) {
$(this).find('.flat-testimonial').owlCarousel({
loop: true,
margin: 30,
nav: true,
dots: false,
autoplay: true,
responsive:{
0:{
items: 1
},
767:{
items: 2
},
991:{
items: 2
},
1200: {
items: 2
}
}
});
}
});
};
var detectViewport = function() {
$('[data-waypoint-active="yes"]').waypoint(function() {
$(this).trigger('on-appear');
}, { offset: '90%', triggerOnce: true });
$(window).on('load', function() {
setTimeout(function() {
$.waypoints('refresh');
}, 100);
});
};
var flatCounter = function() {
$('.counter').on('on-appear', function() {
$(this).find('.numb-count').each(function() {
var to = parseInt( ($(this).attr('data-to')),10 ), speed = parseInt( ($(this).attr('data-speed')),10 );
if ( $().countTo ) {
$(this).countTo({
to: to,
speed: speed
});
}
});
});
};
var flatSearch = function () {
$('.flat-search').on( 'click', function () {
if( !$('.top-search' ).hasClass( "show" ))
$('.top-search').addClass( 'show' );
else
$( '.top-search' ).removeClass( 'show' );
});
}
var googleMap = function() {
if ( $().gmap3 ) {
$("#flat-map").gmap3({
map:{
options:{
zoom: 14,
mapTypeId: 'corvus_style',
mapTypeControlOptions: {
mapTypeIds: ['corvus_style', google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID]
},
scrollwheel: false
}
},
getlatlng:{
address: "121 King Street, Melbourne",
callback: function(results) {
if ( !results ) return;
$(this).gmap3('get').setCenter(new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()));
$(this).gmap3({
marker:{
latLng:results[0].geometry.location,
options:{
icon: 'http://themesflat.com/images/icon/map.png'
}
}
});
}
},
styledmaptype:{
id: "corvus_style",
options:{
name: "Corvus Map"
},
},
});
}
};
var popupGallery = function () {
$('.flat-row').each(function() {
if ( $('a').hasClass('popup-gallery') ) {
$(".popup-gallery").magnificPopup({
type: "image",
tLoading: "Loading image #%curr%...",
removalDelay: 600,
mainClass: "my-mfp-slide-bottom",
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [ 0, 1 ]
},
image: {
tError: '<a href="%url%">The image #%curr%</a> could not be loaded.'
}
});
}
});
}
var flatFilterPrice = function() {
if( $().slider ) {
$( ".price_slider" ).slider({
range: true,
min: 9,
max: 35,
values: [ 9, 35 ],
slide: function( event, ui ) {
$( ".price_label > input " ).val( "£" + ui.values[ 0 ] + " - £" + ui.values[ 1 ] );
}
});
$( ".price_label > input " ).val( "£" + $( ".price_slider" ).slider( "values", 0 ) +
" - £" + $( ".price_slider" ).slider( "values", 1 ) );
$( ".ui-slider-handle").append("<span class='shadow'></span>");
}
};
var flatAccordion = function() {
var args = {duration: 600};
$('.flat-toggle .toggle-title.active').siblings('.toggle-content').show();
$('.flat-toggle.enable .toggle-title').on('click', function() {
$(this).closest('.flat-toggle').find('.toggle-content').slideToggle(args);
$(this).toggleClass('active');
}); // toggle
$('.flat-accordion .toggle-title').on('click', function () {
if( !$(this).is('.active') ) {
$(this).closest('.flat-accordion').find('.toggle-title.active').toggleClass('active').next().slideToggle(args);
$(this).toggleClass('active');
$(this).next().slideToggle(args);
} else {
$(this).toggleClass('active');
$(this).next().slideToggle(args);
}
}); // accordion
};
var portfolioIsotope = function() {
if ( $().isotope ) {
var $container = $('.projects-portfolio');
$container.imagesLoaded(function(){
$container.isotope({
itemSelector: '.item',
transitionDuration: '1s'
});
});
$('.portfolio-filter li').on('click',function() {
var selector = $(this).find("a").attr('data-filter');
$('.portfolio-filter li').removeClass('active');
$(this).addClass('active');
$container.isotope({ filter: selector });
return false;
});
};
};
var flatTabs = function () {
$('.flat-tabs').each(function() {
$(this).children('.content-tab').children().hide();
$(this).children('.content-tab').children().first().show();
$(this).find('.menu-tab').children('li').on('click', function(e) {
var liActive = $(this).index(),
contentActive = $(this).siblings().removeClass('active').parents('.flat-tabs').children('.content-tab').children().eq(liActive);
contentActive.addClass('active').fadeIn('slow');
contentActive.siblings().removeClass('active');
$(this).addClass('active').parents('.flat-tabs').children('.content-tab').children().eq(liActive).siblings().hide();
e.preventDefault();
});
});
};
var shopTabs = function () {
$('.woocommerce-tabs').each(function() {
$(this).children('.content-tab').children().hide();
$(this).children('.content-tab').children().first().show();
$(this).find('.tabs').children('li').on('click', function(e) {
var liActive = $(this).index(),
contentActive = $(this).siblings().removeClass('active').parents('.woocommerce-tabs').children('.content-tab').children().eq(liActive);
contentActive.addClass('active').fadeIn('slow');
contentActive.siblings().removeClass('active');
$(this).addClass('active').parents('.woocommerce-tabs').children('.content-tab').children().eq(liActive).siblings().hide();
e.preventDefault();
});
});
}
var goTop = function() {
$(window).scroll(function() {
if ( $(this).scrollTop() > 800 ) {
$('.go-top').addClass('show');
} else {
$('.go-top').removeClass('show');
}
});
$('.go-top').on('click', function() {
$("html, body").animate({ scrollTop: 0 }, 1000 , 'easeInOutExpo');
return false;
});
};
var retinaLogos = function() {
var retina = window.devicePixelRatio > 1 ? true : false;
if( retina ) {
$( '.header .logo' ).find('img').attr( {src:'./images/logo@2x.png',width:'286',height:'120'} );
}
};
var parallax = function() {
if ( $().parallax && isMobile.any() == null ) {
$('.parallax1').parallax("50%", 0.2);
$('.parallax2').parallax("50%", 0.4);
$('.parallax3').parallax("50%", 0.5);
}
};
var removePreloader = function() {
$('.loading-overlay').fadeOut('slow',function () {
$(this).remove();
});
};
// Dom Ready
$(function() {
if ( matchMedia( 'only screen and (min-width: 991px)' ).matches ) {
headerFixed();
}
googleMap();
blogSlider();
widgetSlider();
goTop();
onepage_nav();
gallerySlider();
popupGallery();
portfolioIsotope();
flatAccordion();
flatTabs();
shopTabs();
flatClients();
flatCounter();
flatSearch();
flatFilterPrice();
responsiveMenu();
flatTestimonial();
detectViewport();
ajaxContactForm();
alertBox();
retinaLogos();
parallax();
removePreloader();
});
})(jQuery);