<commit_before>/*****************************************************************************************************************
 *    Contextmenu
 *    Main class for attributes "context menu"
 *    Created by <NAME>
 *
 ****************************************************************************************************************/

export class Contextmenu {

  constructor(element, vGrid) {
    this.element = element;
    this.vGrid = vGrid;

    //main classes, should I just add these to the v-grid-config?
    this.contextMenuClassName = "v-grid-context-menu";
    this.contextMenuItemClassName = "v-grid-context-menu__item";
    this.contextMenuLinkClassName = "v-grid-context-menu__link";
    this.contextMenuSplitClassName = "v-grid-context-menu__split";


    this.taskItemInContext = null;

    this.clickCoords = null;
    this.clickCoordsX = null;
    this.clickCoordsY = null;


    this.menuState = 0;
    this.menuWidth = null;
    this.menuHeight = null;
    this.menuPosition = null;
    this.menuPositionX = null;
    this.menuPositionY = null;

    this.windowWidth = null;
    this.windowHeight = null;


  }
  
  
  getLang(value){
    return this.vGrid.vGridConfig.attLanguage[value];
  }


  bind(bindingContext, overrideContext) {
    this.bindingContext = bindingContext;
    this.overrideContext = overrideContext;
  }


  attached() {
      this.element.classList.contains(this.classToOpenOn)? null:this.element.classList.add(this.classToOpenOn);
      this.addListener();
  }


  detached() {
      this.removeListener();
  }


  canOpen() {
    return true;
  }


  addListener() {
    this.contextListenerBinded = this.contextListener.bind(this);
    this.element.addEventListener("contextmenu", this.contextListenerBinded);
  }


  removeListener() {
    this.element.removeEventListener("contextmenu", this.contextListenerBinded);
  }


  contextListener(e) {
    if (this.canOpen(e)) {

      this.taskItemInContext = this.clickInsideElement(e, this.classToOpenOn);

      if (this.taskItemInContext) {
        e.preventDefault();
        this.toggleMenuOn();
        this.positionMenu(e);
      } else {
        this.taskItemInContext = null;
        this.toggleMenuOff();
      }

    } else {
      this.toggleMenuOff();
    }<commit_msg>fix (context menu): close existing if already open<commit_after>/*****************************************************************************************************************
 *    Contextmenu
 *    Main class for attributes "context menu"
 *    Created by <NAME>
 *
 ****************************************************************************************************************/

export class Contextmenu {

  constructor(element, vGrid) {
    this.element = element;
    this.vGrid = vGrid;

    //main classes, should I just add these to the v-grid-config?
    this.contextMenuClassName = "v-grid-context-menu";
    this.contextMenuItemClassName = "v-grid-context-menu__item";
    this.contextMenuLinkClassName = "v-grid-context-menu__link";
    this.contextMenuSplitClassName = "v-grid-context-menu__split";


    this.taskItemInContext = null;

    this.clickCoords = null;
    this.clickCoordsX = null;
    this.clickCoordsY = null;


    this.menuState = 0;
    this.menuWidth = null;
    this.menuHeight = null;
    this.menuPosition = null;
    this.menuPositionX = null;
    this.menuPositionY = null;

    this.windowWidth = null;
    this.windowHeight = null;


  }


  getLang(value) {
    return this.vGrid.vGridConfig.attLanguage[value];
  }


  bind(bindingContext, overrideContext) {
    this.bindingContext = bindingContext;
    this.overrideContext = overrideContext;
  }


  attached() {
    this.element.classList.contains(this.classToOpenOn) ? null : this.element.classList.add(this.classToOpenOn);
    this.addListener();
  }


  detached() {
    this.removeListener();
  }


  canOpen() {
    return true;
  }


  closeIfOpen() {
    if (this.menuState) {
      this.toggleMenuOff();
    }
  }


  addListener() {
    this.contextListenerBinded = this.contextListener.bind(this);
    this.closeIfOpenBinded = this.closeIfOpen.bind(this);
    this.element.addEventListener("contextmenu", this.contextListenerBinded);
    this.vGrid.element.addEventListener("vGridCloseContextMenuIfOpen", this.closeIfOpenBinded);
  }


  removeListener() {
    this.element.removeEventListener("contextmenu", this.contextListenerBinded);
    this.element.removeEventListener("vGridCloseContextMenuIfOpen", this.closeIfOpenBinded);

  }


  contextListener(e) {

    //close if menus if they are open when opening a new one
    let event = new CustomEvent("vGridCloseContextMenuIfOpen", {
      detail: "",
      bubbles: true
    });
    this.vGrid.element.dispatchEvent(event);


    if (this.canOpen(e)) {

      this.taskItemInContext = this.clickInsideElement(e, this.classToOpenOn);

      if (this.taskItemInContext) {
        e.preventDefault();
        this.toggleMenuOn();
        this.positionMenu(e);
      } else {
        this.taskItemInContext = null;
        this.toggleMenuOff();
      }

    } else {
      this.toggleMenuOff();
    }
{'fraction_non_alphanumeric': 0.1928835310130274, 'fraction_numerical': 0.00038887808671981335, 'mean_word_length': 3.4730434782608697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2467667', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1445, 'n_words': 248}