<commit_before>$(document).ready(function() {
    function commonInit() {
        $('.chosen-select').chosen({width: "100%"});

        $('.map-select').each(function() {
            mapboxgl.accessToken = '<KEY>';
            var map = new mapboxgl.Map({
                container: $(this).attr('id'),
                style: 'mapbox://styles/mapbox/light-v9',
                center: [7.6700, 45.0516],
                zoom: 12
            });

            var geocoder = new MapboxGeocoder({
                proximity: {latitude: 45.0516, longitude: 7.6700},
                bbox: [7.430458,44.907397,7.900369,45.194847],
                placeholder: 'Scrivi qui l\'indirizzo',
                accessToken: mapboxgl.accessToken
            });
            map.addControl(geocoder);

            /*
                Questo è per forzare l'attributo "required" nel campo di testo dove
                mettere l'indirizzo
            */
            $('.mapboxgl-ctrl-geocoder input:text').attr('required', 'required');
            var form = $(this).closest('form');

            geocoder.on('result', function(ev) {
                $('input[name=address]', form).val(ev.result.place_name);
                $('input[name=coordinates]', form).val(ev.result.geometry.coordinates[1] + ',' + ev.result.geometry.coordinates[0]);
            });
        });
    }

    function dynamicModal(endpoint, id) {
        if (endpoint.indexOf('{id}') != -1)
            endpoint = '/' + endpoint.replace('{id}', id);
        else
            endpoint = '/' + endpoint + '/' + id;

        $.ajax(endpoint, {
            method: 'GET',
            dataType: 'HTML',
            success: function(data) {
                var d = $(data);
                $('body').append(d);
                d.modal('show');
                d.on('hidden.bs.modal', function() {
                    $(this).remove();
                });
                commonInit();
            }
        });
    }

    function previewImage(input, img, angle) {
        var ratio = 400 / img.width;
        var canvas = $("<canvas>")[0];
        canvas.width = img.width * ratio;
        canvas.height = img.height * ratio;
        var ctx = canvas.getContext("2d");

        ctx.save();

        if (angle != 0) {
            ctx.translate(canvas.width / 2, canvas.height / 2);
            ctx.rotate(angle * Math.PI / 180);
        }

        ctx.drawImage(img, -canvas.width/2, -canvas.height/2, canvas.width, canvas.height);

        ctx.restore();

        var cell = $(input).closest('.fileuploader');
        if (cell.attr('data-inited') == null) {
            var ncell = cell.clone();
            ncell.find('input').val('').removeAttr('required');
            cell.after(ncell);
        }
        cell.attr('data-inited', true);

        cell.find('.image-frame').empty().css('background-image', 'url(' + canvas.toDataURL() + ')');<commit_msg>fix orientamento preview immagini<commit_after>$(document).ready(function() {
    function commonInit() {
        $('.chosen-select').chosen({width: "100%"});

        $('.map-select').each(function() {
            mapboxgl.accessToken = '<KEY>';
            var map = new mapboxgl.Map({
                container: $(this).attr('id'),
                style: 'mapbox://styles/mapbox/light-v9',
                center: [7.6700, 45.0516],
                zoom: 12
            });

            var geocoder = new MapboxGeocoder({
                proximity: {latitude: 45.0516, longitude: 7.6700},
                bbox: [7.430458,44.907397,7.900369,45.194847],
                placeholder: 'Scrivi qui l\'indirizzo',
                accessToken: mapboxgl.accessToken
            });
            map.addControl(geocoder);

            /*
                Questo è per forzare l'attributo "required" nel campo di testo dove
                mettere l'indirizzo
            */
            $('.mapboxgl-ctrl-geocoder input:text').attr('required', 'required');
            var form = $(this).closest('form');

            geocoder.on('result', function(ev) {
                $('input[name=address]', form).val(ev.result.place_name);
                $('input[name=coordinates]', form).val(ev.result.geometry.coordinates[1] + ',' + ev.result.geometry.coordinates[0]);
            });
        });
    }

    function dynamicModal(endpoint, id) {
        if (endpoint.indexOf('{id}') != -1)
            endpoint = '/' + endpoint.replace('{id}', id);
        else
            endpoint = '/' + endpoint + '/' + id;

        $.ajax(endpoint, {
            method: 'GET',
            dataType: 'HTML',
            success: function(data) {
                var d = $(data);
                $('body').append(d);
                d.modal('show');
                d.on('hidden.bs.modal', function() {
                    $(this).remove();
                });
                commonInit();
            }
        });
    }

    function previewImage(input, img, angle) {
        var ratio = 400 / img.width;
        var canvas = $("<canvas>")[0];
        canvas.width = img.width * ratio;
        canvas.height = img.height * ratio;
        var ctx = canvas.getContext("2d");

        ctx.save();

        if (angle != 0) {
            ctx.translate(canvas.width / 2, canvas.height / 2);
            ctx.rotate(angle * Math.PI / 180);
            ctx.drawImage(img, -canvas.width/2, -canvas.height/2, canvas.width, canvas.height);
        }
        else {
            ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
        }

        ctx.restore();

        var cell = $(input).closest('.fileuploader');
        if (cell.attr('data-inited') == null) {
            var ncell = cell.clone();
            ncell.find('input').val('').removeAttr('required');
            cell.after(ncell);
        }
        cell.attr('data-inited', true);

        cell.find('.image-frame').empty().css('background-image', 'url(' + canvas.toDataURL() + ')');
{'fraction_non_alphanumeric': 0.16787704779598042, 'fraction_numerical': 0.02533355852052018, 'mean_word_length': 1.6343416370106763, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6465353', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1702, 'n_words': 303}