backup mmenu js

by ian_smithz

JavaScript

//clone desktop menu
        var $origMenu = $('.menu-tier-1').clone();

        $('#duplicate-desktop-menu').html($origMenu);

        // add nav menu as child of menu-tier-1
        $('#duplicate-desktop-menu .menu-tier-1').wrapInner("<nav id='demo-menu'>");

        // add custom close panel
        $('#demo-menu').prepend("<span class='mmenu-custom-nav-panel'><span class='mmenu-custom-home'><a href='/' title='Home'><i class='icon icon-home-1'></i></a></span><span class='mmenu-custom-close'><i class='icon icon-cancel'></i> <span class='mmenu-custom-close-text'>Close</span></span></span>");

        //stop desktop styles
        $('#duplicate-desktop-menu .menu-tier-1').addClass('menu-tier-1-cloned').removeClass('menu-tier-1');
        $('.menu-tier-1-cloned ul.mn').addClass('mn-cloned').removeClass('mn');

        //remove desktop 'departments' title
        $('.menu-tier-1-cloned ul li.first').remove();

        // change tier 1 anchors (only) to spans
        $('.mn-cloned > li > a').each(function() {
            $(this).replaceWith($('<span>' + $(this).text() + '</span>'));
        });

        // change dl dt dd to ul li
        $($('#demo-menu .menu-tier-2').find('dl')).each(function() {
            $(this).replaceWith($('<ul>' + $(this).html() + '</ul>'));
        });

        $($('#demo-menu .menu-tier-2').find('dt')).each(function() {
            $(this).insertBefore($(this).parent());
            $(this).replaceWith($('<span>' + $(this).text() + '</span>'));
        });

        $($('#demo-menu .menu-tier-2').find('dd')).each(function() {
            $(this).replaceWith($('<li>' + $(this).html() + '</li>'));
        });

        //wrap span and next sibling ul in li
        $("#demo-menu .menu-tier-2 span").each(function() {
            $(this).next("ul").andSelf().wrapAll("<li>")
        });

        //add ul around previous
        $('#demo-menu .menu-tier-2').wrapInner("<ul>");

        //call mmenu after manipulating the current html mark up...