Sha256: ba3274c6fb05356fe8ec2b8e518a505f5250b0bb8d139ca4795455843e5e551e

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 KB

Contents

//
// HashiCorp Mega Nav
// --------------------------------------------------

$(function() {

  //handle active product

  var productClass = 'mega-nav-grid-item',
      productActiveClass = 'is-active',
      url = window.location.hostname,
      products = [
        'vagrant',
        'packer',
        'terraform',
        'vault',
        'nomad',
        'consul'
      ];

  for (var i = 0; i < products.length; i++) {
    if (url.indexOf(products[i]) !== -1) {
      $('.' + productClass + '-' + products[i]).addClass(productActiveClass);
    }
  }


  //handle functionality

  var dropDownBreakpoint = window.matchMedia("(min-width: 980px)");

  function megaNavModal() {
    $('#mega-nav-body-ct').attr({
      role: 'dialog',
      tabindex: -1
    });

    $('#mega-nav-ctrl').on('click.megaNav', function(){
      $('#mega-nav-body-ct').modal({
        backdrop: false
      });
    });

    $('#mega-nav-close').on('click.megaNav', function() {
      $('#mega-nav-body-ct').modal('hide');
    });

  }

  function megaNavModalDestroy() {
    $('#mega-nav-ctrl').off('click.megaNav');
    $('#mega-nav-close').off('click.megaNav');
    $('#mega-nav-body-ct')
      .modal('hide')
      .removeAttr('role tabindex style')
      .data('bs.modal', null);
  }

  function megaNavDropDown() {
    $('#mega-nav-ctrl').attr('data-toggle', 'dropdown');
  }

  function megaNavDropDownDestroy() {
    $('#mega-nav-ctrl').parent().removeClass('open');
    $('#mega-nav-ctrl').removeAttr('data-toggle aria-expanded');
    $('#mega-nav-body-ct').removeAttr('aria-labelledby');
  }

  function handleDropDownBreakpoint(breakpoint) {

    if (breakpoint.matches) {
      megaNavModalDestroy();
      megaNavDropDown();
    } else {
      megaNavDropDownDestroy();
      megaNavModal();
    }

  }

  dropDownBreakpoint.addListener(handleDropDownBreakpoint);
  handleDropDownBreakpoint(dropDownBreakpoint);    

});

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
middleman-hashicorp-0.3.15 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.14 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.13 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.12 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.11 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.10 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.9 assets/javascripts/hashicorp/mega-nav.js