Sha256: 78755ae8664d80c7d0129218506842cf985bf7a71d868a184f2c572af93ad8b7

Contents?: true

Size: 1.18 KB

Versions: 26

Compression:

Stored size: 1.18 KB

Contents

// HashiSidebar is the sidebar implementation for mobile websites. It
// appears at a configurable breakpoint in the CSS.
var HashiSidebar = function() {
  var $sidebar = $('.sidebar');
  var $toggle = $('.navbar-toggle');
  var $overlay = $('.sidebar-overlay');

  function sidebarActive() {
    return $sidebar.hasClass('open');
  }

  function hideSidebar() {
    if(sidebarActive()) {
      $sidebar.removeClass('open');
      $overlay.removeClass('active');
    }
  }

  // Hide the sidebar when the user clicks on the overlay. The overlay is
  // only "clickable" when it's active.
  $overlay.unbind().on('click', function(e){
    hideSidebar();
  });

  // Show the sidebar when the user clicks the hamburger menu.
  $toggle.unbind().on('click', function(e) {
    e.preventDefault(); // Don't jump page to "#"

    // Only activate the sidebar if it's not already active. Since these
    // are class selectors, it's possible that we are watching multiple
    // elements.
    if(!sidebarActive()) {
      $overlay.addClass('active');
      $sidebar.toggleClass('open');
    }
  });
}

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

Version data entries

26 entries across 26 versions & 1 rubygems

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