]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Fix filter matching to work with flyout menu
authorjzaefferer <joern.zaefferer@gmail.com>
Thu, 24 Feb 2011 09:50:08 +0000 (10:50 +0100)
committerjzaefferer <joern.zaefferer@gmail.com>
Thu, 24 Feb 2011 10:14:19 +0000 (11:14 +0100)
tests/visual/menu/flyoutmenu.js
ui/jquery.ui.menu.js

index 6fb522680781ff5be6388c48c6b9571c2db16ccd..1e968dd61963adeb6a767dfaccd2e1d25cd2eff1 100644 (file)
@@ -47,53 +47,16 @@ $.widget("ui.flyoutmenu", {
                        case $.ui.keyCode.RIGHT:
                                if (self.right(event)) {
                                        event.stopImmediatePropagation();
-                               } 
+                               }
                                event.preventDefault();
                                break;
                        case $.ui.keyCode.ESCAPE:
                                self.hide();
                                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.activeItem.parent("ul").children("li").filter(function() {
-                                       // TODO why filter child anchor here, but not in the filter below?
-                                       return new RegExp("^" + escape(character), "i").test($("a", this).text());
-                               });
-                               var match = skip && match.index(self.active.next()) != -1 ? match.next() : match;
-                               if (!match.length) {
-                                       character = String.fromCharCode(event.keyCode);
-                                       // TODO why use self.widget() here instead of self.activeItem??
-                                       match = self.widget().children("li").filter(function() {
-                                               return new RegExp("^" + escape(character), "i").test($(this).text());
-                                       });
-                               }
-                               if (match.length) {
-                                       self.activate(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;
-                               }
                        }
                });
        },
+       
        _open: function(submenu) {
                // TODO restrict to widget
                //only one menu can have items open at a time.
index cc221f943d2e3d60a1b92fe56fc013bde75f83be..d7c0f5c74f558089884c0820894dcb15d474d629 100644 (file)
@@ -88,6 +88,7 @@ $.widget("ui.menu", {
                                event.stopImmediatePropagation();
                                break;
                        default:
+                               event.stopPropagation();
                                clearTimeout(self.filterTimer);
                                var prev = self.previousFilter || "";
                                var character = String.fromCharCode(event.keyCode);
@@ -101,13 +102,13 @@ $.widget("ui.menu", {
                                        return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
                                }
                                var match = self.widget().children(".ui-menu-item").filter(function() {
-                                       return new RegExp("^" + escape(character), "i").test($(this).text());
+                                       return new RegExp("^" + escape(character), "i").test($(this).children("a").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());
+                                               return new RegExp("^" + escape(character), "i").test($(this).children("a").text());
                                        });
                                }
                                if (match.length) {