Giter Site home page Giter Site logo

Comments (5)

LaurenceRLewis avatar LaurenceRLewis commented on June 25, 2024

Use a media query and display none on the mega menu. Then display block on your custom menu.

from accessible-mega-menu.

pkavanaghjr avatar pkavanaghjr commented on June 25, 2024

What if I want to use the same menu for both mobile and desktop so doing a display none is not an option? I'm using a CMS and trying to be SEO conscious to not duplicate navigation links that would confuse Google's bots.

Are there any methods for destroying and re-initializing the megamenu js on resize? My event handlers won't function over top of the libraries.

from accessible-mega-menu.

carlafranca avatar carlafranca commented on June 25, 2024

I created a destroy function right below "setOptions" around line 825
destroy: function() {
$(this.menu).off('.accessible-megamenu');
}

Initiate
$("nav:first").accessibleMegaMenu(megamenu);
Remove
$('nav:first').data('plugin_accessibleMegaMenu').destroy();
Re-start
$('nav:first').data('plugin_accessibleMegaMenu').init();

from accessible-mega-menu.

pbhar28 avatar pbhar28 commented on June 25, 2024

@carlafranca Hi, Can you please elaborate further on how can I use the above destroy function. I need to turn-off megamenu below certain resolution and bind different events(touch -tap/doubleTap)

Many thanks in advance.

Regards,

Mark W

from accessible-mega-menu.

carlafranca avatar carlafranca commented on June 25, 2024

@pbhar28 Hi Mark, yes sure. Here is how I use it.

1. On load:

Start the plugin only on specific size:

if($(window).width() >= 992 ){
       $("nav:first").accessibleMegaMenu(megamenu);
}

2. On window resize I call one of the functions below depending on the browser size:

mobileSetup:

On my implementation I remove all the "aria" on links and dropdowns added by the plugin (It will be added again once the plugin is restarted)
I do it because my menu changes completely. No second level on mobile.

//Remove aria on mobile
$('.nav__item > a').removeAttr('aria-controls aria-expanded aria-haspopup');
$('.nav__menu-panel').removeAttr('role aria-expanded aria-hidden aria-labelledby');

//Destroy accessibility plugin on mobile
if($('nav:first').data('plugin_accessibleMegaMenu')) {
       $('nav:first').data('plugin_accessibleMegaMenu').destroy();
}

desktopSetup:

//Check if plugin was started using data and the plugin name
if( $('nav:first').data('plugin_accessibleMegaMenu') ){
     //Restart the plugin
    $('nav:first').data('plugin_accessibleMegaMenu').init();
}else{
    $("nav:first").accessibleMegaMenu(megamenu);
}

from accessible-mega-menu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.