define(function(require, exports, module){ // Module config var config = {}; var App = require('app'); require('jquery.hoverintent'); require('jquery.mousewheel'); require('lightgallery'); require('swiper'); require('jquery.tabs'); require('cookienote'); require('jquery.validate'); module.exports = { init: function(configArg){ // Compile module config from RequireJS module.config() and init() argument $.extend(config, module.config(), configArg); console.log('app-commons.init(); config = ', config); menuHoverIntent(); stickyNav(); initMobileMenu(); initSwiperSlider(); initLightbox(); initTabs(); accordionMenu(); initCookieNote(); validation(); if ($('#imp-carousel').length) { initCarousel(); } }, // Keep config reference outside the module config: config }; function menuHoverIntent() { $('.main-nav__list__submenu').parent().hoverIntent({ sensitivity: 3, interval: 70, timeout: 700, over: function() { $(this).addClass('_--is-hover'); }, out: function() { $(this).removeClass('_--is-hover'); } }); $('.main-nav__list__submenu li').hoverIntent({ sensitivity: 3, interval: 70, timeout: 100, over: function() { $(this).addClass('_--current-submenu-item'); }, out: function() { $(this).removeClass('_--current-submenu-item'); } }); } function stickyNav() { $(window).scroll(function () { if ($(this).scrollTop() > 1) { $('.site-header').addClass('site-header--sticky'); } else { $('.site-header').removeClass('site-header--sticky'); } }); } function initMobileMenu () { $('.mobile-nav-btn').on('click', function (){ $(this).toggleClass('_--is-expanded'); $('.main-nav').toggleClass('_--is-expanded'); }); } function initSwiperSlider() { var swiper = new Swiper('.slider', { pagination: '.slider-pagination', paginationClickable: true, nextButton: '.slider-btn--next', prevButton: '.slider-btn--prev', spaceBetween: 30, autoplay: 3000, effect: 'fade', fade : { crossFade: true } }); } function initLightbox() { $('.lightbox').lightGallery({ thumbnail: true, selector: '.thumb' }); } function initTabs() { $ul = $('.tabs-nav'); $ul.lizardTabs({ open: $ul.data('active-tab') ? $ul.data('active-tab') : 0 }); } function accordionMenu() { $('.accordion-menu__item__title').click(function() { $(this).parent().toggleClass('accordion-menu__item--active'); $(this).siblings('.accordion-menu__item__content').slideToggle(200); }); } function initCarousel() { require('owl-carousel'); var carouselContainer = $('#imp-carousel'); var owl = $('.owl-carousel'); if ($('.refs--small').length) { var carouselItems = 3; } else { var carouselItems = 5; } $('.imp-carousel__item', carouselContainer).first().addClass('imp-carousel__item--active'); carouselContainer.owlCarousel({ items: carouselItems, autoPlay: 3000, addClassActive: true, beforeUpdate: setCarouselHeight, beforeInit: setCarouselHeight, beforeMove: setCarouselHeight, afterAction: setCarouselHeight }); function setCarouselHeight() { var maxHeight = 0, $owlWrapperOuter = $('.owl-wrapper-outer'), $owlItemActive = $('.owl-item.active'); $owlItemActive.each(function () { var thisHeight = parseInt( $(this).height() ); maxHeight = (maxHeight >= thisHeight ? maxHeight : thisHeight); }); $owlWrapperOuter.addClass('autoHeight'); $owlWrapperOuter.css('height', maxHeight); } $(".imp-carousel-nav__next").click(function(){ owl.trigger('owl.next'); }); $(".imp-carousel-nav__prev").click(function(){ owl.trigger('owl.prev'); }); } function initCookieNote() { CookieNote.init(); } function validation() { $('form').each(function(){ var op1 = Math.floor((Math.random() * 100) + 1); $(this).find('input[name=op1]').val(op1); $(this).find('input[name=op2]').val(131 - op1); }); $.validator.addMethod( "regex", function(value, element, regexp) { var re = new RegExp(regexp); return this.optional(element) || re.test(value); }, "Please check your input." ); $('#send-project-form').validate({ rules: { phone: { minlength: 9, regex: "^[0-9\-\+]{9,15}$" } }, errorElement: "span", submitHandler: function(){ $('button').attr('disabled', 'disabled'); $('.send-project-form').css('opacity', '0.3'); form.submit(); } }); } });