r2d2 of Speak Creative
3/27/2019 - 4:49 PM

Click into Nav with link prepend

Sets up click into nav while also allowing the top level items to stay navigable unless there is a submenu in which case this will attach a psuedo "Overview" option to the dropdown that will link to the top level page. This allows us to not have to create extra pages in backend of sitewrench.

      $('header ul#mainnav > li.hasChild').addClass('dropdown');
      $('header ul#mainnav > li.hasChild > a').addClass('dropdown-toggle').attr('data-toggle','dropdown');
      $('header ul#mainnav > li.hasChild > ul').addClass('dropdown-menu');
      var topLinks = document.querySelectorAll("a.dropdown-toggle");
      console.log(topLinks);
      $(topLinks).each(function() {
        var topLink = $(this).attr('href');
        console.log(this)
        $(this).parent('li.dropdown').find("ul.dropdown-menu").prepend("<li class='sw-menucode-list__item' id='" + topLink + "'><a href='" + topLink + "' title='Overview'>Overview</a></li>");
        $(this).attr("href", ""); 
      });