<commit_before>﻿function updateFen() {
    var fenStr = window.ground.getFen();
    if (document.getElementById("whitetomove").checked) {
        fenStr += " w ";
    } else {
        fenStr += " b ";
    }
    var castlingStr = "";
    if (document.getElementById("whitecastlekingside").checked) castlingStr += "K";
    if (document.getElementById("whitecastlequeenside").checked) castlingStr += "Q";
    if (document.getElementById("blackcastlekingside").checked) castlingStr += "k";
    if (document.getElementById("blackcastlequeenside").checked) castlingStr += "q";
    if (castlingStr === "") castlingStr = "-";
    fenStr += castlingStr;
    document.getElementById("fen").innerHTML = fenStr;
}

function dropPiece(dest) {
    if (!window.selectedPiece) return;
    var piecesChange = {};
    piecesChange[dest] = window.selectedPiece;
    window.ground.setPieces(piecesChange);
    updateFen();
}

function pieceSelected(e) {
    e = e || window.event;
    var selected = e.target;
    selected.setAttribute("class", "selectable selected");
    if (window.selectedPieceElement) {
        window.selectedPieceElement.setAttribute("class", "selectable");
    }
    var color = selected.getAttribute("data-color");
    var role = selected.getAttribute("data-role");
    window.selectedPiece = { color: color, role: role };
    window.selectedPieceElement = selected;
}

function clearSelection(e) {
    e = e || window.event;
    e.preventDefault();
    if (!window.selectedPieceElement) return;
    window.selectedPieceElement.setAttribute("class", "selectable");
    delete window.selectedPiece;
}

function goToStep2(e) {
    e = e || window.event;
    e.preventDefault();
    var step1Elements = document.getElementsByClassName("step1");
    for (var i = 0; i < step1Elements.length; i++) {
        step1Elements[i].setAttribute("class", "step1 hidden");
    }
    var step2Elements = document.getElementsByClassName("step2");
    for (var i = 0; i < step2Elements.length; i++) {
        step2Elements[i].setAttribute("class", "step2");
    }
    jsonXhr("/Puzzle/Editor/RegisterPuzzleForEditing", "POST",
        "fen=" + encodeURIComponent(document.getElementById("fen").innerHTML + " - 0 1"), function (req, jsonResponse) {
            window.puzzleId = jsonResponse["id"];
            var whoseTurn = document.getElementById("fen").innerHTML.split(" ")[1] === "w" ? "white" : "black";
            window.ground.set({
                orientation: whoseTurn,
                movable: {
                    free: false,
                    showDests: false,
                    events: {
                        after: submitMove
                    }
                }
            });
            updateChessGroundValidMoves();
        }, function (req, err) {
            alert(err);
        });
}<commit_msg>Editor: clear piece selection when going to step 2<commit_after>﻿function updateFen() {
    var fenStr = window.ground.getFen();
    if (document.getElementById("whitetomove").checked) {
        fenStr += " w ";
    } else {
        fenStr += " b ";
    }
    var castlingStr = "";
    if (document.getElementById("whitecastlekingside").checked) castlingStr += "K";
    if (document.getElementById("whitecastlequeenside").checked) castlingStr += "Q";
    if (document.getElementById("blackcastlekingside").checked) castlingStr += "k";
    if (document.getElementById("blackcastlequeenside").checked) castlingStr += "q";
    if (castlingStr === "") castlingStr = "-";
    fenStr += castlingStr;
    document.getElementById("fen").innerHTML = fenStr;
}

function dropPiece(dest) {
    if (!window.selectedPiece) return;
    var piecesChange = {};
    piecesChange[dest] = window.selectedPiece;
    window.ground.setPieces(piecesChange);
    updateFen();
}

function pieceSelected(e) {
    e = e || window.event;
    var selected = e.target;
    selected.setAttribute("class", "selectable selected");
    if (window.selectedPieceElement) {
        window.selectedPieceElement.setAttribute("class", "selectable");
    }
    var color = selected.getAttribute("data-color");
    var role = selected.getAttribute("data-role");
    window.selectedPiece = { color: color, role: role };
    window.selectedPieceElement = selected;
}

function clearSelection(e) {
    e = e || window.event;
    e.preventDefault();
    if (!window.selectedPieceElement) return;
    window.selectedPieceElement.setAttribute("class", "selectable");
    delete window.selectedPiece;
}

function goToStep2(e) {
    e = e || window.event;
    clearSelection(e);
    var step1Elements = document.getElementsByClassName("step1");
    for (var i = 0; i < step1Elements.length; i++) {
        step1Elements[i].setAttribute("class", "step1 hidden");
    }
    var step2Elements = document.getElementsByClassName("step2");
    for (var i = 0; i < step2Elements.length; i++) {
        step2Elements[i].setAttribute("class", "step2");
    }
    jsonXhr("/Puzzle/Editor/RegisterPuzzleForEditing", "POST",
        "fen=" + encodeURIComponent(document.getElementById("fen").innerHTML + " - 0 1"), function (req, jsonResponse) {
            window.puzzleId = jsonResponse["id"];
            var whoseTurn = document.getElementById("fen").innerHTML.split(" ")[1] === "w" ? "white" : "black";
            window.ground.set({
                orientation: whoseTurn,
                movable: {
                    free: false,
                    showDests: false,
                    events: {
                        after: submitMove
                    }
                }
            });
            updateChessGroundValidMoves();
        }, function (req, err) {
            alert(err);
        });
}
{'fraction_non_alphanumeric': 0.14230362803804156, 'fraction_numerical': 0.005811905600563579, 'mean_word_length': 2.8114093959731545, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7655954', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1614, 'n_words': 316}