/* * Timer * */ var Timer = { start_t: 0, pause_start_t: 0, pause_acc_t: 0, paused: false, start: function() { this.start_t = Date.now(); this.pause_start_t = 0; this.pause_acc_t = 0; this.paused = false; }, pause: function() { this.paused = true; this.pause_start_t = Date.now(); }, unpause: function() { this.paused = false; this.pause_acc_t += Date.now()-this.pause_start_t; this.pause_start_t = 0; }, get: function() { return (Date.now()-this.start_t)-this.pause_acc_t; } } /* * pause/unpause timer * */ function pause() { var paused = document.getElementById("paused"); var button = document.getElementById("pause_button"); var next_button = document.getElementById("next"); var target_textarea = document.getElementById("target_textarea") var initialized = document.getElementById("init"); if (paused.value == 0) { button.innerHTML = "Unpause"; paused.value = 1; next.setAttribute("disabled", "disabled"); target_textarea.setAttribute("disabled", "disabled"); Timer.pause(); } else { button.innerHTML = "Pause"; paused.value = 0; next.removeAttribute("disabled"); if (initialized.value != "") { target_textarea.removeAttribute("disabled"); } Timer.unpause(); } } /* * no newline on return in textarea * */ function catch_return(e) { if (e.keyCode == 13) { e.preventDefault(); Next(); } return false; } /* * working/not working * */ function working() { // elements var button = document.getElementById("next"); var pause_button = document.getElementById("pause_button"); var target_textarea = document.getElementById("target_textarea") var raw_source_textarea = document.getElementById("raw_source_textarea"); var current_seg_id = document.getElementById("current_seg_id"); var source = document.getElementById("source"); var status = document.getElementById("status"); var oov_correct = document.getElementById("oov_correct"); var last_post_edit = document.getElementById("last_post_edit"); if ($("#ui_type").val() == "t") { $("#textboxes").fadeTo(200,0.1); } else { $("#derivation_editor").fadeTo(200,0.1); } // show 'working' message //status.style.display = "block"; $("#status").fadeToggle(); // disable button and textarea button.setAttribute("disabled", "disabled"); pause_button.setAttribute("disabled", "disabled"); target_textarea.setAttribute("disabled", "disabled"); } function not_working(fadein=true) { // elements var button = document.getElementById("next"); var pause_button = document.getElementById("pause_button"); var target_textarea = document.getElementById("target_textarea") var raw_source_textarea = document.getElementById("raw_source_textarea"); var current_seg_id = document.getElementById("current_seg_id"); var source = document.getElementById("source"); var status = document.getElementById("status"); var oov_correct = document.getElementById("oov_correct"); var last_post_edit = document.getElementById("last_post_edit"); if (fadein) { if ($("#ui_type").val() == "t") { $("#textboxes").fadeTo(200,1); } else { $("#derivation_editor").fadeTo(200,1); } } // hide 'working' message //status.style.display = "none"; $("#status").fadeToggle(); // enable buttons document.getElementById("next").removeAttribute("disabled"); document.getElementById("pause_button").removeAttribute("disabled"); } /* * next button * */ function Next() { // elements var button = document.getElementById("next"); var pause_button = document.getElementById("pause_button"); var target_textarea = document.getElementById("target_textarea") var raw_source_textarea = document.getElementById("raw_source_textarea"); var current_seg_id = document.getElementById("current_seg_id"); var source = document.getElementById("source"); var status = document.getElementById("status"); var oov_correct = document.getElementById("oov_correct"); var last_post_edit = document.getElementById("last_post_edit"); working(); // get metadata stored in DOM var base_url = "http://coltrane.cl.uni-heidelberg.de"; var port = document.getElementById("port").value; var key = document.getElementById("key").value; // url next_url = base_url+":"+port+"/next?key="+key; // post edit var post_edit = ''; // extract data from interfaces if (ui_type == 'g') { post_edit = trim(JSON.parse(DE_extract_data())["target"].join(" ")) } else { post_edit = trim(target_textarea.value); } // send data // ??? if (oov_correct.value=="false" && post_edit != "") { // compose request next_url += "&example="+encodeURIComponent(source.value)+"%20%7C%7C%7C%20"+encodeURIComponent(post_edit)+"&duration="+Timer.get(); // no change? if (post_edit == last_post_edit.value) { next_url += "&nochange=1"; } // update document overview document.getElementById("seg_"+(current_seg_id.value)+"_t").innerHTML=post_edit; // OOV correction mode } else if (oov_correct.value=="true") { var l = document.getElementById("oov_num_items").value; var src = []; var tgt = []; for (var i=0; i").replace(/###/g,"")); for (var i=0; i 0) { removeClass(document.getElementById("seg_"+(id-1)), "bold"); } if (translation) target_textarea.rows = Math.round(translation.length/80+0.5); //raw_source_textarea.rows = Math.round(raw_source.length/80+0.5); target_textarea.focus(); target_textarea.selectionStart = 0; target_textarea.selectionEnd = 0; // remember aux data in DOM current_seg_id.value = id; source.value = src; last_post_edit.value = translation; // confirm to server var xhr_confirm = CreateCORSRequest('get', base_url+":"+port+"/confirm"); xhr_confirm.send(); // FIXME: handle errors // load data into graphical UI if (ui_type == "g") { DE_init(); } // start timer Timer.start(); } }; xhr.onerror = function() {}; // FIXME: do something reasonable xhr.send(); // send 'next' request return; } /* * init text interface * */ function init_text_editor() { document.getElementById("target_textarea").value = ""; //document.getElementById("raw_source_textarea").value = ""; document.getElementById("target_textarea").setAttribute("disabled", "disabled"); return false; } /* * init site * */ window.onload = function () { // reset vars document.getElementById("source").value = ""; document.getElementById("current_seg_id").value = ""; document.getElementById("paused").value = ""; document.getElementById("oov_correct").value = false; document.getElementById("displayed_oov_hint").value = false; document.getElementById("init").value = ""; not_working(); ui_type = document.getElementById("ui_type").value; // graphical derivation editor if (ui_type == "g") { document.getElementById("derivation_editor").style.display = "block"; // text based editor } else { init_text_editor(); document.getElementById("textboxes").style.display = "block"; } };