<commit_before>import Ember from 'ember';

const {
  isArray,
  computed,
} = Ember;

const isSelectedOption = (option) => option.$().is(':selected');

/**
 * Wraps a native <select> element so that it can be object and
 * binding aware. It is used in conjuction with the
 * `x-option` component to construct select boxes. E.g.
 *
 *   {{#x-select value="bob" action="selectPerson"}}
 *     {{x-option value="fred"}}<NAME>{{/x-option}}
 *     {{x-option value="bob"}}<NAME>{{/x-option}}
 *   {{/x-select}}
 *
 * the options are always up to date, so that when the object bound to
 * `value` changes, the corresponding option becomes selected.
 *
 * Whenever the select tag receives a change event, it will fire
 * `action`
 *
 * @class Ember.XSelectComponent
 * @extends Ember.Component
 */
export default Ember.Component.extend({
  tagName: "select",
  classNameBindings: [":x-select"],
  attributeBindings: ['disabled', 'tabindex', 'multiple', 'form', 'name', 'autofocus', 'required', 'size', 'title'],

  /**
   * Bound to the `disabled` attribute on the native <select> tag.
   *
   * @property disabled
   * @type Boolean
   * @default false
   */
  disabled: false,

  /**
   * Bound to the `multiple` attribute on the native <select> tag.
   *
   * @property multiple
   * @type Boolean
   * @default false
   */
  multiple: false,

  /**
   * The collection of options for this select box. When options are
   * rendered as a child from x-select, they will register themselves with their
   * containing `x-select`. This is for internal book-keeping only and should
   * not be changed from outside.
   *
   * @private
   * @property options
   */
  options: computed(function() {
    return Ember.A([]);
  }),

  /**
   * Bound to the `tabindex` attribute on the native <select> tag.
   *
   * @property tabindex
   * @type Integer
   * @default 0
   */
  tabindex: 0,

  /**
   * Function for the `on-blur` action
   *
   * @property on-blur
   * @type Function
   */
  "on-blur": Ember.K,

  /**
   * Function for the `on-click` action
   *
   * @property on-click
   * @type Function
   */
  "on-click": Ember.K,

  /**
   * Function for the `on-change` action
   *
   * @property on-change
   * @type Function
   */
  "on-change": Ember.K,

  /**
   * Function for the `on-focus-out` action
   *
   * @property on-focus-out
   * @type Function
   */
  "on-focus-out": Ember.K,

  /**
   * Function that calls an action and sends the proper arguments.
   *
   * @method _handleAction
   * @type Function
   * @param {String} action - string name of the action to invoke
   * @param {String|Object} value - current value of the component
   * @param {Object} event - jQuery event from the current action
   */
  _handleAction(action, value, event) {
    let actionValue = this.get(action);

    if(typeof actionValue === 'string') {
      Ember.warn(`x-select: You must use the action helper for all actions. The try: ${action}=(action "${actionValue}") in your template`, false, {id: 'x-select-string-action'});
      return;
    }

    this.get(action)(value, event);
  },

  /**
   * When the select DOM event fires on the element, trigger the<commit_msg>Replaces `Ember.K` usage with JavaScript syntax (#165)<commit_after>import Ember from 'ember';

const {
  isArray,
  computed,
} = Ember;

const isSelectedOption = (option) => option.$().is(':selected');

/**
 * Wraps a native <select> element so that it can be object and
 * binding aware. It is used in conjuction with the
 * `x-option` component to construct select boxes. E.g.
 *
 *   {{#x-select value="bob" action="selectPerson"}}
 *     {{x-option value="fred"}}<NAME>{{/x-option}}
 *     {{x-option value="bob"}}<NAME>{{/x-option}}
 *   {{/x-select}}
 *
 * the options are always up to date, so that when the object bound to
 * `value` changes, the corresponding option becomes selected.
 *
 * Whenever the select tag receives a change event, it will fire
 * `action`
 *
 * @class Ember.XSelectComponent
 * @extends Ember.Component
 */
export default Ember.Component.extend({
  tagName: "select",
  classNameBindings: [":x-select"],
  attributeBindings: ['disabled', 'tabindex', 'multiple', 'form', 'name', 'autofocus', 'required', 'size', 'title'],

  /**
   * Bound to the `disabled` attribute on the native <select> tag.
   *
   * @property disabled
   * @type Boolean
   * @default false
   */
  disabled: false,

  /**
   * Bound to the `multiple` attribute on the native <select> tag.
   *
   * @property multiple
   * @type Boolean
   * @default false
   */
  multiple: false,

  /**
   * The collection of options for this select box. When options are
   * rendered as a child from x-select, they will register themselves with their
   * containing `x-select`. This is for internal book-keeping only and should
   * not be changed from outside.
   *
   * @private
   * @property options
   */
  options: computed(function() {
    return Ember.A([]);
  }),

  /**
   * Bound to the `tabindex` attribute on the native <select> tag.
   *
   * @property tabindex
   * @type Integer
   * @default 0
   */
  tabindex: 0,

  /**
   * Function for the `on-blur` action
   *
   * @property on-blur
   * @type Function
   */
  "on-blur"() {},

  /**
   * Function for the `on-click` action
   *
   * @property on-click
   * @type Function
   */
  "on-click"() {},

  /**
   * Function for the `on-change` action
   *
   * @property on-change
   * @type Function
   */
  "on-change"() {},

  /**
   * Function for the `on-focus-out` action
   *
   * @property on-focus-out
   * @type Function
   */
  "on-focus-out"() {},

  /**
   * Function that calls an action and sends the proper arguments.
   *
   * @method _handleAction
   * @type Function
   * @param {String} action - string name of the action to invoke
   * @param {String|Object} value - current value of the component
   * @param {Object} event - jQuery event from the current action
   */
  _handleAction(action, value, event) {
    let actionValue = this.get(action);

    if(typeof actionValue === 'string') {
      Ember.warn(`x-select: You must use the action helper for all actions. The try: ${action}=(action "${actionValue}") in your template`, false, {id: 'x-select-string-action'});
      return;
    }

    this.get(action)(value, event);
  },

  /**
   * When the select DOM event fires on the element, trigger the
{'fraction_non_alphanumeric': 0.14175703284614175, 'fraction_numerical': 0.0011001100110011, 'mean_word_length': 2.9381188118811883, 'pattern_counts': {'":': 6, '<': 15, '<?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': '637321', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1971, 'n_words': 659}