allow from all
</Location>
+# Autosuggest for searches
+<Location /opac/extras/autosuggest>
+ SetHandler perl-script
+ PerlHandler OpenILS::WWW::AutoSuggest
+ PerlSendHeader On
+ Allow from All
+</Location>
+
# ----------------------------------------------------------------------------------
# Replace broken cover images with a transparent GIF by default
# ----------------------------------------------------------------------------------
--- /dev/null
+package OpenILS::WWW::AutoSuggest;
+
+use strict;
+use warnings;
+
+use Apache2::Log;
+use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
+use APR::Const -compile => qw(:error SUCCESS);
+use Apache2::RequestRec ();
+use Apache2::RequestIO ();
+use Apache2::RequestUtil;
+use CGI;
+
+my @dict = qw/
+ alpha
+ allstate
+ apple
+ appropriate
+ application
+ arizona
+ bears
+ beta
+ beets
+ gamma
+ gone
+ out
+ tool
+ toad
+ tap
+ sock
+ socket
+ sicken
+ sickening
+ rage
+ right
+ road
+ /;
+
+sub search_dict {
+ my $term = shift;
+ (my $re = $term) =~ s/[^a-z0-9]/\./gi;
+
+ return ($term, grep(/^$re/, @dict));
+}
+
+sub handler {
+ my $r = shift;
+ my $cgi = new CGI;
+
+ my ($term, @matches) = search_dict($cgi->param("query"));
+ my $xml_terms = join("\n", map {
+ qq{<val term="$term" field="123">$_</val>}
+ } @matches);
+ print "Content-type: application/xml; charset=utf-8\n\n";
+
+ print qq{<?xml version="1.0"?>
+<as>
+$xml_terms
+</as>
+ };
+
+ return Apache2::Const::OK;
+}
+
+1;
+
+# vim: et:ts=4:sw=4
var me = this;
var process_feed = function (xmldoc) {
- if (parseInt(me.horizon) >= parseInt(me.root.getAttribute('horizon'))) {
+ console.log("in process_feed()");
+ if (parseInt(me.horizon) >= parseInt(me.root.getAttribute('horizon'))) {
if (me.empty == true) dojo.empty(me.place);
me.root.setAttribute('horizon', this.horizon);
+ console.log("about to do bibtemplate loop, item_query is " + me.item_query);
dojo.query( me.item_query, xmldoc ).forEach(
function (item) {
var template = me.root.cloneNode(true);
dojo.place( template, me.place, me.relativePosition );
+ console.log("instantiating a bibtemplate");
new openils.BibTemplate({ delay : false, xml : item, root : template });
}
);
+ } else {
+ console.log("horizon test failed");
}
};
var newSearchLocation;
var newSearchDepth = null;
+dojo.require("openils.BibTemplate");
+
+
+var autosuggest_ft;
+
+function autosuggestTest() {
+ if (!autosuggest_ft) {
+ autosuggest_ft = new openils.FeedTemplate({
+ "place": dojo.byId("test1"),
+ "root": dojo.byId("template_root"),
+ "empty": true,
+ "query": "as",
+ "preventCache": true /* XXX do we want this permanently? */
+ });
+ }
+
+ autosuggest_ft.feed_uri = "http://dev-vm1/opac/extras/autosuggest?query=" +
+ dojo.byId("search_box").value;
+ console.log(autosuggest_ft.feed_uri);
+
+ autosuggest_ft.render();
+}
function searchBarInit() {
<tr>
<td nowrap='nowrap' align='center' class='color_1 border_5'>
- <input id='search_box' style='width: 300px;' type='text' />
- <span style='padding-left: 6px;'>
- <input type='button' style='width: 40px;' id='search_submit' value='Go!' />
- </span>
+ <div style="width: 340px;">
+ <input id='search_box' style='width: 300px;' type='text' />
+ <span style='padding-left: 6px;'>
+ <input type='button' style='width: 40px;' id='search_submit' value='Go!' /><a href="javascript:unHideMe($('test1'));">unhide</a><a href="javascript:autosuggestTest();">search</a>
+ </span>
+ <br />
+ <div id="test1" style="text-align:left; float:left; width: 300px; background: #ccc; position:absolute;z-index: 100"><a href="javascript:hideMe($('test1'));">hide</a></div>
+ </div>
</td>
</tr>
</div>
-
-
-
-
+<div class="hide_me">
+ <div id="template_root">
+ <span type='opac/slot-data' query='val[field=123]' join="<br />">
+ <span class="hide_me" type="opac/slot-format"><![CDATA[
+ var term = BT.textContent(item);
+ var s = '"' + term + '"';
+
+ return "<a href='javascript:alert(" + s + ");'>" + term + "</a>";
+ ]]></span>
+ </span>
+ </div>
+</div>