<commit_before>/*
 * Copyright 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 * Please see distribution for license.
 *
 * autosuggest combobox
 *
 */
$.register_module({
    name: 'og.common.util.ui.AutoCombo',
    dependencies: [],
    obj: function () {
        /**
         * @param {Object} obj configuration object,
         * selector (String) and data (Array) are required, placeholder (String) is optional
         */
        return function (selector, placeholder, data) {
            var $wrapper, $input, $button, autocomplete_obj,
                open = function () {
                    // open using the current input value or an empty string
                    $input.autocomplete('search', ($input.val() !== placeholder) ? ($input.val() || '') : '').select();
                };
            placeholder = placeholder || '';
            autocomplete_obj = {
                minLength: 0, delay: 0,
                open: function() {$(this).autocomplete('widget').blurkill(function () {$input.autocomplete('close')});},
                source: function (req, res) {
                    var escaped = $.ui.autocomplete.escapeRegex(req.term),
                        matcher = new RegExp(escaped, 'i'),
                        htmlize = function (str) {
                            return !req.term ? str : str.replace(
                                new RegExp('(?![^&;]+;)(?!<[^<>]*)(' + escaped + ')(?![^<>]*>)(?![^&;]+;)', 'gi'),
                                '<strong>$1</strong>'
                            );
                        };
                    res(data.reduce(function (acc, val) {
                        if (!req.term || matcher.test(val.name)) acc.push({label: htmlize(val.name), value: val.id});
                        return acc;
                    }, []));
                }
            };
            $wrapper = $('<div />'); // wrap input in div to enable input width at 100% of parent, FF, IE
            $input = $wrapper.html('<input type="text" />').find('input')
                .autocomplete(autocomplete_obj).attr('placeholder', placeholder).on('mouseup', open)
                .on('blur', function () {if ($input.val() === placeholder) $input.val('');})
                .on('focus', function () {$input.trigger('open', $input)});
            // Enable html list items
            $input.data('autocomplete')._renderItem = function(ul, item) {
                return $('<li></li>').data('item.autocomplete', item).append('<a>' + item.label + '</a>').appendTo(ul);
            };
            $button = $('<div class="OG-icon og-icon-down"></div>').on('click', function () {<commit_msg>fix auto combo opening bug<commit_after>/*
 * Copyright 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 * Please see distribution for license.
 *
 * autosuggest combobox
 *
 */
$.register_module({
    name: 'og.common.util.ui.AutoCombo',
    dependencies: [],
    obj: function () {
        /**
         * @param {Object} obj configuration object,
         * selector (String) and data (Array) are required, placeholder (String) is optional
         */
        return function (selector, placeholder, data) {
            var $wrapper, $input, $button, autocomplete_obj,
                open = function () {$input.autocomplete('search', '').select();};
            placeholder = placeholder || '';
            autocomplete_obj = {
                minLength: 0, delay: 0,
                open: function() {$(this).autocomplete('widget').blurkill(function () {$input.autocomplete('close')});},
                source: function (req, res) {
                    var escaped = $.ui.autocomplete.escapeRegex(req.term),
                        matcher = new RegExp(escaped, 'i'),
                        htmlize = function (str) {
                            return !req.term ? str : str.replace(
                                new RegExp('(?![^&;]+;)(?!<[^<>]*)(' + escaped + ')(?![^<>]*>)(?![^&;]+;)', 'gi'),
                                '<strong>$1</strong>'
                            );
                        };
                    res(data.reduce(function (acc, val) {
                        if (!req.term || matcher.test(val.name)) acc.push({label: htmlize(val.name), value: val.id});
                        return acc;
                    }, []));
                }
            };
            $wrapper = $('<div />'); // wrap input in div to enable input width at 100% of parent, FF, IE
            $input = $wrapper.html('<input type="text" />').find('input')
                .autocomplete(autocomplete_obj).attr('placeholder', placeholder).on('mouseup', open)
                .on('blur', function () {if ($input.val() === placeholder) $input.val('');})
                .on('focus', function () {$input.trigger('open', $input)});
            // Enable html list items
            $input.data('autocomplete')._renderItem = function(ul, item) {
                return $('<li></li>').data('item.autocomplete', item).append('<a>' + item.label + '</a>').appendTo(ul);
            };
            $button = $('<div class="OG-icon og-icon-down"></div>').on('click', function () {
{'fraction_non_alphanumeric': 0.17440960123886953, 'fraction_numerical': 0.0038714672861014324, 'mean_word_length': 1.7572038420490927, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6546013', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1323, 'n_words': 321}