Browse Source

[mod] the search text input gets the focus automatically

dalf 11 years ago
parent
commit
4e8b75a0fb
2 changed files with 28 additions and 0 deletions
  1. 27 0
      searx/static/js/searx.js
  2. 1 0
      searx/templates/base.html

+ 27 - 0
searx/static/js/searx.js

@@ -0,0 +1,27 @@
+(function (w, d) {
+    'use strict';
+    function addListener(el, type, fn) {
+        if (el.addEventListener) {
+            el.addEventListener(type, fn, false);
+        } else {
+            el.attachEvent('on' + type, fn);
+        }
+    }
+
+    function placeCursorAtEnd() {
+        if (this.setSelectionRange) {
+            var len = this.value.length * 2;
+            this.setSelectionRange(len, len);
+        }
+    }
+
+    addListener(w, 'load', function () {
+        var qinput = d.getElementById('q');
+        if (qinput !== null) {
+            addListener(qinput, 'focus', placeCursorAtEnd);
+            qinput.focus();
+        }
+    });
+
+})(window, document);
+

+ 1 - 0
searx/templates/base.html

@@ -18,6 +18,7 @@
 <div id="container">
 <div id="container">
 {% block content %}
 {% block content %}
 {% endblock %}
 {% endblock %}
+<script src="/static/js/searx.js" ></script>
 </div>
 </div>
 </body>
 </body>
 </html>
 </html>