/** * 2018 XTO * * Mega Menu * * NOTICE OF LICENSE * * This source file is subject to the General Public License (GPL 2.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/GPL-2.0 * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade the module to newer * versions in the future. * * @author XTO * @copyright 2018 Expertos Tiendas Online * @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0) */ var responsiveflagXTOmenu = false; var XTOcategoryMenu = $('ul.menu'); var XTOcategoryGrover = $('.default-menu .menu-title'); $(document).ready(function(){ XTOcategoryMenu = $('ul.menu'); XTOcategoryGrover = $('.default-menu .menu-title'); setColumnClean(); responsiveXTOmenu(); $(window).resize(responsiveXTOmenu); }); // check resolution function responsiveXTOmenu() { if ($(document).width() <= 819 && responsiveflagXTOmenu == false) { menuChange('enable'); responsiveflagXTOmenu = true; } else if ($(document).width() >= 820) { menuChange('disable'); responsiveflagXTOmenu = false; } } function XTOdesktopInit() { XTOcategoryGrover.off(); XTOcategoryGrover.removeClass('active'); $('.menu > li > ul, .menu > li > ul.is-simplemenu ul, .menu > li > div.is-megamenu').removeClass('menu-mobile').parent().find('.menu-mobile-grover').remove(); $('.menu').removeAttr('style'); XTOcategoryMenu.superfish('init'); //add class for width define $('.menu > li > ul').addClass('submenu-container clearfix'); $(".top-level-menu-li-span").each(function() { if($(this).parent().children().length > 1) { $(this).addClass('sf-with-ul'); } }); } function XTOmobileInit() { var XTOclickEventType=((document.ontouchstart!==null)?'click':'touchstart'); XTOcategoryMenu.superfish('destroy'); $('.menu').removeAttr('style'); XTOcategoryGrover.on(XTOclickEventType, function(e){ $(this).toggleClass('active').parent().find('ul.menu').stop().slideToggle('medium'); return false; }); $('.menu > li > ul, .menu > li > div.is-megamenu, .menu > li > ul.is-simplemenu ul').addClass('menu-mobile clearfix').parent().prepend(''); $(".menu .menu-mobile-grover").on(XTOclickEventType, function(e){ var catSubUl = $(this).next().next('.menu-mobile'); if (catSubUl.is(':hidden')) { catSubUl.slideDown(); $(this).addClass('active'); } else { catSubUl.slideUp(); $(this).removeClass('active'); } return false; }); $('.default-menu > ul:first > li > a, .block_content > ul:first > li > a').on(XTOclickEventType, function(e){ var parentOffset = $(this).prev().offset(); var relX = parentOffset.left - e.pageX; if ($(this).parent('li').find('ul').length && relX >= 0 && relX <= 20) { e.preventDefault(); var mobCatSubUl = $(this).next('.menu-mobile'); var mobMenuGrover = $(this).prev(); if (mobCatSubUl.is(':hidden')) { mobCatSubUl.slideDown(); mobMenuGrover.addClass('active'); } else { mobCatSubUl.slideUp(); mobMenuGrover.removeClass('active'); } } }); $(".top-level-menu-li-span").each(function() { if($(this).parent().children().length > 1) { $(this).removeClass('sf-with-ul'); } }); } // change the menu display at different resolutions function menuChange(status) { status == 'enable' ? XTOmobileInit(): XTOdesktopInit(); } function setColumnClean() { $('.menu div.is-megamenu > div').each(function(){ i = 1; $(this).children('.megamenu-col').each(function(index, element) { if(i % 3 == 0) { $(this).addClass('first-in-line-sm'); } i++; }); }); }