Drupal.TBMegaMenu = Drupal.TBMegaMenu || {}; (function ($) { Drupal.TBMegaMenu.oldWindowWidth = 0; Drupal.TBMegaMenu.displayedMenuMobile = false; Drupal.TBMegaMenu.supportedScreens = [980]; Drupal.TBMegaMenu.menuResponsive = function () { var windowWidth = window.innerWidth ? window.innerWidth : $(window).width(); var navCollapse = $('.tb-megamenu').children('.nav-collapse'); if (windowWidth < Drupal.TBMegaMenu.supportedScreens[0]) { navCollapse.addClass('collapse'); if (Drupal.TBMegaMenu.displayedMenuMobile) { navCollapse.css({height: 'auto', overflow: 'visible'}); } else { navCollapse.css({height: 0, overflow: 'hidden'}); } } else { // If width of window is greater than 980 (supported screen). navCollapse.removeClass('collapse'); if (navCollapse.height() <= 0) { navCollapse.css({height: 'auto', overflow: 'visible'}); } } }; Drupal.behaviors.tbMegaMenuAction = { attach: function(context) { $('.tb-megamenu-button', context).once('menuIstance', function () { var This = this; $(This).click(function() { if(parseInt($(this).parent().children('.nav-collapse').height())) { $(this).parent().children('.nav-collapse').css({height: 0, overflow: 'hidden'}); Drupal.TBMegaMenu.displayedMenuMobile = false; } else { $(this).parent().children('.nav-collapse').css({height: 'auto', overflow: 'visible'}); Drupal.TBMegaMenu.displayedMenuMobile = true; } }); }); var isTouch = 'ontouchstart' in window && !(/hp-tablet/gi).test(navigator.appVersion); if(!isTouch){ $(document).ready(function($){ var mm_duration = 0; $('.tb-megamenu').each (function(){ if ($(this).data('duration')) { mm_duration = $(this).data('duration'); } }); var mm_timeout = mm_duration ? 100 + mm_duration : 500; $('.nav > li, li.mega').hover(function(event) { var $this = $(this); if ($this.hasClass ('mega')) { $this.addClass ('animating'); clearTimeout ($this.data('animatingTimeout')); $this.data('animatingTimeout', setTimeout(function(){$this.removeClass ('animating')}, mm_timeout)); clearTimeout ($this.data('hoverTimeout')); $this.data('hoverTimeout', setTimeout(function(){$this.addClass ('open')}, 100)); } else { clearTimeout ($this.data('hoverTimeout')); $this.data('hoverTimeout', setTimeout(function(){$this.addClass ('open')}, 100)); } }, function(event) { var $this = $(this); if ($this.hasClass ('mega')) { $this.addClass ('animating'); clearTimeout ($this.data('animatingTimeout')); $this.data('animatingTimeout', setTimeout(function(){$this.removeClass ('animating')}, mm_timeout)); clearTimeout ($this.data('hoverTimeout')); $this.data('hoverTimeout', setTimeout(function(){$this.removeClass ('open')}, 100)); } else { clearTimeout ($this.data('hoverTimeout')); $this.data('hoverTimeout', setTimeout(function(){$this.removeClass ('open')}, 100)); } }); }); } $(window).resize(function() { var windowWidth = window.innerWidth ? window.innerWidth : $(window).width(); if(windowWidth != Drupal.TBMegaMenu.oldWindowWidth){ Drupal.TBMegaMenu.oldWindowWidth = windowWidth; Drupal.TBMegaMenu.menuResponsive(); } }); }, } })(jQuery); ; Drupal.TBMegaMenu = Drupal.TBMegaMenu || {}; (function ($) { Drupal.TBMegaMenu.createTouchMenu = function(items) { items.children('a').each( function() { var $item = $(this); var tbitem = $(this).parent(); $item.click( function(event){ if ($item.hasClass('tb-megamenu-clicked')) { var $uri = $item.attr('href'); window.location.href = $uri; } else { event.preventDefault(); $item.addClass('tb-megamenu-clicked'); if(!tbitem.hasClass('open')){ tbitem.addClass('open'); } } }).closest('li').mouseleave( function(){ $item.removeClass('tb-megamenu-clicked'); tbitem.removeClass('open'); }); }); /* items.children('a').children('span.caret').each( function() { var $item = $(this).parent(); $item.click(function(event){ tbitem = $item.parent(); if ($item.hasClass('tb-megamenu-clicked')) { Drupal.TBMegaMenu.eventStopPropagation(event); if(tbitem.hasClass('open')){ tbitem.removeClass('open'); $item.removeClass('tb-megamenu-clicked'); } } else { Drupal.TBMegaMenu.eventStopPropagation(event); $item.addClass('tb-megamenu-clicked'); if(!tbitem.hasClass('open')){ tbitem.addClass('open'); $item.removeClass('tb-megamenu-clicked'); } } }); }); */ } Drupal.TBMegaMenu.eventStopPropagation = function(event) { if (event.stopPropagation) { event.stopPropagation(); } else if (window.event) { window.event.cancelBubble = true; } } Drupal.behaviors.tbMegaMenuTouchAction = { attach: function(context) { var isTouch = 'ontouchstart' in window && !(/hp-tablet/gi).test(navigator.appVersion); if(isTouch){ $('html').addClass('touch'); Drupal.TBMegaMenu.createTouchMenu($('.tb-megamenu ul.nav li.mega').has('.dropdown-menu')); } } } })(jQuery); ;