/* JS Document */ /****************************** [Table of Contents] 1. Vars and Inits 2. Set Header 3. Init Menu 4. Init Google Map 5. Init Accordions ******************************/ $(document).ready(function() { "use strict"; /* 1. Vars and Inits */ var header = $('.header'); var menuActive = false; var menu = $('.menu'); var burger = $('.burger_container'); var map; setHeader(); $(window).on('resize', function() { setHeader(); }); $(document).on('scroll', function() { setHeader(); }); initMenu(); initGoogleMap(); initAccordions(); /* 2. Set Header */ function setHeader() { if($(window).scrollTop() > 100) { header.addClass('scrolled'); } else { header.removeClass('scrolled'); } } /* 3. Init Menu */ function initMenu() { if($('.menu').length) { var menu = $('.menu'); if($('.burger_container').length) { burger.on('click', function() { if(menuActive) { closeMenu(); } else { openMenu(); $(document).one('click', function cls(e) { if($(e.target).hasClass('menu_mm')) { $(document).one('click', cls); } else { closeMenu(); } }); } }); } } } function openMenu() { menu.addClass('active'); menuActive = true; } function closeMenu() { menu.removeClass('active'); menuActive = false; } /* 4. Init Google Map */ function initGoogleMap() { var myLatlng = new google.maps.LatLng(36.131475, -5.350348); var mapOptions = { center: myLatlng, zoom: 17, mapTypeId: google.maps.MapTypeId.ROADMAP, draggable: true, scrollwheel: false, zoomControl: true, zoomControlOptions: { position: google.maps.ControlPosition.RIGHT_CENTER }, mapTypeControl: false, scaleControl: false, streetViewControl: false, rotateControl: false, fullscreenControl: true, styles:[] } // Initialize a map with options map = new google.maps.Map(document.getElementById('map'), mapOptions); // Re-center map after window resize google.maps.event.addDomListener(window, 'resize', function() { setTimeout(function() { google.maps.event.trigger(map, "resize"); map.setCenter(myLatlng); }, 1400); }); } /* 5. Init Accordions */ function initAccordions() { if($('.accordion').length) { var accs = $('.accordion'); accs.each(function() { var acc = $(this); if(acc.hasClass('active')) { var panel = $(acc.next()); var panelH = panel.prop('scrollHeight') + "px"; if(panel.css('max-height') == "0px") { panel.css('max-height', panel.prop('scrollHeight') + "px"); } else { panel.css('max-height', "0px"); } } acc.on('click', function() { if(acc.hasClass('active')) { acc.removeClass('active'); var panel = $(acc.next()); var panelH = panel.prop('scrollHeight') + "px"; if(panel.css('max-height') == "0px") { panel.css('max-height', panel.prop('scrollHeight') + "px"); } else { panel.css('max-height', "0px"); } } else { acc.addClass('active'); var panel = $(acc.next()); var panelH = panel.prop('scrollHeight') + "px"; if(panel.css('max-height') == "0px") { panel.css('max-height', panel.prop('scrollHeight') + "px"); } else { panel.css('max-height', "0px"); } } }); }); } } });