chiark / gitweb /
Generalise route[text]string
[ypp-sc-tools.main.git] / yarrg / web / qtextstring
1 <%args>
2 $thingstring
3 $qa => $m->caller_args(1)->{'qa'}
4 </%args>
5
6 Enter route (islands, or archipelagoes, separated by |s or commas;
7  abbreviations are OK):<br>
8
9 <&| script &>
10 ts_uri= "check_<% $thingstring %>?format=json&type=text/xml"
11                 + "&ocean=<% uri_escape($qa->{Ocean}) %>";
12
13 ts_timeout=false;
14 ts_request=false;
15 ts_done='';
16 ts_needed='';
17 function ts_Later(){
18   window.clearTimeout(ts_timeout);
19   ts_timeout = window.setTimeout(ts_Needed, 500);
20 }
21 function ts_Needed(){
22   window.clearTimeout(ts_timeout);
23   ts_element= document.getElementById('<% $thingstring %>');
24   ts_needed= ts_element.value;
25   ts_Request();
26 }
27 function ts_Request(){
28   if (ts_request || ts_needed==ts_done) return;
29   ts_done= ts_needed;
30   ts_request= new XMLHttpRequest();
31   uri= ts_uri+'&string='+encodeURIComponent(ts_needed);
32   ts_request.open('GET', uri);
33   ts_request.onreadystatechange= ts_Ready;
34   ts_request.send(null);
35 }
36 function ts_Ready() {
37   if (ts_request.readyState != 4) return;
38   if (ts_request.status == 200) {
39     response= ts_request.responseText;
40     eval('results='+response);
41     toedit= document.getElementById('ts_results');
42     toedit.innerHTML= results.show;
43   }
44   ts_request= false;
45   ts_Request();
46 }
47 window.onload= ts_Needed;
48 </&script>
49
50 <input type="text" <% $m->content %>
51  id="<% $thingstring %>" name="<% $thingstring %>"
52  onchange="ts_Needed();" onkeyup="ts_Later();"
53  value="<% $qa->{$thingstring} |h %>"
54  >
55 <br>
56 <div id="ts_results">&nbsp;</div><br>