<commit_before><?php
/**
*   Generic select picker
*/
    /** Config **/
    $select_threshold = 6; // threshold on which pills will be replace by a select (unused if multiple is > 1)
    $defaults_options = array(
        'select_options' => array(
            // 'multiple' => '', // set to add possibility to pick multiple options in the select
            //'placeholder' => '' // set to replace the default placeholder text
        ),
        'chosen_options' => array(
            'width' => '500px',
            'search_contains' => true, // matches starting from anywhere within a word
            //'no_results_text' => '', // set to replace the default no result text after filtering
            //'max_selected_options' => 'Infinity' // set to replace the max selected options
            'disable_search_threshold' => 10,
            'allow_single_deselect' => true,
        ),
        'multiple' => 0,
        'functionName' => '', // function to be called on submit
        'submitButtonText' => 'Submit',
        'disabledSubmitButton' => false, // wether to not draw the submit button
        'flag_redraw_chosen' => false // should chosen picker be redraw at drawing time
    );
    /** prevent exception if not set **/
    $options = isset($options) ? $options : array();
    $items = isset($items) ? $items : array();
    // merge options with defaults
    $defaults = array_replace_recursive($defaults_options, $options);

    // enforce consistency
    if ($defaults['multiple'] == 0) {
        unset($defaults['select_options']['multiple']);
    } else { // multiple enabled
        $defaults['chosen_options']['max_selected_options'] = $defaults['multiple'] == -1 ? 'Infinity' : $defaults['multiple'];
        $defaults['select_options']['multiple'] = '';
        $select_threshold = 0;
    }
    $use_select = count($items) > $select_threshold;
?>

<script>
function execAndClose(elem, alreadyExecuted) {
    var dismissid = $(elem).closest('div.popover').attr('data-dismissid');
    $('[data-dismissid="' + dismissid + '"]').popover('destroy');
}

function setupChosen(id, redrawChosen) {
    var $elem = $('#'+id);
    var chosen_options = <?php echo json_encode($defaults['chosen_options']); ?>;
    $elem.chosen(chosen_options);
    if (!$elem.prop('multiple')) { // not multiple, selection trigger next event
        $elem.change(function(event, selected) {
            var fn = $elem.data('functionname');
            if (fn !== undefined) {
                fn = window[fn];
                submitFunction(this, fn);
            } else {
                select = this;
                $select = $(select);
                var endpoint;
                if (selected !== undefined) {
                    endpoint = selected.selected;
                } else { //  for obscure reasons, `selected` variable is not set in some cases
                    endpoint = $(event.target).val();
                }
                $select.data('endpoint', endpoint);
                fetchRequestedData($select);
            }
        });
    }

    // hack to add template into the div
    var $chosenContainer = $elem.parent().find('.chosen-container');
    $elem.on('chosen:showing_dropdown chosen:searchdone keyup change', function() {
        redrawChosenWithTemplate($elem, $chosenContainer)
    });

    if (redrawChosen) {
        redrawChosenWithTemplate($elem, $chosenContainer);
    }
}

function redrawChosenWithTemplate($select, $chosenContainer) {
    var optionLength = $select.find('option').length;
    if (optionLength > 1000) {
        $chosenContainer.parent().find('.generic-picker-wrapper-warning-text').show(0)
    } else {
        $chosenContainer.find('.generic-picker-wrapper-warning-text').hide(0)
        var $matches = $chosenContainer.find('.chosen-results .active-result, .chosen-single span, .search-choice span');
        $matches.each(function() {
            var $item = $(this);
            var index = $item.data('option-array-index');
            var $option;
            if (index !== undefined) {
                $option = $select.find('option:eq(' + index + ')');<commit_msg>fix: [UI] generic_picker prevented nested redrawing<commit_after><?php
/**
*   Generic select picker
*/
    /** Config **/
    $select_threshold = 6; // threshold on which pills will be replace by a select (unused if multiple is > 1)
    $defaults_options = array(
        'select_options' => array(
            // 'multiple' => '', // set to add possibility to pick multiple options in the select
            //'placeholder' => '' // set to replace the default placeholder text
        ),
        'chosen_options' => array(
            'width' => '500px',
            'search_contains' => true, // matches starting from anywhere within a word
            //'no_results_text' => '', // set to replace the default no result text after filtering
            //'max_selected_options' => 'Infinity' // set to replace the max selected options
            'disable_search_threshold' => 10,
            'allow_single_deselect' => true,
        ),
        'multiple' => 0,
        'functionName' => '', // function to be called on submit
        'submitButtonText' => 'Submit',
        'disabledSubmitButton' => false, // wether to not draw the submit button
        'flag_redraw_chosen' => false // should chosen picker be redraw at drawing time
    );
    /** prevent exception if not set **/
    $options = isset($options) ? $options : array();
    $items = isset($items) ? $items : array();
    // merge options with defaults
    $defaults = array_replace_recursive($defaults_options, $options);

    // enforce consistency
    if ($defaults['multiple'] == 0) {
        unset($defaults['select_options']['multiple']);
    } else { // multiple enabled
        $defaults['chosen_options']['max_selected_options'] = $defaults['multiple'] == -1 ? 'Infinity' : $defaults['multiple'];
        $defaults['select_options']['multiple'] = '';
        $select_threshold = 0;
    }
    $use_select = count($items) > $select_threshold;
?>

<script>
function execAndClose(elem, alreadyExecuted) {
    var dismissid = $(elem).closest('div.popover').attr('data-dismissid');
    $('[data-dismissid="' + dismissid + '"]').popover('destroy');
}

function setupChosen(id, redrawChosen) {
    var $elem = $('#'+id);
    var chosen_options = <?php echo json_encode($defaults['chosen_options']); ?>;
    $elem.chosen(chosen_options);
    if (!$elem.prop('multiple')) { // not multiple, selection trigger next event
        $elem.change(function(event, selected) {
            var fn = $elem.data('functionname');
            if (fn !== undefined) {
                fn = window[fn];
                submitFunction(this, fn);
            } else {
                select = this;
                $select = $(select);
                var endpoint;
                if (selected !== undefined) {
                    endpoint = selected.selected;
                } else { //  for obscure reasons, `selected` variable is not set in some cases
                    endpoint = $(event.target).val();
                }
                $select.data('endpoint', endpoint);
                fetchRequestedData($select);
            }
        });
    }

    // hack to add template into the div
    var $chosenContainer = $elem.parent().find('.chosen-container');
    $elem.on('chosen:showing_dropdown chosen:searchdone keyup change', function() {
        redrawChosenWithTemplate($elem, $chosenContainer)
    });

    if (redrawChosen) {
        redrawChosenWithTemplate($elem, $chosenContainer);
    }
}

function redrawChosenWithTemplate($select, $chosenContainer) {
    var optionLength = $select.find('option').length;
    if (optionLength > 1000) {
        $chosenContainer.parent().find('.generic-picker-wrapper-warning-text').show(0)
    } else {
        $chosenContainer.find('.generic-picker-wrapper-warning-text').hide(0)
        var $matches = $chosenContainer.find('.chosen-results .active-result, .chosen-single > span, .search-choice > span');
        $matches.each(function() {
            var $item = $(this);
            var index = $item.data('option-array-index');
            var $option;
            if (index !== undefined) {
                $option = $select.find('option:eq(' + index + ')');
{'fraction_non_alphanumeric': 0.14566265060240963, 'fraction_numerical': 0.004096385542168675, 'mean_word_length': 2.4472591362126246, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, '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': '1867192', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2228, 'n_words': 565}