<commit_before>$(document).ready(function() {
    changeBackgroundSample();
    changeForegroundSample();
    document.getElementById("foreground-input").onchange = function() {
        changeForegroundSample();
        console.log("change foreground Appel");
    };
    document.getElementById("background-input").onchange = function() {
        changeBackgroundSample();
    };
});

function changeForegroundSample() {
    var input = document.getElementById("foreground-input");
    var color = input.value;
    var sample = document.getElementById("foreground-sample");
    color = color.toString().trim();
 // color = color.toString().replace(/\s/g,""); // replace ' ', \t, \n, ...
    color = isValidateColor(color.toString());
    if (color !== "false") {
        sample.style.backgroundColor = color;
        sample.classList.add('color-sample');
        sample.classList.add('sample-bordered');
        document.getElementById("foreground-sample-invalid").style.display = "none";
        input.classList.remove('error');
    } else {
        sample.style.backgroundColor = "rgba(0,0,0,0)";
        sample.classList.remove('color-sample');
        sample.classList.remove('sample-bordered');
        document.getElementById("foreground-sample-invalid").style.display = "inherit";
        input.classList.add('error');
    }
}

function changeBackgroundSample() {
    var input = document.getElementById("background-input");
    var color = input.value;
    var sample = document.getElementById("background-sample");
 // color = color.toString().trim();
    color = color.toString().replace(/\s/g,""); // replace ' ', \t, \n, ...
    color = isValidateColor(color.toString());
    if (color !== "false") {
        sample.style.backgroundColor = color;
        sample.classList.add('color-sample');
        sample.classList.add('sample-bordered');
        document.getElementById("background-sample-invalid").style.display = "none";
        input.classList.remove('error');
    } else {
        sample.style.backgroundColor = "rgba(0,0,0,0)";
        sample.classList.remove('color-sample');
        sample.classList.remove('sample-bordered');
        document.getElementById("background-sample-invalid").style.display = "inherit";
        input.classList.add('error');
    }
}

function isValidateColor(str) {
    if (str.match(/^#[a-fA-F0-9]{6}$/i) !== null
            || str.match(/^#[a-fA-F0-9]{3}$/i) !== null)
    {
        return str;
    }
    else if (str.match(/^#?([a-fA-F0-9]{6})$/) !== null
            || str.match(/^#?([a-fA-F0-9]{3})$/) !== null) {<commit_msg>Javascript - Replaced change*Sample() functions by changeColorSample()<commit_after>$(document).ready(function() {
    changeColorSample("foreground");
    changeColorSample("background");
    document.getElementById("foreground-input").onchange = function() {
        changeColorSample("foreground");
        console.log("change foreground Appel");
    };
    document.getElementById("background-input").onchange = function() {
        changeColorSample("background");
    };
});


function changeColorSample(colorPrefix) {
    var input = document.getElementById(colorPrefix + "-input");
    var color = input.value;
    var sample = document.getElementById(colorPrefix + "-sample");
    color = color.toString().trim();
 // color = color.toString().replace(/\s/g,""); // replace ' ', \t, \n, ...
    color = isValidateColor(color.toString());
    if (color !== "false") {
        sample.style.backgroundColor = color;
        sample.classList.add('color-sample');
        sample.classList.add('sample-bordered');
        document.getElementById(colorPrefix + "-sample-invalid").style.display = "none";
        input.classList.remove('error');
    } else {
        sample.style.backgroundColor = "rgba(0,0,0,0)";
        sample.classList.remove('color-sample');
        sample.classList.remove('sample-bordered');
        document.getElementById(colorPrefix + "-sample-invalid").style.display = "inherit";
        input.classList.add('error');
    }
}

function isValidateColor(str) {
    if (str.match(/^#[a-fA-F0-9]{6}$/i) !== null
            || str.match(/^#[a-fA-F0-9]{3}$/i) !== null)
    {
        return str;
    }
    else if (str.match(/^#?([a-fA-F0-9]{6})$/) !== null
            || str.match(/^#?([a-fA-F0-9]{3})$/) !== null) {
{'fraction_non_alphanumeric': 0.1877890841813136, 'fraction_numerical': 0.008325624421831638, 'mean_word_length': 3.154658981748319, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3748460', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1274, 'n_words': 177}