The switch to autosuggest gave us great functionality, but we lost
autofocus for effortless initial searching. Restore it, with and without
Dojo. For the latter case, just use HTML5's autofocus attribute to begin
with; later on we can use something like Modernizr to detect browsers
that don't support this attribute and prop them up with additional
JavaScript, but let's not let that prevent us from getting a good bang
for our attribute buck in the short term.
Note the slightly painful workaround required to get the cursor to
position itself at the end of the input value of the Dojo autosuggest
widget on page load. This is what we get for stepping back into the
world of JavaScript :)
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
[% IF use_autosuggest.enabled == "t"; %]
<script type="text/javascript">
dojo.require("openils.widget.AutoSuggest");
+
+ /* Set focus, and place the cursor at the end of the input string */
+ dojo.addOnLoad(function() {
+ dijit.byId('search_box').focus();
+
+ var sb_value = dijit.byId('search_box').value;
+ /* Dojo won't trigger a change if the value doesn't change */
+ if (sb_value) {
+ dijit.byId('search_box').setValue(sb_value + ' ');
+ dijit.byId('search_box').setValue(sb_value);
+ }
+ });
</script>
[% END; # use_autosuggest %]
store_args='{"org_unit_getter": function() { return [% ctx.search_ou %]; }}'
[%- END # opac_visible -%]
[%- ELSE -%]
- x-webkit-speech
+ autofocus x-webkit-speech
[%- END # autosuggest enabled %] />
</span>
[%- INCLUDE "opac/parts/qtype_selector.tt2" id="qtype";