<commit_before>
/**
 * Initialisation
 ******************************************/




(function ($)
{

    var options = {
        selectors: {
            ajaxModal: '#ajax-modal'
        }
    };

    $(document).ready(function ()
    {
        $(document).initAdvancedElements();

        $.initQueryHash();

        $(options.selectors.ajaxModal).on("show.bs.modal", function (e) {
            var link = $(e.relatedTarget);
            $(this).load(link.attr("href"), function () {
                $(this).initAdvancedElements();
            });
        });
        $(options.selectors.ajaxModal).on("hidden.bs.modal", function (e) {
            $(this).html("");
        });

    });

    $.fn.initAdvancedElements = function () {

        var element = $(this);

        $(this).find('.input-float').inputNumberFormat({'decimal': 4, 'decimalAuto': 2});
        $(this).find('.input-integer').inputNumberFormat({'decimal': 0, 'decimalAuto': 0});

        $(this).find("select.select2").select2({
            allowClear: true
        });

        $(this).find(".select2autocomplete").each(function () {
            var urlAjax = $(this).data('ajax');
            var defaultValue = $(this).val();
            var defaultValueSplitted = defaultValue.split(',');
            var select2 = $(this);
            $(this).select2({
                onselected: function () {
                    console.log('fre');
                },
                initSelection: function (element, callback) {
                    if (defaultValue != '') {
                        callback({id: defaultValueSplitted[0], text: defaultValueSplitted[1]});
                        select2.val(defaultValueSplitted[0]);
                    }
                },
                placeholder: 'Entrer un nom',
                minimumInputLength: 3,
                formatInputTooShort: function (input, min) {
                    var n = min - input.length;
                    return  min + " caractère" + (n == 1 ? "" : "s") + " min";
                },
                formatNoMatches: function () {
                    return "Aucun résultat";
                },
                formatSearching: function () {
                    return "Recherche…";
                },
                allowClear: true,
                ajax: {
                    quietMillis: 150,
                    url: urlAjax,
                    dataType: 'json',
                    type: "GET",
                    data: function (term, page) {
                        return {
                            q: term
                        };
                    },
                    results: function (data) {
                        var results = [];
                        $.each(data, function (index, item) {
                            results.push({
                                id: index,
                                text: item
                            });
                        });
                        return {
                            results: results
                        }

                    }}
            });
        });

        $(this).find(".select2SubmitOnChange").on("change", function (e) {
            if (e.val) {
                $(this).parents('form').submit();
            }
        });

        if ($(this).find('.select2permissifNoAjax').length) {
            var lastValue = null;
            $('.select2permissifNoAjax').select2({
                data: JSON.parse($('input.select2permissifNoAjax').attr('data-choices')),
                multiple: false,
                placeholder: true,
                createSearchChoice: function (term, data) {
                    if ($(data).filter(function () {
                        return this.text.localeCompare(term) === 0;
                    }).length === 0) {
                        return {id: term, text: term + ' (nouveau)'};
                    }
                }
            }).on("select2-close", function () {
                var old_choices = JSON.parse($('input.select2permissifNoAjax').attr('data-choices'));
                old_choices.push({id: lastValue, text: lastValue + ' (nouveau)'});
                $('input.select2permissifNoAjax').select2("val", lastValue);
                $('input.select2permissifNoAjax').val(lastValue);
                $('.select2permissifNoAjax .select2-chosen').text(lastValue);
            }).on("select2-highlight", function (e) {
                lastValue = e.val;
            })
        }

        $(this).find('.hamzastyle').each(function () {
            var select2 = $(this);
            select2.select2({
                multiple: true,
                data: function () {
                    var data = [];
                    element.find('.hamzastyle-item').each(function () {
                        data = data.concat(JSON.parse($(this).attr('data-words')));
                    });

                    var data = unique(data.sort());

                    dataFinal = [];
                    for (key in data) {
                        if (data[key] + "") {
                            dataFinal.push({id: (data[key] + ""), text: (data[key] + "")});
                        }
                    }

                    return {results: dataFinal};
                }
            })
        });

        $(this).find('.hamzastyle').on("change", function (e) {
            var select2Data = $(this).select2("data");
            var selectedWords = [];
            for (key in select2Data) {<commit_msg>Autocomplete permissif multiple<commit_after>
/**
 * Initialisation
 ******************************************/




(function ($)
{

    var options = {
        selectors: {
            ajaxModal: '#ajax-modal'
        }
    };

    $(document).ready(function ()
    {
        $(document).initAdvancedElements();

        $.initQueryHash();

        $(options.selectors.ajaxModal).on("show.bs.modal", function (e) {
            var link = $(e.relatedTarget);
            $(this).load(link.attr("href"), function () {
                $(this).initAdvancedElements();
            });
        });
        $(options.selectors.ajaxModal).on("hidden.bs.modal", function (e) {
            $(this).html("");
        });

    });

    $.fn.initAdvancedElements = function () {

        var element = $(this);

        $(this).find('.input-float').inputNumberFormat({'decimal': 4, 'decimalAuto': 2});
        $(this).find('.input-integer').inputNumberFormat({'decimal': 0, 'decimalAuto': 0});

        $(this).find("select.select2").select2({
            allowClear: true
        });

        $(this).find(".select2autocomplete").each(function () {
            var urlAjax = $(this).data('ajax');
            var defaultValue = $(this).val();
            var defaultValueSplitted = defaultValue.split(',');
            var select2 = $(this);
            $(this).select2({
                onselected: function () {
                    console.log('fre');
                },
                initSelection: function (element, callback) {
                    if (defaultValue != '') {
                        callback({id: defaultValueSplitted[0], text: defaultValueSplitted[1]});
                        select2.val(defaultValueSplitted[0]);
                    }
                },
                placeholder: 'Entrer un nom',
                minimumInputLength: 3,
                formatInputTooShort: function (input, min) {
                    var n = min - input.length;
                    return  min + " caractère" + (n == 1 ? "" : "s") + " min";
                },
                formatNoMatches: function () {
                    return "Aucun résultat";
                },
                formatSearching: function () {
                    return "Recherche…";
                },
                allowClear: true,
                ajax: {
                    quietMillis: 150,
                    url: urlAjax,
                    dataType: 'json',
                    type: "GET",
                    data: function (term, page) {
                        return {
                            q: term
                        };
                    },
                    results: function (data) {
                        var results = [];
                        $.each(data, function (index, item) {
                            results.push({
                                id: index,
                                text: item
                            });
                        });
                        return {
                            results: results
                        }

                    }}
            });
        });

        $(this).find(".select2SubmitOnChange").on("change", function (e) {
            if (e.val) {
                $(this).parents('form').submit();
            }
        });

        $(this).find('.select2permissifNoAjax').each(function() {
	    var element = $(this);
	    var id = $(this).attr('id');
	    $(this).select2({
                data: JSON.parse($(this).attr('data-choices')),
                multiple: false,
                createSearchChoice: function (term, data) {
                    if ($(data).filter(function () {
                        return this.text.localeCompare(term) === 0;
                    }).length === 0) {
                        return {id: term, text: term + ' (nouveau)'};
                    }
                }
            }).on("select2-close", function (e) {
		lastValue = $('#'+id).val();
                $(this).select2("val", lastValue);
                $(this).val(lastValue);
                $('#s2id_'+id).find('.select2-chosen').text(lastValue);
            })
        });

        $(this).find('.hamzastyle').each(function () {
            var select2 = $(this);
            select2.select2({
                multiple: true,
                data: function () {
                    var data = [];
                    element.find('.hamzastyle-item').each(function () {
                        data = data.concat(JSON.parse($(this).attr('data-words')));
                    });

                    var data = unique(data.sort());

                    dataFinal = [];
                    for (key in data) {
                        if (data[key] + "") {
                            dataFinal.push({id: (data[key] + ""), text: (data[key] + "")});
                        }
                    }

                    return {results: dataFinal};
                }
            })
        });

        $(this).find('.hamzastyle').on("change", function (e) {
            var select2Data = $(this).select2("data");
            var selectedWords = [];
            for (key in select2Data) {
{'fraction_non_alphanumeric': 0.1526025605083637, 'fraction_numerical': 0.00672834314550042, 'mean_word_length': 1.1598385469223007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5794506', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2545, 'n_words': 453}