<commit_before>// VARIABLES
var cookie_name = "kriptogram_alphabet_points";
var expDays = 365;
var ansHist = [];
var histPtr = 0;
var curHandPos = [0,0];
var pointsForClueReadMedium = 30;
var pointsForClueReadHard = 50;
// x = [right, left]
var positions = {
        'a':[135,180],'b':[90,180],'c':[45,180],'d':[0,180],'e':[180,45],'f':[180,90],
        'g':[180,135],'h':[90,225],'i':[45,225],'j':[0,90],'k':[135,0],'l':[135,45],
        'm':[135,90],'n':[135,135],'o':[90,315],'p':[90,0],'q':[90,45],'r':[90,90],
        's':[90,135],'t':[45,0],'u':[45,45],'v':[0,135],'w':[315,90],'x':[315,135],
        'y':[45,90],'z':[225,90],' ':[180,180],'init':[0,0]
    };

function initialize_alphabet(mode, level) {
    if (mode == "read") {
        if (level == "easy") {
            read_easy();
        } else if (level == "medium") {
            read_medium();
        } else if (level == "hard") {
            read_hard();
        }
    } else if (mode == "write") {
        if (level == "easy") {
            write_easy();
        } else if (level == "medium") {
            write_medium();
        } else if (level == "hard") {
            write_hard();
        }
    }
}

function read_easy() {
    console.log("read, easy");
}

function write_easy() {
    console.log("write, easy");
}

function read_medium() {
    $("#read_medium_solution").removeAttr("disabled");
    setTimeout(function() {
        $("#letterInput").focus();
    }, 500);
}

function write_medium() {
    setCanvas();
    semaforSetMedium(2);
}

function read_hard() {
    // Clean up
    $(".level-read-hard .panel-body .well").html("");
    $("#input-string-hard").html("");
    $("#next-arrow").removeAttr("href");
    $("#start-animation").removeAttr("disabled");
    $("#start-animation").removeClass("used");
    $("#start-animation").text("Začni!");
    
    var word = selectNewWord(window.words);
    var letters = word.split("");
    var idNumber = 1;
    for (i = 0; i < letters.length; i++) {
        var letter = letters[i];
        $(".level-read-hard .panel-body .well").append("<img src='" + flagsDir + letter + ".png' class='hidden'>");
        $("#input-string-hard").append('<input id="num' + idNumber + '" class = "letterInputClass" type="text" maxlength="1" onkeyup="focusNext(event, \'#num' + (idNumber+1) + '.letterInputClass\')">');
        //$("#input-string-hard").append('<input id="num' + idNumber + '" class = "letterInputClass" type="text" maxlength="1">');
        idNumber++;
    }
}

var zaseden = false;

function write_hard() {
    setCanvas();
    semaforSetHard(positions['init']);
}

$( document ).ready(function() {
    checkCookie(cookie_name);
    
    $("#choices .btn").click(function() {
       var letter = getLetterFromURL($("#picture-letter img").attr("src"));
       if ((this.innerHTML).toUpperCase() === letter.toUpperCase()) {
           $(this).removeClass("btn-info");
           $(this).addClass("btn-success");
           $("#next-arrow").attr("href", "next");
           buttonsDisable();
           addHistoryEasy();
           addPoints(1);
       } else {
           $(this).removeClass("btn-info");
           $(this).addClass("btn-danger");
           $(this).attr("disabled", "disabled");
           removePoints(1);
       }
    });
    
    //BRANJE-SREDNJE: ob pritisku na enter preveri vnos
    $("#letterInput").keypress(function(e) {
        //Enter pressed?
        if(e.which == 10 || e.which == 13) {
            if ($("#picture-letter").hasClass("tested")) {
                // Enter je bil pritisnjen brez spremembe crke.
                return;
            } else {
                // Oznaci, da je bil pritisnjen enter - dokler uporabnik ne spremeni crke, mu ponovni pritiski na enter ne odstevajo tock.
                $("#picture-letter").addClass("tested");
            }
            
            var vnos = (document.getElementById('letterInput')).value;
            console.log("crka: "+vnos);
            //preveri ce se vpisana crka ujema z resitvijo
            var image_link = $("#picture-letter img").attr("src").split("/");
            var image_name = image_link[image_link.length - 1];
            var letter = image_name.split(".")[0];
            
            console.log("Pravilna crka: "+letter+" vnos: "+vnos);
            
            if(vnos.toUpperCase() === letter.toUpperCase()){
                console.log("pravilno");
                $("#letterInput").addClass("correctInput");
                $("#letterInput").removeClass("wrongInput");
                $("#next-arrow").attr("href", "next");
                document.getElementById('letterInput').disabled = true;
                addHistoryMedium();
                addPoints(1);
                $("#picture-letter").removeClass("tested");
                $("#next-arrow").focus();
            }
            else{
                console.log("napacno");
                $("#letterInput").addClass("wrongInput");
                $("#letterInput").removeClass("correctInput");
                removePoints(1);
            }
                
        } else {
            $("#picture-letter").removeClass("tested");
        }
    });
    
    // BRANJE MEDIUM - resitev
    $("#read_medium_solution").click(function(){
        $(this).attr("disabled", "disabled");
        if (getPoints() >= pointsForClueReadMedium) {
            var url = $("#picture-letter img").attr("src");
            var letterSelected = getLetterFromURL(url);
            $("#letterInput").val(letterSelected);
            $("#next-arrow").attr("href", "next");
            $("#letterInput").addClass("correctInput");
            $("#letterInput").removeClass("wrongInput");
            addHistoryMedium();
            removePoints(pointsForClueReadMedium);
        }
    });
    
    //preveri vnos gesla ko je pritisnjen enter - branje hard
    $("#input-string-hard").keypress(function(e) {
        //Enter pressed?
        if(e.which == 10 || e.which == 13) {
            var index = 0;
            var numWrongOrUnanswered = 0;
            var numWrong = 0; var numCorrect = 0;
            $("#input-string-hard .letterInputClass").each(function(index) {
                var input = $(this).val();
                var letter = getLetterFromURL($(".level-read-hard img:eq(" + index + ")").attr("src"));
                if (input.toUpperCase() === letter.toUpperCase()) {
                    // Correct input
                    if ($(this).attr("disabled") != "disabled") {
                        $(this).addClass("correctInput");
                        $(this).removeClass("wrongInput");
                        $(this).removeClass("tested");
                        $(this).attr("disabled", "disabled");
                        numCorrect++;
                    }<commit_msg>Read medium: trying to improve user experience<commit_after>// VARIABLES
var cookie_name = "kriptogram_alphabet_points";
var expDays = 365;
var ansHist = [];
var histPtr = 0;
var curHandPos = [0,0];
var pointsForClueReadMedium = 30;
var pointsForClueReadHard = 50;
// x = [right, left]
var positions = {
        'a':[135,180],'b':[90,180],'c':[45,180],'d':[0,180],'e':[180,45],'f':[180,90],
        'g':[180,135],'h':[90,225],'i':[45,225],'j':[0,90],'k':[135,0],'l':[135,45],
        'm':[135,90],'n':[135,135],'o':[90,315],'p':[90,0],'q':[90,45],'r':[90,90],
        's':[90,135],'t':[45,0],'u':[45,45],'v':[0,135],'w':[315,90],'x':[315,135],
        'y':[45,90],'z':[225,90],' ':[180,180],'init':[0,0]
    };

function initialize_alphabet(mode, level) {
    if (mode == "read") {
        if (level == "easy") {
            read_easy();
        } else if (level == "medium") {
            read_medium();
        } else if (level == "hard") {
            read_hard();
        }
    } else if (mode == "write") {
        if (level == "easy") {
            write_easy();
        } else if (level == "medium") {
            write_medium();
        } else if (level == "hard") {
            write_hard();
        }
    }
}

function read_easy() {
    console.log("read, easy");
}

function write_easy() {
    console.log("write, easy");
}

function read_medium() {
    $("#read_medium_solution").removeAttr("disabled");
    setTimeout(function() {
        $("#letterInput").focus();
    }, 500);
}

function write_medium() {
    setCanvas();
    semaforSetMedium(2);
}

function read_hard() {
    // Clean up
    $(".level-read-hard .panel-body .well").html("");
    $("#input-string-hard").html("");
    $("#next-arrow").removeAttr("href");
    $("#start-animation").removeAttr("disabled");
    $("#start-animation").removeClass("used");
    $("#start-animation").text("Začni!");
    
    var word = selectNewWord(window.words);
    var letters = word.split("");
    var idNumber = 1;
    for (i = 0; i < letters.length; i++) {
        var letter = letters[i];
        $(".level-read-hard .panel-body .well").append("<img src='" + flagsDir + letter + ".png' class='hidden'>");
        $("#input-string-hard").append('<input id="num' + idNumber + '" class = "letterInputClass" type="text" maxlength="1" onkeyup="focusNext(event, \'#num' + (idNumber+1) + '.letterInputClass\')">');
        //$("#input-string-hard").append('<input id="num' + idNumber + '" class = "letterInputClass" type="text" maxlength="1">');
        idNumber++;
    }
}

var zaseden = false;

function write_hard() {
    setCanvas();
    semaforSetHard(positions['init']);
}

$( document ).ready(function() {
    checkCookie(cookie_name);
    
    $("#choices .btn").click(function() {
       var letter = getLetterFromURL($("#picture-letter img").attr("src"));
       if ((this.innerHTML).toUpperCase() === letter.toUpperCase()) {
           $(this).removeClass("btn-info");
           $(this).addClass("btn-success");
           $("#next-arrow").attr("href", "next");
           buttonsDisable();
           addHistoryEasy();
           addPoints(1);
       } else {
           $(this).removeClass("btn-info");
           $(this).addClass("btn-danger");
           $(this).attr("disabled", "disabled");
           removePoints(1);
       }
    });
    
    //BRANJE-SREDNJE: ob pritisku na enter preveri vnos
    $("#letterInput").keypress(function(e) {
        //Enter pressed?
        if(e.which == 10 || e.which == 13) {
            var vnos = (document.getElementById('letterInput')).value;
            
            if ($("#picture-letter").hasClass("tested") || vnos === "") {
                // Enter je bil pritisnjen brez spremembe crke.
                // Ali: polje je prazno
                return;
            } else {
                // Oznaci, da je bil pritisnjen enter - dokler uporabnik ne spremeni crke, mu ponovni pritiski na enter ne odstevajo tock.
                $("#picture-letter").addClass("tested");
            }
            
            console.log("crka: "+vnos);
            //preveri ce se vpisana crka ujema z resitvijo
            var image_link = $("#picture-letter img").attr("src").split("/");
            var image_name = image_link[image_link.length - 1];
            var letter = image_name.split(".")[0];
            
            console.log("Pravilna crka: "+letter+" vnos: "+vnos);
            
            if(vnos.toUpperCase() === letter.toUpperCase()){
                console.log("pravilno");
                $("#letterInput").addClass("correctInput");
                $("#letterInput").removeClass("wrongInput");
                $("#next-arrow").attr("href", "next");
                document.getElementById('letterInput').disabled = true;
                addHistoryMedium();
                addPoints(1);
                $("#picture-letter").removeClass("tested");
                $("#next-arrow").focus();
            } else {
                console.log("napacno");
                $("#letterInput").addClass("wrongInput");
                $("#letterInput").removeClass("correctInput");
                removePoints(1);
                $("#letterInput").focus().select();
            }
                
        } else {
            $("#picture-letter").removeClass("tested");
        }
    });
    
    // BRANJE MEDIUM - resitev
    $("#read_medium_solution").click(function(){
        $(this).attr("disabled", "disabled");
        if (getPoints() >= pointsForClueReadMedium) {
            var url = $("#picture-letter img").attr("src");
            var letterSelected = getLetterFromURL(url);
            $("#letterInput").val(letterSelected);
            $("#next-arrow").attr("href", "next");
            $("#letterInput").addClass("correctInput");
            $("#letterInput").removeClass("wrongInput");
            addHistoryMedium();
            removePoints(pointsForClueReadMedium);
            $("#next-arrow").focus();
        } else {
            $("#letterInput").focus();
        }
    });
    
    //preveri vnos gesla ko je pritisnjen enter - branje hard
    $("#input-string-hard").keypress(function(e) {
        //Enter pressed?
        if(e.which == 10 || e.which == 13) {
            var index = 0;
            var numWrongOrUnanswered = 0;
            var numWrong = 0; var numCorrect = 0;
            $("#input-string-hard .letterInputClass").each(function(index) {
                var input = $(this).val();
                var letter = getLetterFromURL($(".level-read-hard img:eq(" + index + ")").attr("src"));
                if (input.toUpperCase() === letter.toUpperCase()) {
                    // Correct input
                    if ($(this).attr("disabled") != "disabled") {
                        $(this).addClass("correctInput");
                        $(this).removeClass("wrongInput");
                        $(this).removeClass("tested");
                        $(this).attr("disabled", "disabled");
                        numCorrect++;
                    }
{'fraction_non_alphanumeric': 0.19685552818432112, 'fraction_numerical': 0.024054484857267064, 'mean_word_length': 2.1564143608506745, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5960074', 'n_tokens_mistral': 4378, 'n_tokens_neox': 4123, 'n_words': 711}