Sha256: 5652501f1482befbeb43b07598259f7d93054755848e7496f1e479fb1ee6e979

Contents?: true

Size: 710 Bytes

Versions: 4

Compression:

Stored size: 710 Bytes

Contents

(function() {
  document.querySelectorAll('.dropdown-toggle').forEach(function(element){
    var dropdown = element.closest('.dropdown')

    function openMenu() {
      dropdown.classList.add('open')
      document.addEventListener('click', closeMenuOutside);
    }

    function closeMenu() {
      dropdown.classList.remove('open');
      document.removeEventListener('click', closeMenuOutside);
    }

    function closeMenuOutside(event) {
      if (!dropdown.contains(event.target)) {
        closeMenu();
      }
    }

    element.addEventListener('click', function() {
      if (dropdown.classList.contains('open')) {
        closeMenu();
      } else {
        openMenu();
      }
    });
  })
})();

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
asciibook-0.0.2 theme/html/html.js
asciibook-0.0.2.beta2 theme/html/html.js
asciibook-0.0.2.beta1 theme/html/html.js
asciibook-0.0.1 theme/html/html.js