;(function($, window, document, undefined) { "use strict"; /*============================*/ /* 01 - VARIABLES */ /*============================*/ var swipers = [], winW, winH, winScr, _isresponsive, smPoint = 768, mdPoint = 992, lgPoint = 1200, addPoint = 1600, _ismobile = navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i); /*========================*/ /* 02 - PAGE CALCULATIONS */ /*========================*/ if (typeof pageCalculations !== 'function') { var winW, winH, winS, pageCalculations,onEvent = window.addEventListener; pageCalculations = function(func){ winW = window.innerWidth; winH = window.innerHeight; winS = document.body.scrollTop; if (!func) return; onEvent('load', func, true); // window onload onEvent('resize', func, true); // window resize onEvent("orientationchange", func, false); // window orientationchange } // end pageCalculations pageCalculations(function(){ if( $('.wpc-map').length ) { $('.wpc-map').each(function() { initializeMap(this); }); } initIsotope(); }); } /*=================================*/ /* 03 - FUNCTION ON DOCUMENT READY */ /*=================================*/ /*============================*/ /* 04 - FUNCTION ON PAGE LOAD */ /*============================*/ $(window).on('load', function(){ $('body').addClass('loaded').find('.preloader-wrap').addClass('loaded'); initSwiper(); }); /*==============================*/ /* 05 - FUNCTION ON PAGE RESIZE */ /*==============================*/ function resizeCall(){ pageCalculations(); $('.swiper-container.initialized[data-slides-per-view="responsive"]').each(function(){ var thisSwiper = swipers['swiper-'+$(this).attr('id')], $t = $(this), slidesPerViewVar = updateSlidesPerView($t), centerVar = thisSwiper.params.centeredSlides; thisSwiper.params.slidesPerView = slidesPerViewVar; thisSwiper.reInit(); if(!centerVar){ var paginationSpan = $t.find('.pagination span'); var paginationSlice = paginationSpan.hide().slice(0,(paginationSpan.length+1-slidesPerViewVar)); if(paginationSlice.length<=1 || slidesPerViewVar>=$t.find('.swiper-slide').length) $t.addClass('pagination-hidden'); else $t.removeClass('pagination-hidden'); paginationSlice.show(); } }); } if(!_ismobile){ $(window).resize(function(){ resizeCall(); }); } else{ window.addEventListener("orientationchange", function() { resizeCall(); }, false); } /*=====================*/ /* 07 - SWIPER SLIDERS */ /*=====================*/ function initSwiper(){ var initIterator = 0; $('.swiper-container').each(function(){ var $t = $(this); var index = 'swiper-unique-id-'+initIterator; $t.addClass('swiper-'+index + ' initialized').attr('id', index); $t.find('.pagination').addClass('pagination-'+index); var autoPlayVar = parseInt($t.attr('data-autoplay'),10); var mode = $t.attr('data-mode'); var slidesPerViewVar = $t.attr('data-slides-per-view'); if(slidesPerViewVar == 'responsive'){ slidesPerViewVar = updateSlidesPerView($t); } else slidesPerViewVar = parseInt(slidesPerViewVar,10); var loopVar = parseInt($t.attr('data-loop'),10); var speedVar = parseInt($t.attr('data-speed'),10); var centerVar = parseInt($t.attr('data-center'),10); swipers['swiper-'+index] = new Swiper('.swiper-'+index,{ speed: speedVar, pagination: '.pagination-'+index, loop: loopVar, paginationClickable: true, autoplay: autoPlayVar, slidesPerView: slidesPerViewVar, keyboardControl: true, calculateHeight: true, simulateTouch: true, roundLengths: true, centeredSlides: centerVar, mode: mode || 'horizontal', onInit: function(swiper){ $t.find('.swiper-slide').addClass('active'); }, onSlideChangeEnd: function(swiper){ var activeIndex = (loopVar===1)?swiper.activeLoopIndex:swiper.activeIndex; }, onSlideChangeStart: function(swiper){ $t.find('.swiper-slide.active').removeClass('active'); } }); swipers['swiper-'+index].reInit(); if($t.attr('data-slides-per-view')=='responsive'){ var paginationSpan = $t.find('.pagination span'); var paginationSlice = paginationSpan.hide().slice(0,(paginationSpan.length+1-slidesPerViewVar)); if(paginationSlice.length<=1 || slidesPerViewVar>=$t.find('.swiper-slide').length) $t.addClass('pagination-hidden'); else $t.removeClass('pagination-hidden'); paginationSlice.show(); } if($t.find('.default-active').length){ swipers['swiper-'+index].swipeTo($t.find('.swiper-slide').index($t.find('.default-active')), 0); } initIterator++; }); } function updateSlidesPerView(swiperContainer){ if(winW>=addPoint) return parseInt(swiperContainer.attr('data-add-slides'),10); else if(winW>=lgPoint) return parseInt(swiperContainer.attr('data-lg-slides'),10); else if(winW>=mdPoint) return parseInt(swiperContainer.attr('data-md-slides'),10); else if(winW>=smPoint) return parseInt(swiperContainer.attr('data-sm-slides'),10); else return parseInt(swiperContainer.attr('data-xs-slides'),10); } //swiper arrows $('.swiper-arrow-left').on('click', function(){ swipers['swiper-'+$(this).parent().attr('id')].swipePrev(); }); $('.swiper-arrow-right').on('click', function(){ swipers['swiper-'+$(this).parent().attr('id')].swipeNext(); }); $('.swiper-outer-left').on('click', function(){ swipers['swiper-'+$(this).parent().find('.swiper-container').attr('id')].swipePrev(); }); $('.swiper-outer-right').on('click', function(){ swipers['swiper-'+$(this).parent().find('.swiper-container').attr('id')].swipeNext(); }); /***********************************/ /*WINDOW SCROLL*/ /**********************************/ /***********************************/ /*VIDEO*/ /**********************************/ $('.cut_video_btn').on('click', function(){ var video = $(this).data('video'); $(this).parents('.cut_video_block').addClass('active'); $(this).siblings('.cut_video_iframe').attr('src',video); return false; }); $('.cut_video_close').on('click', function(){ $(this).parents('.cut_video_block').removeClass('active'); $(this).siblings('.cut_video_iframe').attr('src','about:blank'); return false; }); /***********************************/ /*BACKGROUND*/ /**********************************/ //sets child image as a background $('.s-back-switch').each(function(){ var $img = $(this).find('.s-img-switch'); var $imgSrc = $img.attr('src'); var $imgDataHidden = $img.data('s-hidden'); $(this).css('background-image' , 'url(' + $imgSrc + ')'); if($imgDataHidden){ $img.css('visibility', 'hidden'); }else{ $img.hide(); } }); /**********************************/ /*HEADER*/ /**********************************/ var $first_child_link = $('.menu-item-has-children > a').append(''); $('.maldive-nav-menu-icon').on('click', function(e) { $(this).toggleClass('active'); $('.maldive-navigation-wrapper').toggleClass('active'); $('.hr-static').toggleClass('hr-static-fix'); e.preventDefault(); }); $first_child_link.find('span').on('click', function(e) { $(this).closest('li').toggleClass('active'); e.preventDefault(); }); $('a[href*="#"]:not([href="#"])').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 }, 1000); return false; } } }); /**********************************/ /*PORTFOLIO*/ /**********************************/ function initIsotope() { $('.isotope-container').each(function(){ var $container = $(this).find('.portfolio-list'); var $filter = $(this).find('.filters'); /* Init isotope */ if( $container.hasClass('maldives-isotope-content') ) { $container.isotope({ itemSelector: '.grid-item', layoutMode: 'masonry', }); } else { $container.isotope({ itemSelector: '.grid-item', layoutMode: 'fitRows' }); } /* Filter */ $filter.on('click', '.but', function() { $filter.find('.but').removeClass('activbut'); $(this).addClass('activbut'); var filterValue = $(this).attr('data-filter'); $container.isotope({filter: filterValue}); return false; }); }); } /**********************************/ /*POP UP*/ /**********************************/ if ($('.popup-gallery').length) { $('.popup-gallery').magnificPopup({ delegate: '.view-item', type: 'image', removalDelay: 100, tLoading: 'Loading image #%curr%...', mainClass: 'mfp-fade', closeBtnInside: false, gallery: { enabled: true, }, callbacks: { beforeOpen: function() { this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure animated ' + this.st.el.attr('data-effect')); } } }) } /**********************************/ /*TEAM ANIMATION*/ /**********************************/ $('.maldives-team-item-wrapper').on('mouseenter', function(){ var progressLine = $(this).find('.progress-line'); var skillsWidth = progressLine.attr('data-width'); progressLine.width(skillsWidth); }) $('.maldives-team-item-wrapper').on('mouseleave', function(){ var progressLine = $(this).find('.progress-line'); progressLine.width(0); }) /**********************************/ /*GOOGLE MAP*/ /**********************************/ if( $('.wpc-map').length ) { $('.wpc-map').each(function() { initializeMap(this); }); } function initializeMap(_this) { var stylesArray = { //style 1 'style-1' : [{"featureType":"all","elementType":"labels.text.fill","stylers":[{"saturation":36},{"color":"#000000"},{"lightness":40}]},{"featureType":"all","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#000000"},{"lightness":16}]},{"featureType":"all","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry.fill","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":17},{"weight":1.2}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":21}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"color":"#000000"},{"lightness":17}]},{"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":29},{"weight":0.2}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":18}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":16}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":19}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":17}]}] }; var styles, map, marker, infowindow, lat = $(_this).attr("data-lat"), lng = $(_this).attr("data-lng"), contentString = $(_this).attr("data-string"), image = $(_this).attr("data-marker"), styles_attr = $(_this).attr("data-style"), zoomLevel = parseInt($(_this).attr("data-zoom"),10), myLatlng = new google.maps.LatLng(lat,lng); // style_1 if (styles_attr == 'style-1') { styles = stylesArray[styles_attr]; } // custom if (typeof maldives_style_map != 'undefined' && styles_attr == 'custom') { styles = maldives_style_map; } // or default style var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"}); var mapOptions = { zoom: zoomLevel, disableDefaultUI: true, center: myLatlng, scrollwheel: false, draggable: _ismobile, mapTypeControlOptions: { mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style'] } }; map = new google.maps.Map(_this, mapOptions); map.mapTypes.set('map_style', styledMap); map.setMapTypeId('map_style'); infowindow = new google.maps.InfoWindow({ content: contentString }); marker = new google.maps.Marker({ position: myLatlng, map: map, icon: image }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); } /**********************************/ /*CONTACT FORM*/ /**********************************/ $('.js-contact-form').submit(function(e){ $('.ajax-loader').show(); var url = 'mail.php', form = this; $(form).find('[name="fields[code]"]').remove(); function result(class_key, data){ setTimeout(function(){ $('.ajax-loader').hide(); $('.ajax-result').find(class_key).show().text(data); },500); } $.ajax({ type: "POST", url: url, data: $(form).serialize(), }) .done(function(data) { result('.success', data); }).error(function(data){ result('.error', data); }) e.preventDefault(); }); })(jQuery, window, document);