<commit_before>var workspace = Blockly.inject('blocklyDiv', {toolbox: document.getElementById('toolbox')});
var myInterpreter;

var firstrun = true;


function myUpdateFunction(event) {
    var code = Blockly.JavaScript.workspaceToCode(workspace);

    document.getElementById('code').innerHTML = code;
    var xmlDom = Blockly.Xml.workspaceToDom(workspace);
    var xmlText = Blockly.Xml.domToPrettyText(xmlDom);

    document.getElementById('xml').value = xmlText;
}

workspace.addChangeListener(myUpdateFunction);

var runButton = function() {
    var code = Blockly.JavaScript.workspaceToCode(workspace);
    if(firstrun) {
        firstrun = false;
    } else {
        var console = document.getElementById('console');

        var n = document.createElement('br');
        console.appendChild(n);

        n = document.createElement('hr');
        console.appendChild(n);
    }

    var div = document.getElementById('code');
    div.innerHTML = code;


    myInterpreter = new Interpreter(code, initApi);
    var runCode = function () {
        if(myInterpreter.run()) {
            // Ran until an async call.  Give this call a chance to run.
            // Then start running again later.
            // 1000ms is waaay too long, but is used here to demo the pause.
            setTimeout(runCode, 10);
        };
    };
    runCode();
};

var clean = function () {
    var div = document.getElementById('console');
    div.innerHTML = "";
}

function displayText(text) {
    var div = document.getElementById('console');
    var t = document.createTextNode(text);
    div.appendChild(t);
}

function displayTextLN(text) {
    var div = document.getElementById('console');
    var n = document.createTextNode(text);
    div.appendChild(n);
    n = document.createNode('br');
    div.appendChild(n);
}

function saveWorkspace() {
    var xmlDom = Blockly.Xml.workspaceToDom(workspace);
    var xmlText = Blockly.Xml.domToPrettyText(xmlDom);

    localStorage.setItem("blockly.xml", xmlText);
}

function loadWorkspace() {
    var xmlText = localStorage.getItem("blockly.xml");
    if (xmlText) {
        workspace.clear();
        xmlDom = Blockly.Xml.textToDom(xmlText);
        Blockly.Xml.domToWorkspace(workspace, xmlDom);
    }
}

var promptId;
var promptOk;

function consolePrompt(text) {
    var div = document.getElementById('console');

    var n = document.createTextNode(text);
    div.appendChild(n);

    n = document.createElement('input');
    n.setAttribute('type', 'text');
    promptId = Date.now();
    n.setAttribute('name', promptId);
    n.setAttribute('id', 'input' + promptId);
    n.setAttribute('onchange', 'promptOk();');
    div.appendChild(n);
    n.focus();

    n = document.createElement('button');
    n.setAttribute('type', 'button');
    n.setAttribute('onclick', 'promptOk();');
    n.setAttribute('id', 'button' + promptId);

    n.innerHTML = 'ok';
    div.appendChild(n);

    n = document.createElement('br');
    div.appendChild(n);
}

function initApi(interpreter, scope) {
    // Add an API function for the alert() block.
    var wrapper = function(text) {
        text = text ? text.toString() : '';
        return interpreter.createPrimitive(displayText(text));
    };

    interpreter.setProperty(scope, 'alert',
                            interpreter.createNativeFunction(wrapper));

    // Add an API function for the prompt() block.
    wrapper = function(text,callback) {<commit_msg>Je ne gère que les nombres pour les inputs<commit_after>var workspace = Blockly.inject('blocklyDiv', {toolbox: document.getElementById('toolbox')});
var myInterpreter;

var firstrun = true;


function myUpdateFunction(event) {
    var code = Blockly.JavaScript.workspaceToCode(workspace);

    document.getElementById('code').innerHTML = code;
    var xmlDom = Blockly.Xml.workspaceToDom(workspace);
    var xmlText = Blockly.Xml.domToPrettyText(xmlDom);

    document.getElementById('xml').value = xmlText;
}

workspace.addChangeListener(myUpdateFunction);

var runButton = function() {
    var code = Blockly.JavaScript.workspaceToCode(workspace);
    if(firstrun) {
        firstrun = false;
    } else {
        var console = document.getElementById('console');

        var n = document.createElement('br');
        console.appendChild(n);

        n = document.createElement('hr');
        console.appendChild(n);
    }

    var div = document.getElementById('code');
    div.innerHTML = code;


    myInterpreter = new Interpreter(code, initApi);
    var runCode = function () {
        if(myInterpreter.run()) {
            // Ran until an async call.  Give this call a chance to run.
            // Then start running again later.
            // 1000ms is waaay too long, but is used here to demo the pause.
            setTimeout(runCode, 10);
        };
    };
    runCode();
};

var clean = function () {
    var div = document.getElementById('console');
    div.innerHTML = "";
}

function displayText(text) {
    var div = document.getElementById('console');
    var t = document.createTextNode(text);
    div.appendChild(t);
}

function displayTextLN(text) {
    var div = document.getElementById('console');
    var n = document.createTextNode(text);
    div.appendChild(n);
    n = document.createNode('br');
    div.appendChild(n);
}

function saveWorkspace() {
    var xmlDom = Blockly.Xml.workspaceToDom(workspace);
    var xmlText = Blockly.Xml.domToPrettyText(xmlDom);

    localStorage.setItem("blockly.xml", xmlText);
}

function loadWorkspace() {
    var xmlText = localStorage.getItem("blockly.xml");
    if (xmlText) {
        workspace.clear();
        xmlDom = Blockly.Xml.textToDom(xmlText);
        Blockly.Xml.domToWorkspace(workspace, xmlDom);
    }
}

var promptId;
var promptOk;

function consolePrompt(text) {
    var div = document.getElementById('console');

    var n = document.createTextNode(text);
    div.appendChild(n);

    n = document.createElement('input');
    n.setAttribute('type', 'number');
    promptId = Date.now();
    n.setAttribute('name', promptId);
    n.setAttribute('id', 'input' + promptId);
    n.setAttribute('onchange', 'promptOk();');
    div.appendChild(n);
    n.focus();

    n = document.createElement('button');
    n.setAttribute('type', 'button');
    n.setAttribute('onclick', 'promptOk();');
    n.setAttribute('id', 'button' + promptId);

    n.innerHTML = 'ok';
    div.appendChild(n);

    n = document.createElement('br');
    div.appendChild(n);
}

function initApi(interpreter, scope) {
    // Add an API function for the alert() block.
    var wrapper = function(text) {
        text = text ? text.toString() : '';
        return interpreter.createPrimitive(displayText(text));
    };

    interpreter.setProperty(scope, 'alert',
                            interpreter.createNativeFunction(wrapper));

    // Add an API function for the prompt() block.
    wrapper = function(text,callback) {
{'fraction_non_alphanumeric': 0.13668545007946828, 'fraction_numerical': 0.0017338534893801473, 'mean_word_length': 3.2181596587446677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 32}, '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': '5338656', 'n_tokens_mistral': 2019, 'n_tokens_neox': 2021, 'n_words': 442}