<commit_before>(function($, window, document, undefined){
    window.HLSelect2 = {
        config: {
            tagInputs: 'input.tags',
            ajaxInputs: 'input.select2ajax',
            tagsAjaxClass: 'tags-ajax',
            ajaxPageLimit: 30,
            clearText: '-- Clear --',
        },

        init: function( config ) {
            var self = this;
            // Setup configuration
            if ($.isPlainObject(config)) {
                $.extend(self.config, config);
            }
            // On initialize, setup select2
            self.setupSelect2();
            self.initListeners();
        },

        initListeners: function() {
            var self = this;
            // When modal is shown, lets instantiate the select2 in the modals
            $(document).on('shown.bs.modal', '.modal', function() {
                self.setupSelect2();
            });
        },

        setupSelect2: function() {
            // Setup select2 for non-ajaxified selects, ajaxified selects
            // are using hidden inputs.
            $('select').select2({
                // at least this many results are needed to enable the search field
                // (9 is the amount at which the user must scroll to see all items)
                minimumResultsForSearch: 9,
            });
            this.createTagInputs();
            this.createAjaxInputs();
        },

        createTagInputs: function() {
            // Setup tag inputs
            $(this.config.tagInputs).each(function() {
                if (!$(this).data().hasOwnProperty('select2')) {
                    var tags = [];
                    var $this = $(this);
                    if ($this.data('choices')) {
                        tags = $this.data('choices').split(',');
                    }
                    $this.select2({
                        tags: tags,
                        tokenSeparators: [','],
                        width: '100%',
                        createSearchChoice: function (term, data) {
                            if ($(data).filter(function () {
                                    return this.text.localeCompare(term) === 0;
                                }).length === 0) {
                                return {
                                    id: term,
                                    text: term + ' (new tag)',
                                };
                            }
                        },
                    });
                }
            });
        },

        formatResult: function(result, container, query, escapeMarkup) {
            var resultRow = '';
            var nameMarkup = [];
            var emailMarkup = [];
            var markup = [];

            if (result.name && result.email_address) {
                window.Select2.util.markMatch(result.name, query.term, nameMarkup, escapeMarkup);
                window.Select2.util.markMatch(result.email_address, query.term, emailMarkup, escapeMarkup);

                resultRow =
                '<div>' +
                    '<div>' + nameMarkup.join('') + '</div>' +
                    '<div class="text-muted">' + emailMarkup.join('') + '</div>' +
                '</div>';
            } else {
                window.Select2.util.markMatch(result.text, query.term, markup, escapeMarkup);

                resultRow =
                '<div>' +
                    '<div>' + markup.join('') + '</div>' +
                '</div>';
            }

            return resultRow;
        },

        createAjaxInputs: function() {
            // Setup inputs that needs remote link
            var self = this;
            var cf = self.config;

            $(cf.ajaxInputs).each(function() {
                var $this = $(this);
                var _data = $this.data();
                // _data.tags is a marker for AjaxSelect2Widget which indicates
                // that it expects multiple values as input.

                // Prevent Select2 from being initialized on elements that already have Select2
                if (!_data.hasOwnProperty('select2')) {
                    var options = {
                        formatResult: self.formatResult,
                        ajax: {
                            cache: true,
                            data: function (term, page) {
                                // page is the one-based page number tracked by Select2
                                var data = null;

                                if ($this.hasClass(cf.tagsAjaxClass) && !_data.tags) {
                                    if (term === '') {
                                        // elasticsearch breaks when the term is empty, so just look for non-empty results
                                        term = '*';
                                    }
                                    // search for contacts and accounts containing the search term, but only those with an email address
                                    var filterQuery = '((_type:contacts_contact AND (name:' + term + ' OR email_addresses.email_address:' + term + ')) ' +
                                        'OR (_type:accounts_account AND (name:' + term + ' OR email_addresses.email_address:' + term + '))) ' +
                                        'AND email_addresses.email_address:*';

                                    data = {
                                        filterquery: filterQuery,
                                        size: cf.ajaxPageLimit, // page size
                                        page: (page - 1), // page number, zero-based
                                        sort: '-modified' // sort modified descending
                                    };
                                }
                                else {
                                    var term_stripped = term.trim();
                                    data = {
                                        filterquery: term_stripped ? 'name:('+term_stripped+')' : '', //search term
                                        size: cf.ajaxPageLimit, // page size
                                        page: (page - 1), // page number, zero-based
                                        sort: '-modified' // sort modified descending
                                    };<commit_msg>LILY-1575: Email search Compose To with space<commit_after>(function($, window, document, undefined){
    window.HLSelect2 = {
        config: {
            tagInputs: 'input.tags',
            ajaxInputs: 'input.select2ajax',
            tagsAjaxClass: 'tags-ajax',
            ajaxPageLimit: 30,
            clearText: '-- Clear --',
        },

        init: function( config ) {
            var self = this;
            // Setup configuration
            if ($.isPlainObject(config)) {
                $.extend(self.config, config);
            }
            // On initialize, setup select2
            self.setupSelect2();
            self.initListeners();
        },

        initListeners: function() {
            var self = this;
            // When modal is shown, lets instantiate the select2 in the modals
            $(document).on('shown.bs.modal', '.modal', function() {
                self.setupSelect2();
            });
        },

        setupSelect2: function() {
            // Setup select2 for non-ajaxified selects, ajaxified selects
            // are using hidden inputs.
            $('select').select2({
                // at least this many results are needed to enable the search field
                // (9 is the amount at which the user must scroll to see all items)
                minimumResultsForSearch: 9,
            });
            this.createTagInputs();
            this.createAjaxInputs();
        },

        createTagInputs: function() {
            // Setup tag inputs
            $(this.config.tagInputs).each(function() {
                if (!$(this).data().hasOwnProperty('select2')) {
                    var tags = [];
                    var $this = $(this);
                    if ($this.data('choices')) {
                        tags = $this.data('choices').split(',');
                    }
                    $this.select2({
                        tags: tags,
                        tokenSeparators: [','],
                        width: '100%',
                        createSearchChoice: function (term, data) {
                            if ($(data).filter(function () {
                                    return this.text.localeCompare(term) === 0;
                                }).length === 0) {
                                return {
                                    id: term,
                                    text: term + ' (new tag)',
                                };
                            }
                        },
                    });
                }
            });
        },

        formatResult: function(result, container, query, escapeMarkup) {
            var resultRow = '';
            var nameMarkup = [];
            var emailMarkup = [];
            var markup = [];

            if (result.name && result.email_address) {
                window.Select2.util.markMatch(result.name, query.term, nameMarkup, escapeMarkup);
                window.Select2.util.markMatch(result.email_address, query.term, emailMarkup, escapeMarkup);

                resultRow =
                '<div>' +
                    '<div>' + nameMarkup.join('') + '</div>' +
                    '<div class="text-muted">' + emailMarkup.join('') + '</div>' +
                '</div>';
            } else {
                window.Select2.util.markMatch(result.text, query.term, markup, escapeMarkup);

                resultRow =
                '<div>' +
                    '<div>' + markup.join('') + '</div>' +
                '</div>';
            }

            return resultRow;
        },

        createAjaxInputs: function() {
            // Setup inputs that needs remote link
            var self = this;
            var cf = self.config;

            $(cf.ajaxInputs).each(function() {
                var $this = $(this);
                var _data = $this.data();
                // _data.tags is a marker for AjaxSelect2Widget which indicates
                // that it expects multiple values as input.

                // Prevent Select2 from being initialized on elements that already have Select2
                if (!_data.hasOwnProperty('select2')) {
                    var options = {
                        formatResult: self.formatResult,
                        ajax: {
                            cache: true,
                            data: function (term, page) {
                                // page is the one-based page number tracked by Select2
                                var data = null;

                                if ($this.hasClass(cf.tagsAjaxClass) && !_data.tags) {
                                    if (term === '') {
                                        // elasticsearch breaks when the term is empty, so just look for non-empty results
                                        term = '*';
                                    }
                                    // search for contacts and accounts containing the search term, but only those with an email address
                                    var filterQuery = '((_type:contacts_contact AND (name:(' + term + ') OR email_addresses.email_address:(' + term + '))) ' +
                                        'OR (_type:accounts_account AND (name:(' + term + ') OR email_addresses.email_address:(' + term + ')))) ' +
                                        'AND email_addresses.email_address:*';

                                    data = {
                                        filterquery: filterQuery,
                                        size: cf.ajaxPageLimit, // page size
                                        page: (page - 1), // page number, zero-based
                                        sort: '-modified' // sort modified descending
                                    };
                                }
                                else {
                                    var term_stripped = term.trim();
                                    data = {
                                        filterquery: term_stripped ? 'name:('+term_stripped+')' : '', //search term
                                        size: cf.ajaxPageLimit, // page size
                                        page: (page - 1), // page number, zero-based
                                        sort: '-modified' // sort modified descending
                                    };
{'fraction_non_alphanumeric': 0.10465116279069768, 'fraction_numerical': 0.00502828409805154, 'mean_word_length': 0.9734883720930233, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 64, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4306365', 'n_tokens_mistral': 2864, 'n_tokens_neox': 2694, 'n_words': 716}