From 04563ca60c3ffb2c02edf5e09582528d837aa925 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Wed, 28 Oct 2015 13:43:08 +0100
Subject: mv
---
js/common.js | 58 ++++++++++
js/lfpe.js | 357 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 415 insertions(+)
create mode 100644 js/common.js
create mode 100644 js/lfpe.js
(limited to 'js')
diff --git a/js/common.js b/js/common.js
new file mode 100644
index 0000000..11dcdba
--- /dev/null
+++ b/js/common.js
@@ -0,0 +1,58 @@
+var data,
+ ui_type;
+
+
+/*
+ * hacky way to remove class from node
+ *
+ */
+function removeClass(node, className)
+{
+ node.className =
+ node.className.replace(" "+className,'');
+ node.className =
+ node.className.replace(" "+className,''); // ???
+
+ return false;
+}
+
+/*
+ *
+ *
+ */
+function toggleDisplay(node)
+{
+ if (node.style.display=='none') {
+ node.style.display = 'block';
+ } else {
+ node.style.display = 'none';
+ }
+
+ return false;
+}
+
+/*
+ * trim string
+ *
+ */
+function trim(s)
+{
+ return s.replace(/^\s+|\s+$/g, '');
+}
+
+/*
+ * cross-site request
+ *
+ */
+function CreateCORSRequest(method, url)
+{
+ var xhr = new XMLHttpRequest();
+ if ("withCredentials" in xhr) {
+ xhr.open(method, url, true);
+ } else {
+ xhr = null;
+ }
+
+ return xhr;
+}
+
diff --git a/js/lfpe.js b/js/lfpe.js
new file mode 100644
index 0000000..1cf88bf
--- /dev/null
+++ b/js/lfpe.js
@@ -0,0 +1,357 @@
+/*
+ * 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;
+}
+
+/*
+ *
+ *
+ */
+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");
+
+ // show 'working' message
+ status.style.display = "block";
+
+ // disable button and textarea
+ button.setAttribute("disabled", "disabled");
+ pause_button.setAttribute("disabled", "disabled");
+ target_textarea.setAttribute("disabled", "disabled");
+}
+
+/*
+ *
+ *
+ */
+function not_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");
+
+ // hide 'working' message
+ status.style.display = "none";
+
+ // 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 = 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_fields").children.length;
+ var src = [];
+ var tgt = [];
+ for (var i=0; i