<commit_before>/**
 * Expose `Select`.
 */

exports.Select = Select;

/**
 * Initialize a new `Select`
 * with an optional `label`.
 *
 * @param {String} label
 * @api public
 */

function Select(namespace, label) {
  ui.Emitter.call(this);

  this.btn = new namespace.SplitButton(label);
  this.el = this.btn.el;
  this.menu = new namespace.menu();
  this.menu.el.appendTo('body');
  this.onChange = function(){};

  // Carry over functions
  this.remove = this.menu.remove;
  this.has = this.menu.has;

  // On click
  this.el.click(function() {
    var p = this.el.offset();
    this.menu.moveTo(p.left, p.top + this.el.outerHeight()).show();
    this.menu.el.css('width', this.el.outerWidth() + 'px');
  }.bind(this));

  this.show();
}

/**
 * Inherit from `Emitter.prototype`.
 */

Select.prototype = new ui.Emitter();

/**
 * Add a menu item(s)
 * @return {Select}
 * @api public
 */
Select.prototype.add = function(o) {

    // Handler for determing if a value actually changed
    var itemClick = function(e) {
        var label = this.el.find('.ui-text');
        if (label.text() !== e.name) {
            if (typeof this.onChange === 'function') {
                this.onChange(e);
            }
        }
    }.bind(this);

    // Add by array or single item
    if (Array.isArray(o)) {
        o.forEach(function(item){
            this.menu.add(item, itemClick);
        }.bind(this));
    } else {
        this.menu.add(o, itemClick);<commit_msg>Prevent the menu from being hidden on select click<commit_after>
/**
 * Initialize a new `Select`
 * with an optional `label`.
 *
 * @param {String} label
 * @api public
 */

function Select(namespace, label) {
  ui.Emitter.call(this);

  this.btn = new namespace.SplitButton(label);
  this.el = this.btn.el;
  this.menu = new namespace.menu();
  this.menu.el.appendTo('body');
  this.onChange = function(){};

  // Carry over functions
  this.remove = this.menu.remove;
  this.has = this.menu.has;

  // On click
  this.el.click(function(e) {
    var p = this.el.offset();
    this.menu.moveTo(p.left, p.top + this.el.outerHeight()).show();
    this.menu.el.css('width', this.el.outerWidth() + 'px');
    return false;
  }.bind(this));

  this.show();
}

/**
 * Expose `Select`.
 */

exports.Select = Select;

/**
 * Inherit from `Emitter.prototype`.
 */

Select.prototype = new ui.Emitter();

/**
 * Add a menu item(s)
 * @return {Select}
 * @api public
 */
Select.prototype.add = function(o) {

    // Handler for determing if a value actually changed
    var itemClick = function(e) {
        var label = this.el.find('.ui-text');
        if (label.text() !== e.name) {
            if (typeof this.onChange === 'function') {
                this.onChange(e);
            }
        }
    }.bind(this);

    // Add by array or single item
    if (Array.isArray(o)) {
        o.forEach(function(item){
            this.menu.add(item, itemClick);
        }.bind(this));
    } else {
        this.menu.add(o, itemClick);
{'fraction_non_alphanumeric': 0.17410265011741027, 'fraction_numerical': 0.0, 'mean_word_length': 2.4674418604651165, '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': '1662225', 'n_tokens_mistral': 1010, 'n_tokens_neox': 995, 'n_words': 225}