diff options
author | jzaefferer <joern.zaefferer@gmail.com> | 2011-02-24 10:40:12 +0100 |
---|---|---|
committer | jzaefferer <joern.zaefferer@gmail.com> | 2011-02-24 11:14:19 +0100 |
commit | 5d3f91bcbef40832e6eb45a6b4f519353fbe2529 (patch) | |
tree | 3ad0fa08c86bcdc538bd1fac7fdb00f48712c6c0 | |
parent | 50958718c22aab5a4f5061c313531259761648c5 (diff) | |
download | jquery-ui-5d3f91bcbef40832e6eb45a6b4f519353fbe2529.tar.gz jquery-ui-5d3f91bcbef40832e6eb45a6b4f519353fbe2529.zip |
Menu: Move item matching code into menu
-rw-r--r-- | tests/visual/menu/contextmenu.html | 32 | ||||
-rw-r--r-- | tests/visual/menu/menu.html | 4 | ||||
-rw-r--r-- | ui/jquery.ui.menu.js | 36 |
3 files changed, 39 insertions, 33 deletions
diff --git a/tests/visual/menu/contextmenu.html b/tests/visual/menu/contextmenu.html index 03e21fdc3..dae366158 100644 --- a/tests/visual/menu/contextmenu.html +++ b/tests/visual/menu/contextmenu.html @@ -51,39 +51,7 @@ menu.widget().hide(); break; default: - clearTimeout(menu.filterTimer); - var prev = menu.previousFilter || ""; - var character = String.fromCharCode(event.keyCode); - var skip = false; - if (character == prev) { - skip = true; - } else { - character = prev + character; - } - var match = menu.widget().children("li").filter(function() { - return new RegExp("^" + character, "i").test($(this).text()); - }); - var match = skip && match.index(menu.active.next()) != -1 ? match.next() : match; - if (!match.length) { - character = String.fromCharCode(event.keyCode); - match = menu.widget().children("li").filter(function() { - return new RegExp("^" + character, "i").test($(this).text()); - }); - } - if (match.length) { - menu.focus(event, match); - if (match.length > 1) { - menu.previousFilter = character; - menu.filterTimer = setTimeout(function() { - delete menu.previousFilter; - }, 1000); - } else { - delete menu.previousFilter; - } - } else { - delete menu.previousFilter; - } } }); }); diff --git a/tests/visual/menu/menu.html b/tests/visual/menu/menu.html index ec31a0f96..395a06bdf 100644 --- a/tests/visual/menu/menu.html +++ b/tests/visual/menu/menu.html @@ -50,7 +50,9 @@ <li><a href="#">Ada</a></li> <li><a href="#">Adamsville</a></li> <li><a href="#">Addyston</a></li> - <li><a href="#">Adelphi</a></li> + <li><a href="#">Delphi</a></li> + <li><a href="#">Saarland</a></li> + <li><a href="#">Salzburg</a></li> </ul> <ul id="menu2"> 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; + } } }); }, |