瀏覽代碼

[mod] the search text input gets the focus automatically

dalf 11 年之前
父節點
當前提交
4e8b75a0fb
共有 2 個檔案被更改,包括 28 行新增0 行删除
  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 @@
1
+(function (w, d) {
2
+    'use strict';
3
+    function addListener(el, type, fn) {
4
+        if (el.addEventListener) {
5
+            el.addEventListener(type, fn, false);
6
+        } else {
7
+            el.attachEvent('on' + type, fn);
8
+        }
9
+    }
10
+
11
+    function placeCursorAtEnd() {
12
+        if (this.setSelectionRange) {
13
+            var len = this.value.length * 2;
14
+            this.setSelectionRange(len, len);
15
+        }
16
+    }
17
+
18
+    addListener(w, 'load', function () {
19
+        var qinput = d.getElementById('q');
20
+        if (qinput !== null) {
21
+            addListener(qinput, 'focus', placeCursorAtEnd);
22
+            qinput.focus();
23
+        }
24
+    });
25
+
26
+})(window, document);
27
+

+ 1
- 0
searx/templates/base.html 查看文件

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