]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - js/search.js
improvements related to page search
[Rakka.git] / js / search.js
index c1a90f84aa493a6c4691091bc3ca8ea293012616..3367804c97d0dd51facad3753446f8be13549b5d 100644 (file)
@@ -1,23 +1,34 @@
 (function () {
 
     $(document).ready(function () {
-        $("input.searchField")
-            .val("Search")
-            .removeClass("activeField")
-            .addClass("inactiveField")
-            .focus(function () {
-                if ($(this).attr("class").indexOf("inactiveField")) {
-                    $(this)
-                        .val("")
-                        .removeClass("inactiveField")
-                        .addClass("activeField");
-                }
-            })
-            .keypress(function (e) {
+        var $fld = $("input.searchField")
+
+        $fld.keypress(function (e) {
                 if (e.which == 10 || e.which == 13) {
                     window.location = Rakka.baseURI + "search.html?q=" + encodeURI($(this).val());
                 }
             });
+
+        /* 檢索 query が指定されてゐれば、それが最初から入力されてゐる
+         * 状態にする。
+         */
+        var form = Rakka.getQueryForm();
+        if (form["q"] == null) {
+            $fld.val("Search")
+                .removeClass("activeField")
+                .addClass("inactiveField")
+                .focus(function () {
+                    if ($(this).attr("class").indexOf("inactiveField")) {
+                        $(this)
+                            .val("")
+                            .removeClass("inactiveField")
+                            .addClass("activeField");
+                    }
+                });
+        }
+        else {
+            $fld.val(form["q"]);
+        }
     });
 
 })();
\ No newline at end of file