Sha256: 1b7a89288e267d0afc4d45aea12783b8485b6a0efda9f5096e1c7ce627954592

Contents?: true

Size: 1.51 KB

Versions: 26

Compression:

Stored size: 1.51 KB

Contents

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

var HashiMegaNav = function() {
  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);
    }
  }

  var $body = $('#mega-nav-body-ct');
  var $arrow = $('#mega-nav-ctrl');
  var $nav = $arrow.parent();
  var $close = $('#mega-nav-close');

  function matchesBreakpoint() {
    return window.matchMedia("(min-width: 980px)").matches;
  }

  function openNav() {
    if(matchesBreakpoint()) {
      $body.slideDown('fast');
      $nav.addClass('open');
    } else {
      $body.fadeIn('fast');
    }
  }

  function closeNav() {
    if(matchesBreakpoint()) {
      $body.slideUp('fast');
      $nav.removeClass('open');
    } else {
      $body.fadeOut('fast');
    }
  }

  function isNavOpen() {
    return $nav.hasClass('open');
  }

  $arrow.unbind().on('click', function(e) {
    e.preventDefault(); // Don't jump page to "#"

    if(isNavOpen()) {
      closeNav();
    } else {
      openNav();
    }
  });

  $close.unbind().on('click', function() {
    closeNav();
  });
}

// Handle document ready function and the turbolinks load.
$(document).on("ready turbolinks:load", HashiMegaNav);

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
middleman-hashicorp-0.3.47 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.46 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.45 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.44 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.43 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.41 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.40 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.39 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.38 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.37 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.35 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.34 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.33 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.32 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.31 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.30 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.29 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.28 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.26 assets/javascripts/hashicorp/mega-nav.js
middleman-hashicorp-0.3.25 assets/javascripts/hashicorp/mega-nav.js