<commit_before>/**
 * Created by huangxinghui on 2015/5/19.
 */

var $ = require('jquery');
var _ = require('underscore');
var plugin = require('../plugin');
var Widget = require('../widget');
var $document = require('../document');
var toggle = '[data-toggle="dropdown"]';

var DropDown = Widget.extend({
  options: {
    target: null,
    position: 'bottomLeft' // topLeft/topRight/bottomLeft/bottomRight
  },

  events: {
    'click': 'toggle'
  },

  _create: function() {
    var parentClass = 'dropdown';
    this.$parent = this.getParent();

    if (this.options.position.indexOf('top') !== -1) {
      parentClass = 'dropup';
    }
    this.$parent.addClass(parentClass);

    if (this.options.position.indexOf('Right') !== -1) {
      this.$parent.children('.dropdown-menu').addClass('dropdown-menu-right')
    }
  },

  open: function() {
    this.$parent.addClass('open');
    this._trigger('open');
  },

  close: function() {
    this.$parent.removeClass('open');
    this._trigger('close');
  },

  toggle: function(e) {
    var isActive = this.$parent.hasClass('open');

    clearMenus(e);

    if (!isActive) this.open();
    return false;
  },

  getParent: function() {
    if (this.options.target) {
      return (this.options.target instanceof $ ? this.options.target : $(this.options.target)).parent();
    } else {
      return this.$element.parent();
    }
  }
});

plugin('dropdown', DropDown);

module.exports = DropDown;

function clearMenus(e) {
  if (e && e.which === 3) return;

  $(toggle).dropdown('close');
}

$document
    .on('click.dropdown.data-api', clearMenus)
    .on('click.dropdown.data-api', '[data-toggle="dropdown"]', function(e) {
      return $(this).dropdown('toggle');
    });<commit_msg>add dropdown input/textarea tag ignore<commit_after>/**
 * Created by huangxinghui on 2015/5/19.
 */

var $ = require('jquery');
var _ = require('underscore');
var plugin = require('../plugin');
var Widget = require('../widget');
var $document = require('../document');
var DATA_TOGGLE = '[data-toggle="dropdown"]';
var CLASS_NAME = {
  OPEN: 'open'
};

var DropDown = Widget.extend({
  options: {
    target: null,
    position: 'bottomLeft' // topLeft/topRight/bottomLeft/bottomRight
  },

  events: {
    'click': 'toggle'
  },

  _create: function() {
    var parentClass = 'dropdown';
    this.$parent = this.getParent();

    if (this.options.position.indexOf('top') !== -1) {
      parentClass = 'dropup';
    }
    this.$parent.addClass(parentClass);

    if (this.options.position.indexOf('Right') !== -1) {
      this.$parent.children('.dropdown-menu').addClass('dropdown-menu-right')
    }
  },

  open: function() {
    this.$parent.addClass(CLASS_NAME.OPEN);
    this._trigger('open');
  },

  close: function() {
    if (this._trigger('beforeClose')){
      return false;
    }

    this.$parent.removeClass(CLASS_NAME.OPEN);
    this._trigger('close');
    return true;
  },

  toggle: function(e) {
    var isActive = this.$parent.hasClass(CLASS_NAME.OPEN);

    clearMenus(e);

    if (!isActive) this.open();
    return false;
  },

  getParent: function() {
    if (this.options.target) {
      return (this.options.target instanceof $ ? this.options.target : $(this.options.target)).parent();
    } else {
      return this.$element.parent();
    }
  }
});

plugin('dropdown', DropDown);

module.exports = DropDown;

function clearMenus(e) {
  if (e && e.which === 3) return;

  var toggles = $.makeArray($(DATA_TOGGLE)),
      i = 0,
      n = toggles.length,
      $parent, $toggle;

  for (; i < n; i++) {
    $toggle = $(toggles[i]);
    $parent = $toggle.dropdown('getParent');

    if (!$parent.hasClass(CLASS_NAME.OPEN)) continue;

    if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return

    if (!$toggle.dropdown('close')) return;
  }
}

$document
    .on('click.dropdown.data-api', clearMenus)
    .on('click.dropdown.data-api', DATA_TOGGLE, function(e) {
      return $(this).dropdown('toggle');
    });
{'fraction_non_alphanumeric': 0.19241259608232086, 'fraction_numerical': 0.005454996280684354, 'mean_word_length': 3.2463157894736843, 'pattern_counts': {'":': 0, '<': 4, '<?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': '1974717', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1309, 'n_words': 248}