nitdoc: set timeout on keypress to limit quicksearch overhead
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 13 Feb 2014 03:29:25 +0000 (22:29 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 20 Feb 2014 19:11:59 +0000 (14:11 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

share/nitdoc/js/plugins/quicksearch.js
share/nitdoc/js/plugins/utils.js

index db7d693..32204a4 100644 (file)
@@ -99,7 +99,7 @@ define([
                                        this.closeTable();
                                        break;
                                default: // Other keys
-                                       this.search();
+                                       utils.delayEvent($.proxy(this.search, this));
                                        break;
                        }
                },
index fe9dca1..397ec12 100644 (file)
@@ -69,6 +69,15 @@ define([
                                return url.substring(index + 1);\r
                        }\r
                        return null;\r
+               },\r
+\r
+               delayEvent: function(handler, event) {\r
+                       if(this.delayEvent.timeout) {\r
+                               clearTimeout(this.delayEvent.timeout);\r
+                       }\r
+                       this.delayEvent.timeout = setTimeout(function() {\r
+                           handler.call(event);\r
+                       }, 50);\r
                }\r
        };\r
 });\r