View Single Post
  #3  
Old 05-02-2017, 09:19 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Re: Load mobile menu on click via AJAX

With the hamburger menu (for mobile and small screens) I have this working as well. So now the page loads and the menu items are only loaded into the HTML when requested by a click or press.

I've used v6 of the menu system (mmenu.frebsite.nl/) and made a couple of template and CSS tweaks.

This code could probably be improved because I don't 100% understand what X-cart does to make the mmenu work with the rest of the system.

customer/js/slidebar.js

Code:
function slidebar() { var self = this; $("#main_menu").one('mouseenter touchstart', function(event) { event.preventDefault(); core.trigger('mm-menu.before_create', jQuery('#slidebar')); var $ul = jQuery('#slidebar').find(".slidebar-categories").parent(); $.get("megamenuminifiedmobile.txt", function(menuhtmldata) { // add text file to menuhtmldata var var new_content = menuhtmldata; //sessionStorage.mobilemenu; jQuery('#slidebar').find(".slidebar-categories").after(new_content); jQuery('#slidebar').mmenu(self.options, self.configuration); var api = jQuery('#slidebar').data('mmenu'); api.initPanels(); if (event.type === 'touchstart') { // touchmove has been triggered api.open(); } core.trigger('mm-menu.created', api); api.bind('closed', function() { api.closeAllPanels(); }); }); jQuery('.dropdown-menu#search_box').parent().on('shown.bs.dropdown', function() { jQuery('#header').addClass('hidden'); }); jQuery('.dropdown-menu#search_box').parent().on('hidden.bs.dropdown', function() { jQuery('#header').removeClass('hidden'); }); }); }

Mouseenter (followed by a click to open the menu) works without the api.open code but mobile needs this to make the menu appear.
__________________
Core version: 5.5.xx
Reply With Quote