aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorjzaefferer <joern.zaefferer@gmail.com>2011-02-24 10:40:12 +0100
committerjzaefferer <joern.zaefferer@gmail.com>2011-02-24 11:14:19 +0100
commit5d3f91bcbef40832e6eb45a6b4f519353fbe2529 (patch)
tree3ad0fa08c86bcdc538bd1fac7fdb00f48712c6c0 /ui
parent50958718c22aab5a4f5061c313531259761648c5 (diff)
downloadjquery-ui-5d3f91bcbef40832e6eb45a6b4f519353fbe2529.tar.gz
jquery-ui-5d3f91bcbef40832e6eb45a6b4f519353fbe2529.zip
Menu: Move item matching code into menu
Diffstat (limited to 'ui')
-rw-r--r--ui/jquery.ui.menu.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js
index 346d1a982..cc221f943 100644
--- a/ui/jquery.ui.menu.js
+++ b/ui/jquery.ui.menu.js
@@ -87,6 +87,42 @@ $.widget("ui.menu", {
event.preventDefault();
event.stopImmediatePropagation();
break;
+ default:
+ clearTimeout(self.filterTimer);
+ var prev = self.previousFilter || "";
+ var character = String.fromCharCode(event.keyCode);
+ var skip = false;
+ if (character == prev) {
+ skip = true;
+ } else {
+ character = prev + character;
+ }
+ function escape(value) {
+ return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+ }
+ var match = self.widget().children(".ui-menu-item").filter(function() {
+ return new RegExp("^" + escape(character), "i").test($(this).text());
+ });
+ var match = skip && match.index(self.active.next()) != -1 ? self.active.nextAll(".ui-menu-item") : match;
+ if (!match.length) {
+ character = String.fromCharCode(event.keyCode);
+ match = self.widget().children(".ui-menu-item").filter(function() {
+ return new RegExp("^" + escape(character), "i").test($(this).text());
+ });
+ }
+ if (match.length) {
+ self.focus(event, match);
+ if (match.length > 1) {
+ self.previousFilter = character;
+ self.filterTimer = setTimeout(function() {
+ delete self.previousFilter;
+ }, 1000);
+ } else {
+ delete self.previousFilter;
+ }
+ } else {
+ delete self.previousFilter;
+ }
}
});
},