3 This is part of the YARRG website. YARRG is a tool and website
4 for assisting players of Yohoho Puzzle Pirates.
6 Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7 Copyright (C) 2009 Clare Boothby
9 YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
10 The YARRG website is covered by the GNU Affero GPL v3 or later, which
11 basically means that every installation of the website will let you
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Affero General Public License as
16 published by the Free Software Foundation, either version 3 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Affero General Public License for more details.
24 You should have received a copy of the GNU Affero General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
28 are used without permission. This program is not endorsed or
29 sponsored by Three Rings.
32 This Mason component handles analysis of text string entries, including
33 both the AJAX calls from web page javascript and the entry validation
34 and processing calls from other components.
39 $qa => $m->caller_args(1)->{'qa'}
48 my $stringval= $qa->{$thingstring};
49 $stringval='' if !defined $stringval;
52 my $checker= $m->fetch_comp("check_${thingstring}");
53 my $significant_nonempty= $checker->attr_exists('significant_nonempty');
58 <%$p%>uri= "qtextstringcheck?format=application/json&ctype=text/xml"
59 + "&what=<% $thingstring %>"
60 + "&ocean=<% uri_escape($qa->{Ocean}) %>";
64 <%$p%>done=<% $significant_nonempty ? "null" : "''" %>;
66 function <%$p%>Later(){
67 window.clearTimeout(<%$p%>timeout);
68 <%$p%>timeout = window.setTimeout(<%$p%>Needed, 500);
70 function <%$p%>Needed(){
71 window.clearTimeout(<%$p%>timeout);
72 <%$p%>element= document.getElementById('<% $thingstring %>');
73 <%$p%>needed= <%$p%>element.value;
76 function <%$p%>Request(){
77 if (<%$p%>request || <%$p%>needed==<%$p%>done) return;
78 <%$p%>done= <%$p%>needed;
79 <%$p%>request= new XMLHttpRequest();
80 uri= <%$p%>uri+'&string='+encodeURIComponent(<%$p%>needed);
81 <%$p%>request.open('GET', uri);
82 <%$p%>request.onreadystatechange= <%$p%>Ready;
83 <%$p%>request.send(null);
85 function <%$p%>Ready() {
86 if (<%$p%>request.readyState != 4) return;
87 if (<%$p%>request.status == 200) {
88 response= <%$p%>request.responseText;
89 debug('<%$p%> got '+response);
90 eval('results='+response);
91 toedit= document.getElementById('<%$p%>results');
92 toedit.innerHTML= results.show;
97 register_onload(<%$p%>Needed);
100 % if (!printable($m)) {
101 <input type="text" <% $m->content %>
102 id="<% $thingstring %>" name="<% $thingstring %>"
103 onchange="<%$p%>Needed();" onkeyup="<%$p%>Later();"
104 value="<% $stringval |h %>"
105 ><% defined($helpref) ? "<a href=\"docs#$helpref\">[?]</a>" : '' %>
107 <div id="<%$p%>results"> </div><br>
109 <kbd><strong><% $stringval |h %></strong></kbd>
115 if ($significant_nonempty || length $thingstring) {
116 my ($emsg,$canonstring,@results)= $m->comp('qtextstringcheck',
117 what => $thingstring,
118 ocean => $qa->{Ocean},
119 string => $stringval,
122 if (defined $emsg and length $emsg) {
123 $$emsgstore='' unless defined $$emsgstore;
124 $$emsgstore .= $emsg. ' ';
126 $onresults->(@results);