<commit_before>// /**
//  * This file is part of Shuup.
//  *
//  * Copyright (c) 2012-2018, Shuup Inc. All rights reserved.
//  *
//  * This source code is licensed under the OSL-3.0 license found in the
//  * LICENSE file in the root directory of this source tree.
//  */

const handleMainMenu = () => {
  const categoryLink = document.getElementsByClassName('item-category');

  const closeMenu = () => {
    Array.from(categoryLink).forEach((item) => {
      const categoryArrow = item.querySelector('.item-arrow');
      const submenu = item.nextElementSibling;

      if (item.classList.contains('item-active')) {
        item.classList.remove('item-active');
        submenu.classList.remove('active');
        categoryArrow.classList.remove('rotate');
      }
    });
  }

  const openMenu = (element) => {
    const categoryArrow = element.querySelector('.item-arrow');
    const submenu = element.nextElementSibling;

    element.classList.add('item-active');
    submenu.classList.add('active');
    categoryArrow.classList.add('rotate');
  }

  Array.from(categoryLink).forEach((item) => {
    item.addEventListener('click', (event) => {
      event.preventDefault();

      const currentItem = event.currentTarget;
      const isActive = currentItem.classList.contains('item-active');

      closeMenu();
      openMenu(item);

      if (isActive) {
        closeMenu();
      }
    });
  });

  const toggleBtn = document.getElementById('menu-button');
  const mainMenu = document.getElementById('js-main-menu');

  function hideMainMenu() {
    document.addEventListener('click', event => {
      if (!mainMenu.contains(event.target) && !toggleBtn.contains(event.target)) {
        mainMenu.classList.remove('open');
        document.removeEventListener('click', hideMainMenu);
      }
    });
  }

  toggleBtn.addEventListener('click', (event) => {
    if (mainMenu.classList.contains('open')) {
      mainMenu.classList.remove('open');
    } else {
      mainMenu.classList.add('open');
      hideMainMenu();
    }
  });
}

export default handleMainMenu;<commit_msg>Add check to menu script<commit_after>// /**
//  * This file is part of Shuup.
//  *
//  * Copyright (c) 2012-2018, Shuup Inc. All rights reserved.
//  *
//  * This source code is licensed under the OSL-3.0 license found in the
//  * LICENSE file in the root directory of this source tree.
//  */

const handleMainMenu = () => {
  const categoryLink = document.getElementsByClassName('item-category');

  const closeMenu = () => {
    Array.from(categoryLink).forEach((item) => {
      const categoryArrow = item.querySelector('.item-arrow');
      const submenu = item.nextElementSibling;

      if (item.classList.contains('item-active')) {
        item.classList.remove('item-active');
        submenu.classList.remove('active');
        categoryArrow.classList.remove('rotate');
      }
    });
  }

  const openMenu = (element) => {
    const categoryArrow = element.querySelector('.item-arrow');
    const submenu = element.nextElementSibling;

    element.classList.add('item-active');
    submenu.classList.add('active');
    categoryArrow.classList.add('rotate');
  }

  Array.from(categoryLink).forEach((item) => {
    item.addEventListener('click', (event) => {
      event.preventDefault();

      const currentItem = event.currentTarget;
      const isActive = currentItem.classList.contains('item-active');

      closeMenu();
      openMenu(item);

      if (isActive) {
        closeMenu();
      }
    });
  });

  const toggleBtn = document.getElementById('menu-button');
  const mainMenu = document.getElementById('js-main-menu');

  function hideMainMenu() {
    document.addEventListener('click', event => {
      if (!mainMenu.contains(event.target) && !toggleBtn.contains(event.target)) {
        mainMenu.classList.remove('open');
        document.removeEventListener('click', hideMainMenu);
      }
    });
  }

  if (toggleBtn) {
    toggleBtn.addEventListener('click', (event) => {
      if (mainMenu.classList.contains('open')) {
        mainMenu.classList.remove('open');
      } else {
        mainMenu.classList.add('open');
        hideMainMenu();
      }
    });
  }
}

export default handleMainMenu;
{'fraction_non_alphanumeric': 0.1532258064516129, 'fraction_numerical': 0.004743833017077799, 'mean_word_length': 3.0743961352657005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5515948', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1222, 'n_words': 225}