<commit_before>import { CLASSNAME, eventType as EVENT_TYPE } from './constants';
import utils from './utils';


/**
 * @class Internal
 */
export class Internal {
  /**
   * @constructor
   * @param {Function} base Base class.
   */
  constructor(base) {
    /**
     * @type {ol.control.Control}
     */
    this.Base = base;
    /**
     * @type {ol.Map}
     */
    this.map = undefined;
    /**
     * @type {Element}
     */
    this.map_element = undefined;
    /**
     * @type {ol.Coordinate}
     */
    this.coordinate_clicked = undefined;
    /**
     * @type {ol.Pixel}
     */
    this.pixel_clicked = undefined;
    /**
     * @type {Number}
     */
    this.counter = 0;
    /**
     * @type {Number}
     */
    this.lineHeight = 0;
    /**
     * @type {Object}
     */
    this.items = {};
    /**
     * @type {Boolean}
     */
    this.opened = false;
    /**
     * @type {Object}
     */
    this.submenu = {
      left: this.Base.options.width - 15 + 'px',
      last_left: '' // string + px
    };
    /**
     * @type {Function}
     */
    this.eventHandler = this.handleEvent.bind(this);

    return this;
  }

  init(map) {
    this.map = map;
    this.map_element = map.getTargetElement();
    this.setListeners();
    this.Base.constructor.Html.createMenu();

    this.lineHeight = this.getItemsLength() > 0 ?
      this.Base.container.offsetHeight / this.getItemsLength() :
      this.Base.constructor.Html.cloneAndGetLineHeight();
  }

  getItemsLength() {
    let count = 0;
    Object.keys(this.items).forEach(k => {
      if (this.items[k].submenu || this.items[k].separator) return;
      count++;
    });
    return count;
  }

  getPixelClicked() {
    return this.pixel_clicked;
  }

  getCoordinateClicked() {
    return this.coordinate_clicked;
  }

  positionContainer(pixel) {
    let map_size = this.map.getSize(),
        map_w = map_size[0],
        map_h = map_size[1],
        // how much (width) space left over
        space_left_h = map_h - pixel[1],
        // how much (height) space left over
        space_left_w = map_w - pixel[0],
        menu_size = {
          w: this.Base.container.offsetWidth,
          // a cheap way to recalculate container height
          // since offsetHeight is like cached
          h: Math.round(this.lineHeight * this.getItemsLength())
        },
        // submenus <ul>
        uls = utils.find('li.' + CLASSNAME.submenu + '>ul',
            this.Base.container, true);

    if (space_left_w >= menu_size.w) {
      this.Base.container.style.right = 'auto';
      this.Base.container.style.left = `${pixel[0] + 5}px`;
    } else {
      this.Base.container.style.left = 'auto';
      this.Base.container.style.right = '15px';
    }
    // set top or bottom
    if (space_left_h >= menu_size.h) {
      this.Base.container.style.bottom = 'auto';
      this.Base.container.style.top = `${pixel[1] - 10}px`;
    } else {
      this.Base.container.style.top = 'auto';
      this.Base.container.style.bottom = 0;
    }

    utils.removeClass(this.Base.container, CLASSNAME.hidden);

    if (uls.length) {
      if (space_left_w < (menu_size.w * 2)) {
        // no space (at right) for submenu
        // position them at left
        this.submenu.last_left = `-${menu_size.w}px`;
      } else {
        this.submenu.last_left = this.submenu.left;
      }
      uls.forEach(ul => {
        // is there enough space for submenu height?
        let countChild = [].filter.call(ul.childNodes, function (el) {
          return el.nodeType === 1;
        }).length;
        let viewport = utils.getViewportSize();
        let sub_offset = utils.offset(ul);
        let sub_height = sub_offset.height;
        let sub_top = space_left_h - sub_height;<commit_msg>Remove unsed variable<commit_after>import { CLASSNAME, eventType as EVENT_TYPE } from './constants';
import utils from './utils';


/**
 * @class Internal
 */
export class Internal {
  /**
   * @constructor
   * @param {Function} base Base class.
   */
  constructor(base) {
    /**
     * @type {ol.control.Control}
     */
    this.Base = base;
    /**
     * @type {ol.Map}
     */
    this.map = undefined;
    /**
     * @type {Element}
     */
    this.map_element = undefined;
    /**
     * @type {ol.Coordinate}
     */
    this.coordinate_clicked = undefined;
    /**
     * @type {ol.Pixel}
     */
    this.pixel_clicked = undefined;
    /**
     * @type {Number}
     */
    this.counter = 0;
    /**
     * @type {Number}
     */
    this.lineHeight = 0;
    /**
     * @type {Object}
     */
    this.items = {};
    /**
     * @type {Boolean}
     */
    this.opened = false;
    /**
     * @type {Object}
     */
    this.submenu = {
      left: this.Base.options.width - 15 + 'px',
      last_left: '' // string + px
    };
    /**
     * @type {Function}
     */
    this.eventHandler = this.handleEvent.bind(this);

    return this;
  }

  init(map) {
    this.map = map;
    this.map_element = map.getTargetElement();
    this.setListeners();
    this.Base.constructor.Html.createMenu();

    this.lineHeight = this.getItemsLength() > 0 ?
      this.Base.container.offsetHeight / this.getItemsLength() :
      this.Base.constructor.Html.cloneAndGetLineHeight();
  }

  getItemsLength() {
    let count = 0;
    Object.keys(this.items).forEach(k => {
      if (this.items[k].submenu || this.items[k].separator) return;
      count++;
    });
    return count;
  }

  getPixelClicked() {
    return this.pixel_clicked;
  }

  getCoordinateClicked() {
    return this.coordinate_clicked;
  }

  positionContainer(pixel) {
    let map_size = this.map.getSize(),
        map_w = map_size[0],
        map_h = map_size[1],
        // how much (width) space left over
        space_left_h = map_h - pixel[1],
        // how much (height) space left over
        space_left_w = map_w - pixel[0],
        menu_size = {
          w: this.Base.container.offsetWidth,
          // a cheap way to recalculate container height
          // since offsetHeight is like cached
          h: Math.round(this.lineHeight * this.getItemsLength())
        },
        // submenus <ul>
        uls = utils.find('li.' + CLASSNAME.submenu + '>ul',
            this.Base.container, true);

    if (space_left_w >= menu_size.w) {
      this.Base.container.style.right = 'auto';
      this.Base.container.style.left = `${pixel[0] + 5}px`;
    } else {
      this.Base.container.style.left = 'auto';
      this.Base.container.style.right = '15px';
    }
    // set top or bottom
    if (space_left_h >= menu_size.h) {
      this.Base.container.style.bottom = 'auto';
      this.Base.container.style.top = `${pixel[1] - 10}px`;
    } else {
      this.Base.container.style.top = 'auto';
      this.Base.container.style.bottom = 0;
    }

    utils.removeClass(this.Base.container, CLASSNAME.hidden);

    if (uls.length) {
      if (space_left_w < (menu_size.w * 2)) {
        // no space (at right) for submenu
        // position them at left
        this.submenu.last_left = `-${menu_size.w}px`;
      } else {
        this.submenu.last_left = this.submenu.left;
      }
      uls.forEach(ul => {
        // is there enough space for submenu height?
        let viewport = utils.getViewportSize();
        let sub_offset = utils.offset(ul);
        let sub_height = sub_offset.height;
        let sub_top = space_left_h - sub_height;
{'fraction_non_alphanumeric': 0.14852022807493892, 'fraction_numerical': 0.005294596796090144, 'mean_word_length': 2.0291940789473686, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '6915879', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2423, 'n_words': 472}