Subnav

<nav class="innerpage-nav" role="navigation" id="innerpage-nav">
    <ul class="innerpage-nav-list">
        <li><a href="#">Academics</a></li>
        <li><a href="#">Career Services</a></li>
        <li><a href="#">Resources</a></li>
        <li><a href="#">Entrepreneurship</a></li>
        <li><a href="#">Additional Information</a></li>
    </ul>
    <label for="innerpage-nav-select" class="u-a11y-text">Choose a section on this page to quickly navigate to</label>
    <select id="innerpage-nav-select">
        <option selected="selected" value="">On this page</option>
        <option value="#">Academics</option>
        <option value="#">Career Services</option>
        <option value="#">Resources</option>
        <option value="#">Entrepreneurship</option>
        <option value="#">Additional Information</option>
    </select>
    <button id="innerpage-nav-select-button">Navigate to Section</button>
</nav>
<nav class="innerpage-nav" role="navigation" id="innerpage-nav">
    <ul class="innerpage-nav-list">
      {% block cms_override_list %}
        {% for innerpage_item in innerpage_items %}
            <li><a href="{{ innerpage_item.url }}">{{ innerpage_item.nav_item }}</a></li>
        {% endfor %}
      {% endblock cms_override_list %}
    </ul>
    <label for="innerpage-nav-select" class="u-a11y-text">Choose a section on this page to quickly navigate to</label>
    <select id="innerpage-nav-select">
      <option selected="selected" value="">On this page</option>
      {% block cms_override_select %}
        {% for innerpage_itemm in innerpage_items %}
            <option value="{{ innerpage_itemm.url }}">{{ innerpage_itemm.nav_item }}</option>
        {% endfor %}
      {% endblock cms_override_select %}
    </select>
    <button id="innerpage-nav-select-button">Navigate to Section</button>
</nav>
{
  "innerpage_items": {
    "1": {
      "url": "#",
      "nav_item": "Academics"
    },
    "2": {
      "url": "#",
      "nav_item": "Career Services"
    },
    "3": {
      "url": "#",
      "nav_item": "Resources"
    },
    "4": {
      "url": "#",
      "nav_item": "Entrepreneurship"
    },
    "5": {
      "url": "#",
      "nav_item": "Additional Information"
    }
  }
}
  • Content:
    (function ($) {
      $(document).ready(function () {
        $("section.section-first-level").each(function () {
          console.log("APPENDING");
          const navText = $(this).find('h2.navigation-text').attr('data-nav-text');
          const navAnchor = $(this).find('h2.navigation-text').attr('data-section-name');
          $('.innerpage-nav-list').append('<li><a href="#'+navAnchor+'">'+navText+'</a></li>');
          $('#innerpage-nav-select').append('<option value="#'+navAnchor+'">'+navText+'</option>');
        });
      });
    })(jQuery);
    
    var Drupal = Drupal || {};
    (function ($, Drupal) {
      Drupal.behaviors = Drupal.behaviors || {};
      Drupal.behaviors.lehigh_business_subnav = {
        attach: function(context) {
          $(document).ready(function(){
            console.log('morning tacos');
            jQuery.each(jQuery(".innerpage-nav .innerpage-nav-list li"), function() {
    
              jQuery(this).on("mouseover", function(){$(this).addClass("active")});
    
              jQuery(this).on("mouseout", function(){$(this).removeClass("active")});
    
            });
          });
    
          console.log('night tacos');
          $goto = $('#innerpage-nav-select');
          if ($goto.length) {
            /* If the Submit button is triggered... */
            $('#innerpage-nav-select-button').click(function(e) {	/* (The click event also fires by hitting Enter or Spacebar while the button has the focus.) */
              /* Prevent the Submit button from merely causing a refresh of the current page. */
              e.preventDefault();
              if ($goto.val() == "") return;
              /* Navigate to the URL */
              window.location.href = $goto.val();
              /* To be tidy, reset the <select> to the first value */
              $goto.val($goto.children('option:first').val());
            });
    
            // Run on hash change (user clicked on anchor link)
            if ( 'onhashchange' in window ) {
              window.addEventListener('hashchange', scrollUpToCompensateForFixedHeader);
            }
    
            function scrollUpToCompensateForFixedHeader()
            {
              var hash,
                target,
                offset;
    
              // Get hash, e.g. #mathematics
              hash = window.location.hash;
              if ( hash.length < 2 ) { return; }
    
              // Get :target, e.g. <h2 id="mathematics">...</h2>
              target = document.getElementById( hash.slice(1) );
              if ( target === null ) { return; }
    
              // Get distance of :target from top of viewport. If it's near zero, we assume
              // that the user was just scrolled to the :target.
              if ( target.getBoundingClientRect().top < 2 ) {
                window.scrollBy(0, -100);
              }
            }
    
          }
        }
      };
    })(jQuery, Drupal);
    
  • URL: /components/raw/subnav/subnav.js
  • Filesystem Path: components/02-pieces/03-menus/03-subnav/subnav.js
  • Size: 2.7 KB
  • Content:
    .innerpage-nav {
      margin: 0 auto;
      width: 100%;
      box-shadow: 0 2px 5px $drop_shadow;
      background-color: $white;
      z-index: 500;
      position: relative;
    
      &.sticky {
        position: fixed;
        top: 120px;
        width: 100%;
        max-width: 1920px;
      }
    
      @media only screen and (min-width: $break-desktop) {
      &-list {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: space-evenly;
        @include reset-list-nav;
    
        li {
          padding: $space $space-double;
          font-size: 0.875rem;
          line-height: 1;
    
          a {
            color: $lehigh-brown;
            font-weight: bold;
    
            &:hover {
              text-decoration: none;
            }
          }
    
          &.active,
          &:hover {
            background-color: $gold;
            position: relative;
    
            &::before {
              content: '';
              position: absolute;
              left: -2.8rem;
              top: 0;
              width: 0;
              height: 0;
              border-top: 46px solid transparent;
              border-right: 46px solid $gold;
            }
    
            &::after {
              content: '';
              position: absolute;
              right: -2.8rem;
              top: 0;
              width: 0;
              height: 0;
              border-top: 46px solid $gold;
              border-right: 46px solid transparent;
            }
          }
        }
      }
      #innerpage-nav-select {
    	display: none;
    	+ button {
    		display: none;
    	}
      }
      }
      @media only screen and (max-width: 768px) {
        &-list {
    	display: none;
        }
        display: flex;
        justify-content: center;
    
      }
    }
    
  • URL: /components/raw/subnav/subnav.scss
  • Filesystem Path: components/02-pieces/03-menus/03-subnav/subnav.scss
  • Size: 1.5 KB

No notes defined.