Prechádzať zdrojové kódy

Remove autofocus from search form, add "s" key shortcut to access it (tab works too)

Jordi Boggiano 10 rokov pred
rodič
commit
0ac50c70e0

+ 7 - 0
src/Packagist/WebBundle/Resources/public/js/search.js

@@ -149,4 +149,11 @@
             }
         }
     });
+
+    // handle pressing S to focus the search
+    $(document.body).bind('keyup', function (event) {
+        if (event.which === 83 && (!document.activeElement || document.activeElement.tagName !== 'INPUT')) {
+            $('#search_query_query').focus();
+        }
+    });
 }(jQuery));

+ 1 - 1
src/Packagist/WebBundle/Resources/views/Web/searchForm.html.twig

@@ -2,7 +2,7 @@
     <div class="{% if orderBys is defined %}sortable{% endif %} row">
         <div class="hidden">{{ form_errors(searchForm.query) }}</div>
         <div class="{% if searchForm.vars.value.query is empty %}col-xs-12{% else %}col-xs-8{% endif %} js-search-field-wrapper col-sm-9">
-            {{ form_widget(searchForm.query, {'attr': {'autocomplete': 'off', 'autofocus': 'autofocus', 'placeholder': 'Search packages...', 'tabindex': 1}}) }}
+            {{ form_widget(searchForm.query, {'attr': {'autocomplete': 'off', 'placeholder': 'Search packages...', 'tabindex': 1}}) }}
         </div>
 
         {% set hasActiveOrderBy = false %}