<commit_before>var csv_migrations_select2 = csv_migrations_select2 || {};

(function ($) {
    /**
     * Select2 Logic.
     */
    function Select2()
    {
        //
    }

    /**
     * Setup method.
     *
     * @return {undefined}
     */
    Select2.prototype.setup = function (options) {
        this.min_length = options.hasOwnProperty('min_length') ? options.min_length : 1;
        this.timeout = options.hasOwnProperty('timeout') ? options.timeout : 300;
        this.api_token = options.hasOwnProperty('token') ? options.token : null;
        this.limit = options.hasOwnProperty('limit') ? options.limit : 10;
        this.id = options.hasOwnProperty('id') ? options.id : null;

        var that = this;
        // loop through select2 inputs
        $(this.id).each(function () {
            that.init(this);
        });

        // call observe method
        this._observe();
    };

    /**
     * Initialize method.
     *
     * @return {undefined}
     */
    Select2.prototype.init = function (element) {
        // set select2 option label, if is empty and the option value is set
        if ($(element).val() && !$(element).text()) {
            this._setDisplayValue($(element).val(), element);
        }

        // enable select2 functionality
        this._enable(element);
    };

    /**
     * Observe for select2 inputs added to the DOM client side.
     *
     * @return {undefined}
     */
    Select2.prototype._observe = function () {
        var that = this;

        MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
        // observe for client side appended select2 elements
        var observer = new MutationObserver(function (mutations, observer) {
            // look through all mutations that just occured
            mutationsLength = mutations.length;
            for (var i = 0; i < mutationsLength; ++i) {
                // look through all added nodes of this mutation
                mutationNodesLength = mutations[i].addedNodes.length;
                for (var j = 0; j < mutationNodesLength; ++j) {
                    // look for select2 elements
                    var select2 = that._getSelect2(mutations[i].addedNodes[j]);
                    if ($.isEmptyObject(select2)) {
                        continue;
                    }

                    that.init(select2);
                }
            }
        });

        // define what element should be observed by the observer
        // and what types of mutations trigger the callback
        observer.observe(document, {
            childList: true,
            subtree: true
        });
    };

    /**
     * Find out if added node is a select2 element
     * and return it if it is, otherwise return empty object.
     *
     * @param  {object} node Added DOM node
     * @return {object}
     */
    Select2.prototype._getSelect2 = function (node) {
        var result = {};
        $(node).find(this.id).each(function () {
            result = this;
        });

        return result;
    };

    /**
     * Method that enables select2 functionality on specified input.
     *
     * @param {string} input select2 input
     * @return {undefined}
     * {@link plugin: https://select2.github.io}
     */
    Select2.prototype._enable = function (input) {
        var that = this;
        var placeholder = $(input).attr('title');
        // enable select2
        $(input).select2({
            theme: 'bootstrap',
            placeholder: placeholder,
            minimumInputLength: that.min_length,
            ajax: {
                url: $(input).data('url'),
                dataType: 'json',
                contentType: 'application/json',
                accepts: {
                    json: 'application/json'
                },<commit_msg>fixes issue with inconsistent width on select2 fields (task #3069)<commit_after>var csv_migrations_select2 = csv_migrations_select2 || {};

(function ($) {
    /**
     * Select2 Logic.
     */
    function Select2()
    {
        //
    }

    /**
     * Setup method.
     *
     * @return {undefined}
     */
    Select2.prototype.setup = function (options) {
        this.min_length = options.hasOwnProperty('min_length') ? options.min_length : 1;
        this.timeout = options.hasOwnProperty('timeout') ? options.timeout : 300;
        this.api_token = options.hasOwnProperty('token') ? options.token : null;
        this.limit = options.hasOwnProperty('limit') ? options.limit : 10;
        this.id = options.hasOwnProperty('id') ? options.id : null;

        var that = this;
        // loop through select2 inputs
        $(this.id).each(function () {
            that.init(this);
        });

        // call observe method
        this._observe();
    };

    /**
     * Initialize method.
     *
     * @return {undefined}
     */
    Select2.prototype.init = function (element) {
        // set select2 option label, if is empty and the option value is set
        if ($(element).val() && !$(element).text()) {
            this._setDisplayValue($(element).val(), element);
        }

        // enable select2 functionality
        this._enable(element);
    };

    /**
     * Observe for select2 inputs added to the DOM client side.
     *
     * @return {undefined}
     */
    Select2.prototype._observe = function () {
        var that = this;

        MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
        // observe for client side appended select2 elements
        var observer = new MutationObserver(function (mutations, observer) {
            // look through all mutations that just occured
            mutationsLength = mutations.length;
            for (var i = 0; i < mutationsLength; ++i) {
                // look through all added nodes of this mutation
                mutationNodesLength = mutations[i].addedNodes.length;
                for (var j = 0; j < mutationNodesLength; ++j) {
                    // look for select2 elements
                    var select2 = that._getSelect2(mutations[i].addedNodes[j]);
                    if ($.isEmptyObject(select2)) {
                        continue;
                    }

                    that.init(select2);
                }
            }
        });

        // define what element should be observed by the observer
        // and what types of mutations trigger the callback
        observer.observe(document, {
            childList: true,
            subtree: true
        });
    };

    /**
     * Find out if added node is a select2 element
     * and return it if it is, otherwise return empty object.
     *
     * @param  {object} node Added DOM node
     * @return {object}
     */
    Select2.prototype._getSelect2 = function (node) {
        var result = {};
        $(node).find(this.id).each(function () {
            result = this;
        });

        return result;
    };

    /**
     * Method that enables select2 functionality on specified input.
     *
     * @param {string} input select2 input
     * @return {undefined}
     * {@link plugin: https://select2.github.io}
     */
    Select2.prototype._enable = function (input) {
        var that = this;
        var placeholder = $(input).attr('title');
        // enable select2
        $(input).select2({
            theme: 'bootstrap',
            width: '100%',
            placeholder: placeholder,
            minimumInputLength: that.min_length,
            ajax: {
                url: $(input).data('url'),
                dataType: 'json',
                contentType: 'application/json',
                accepts: {
                    json: 'application/json'
                },
{'fraction_non_alphanumeric': 0.11443433029908973, 'fraction_numerical': 0.00988296488946684, 'mean_word_length': 1.7061928219563687, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7353261', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1970, 'n_words': 529}