]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Move item matching code into menu
authorjzaefferer <joern.zaefferer@gmail.com>
Thu, 24 Feb 2011 09:40:12 +0000 (10:40 +0100)
committerjzaefferer <joern.zaefferer@gmail.com>
Thu, 24 Feb 2011 10:14:19 +0000 (11:14 +0100)
tests/visual/menu/contextmenu.html
tests/visual/menu/menu.html
ui/jquery.ui.menu.js

index 03e21fdc3ad51ed56fc098eecf0b6f1af65d2479..dae366158f47777a8f75405bb5cd6f73bbaa8ed0 100644 (file)
                                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;
-                               }
                        }
                });
        });
index ec31a0f960190183f2fa784e4c451db5291542fd..395a06bdfd630ce6f89887831774ccb5263315bb 100644 (file)
@@ -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">
index 346d1a98210d48807ed60bee9cc2d3b0a4293543..cc221f943d2e3d60a1b92fe56fc013bde75f83be 100644 (file)
@@ -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;
+                               }
                        }
                });
        },