chiark / gitweb /
Generalise route[text]string
[ypp-sc-tools.web-test.git] / yarrg / web / qtextstring
diff --git a/yarrg/web/qtextstring b/yarrg/web/qtextstring
new file mode 100644 (file)
index 0000000..c0f2482
--- /dev/null
@@ -0,0 +1,56 @@
+<%args>
+$thingstring
+$qa => $m->caller_args(1)->{'qa'}
+</%args>
+
+Enter route (islands, or archipelagoes, separated by |s or commas;
+ abbreviations are OK):<br>
+
+<&| script &>
+ts_uri= "check_<% $thingstring %>?format=json&type=text/xml"
+               + "&ocean=<% uri_escape($qa->{Ocean}) %>";
+
+ts_timeout=false;
+ts_request=false;
+ts_done='';
+ts_needed='';
+function ts_Later(){
+  window.clearTimeout(ts_timeout);
+  ts_timeout = window.setTimeout(ts_Needed, 500);
+}
+function ts_Needed(){
+  window.clearTimeout(ts_timeout);
+  ts_element= document.getElementById('<% $thingstring %>');
+  ts_needed= ts_element.value;
+  ts_Request();
+}
+function ts_Request(){
+  if (ts_request || ts_needed==ts_done) return;
+  ts_done= ts_needed;
+  ts_request= new XMLHttpRequest();
+  uri= ts_uri+'&string='+encodeURIComponent(ts_needed);
+  ts_request.open('GET', uri);
+  ts_request.onreadystatechange= ts_Ready;
+  ts_request.send(null);
+}
+function ts_Ready() {
+  if (ts_request.readyState != 4) return;
+  if (ts_request.status == 200) {
+    response= ts_request.responseText;
+    eval('results='+response);
+    toedit= document.getElementById('ts_results');
+    toedit.innerHTML= results.show;
+  }
+  ts_request= false;
+  ts_Request();
+}
+window.onload= ts_Needed;
+</&script>
+
+<input type="text" <% $m->content %>
+ id="<% $thingstring %>" name="<% $thingstring %>"
+ onchange="ts_Needed();" onkeyup="ts_Later();"
+ value="<% $qa->{$thingstring} |h %>"
+ >
+<br>
+<div id="ts_results">&nbsp;</div><br>