<commit_before>/**
 * full-select
 * A lightweight JS script for custom select creation.
 *
 * v0.0.1
 * (https://github.com/gionatan-lombardi/full-select)
 *
 * Copyright (c) 2016 <NAME>
 * MIT License
 */

const defaultOptions = {
  containerClass: 'full-select-container',
  openerClass: 'full-select-opener',
  panelClass: 'full-select-panel',
  optionClass: 'full-select-option',
  optgroupClass: 'full-select-optgroup',
  scrollToSelected: true,
};

function builder(el, cstOptions) {
  var isOpen = false;
  const containerClass = 'fullSelect';
  const isSelectedClass = 'is-selected';
  const hasFocusClass = 'has-focus';
  const isDisabledClass = 'is-disabled';
  const isActiveClass = 'is-active';
  const isOpenClass = 'is-open';
  var select = el;
  var container;
  var opener;
  var focusedElement;
  var selectedElement;
  var panel;

  // Private Fuctions
  function open() {
    // Closes all instances of plugin
    var openedFullSelect = document.querySelector(`.${containerClass} .${isOpenClass}`);
    if (openedFullSelect) {
      openedFullSelect.parentNode.fullSelect.close();
    }

    // Opens only the clicked one
    opener.classList.add(isActiveClass);
    panel.classList.add(isOpenClass);

    isOpen = true;
  }

  function close() {
    opener.classList.remove(isActiveClass);
    panel.classList.remove(isOpenClass);

    focusedElement = selectedElement;

    isOpen = false;
  }

  function setSelectedElement(cstOption) {
    focusedElement.classList.remove(hasFocusClass);
    selectedElement.classList.remove(isSelectedClass);
    cstOption.classList.add(isSelectedClass, hasFocusClass);
    selectedElement = focusedElement = cstOption;
    opener.children[0].textContent = selectedElement.fullSelectOriginalOption.text;
  }

  function setValue(value) {
    let toSelect = select.querySelector(`option[value='${value}']`);
    if (!toSelect) {
      toSelect = select.options[0];
    }
    toSelect.selected = true;
    setSelectedElement(toSelect.fullSelectCstOption);
  }

  function clickEvent(e) {
    // Opener click
    if (e.target === opener || opener.contains(e.target)) {
      if (isOpen) {
        close();
      } else {
        open();
      }
    // Option click
    } else if (e.target.classList.contains(cstOptions.optionClass) && panel.contains(e.target)) {
      setSelectedElement(e.target);
      selectedElement.fullSelectOriginalOption.selected = true;
      close();
    } else if (isOpen) {
      close();
    }
  }

  function mouseoverEvent(e) {
    if (e.target.classList.contains(cstOptions.optionClass)) {
      focusedElement.classList.remove(hasFocusClass);
      e.target.classList.add(hasFocusClass);
      focusedElement = e.target;
    }
  }

  function keydownEvent(e) {
    if (!isOpen) {
      // On "Arrow down", "Arrow up" and "Space" keys opens the panel
      if (e.keyCode === 40 || e.keyCode === 38 || e.keyCode === 32) {
        open();
      }
    }
  }

  function changeEvent() {<commit_msg>keyboard events - no test<commit_after>/**
 * full-select
 * A lightweight JS script for custom select creation.
 *
 * v0.0.1
 * (https://github.com/gionatan-lombardi/full-select)
 *
 * Copyright (c) 2016 <NAME>
 * MIT License
 */

const defaultOptions = {
  containerClass: 'full-select-container',
  openerClass: 'full-select-opener',
  panelClass: 'full-select-panel',
  optionClass: 'full-select-option',
  optgroupClass: 'full-select-optgroup',
  scrollToSelected: true,
};

function builder(el, cstOptions) {
  var isOpen = false;
  const containerClass = 'fullSelect';
  const isSelectedClass = 'is-selected';
  const hasFocusClass = 'has-focus';
  const isDisabledClass = 'is-disabled';
  const isActiveClass = 'is-active';
  const isOpenClass = 'is-open';
  var select = el;
  var container;
  var opener;
  var focusedElement;
  var selectedElement;
  var panel;

  // Private Fuctions
  function setFocusedElement(cstOption) {
    focusedElement.classList.remove(hasFocusClass);
    focusedElement = cstOption;
    focusedElement.classList.add(hasFocusClass);
  }

  function setSelectedElement(cstOption) {
    focusedElement.classList.remove(hasFocusClass);
    selectedElement.classList.remove(isSelectedClass);
    cstOption.classList.add(isSelectedClass, hasFocusClass);
    selectedElement = focusedElement = cstOption;
    opener.children[0].textContent = selectedElement.fullSelectOriginalOption.text;
  }

  function setValue(value) {
    let toSelect = select.querySelector(`option[value='${value}']`);
    if (!toSelect) {
      toSelect = select.options[0];
    }
    toSelect.selected = true;
    setSelectedElement(toSelect.fullSelectCstOption);
  }

  function moveFocuesedElement(direction) {
    const optionsList = panel.getElementsByClassName(cstOptions.optionClass);
    const currentFocusedIndex = [].indexOf.call(optionsList, focusedElement);
    if (optionsList[currentFocusedIndex + direction]) {
      setFocusedElement(optionsList[currentFocusedIndex + direction]);
    }
  }

  function open() {
    // Closes all instances of plugin
    var openedFullSelect = document.querySelector(`.${containerClass} .${isOpenClass}`);
    if (openedFullSelect) {
      openedFullSelect.parentNode.fullSelect.close();
    }

    // Opens only the clicked one
    opener.classList.add(isActiveClass);
    panel.classList.add(isOpenClass);

    isOpen = true;
  }

  function close() {
    opener.classList.remove(isActiveClass);
    panel.classList.remove(isOpenClass);

    setFocusedElement(selectedElement);

    isOpen = false;
  }

  function clickEvent(e) {
    // Opener click
    if (e.target === opener || opener.contains(e.target)) {
      if (isOpen) {
        close();
      } else {
        open();
      }
    // Option click
    } else if (e.target.classList.contains(cstOptions.optionClass) && panel.contains(e.target)) {
      setSelectedElement(e.target);
      selectedElement.fullSelectOriginalOption.selected = true;
      close();
    } else if (isOpen) {
      close();
    }
  }

  function mouseoverEvent(e) {
    if (e.target.classList.contains(cstOptions.optionClass)) {
      setFocusedElement(e.target);
    }
  }

  function keydownEvent(e) {
    if (!isOpen) {
      // On "Arrow down", "Arrow up" and "Space" keys opens the panel
      if (e.keyCode === 40 || e.keyCode === 38 || e.keyCode === 32) {
        open();
      }
    } else {
      // On "Enter" selects the focused element
      if (e.keyCode === 13) {
        setSelectedElement(focusedElement);
        selectedElement.fullSelectOriginalOption.selected = true;

        // and close
        close();
      }

      // On "Escape"
      if (e.keyCode === 27) {
        // close
        close();
      }

      // On "Arrow down" set focues to the next option
      if (e.keyCode === 40) {
        moveFocuesedElement(+1);
      }

      if (e.keyCode === 38) {
        moveFocuesedElement(-1);
      }
    }
  }

  function changeEvent() {
{'fraction_non_alphanumeric': 0.126657060518732, 'fraction_numerical': 0.005763688760806916, 'mean_word_length': 3.158777711204314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '3457702', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2140, 'n_words': 429}