TPAC: Set autofocus appropriately for different contexts
authorDan Scott <dscott@laurentian.ca>
Thu, 12 Jul 2012 23:12:06 +0000 (19:12 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 23 Jul 2012 15:20:28 +0000 (11:20 -0400)
At login, the basic search bar was fighting (and winning) for the
default focus rather than the username field. Additionally, in the
advanced search pages, no field was getting focus. Therefore, check to
see if we expect to be in a context where it makes sense to set the
default focus to the basic search input field; otherwise, set the focus
to the login username field or the appropriate advanced search field.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>

Open-ILS/src/templates/opac/login.tt2
Open-ILS/src/templates/opac/parts/advanced/expert.tt2
Open-ILS/src/templates/opac/parts/advanced/global_row.tt2
Open-ILS/src/templates/opac/parts/advanced/numeric.tt2
Open-ILS/src/templates/opac/parts/js.tt2
Open-ILS/src/templates/opac/parts/login/form.tt2
Open-ILS/src/templates/opac/parts/searchbar.tt2
Open-ILS/src/templates/opac/record.tt2

index 29994ad..f6892bb 100644 (file)
@@ -1,6 +1,7 @@
 [%  PROCESS "opac/parts/header.tt2";
     WRAPPER "opac/parts/base.tt2";
     INCLUDE "opac/parts/topnav.tt2";
+    basic_search = "f";
     ctx.page_title = l("Account Login") %]
     <div id="search-wrapper">
         [% INCLUDE "opac/parts/searchbar.tt2" %]
@@ -9,18 +10,6 @@
         <div id="main-content">
             [% INCLUDE "opac/parts/login/form.tt2" %]
             <div class="clear-both very-big-height"></div>     
-            <script type="text/javascript">
-                /* Note: when common browsers support HTML5 "autofocus", we can remove this */
-                var _onload = window.onload;
-                window.onload = function() {
-                    try {
-                        document.getElementById("username_field").focus();
-                        if (_onload) _onload();
-                    } catch (E) {
-                        void(0);
-                    }
-                };
-            </script>
         </div>
     </div>
 [% END %]
index da8bba6..7d1ffa1 100644 (file)
@@ -6,7 +6,7 @@
         <tbody id="adv_expert_rows_here">
             <tr id="adv_expert_row">
                 <th>[% l("Tag:") %]</th>
-                <td><input type="text" name="tag" size="3" /></td>
+                <td><input type="text" name="tag" size="3" autofocus /></td>
                 <th>[% l("Subfield:") %]</th>
                 <td><input type="text" name="subfield" size="1" /></td>
                 <th>[% l("Value:") %]</th>
index 02aa5d1..5171c35 100644 (file)
@@ -42,7 +42,7 @@
             <option value="[% o.value %]" [% c == o.value ? ' selected="selected"' : '' %]>[% o.label %]</option>
             [% END %]
         </select>
-        <input type='text' size='18' name='query' value="[% q | html %]" x-webkit-speech />
+        <input type='text' size='18' name='query' value="[% q | html %]" x-webkit-speech [% IF loop.index == 0 %] autofocus [% END %] />
         <a href="javascript:;" class="row-remover"
             title="[% l('Remove row') %]" alt="[% l('Remove row') %]"
             onclick='return killRowIfAtLeast(2, this);'><img src="[% ctx.media_prefix %]/images/adv_row_close_btn.png" /></a>
index 7262801..32bf56e 100644 (file)
@@ -18,7 +18,7 @@
                 </select>
             </td>
             <td>
-                <input type="text" name="query" size="16" />
+                <input type="text" name="query" size="16" autofocus />
             </td>
         </tr>
         <tr>
index 7029554..e4aabb3 100644 (file)
@@ -59,7 +59,7 @@
 <script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/opensrf/opensrf_xhr.js?[% ctx.eg_cache_hash %]"></script>
 <script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/opensrf/JSON_v1.js?[% ctx.eg_cache_hash %]"></script>
 
-[% IF use_autosuggest.enabled == "t"; %]
+[% IF use_autosuggest.enabled == "t" AND basic_search != "f"; %]
 <script type="text/javascript">
     dojo.require("openils.widget.AutoSuggest");
 
index 48f2f67..e4200bd 100644 (file)
@@ -95,7 +95,7 @@
                             </td>
                             <td width="58%" valign="top">
                                 <div class="input_bg">
-                                    <input type="text" id="username_field" name="username"/>
+                                    <input type="text" id="username_field" name="username" autofocus />
                                 </div>
                             </td>
                         </tr>
index f4ee110..d20d36b 100644 (file)
@@ -24,7 +24,7 @@
                 store_args='{"org_unit_getter": function() { return [% ctx.search_ou %]; }}'
                 [%-     END # opac_visible -%]
                 [%- ELSE -%]
-                autofocus x-webkit-speech
+                    [% IF basic_search != "f" %] autofocus [% END %] x-webkit-speech
                 [%- END # autosuggest enabled %] />
         </span>
         [%- INCLUDE "opac/parts/qtype_selector.tt2" id="qtype";
index 9503cb8..374cca4 100644 (file)
@@ -1,7 +1,9 @@
 [%  PROCESS "opac/parts/header.tt2";
     WRAPPER "opac/parts/base.tt2";
     INCLUDE "opac/parts/topnav.tt2";
-    ctx.page_title = l("Record Detail") %]
+    ctx.page_title = l("Record Detail");
+    IF CGI.param("expand"); basic_search = "f"; END;    
+-%]
     <div id="search-wrapper">
         [% INCLUDE "opac/parts/searchbar.tt2" %]
     </div>