nitdoc: Preselect first result of quicksearch list and easy close on click
authorAlexandre Terrasa <alexandre@moz-concept.com>
Wed, 25 Apr 2012 23:31:25 +0000 (19:31 -0400)
committerAlexandre Terrasa <alexandre@moz-concept.com>
Thu, 26 Apr 2012 15:35:36 +0000 (11:35 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-concept.com>

share/nitdoc/scripts/js-facilities.js

index d67ef9c..7911cb8 100644 (file)
@@ -187,6 +187,13 @@ $(document).ready(function() {
                                                        currentTable.width($("#search").outerWidth());\r
                                                        $("header").append(currentTable);\r
                                                        currentTable.offset({left: $("#search").offset().left + ($("#search").outerWidth() - currentTable.outerWidth()), top: $("#search").offset().top + $("#search").outerHeight()});\r
+\r
+                                                       // Preselect first entry\r
+                                                       if(currentTable.find("tr").length > 0) {\r
+                                                               currentIndex = 0;\r
+                                                               $(currentTable.find("tr")[currentIndex]).addClass("activeSearchResult");\r
+                                                               $("#search").focus();\r
+                                                       }\r
                                                break;\r
                                        }\r
                                })\r
@@ -208,6 +215,16 @@ $(document).ready(function() {
                        })\r
                )\r
         );\r
+\r
+        // Close quicksearch list on click\r
+        $(document).click(function(e) {\r
+               if(e.target != $("#search")[0] && e.target != $("#searchTable")[0]) {\r
+                       if(currentTable != null) {\r
+                               currentTable.remove();\r
+                               currentTable = null;\r
+                       }\r
+               }\r
+        });\r
        \r
        /*\r
        * Anchors jumps\r