<commit_before>/*
	jQuery tagEditor v1.0.20
    Copyright (c) 2014 <NAME> / Pixabay
    GitHub: https://github.com/Pixabay/jQuery-tagEditor
	License: http://www.opensource.org/licenses/mit-license.php
*/
(function($) {
  // auto grow input (stackoverflow.com/questions/931207)
  $.fn.tagEditorInput = function() {
    var t = " ";
    var e = $(this);
    var n = parseInt(e.css("fontSize"));
    var i = $("<span/>").css({
      position: "absolute",
      top: -9999,
      left: -9999,
      width: "auto",
      fontSize: e.css("fontSize"),
      fontFamily: e.css("fontFamily"),
      fontWeight: e.css("fontWeight"),
      letterSpacing: e.css("letterSpacing"),
      whiteSpace: "nowrap"
    });
    var s = function() {
      if (t !== (t = e.val())) {
        i.text(t);
        var s = i.width() + n;
        20 > s && (s = 20), s != e.width() && e.width(s)
      }
    };
    return i.insertAfter(e), e.bind("keyup keydown focus", s)
  };

  // plugin with val as parameter for public methods
  $.fn.tagEditor = function(options, val, blur) {

    // helper
    function escape(tag) {
      return tag.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
    }

    // build options dictionary with default values
    var blur_result;
    var o = $.extend({}, $.fn.tagEditor.defaults, options);
    var selector = this;

    // store regex and default delimiter in options for later use
    o.dregex = new RegExp('[' + o.delimiter.replace('-', '\-') + ']', 'g');

    // public methods
    if (typeof options == 'string') {
      // depending on selector, response may contain tag lists of multiple editor instances
      var response = [];
      selector.each(function() {
        // the editor is the next sibling to the hidden, original field
        var el = $(this);
        var o = el.data('options');
        var ed = el.next('.tag-editor');

        if (options == 'getTags') {
          response.push({
            field: el[0],
            editor: ed,
            tags: ed.data('tags')
          });
        } else if (options == 'addTag') {
          if (o.maxTags && ed.data('tags').length >= o.maxTags) {
            return false;
          }
          // insert new tag
          $('<li><div class="tag-editor-spacer">&nbsp;' + o.delimiter[0] + '</div><div class="tag-editor-tag"></div><div class="tag-editor-delete"><i></i></div></li>').appendTo(ed).find('.tag-editor-tag')
            .html('<input type="text" maxlength="' + o.maxLength + '">').addClass('active').find('input').val(val).blur();

          if (!blur) {
            ed.click();
          } else {
            $('.placeholder', ed).remove();
          }
        } else if (options == 'removeTag') {
          // trigger delete on matching tag, then click editor to create a new tag
          $('.tag-editor-tag', ed).filter(function() {
            return $(this).text() == val;
          }).closest('li').find('.tag-editor-delete').click();
          if (!blur) {
            ed.click();
          }
        } else if (options == 'destroy') {
          el .removeClass('tag-editor-hidden-src')
            .removeData('options')
            .off('focus.tag-editor')
            .next('.tag-editor')
            .remove();
        }
      });
      return options == 'getTags' ? response : this;
    }

    // delete selected tags on backspace, delete, ctrl+x
    if (window.getSelection) {
      $(document).off('keydown.tag-editor').on('keydown.tag-editor', function(e) {
        if (e.which == 8 || e.which == 46 || e.ctrlKey && e.which == 88) {
          try {
            var sel = getSelection();
            var el = document.activeElement.tagName == 'BODY'
              ? $(sel.getRangeAt(0).startContainer.parentNode).closest('.tag-editor')
              : 0;
          } catch (e) {
            el = 0;
          }
          if (sel.rangeCount > 0 && el && el.length) {
            var tags = [],
            splits = sel.toString().split(el.prev().data('options').dregex);
            for (i = 0; i < splits.length; i++) {
              var tag = $.trim(splits[i]);
              if (tag) {
                tags.push(tag);
              }
            }
            $('.tag-editor-tag', el).each(function() {
              if (~$.inArray($(this).text(), tags)) {
                $(this).closest('li').find('.tag-editor-delete').click();
              }
            });
            return false;
          }
        }
      });
    }

    return selector.each(function() {
      var el = $(this);
      var tag_list = []; // cache current tags

      // create editor (ed) instance
      var ed = $('<ul ' + (o.clickDelete ? 'oncontextmenu="return false;" ' : '') + 'class="tag-editor"></ul>').insertAfter(el);
      el.addClass('tag-editor-hidden-src') // hide original field
        .data('options', o) // set data on hidden field
        .on('focus.tag-editor', function() {
          ed.click();
        }); // simulate tabindex

      // add dummy item for min-height on empty editor
      ed.append('<li style="width:1px">&nbsp;</li>');

      // markup for new tag
      var new_tag = '<li><div class="tag-editor-spacer">&nbsp;' + o.delimiter[0] + '</div><div class="tag-editor-tag"></div><div class="tag-editor-delete"><i></i></div></li>';

      // helper: update global data
      function set_placeholder() {
        if (o.placeholder && !tag_list.length && !$('.deleted, .placeholder, input', ed).length) {
          ed.append('<li class="placeholder"><div>' + o.placeholder + '</div></li>');
        }
      }

      // helper: update global data
      function update_globals(init) {
        var old_tags = tag_list.toString();
        tag_list = $('.tag-editor-tag:not(.deleted)', ed).map(function(i, e) {
          var val = $.trim($(this).hasClass('active') ? $(this).find('input').val() : $(e).text());
          if (val) {
            return val;
          }
        }).get();
        ed.data('tags', tag_list);
        el.val(tag_list.join(o.delimiter[0]));
        // change callback except for plugin init
        if (!init && old_tags != tag_list.toString()) {
          o.onChange(el, ed, tag_list);
        }
        set_placeholder();
      }

      ed.click(function(e, closest_tag) {
        var d, dist = 99999, loc;

        // do not create tag when user selects tags by text selection
        if (window.getSelection && getSelection() != '') {
          return;
        }

        if (o.maxTags && ed.data('tags').length >= o.maxTags) {
          ed.find('input').blur();
          return false;
        }

        blur_result = true
        $('input:focus', ed).blur();
        if (!blur_result) {
          return false;
        }
        blur_result = true

        // always remove placeholder on click
        $('.placeholder', ed).remove();
        if (closest_tag && closest_tag.length) {
          loc = 'before';<commit_msg>Fix focusing tags input with the tab key<commit_after>/*
	jQuery tagEditor v1.0.20
    Copyright (c) 2014 <NAME> / Pixabay
    GitHub: https://github.com/Pixabay/jQuery-tagEditor
	License: http://www.opensource.org/licenses/mit-license.php
*/
(function($) {
  // auto grow input (stackoverflow.com/questions/931207)
  $.fn.tagEditorInput = function() {
    var t = " ";
    var e = $(this);
    var n = parseInt(e.css("fontSize"));
    var i = $("<span/>").css({
      position: "absolute",
      top: -9999,
      left: -9999,
      width: "auto",
      fontSize: e.css("fontSize"),
      fontFamily: e.css("fontFamily"),
      fontWeight: e.css("fontWeight"),
      letterSpacing: e.css("letterSpacing"),
      whiteSpace: "nowrap"
    });
    var s = function() {
      if (t !== (t = e.val())) {
        i.text(t);
        var s = i.width() + n;
        20 > s && (s = 20), s != e.width() && e.width(s)
      }
    };
    return i.insertAfter(e), e.bind("keyup keydown focus", s)
  };

  // plugin with val as parameter for public methods
  $.fn.tagEditor = function(options, val, blur) {

    // helper
    function escape(tag) {
      return tag.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
    }

    // build options dictionary with default values
    var blur_result;
    var o = $.extend({}, $.fn.tagEditor.defaults, options);
    var selector = this;

    // store regex and default delimiter in options for later use
    o.dregex = new RegExp('[' + o.delimiter.replace('-', '\-') + ']', 'g');

    // public methods
    if (typeof options == 'string') {
      // depending on selector, response may contain tag lists of multiple editor instances
      var response = [];
      selector.each(function() {
        // the editor is the next sibling to the hidden, original field
        var el = $(this);
        var o = el.data('options');
        var ed = el.next('.tag-editor');

        if (options == 'getTags') {
          response.push({
            field: el[0],
            editor: ed,
            tags: ed.data('tags')
          });
        } else if (options == 'addTag') {
          if (o.maxTags && ed.data('tags').length >= o.maxTags) {
            return false;
          }
          // insert new tag
          $('<li><div class="tag-editor-spacer">&nbsp;' + o.delimiter[0] + '</div><div class="tag-editor-tag"></div><div class="tag-editor-delete"><i></i></div></li>').appendTo(ed).find('.tag-editor-tag')
            .html('<input type="text" maxlength="' + o.maxLength + '">').addClass('active').find('input').val(val).blur();

          if (!blur) {
            ed.click();
          } else {
            $('.placeholder', ed).remove();
          }
        } else if (options == 'removeTag') {
          // trigger delete on matching tag, then click editor to create a new tag
          $('.tag-editor-tag', ed).filter(function() {
            return $(this).text() == val;
          }).closest('li').find('.tag-editor-delete').click();
          if (!blur) {
            ed.click();
          }
        } else if (options == 'destroy') {
          el .removeClass('tag-editor-hidden-src')
            .removeData('options')
            .off('focus.tag-editor')
            .next('.tag-editor')
            .remove();
        }
      });
      return options == 'getTags' ? response : this;
    }

    // delete selected tags on backspace, delete, ctrl+x
    if (window.getSelection) {
      $(document).off('keydown.tag-editor').on('keydown.tag-editor', function(e) {
        if (e.which == 8 || e.which == 46 || e.ctrlKey && e.which == 88) {
          try {
            var sel = getSelection();
            var el = document.activeElement.tagName == 'BODY'
              ? $(sel.getRangeAt(0).startContainer.parentNode).closest('.tag-editor')
              : 0;
          } catch (e) {
            el = 0;
          }
          if (sel.rangeCount > 0 && el && el.length) {
            var tags = [],
            splits = sel.toString().split(el.prev().data('options').dregex);
            for (i = 0; i < splits.length; i++) {
              var tag = $.trim(splits[i]);
              if (tag) {
                tags.push(tag);
              }
            }
            $('.tag-editor-tag', el).each(function() {
              if (~$.inArray($(this).text(), tags)) {
                $(this).closest('li').find('.tag-editor-delete').click();
              }
            });
            return false;
          }
        }
      });
    }

    return selector.each(function() {
      var el = $(this);
      var tag_list = []; // cache current tags

      // create editor (ed) instance
      var ed = $('<ul ' + (o.clickDelete ? 'oncontextmenu="return false;" ' : '') + 'class="tag-editor"></ul>').insertAfter(el);
      el.addClass('tag-editor-hidden-src') // hide original field
        .data('options', o) // set data on hidden field
        .on('focus.tag-editor', function() {
          ed.click();
        }); // simulate tabindex

      // add dummy item for min-height on empty editor
      ed.append('<li style="width:1px">&nbsp;</li>');

      // markup for new tag
      var new_tag = '<li><div class="tag-editor-spacer">&nbsp;' + o.delimiter[0] + '</div><div class="tag-editor-tag"></div><div class="tag-editor-delete"><i></i></div></li>';

      // helper: update global data
      function set_placeholder() {
        if (o.placeholder && !tag_list.length && !$('.deleted, .placeholder, input', ed).length) {
          ed.append('<li class="placeholder"><div>' + o.placeholder + '</div></li>');
        }
      }

      // helper: update global data
      function update_globals(init) {
        var old_tags = tag_list.toString();
        tag_list = $('.tag-editor-tag:not(.deleted)', ed).map(function(i, e) {
          var val = $.trim($(this).hasClass('active') ? $(this).find('input').val() : $(e).text());
          if (val) {
            return val;
          }
        }).get();
        ed.data('tags', tag_list);
        el.val(tag_list.join(o.delimiter[0]));
        // change callback except for plugin init
        if (!init && old_tags != tag_list.toString()) {
          o.onChange(el, ed, tag_list);
        }
        set_placeholder();
      }

      ed.click(function(e, closest_tag) {
        var d, dist = 99999, loc;

        // do not create tag when user selects tags by text selection
        //
        // NOTE: commented by dfrank since this code just prevents tags input
        // to be focused if there are already tags in it, and that's bad.
        //
        // For some reason, getSelection().toString() returns selected tags,
        // comma separated.
        //
        // I'm not sure what's the intended behaviour of this, so, leaving it
        // commented for now.
        //
        //if (window.getSelection && getSelection() != '') {
        //return;
        //}

        if (o.maxTags && ed.data('tags').length >= o.maxTags) {
          ed.find('input').blur();
          return false;
        }

        blur_result = true
        $('input:focus', ed).blur();
        if (!blur_result) {
          return false;
        }
        blur_result = true

        // always remove placeholder on click
        $('.placeholder', ed).remove();
        if (closest_tag && closest_tag.length) {
          loc = 'before';
{'fraction_non_alphanumeric': 0.18163379493635473, 'fraction_numerical': 0.006714225765841376, 'mean_word_length': 1.9098494098494099, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 75, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4150679', 'n_tokens_mistral': 4381, 'n_tokens_neox': 4244, 'n_words': 1010}