<commit_before>/**
  @module ember-ui-components
*/
import Ember from 'ember';
import ClickOutsideMixin from 'ember-ui-components/mixins/click-outside';
import layout from '../templates/components/uic-context-menu-container';
import { getDimensions, getMousePosition, calculatePosition } from 'ember-ui-components/lib/fn';

/**
  @class ContextMenuContainerComponent
  @namespace Components
*/
export default Ember.Component.extend(ClickOutsideMixin, {
  layout,

  /**
    @property tagName
    @type {String}
    @private
    @default 'menu'
  */
  tagName: 'menu',

  /**
    @property classNames
    @type {Array}
    @private
    @default `['uic-context-menu-container', 'uic-menu-container']`
  */
  classNames: ['uic-context-menu-container', 'uic-menu-container'],

  /**
    ## setPosition

    Set the left/top css properties of an element.

    `element` should be a reference to an HTML element.  Either a string selector
    that can be used with jQuery, or a jQuery selection object.

    If `position` is not specified, then the current mouse position will be used.

    `position` should be an Ember.Object with `x` and `y` properties.
    Both `x` and `y` should be numbers

    @method setPosition
    @param {String|Object} element
    @param {Object} position
  */
  setPosition(element, position) {
    let margin = 5;
    if (typeof element === 'string') {
      element = Ember.$(element);
    }
    if (!position) {
      position = getMousePosition(window.event || window._event);
    }
    let scrollBarWidth = (window.innerWidth - $(window).width());
    let el = getDimensions(element);
    element.css({
      'left': calculatePosition( position.get('x') + 2, el.width, window.innerWidth - ( margin + scrollBarWidth)),
      'top': calculatePosition( position.get('y'), el.height, window.innerHeight - margin)
    });
  },

  /**
    @method handleClickOutside
    @private
  */
  handleClickOutside() {
    this.sendAction();
  },

  didInsertElement() {
    this._super(...arguments);
    this.setPosition(this.$());
  },

  click() {
    this.sendAction();
  }

});<commit_msg>update context-menu-container component<commit_after>/**
  @module ember-ui-components
*/
import Ember from 'ember';
import ClickOutsideMixin from 'ember-ui-components/mixins/click-outside';
import layout from '../templates/components/uic-context-menu-container';
import { getDimensions, getMousePosition, calculatePosition } from 'ember-ui-components/lib/fn';

const { alias } = Ember.computed;

/**
  @class ContextMenuContainerComponent
  @namespace Components
*/
export default Ember.Component.extend(ClickOutsideMixin, {
  layout,

  /**
    Injected `contextMenu` service
    @property contextMenuService
    @type {Object}
    @private
  */
  contextMenuService: Ember.inject.service('context-menu'),

  /**
    @property tagName
    @type {String}
    @private
    @default 'menu'
  */
  tagName: 'menu',

  /**
    @property classNames
    @type {Array}
    @private
    @default `['uic-context-menu-container', 'uic-menu-container']`
  */
  classNames: ['uic-context-menu-container', 'uic-menu-container'],

  /**
    @property contextMenuParams
    @type {Object}
    @private
  */
  contextMenuParams: alias('contextMenuService.contextMenuParams'),

  /**
    ## setPosition

    Set the left/top css properties of an element.

    `element` should be a reference to an HTML element.  Either a string selector
    that can be used with jQuery, or a jQuery selection object.

    If `position` is not specified, then the current mouse position will be used.

    `position` should be an Ember.Object with `x` and `y` properties.
    Both `x` and `y` should be numbers

    @method setPosition
    @param {String|Object} element
    @param {Object} position
  */
  setPosition(element, position) {
    let margin = 5;
    if (typeof element === 'string') {
      element = Ember.$(element);
    }
    if (!position) {
      position = getMousePosition(window.event || window._event);
    }
    let scrollBarWidth = (window.innerWidth - $(window).width());
    let el = getDimensions(element);
    element.css({
      'left': calculatePosition( position.get('x') + 2, el.width, window.innerWidth - ( margin + scrollBarWidth)),
      'top': calculatePosition( position.get('y'), el.height, window.innerHeight - margin)
    });
  },

  /**
    @method handleClickOutside
    @private
  */
  handleClickOutside() {
    this.sendAction();
  },

  /**
    @method didInsertElement
    @private
  */
  didInsertElement() {
    this._super(...arguments);
    this.setPosition(this.$(), getMousePosition(this.get('contextMenuParams.event')));
  },

  /**
    @method click
    @private
  */
  click() {
    this.sendAction();
  }
});
{'fraction_non_alphanumeric': 0.13707296499367355, 'fraction_numerical': 0.0008435259384226065, 'mean_word_length': 3.25, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5003356', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1403, 'n_words': 365}