diff options
-rw-r--r-- | tests/visual/menu/contextmenu.html | 51 | ||||
-rw-r--r-- | tests/visual/menu/drilldown.html | 2 | ||||
-rw-r--r-- | tests/visual/menu/menu.html | 33 | ||||
-rw-r--r-- | tests/visual/menu/nested.html | 2 | ||||
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 2 | ||||
-rw-r--r-- | ui/jquery.ui.menu.js | 33 |
6 files changed, 59 insertions, 64 deletions
diff --git a/tests/visual/menu/contextmenu.html b/tests/visual/menu/contextmenu.html index a6b8c4b8f..d73be5ee4 100644 --- a/tests/visual/menu/contextmenu.html +++ b/tests/visual/menu/contextmenu.html @@ -18,23 +18,24 @@ top: 10 }).appendTo(document.body).themeswitcher(); - var menus = $("#menu1, #menu2").menu({ - selected: function(event, ui) { - $("#log").append("<div>Selected " + ui.item.text() + "</div>"); - } - }).hide(); - - - $("button").click(function(event) { + $("button").each(function() { + $(this).next().menu({ + selected: function(event, ui) { + $(this).hide(); + $("#log").append("<div>Selected " + ui.item.text() + "</div>"); + }, + input: $(this) + }).hide(); + }).click(function(event) { // TODO required to prevent the click handler below from handling this event event.stopPropagation(); - $("#menu" + this.id).menu("deactivate").show().position({ + var menu = $("#menu" + this.id).menu("deactivate").show().position({ my: "left top", at: "right top", of: event.pageX > 0 ? event : this }); $(document).one("click", function() { - menus.hide(); + menu.hide(); }) }).keydown(function(event) { var menu = $("#menu" + this.id).data("menu"); @@ -42,24 +43,8 @@ return; event.stopPropagation(); switch (event.keyCode) { - case $.ui.keyCode.PAGE_UP: - menu.previousPage(); - break; - case $.ui.keyCode.PAGE_DOWN: - menu.nextPage(); - break; - case $.ui.keyCode.UP: - menu.previous(); - break; - case $.ui.keyCode.DOWN: - menu.next(); - event.preventDefault(); - break; - case $.ui.keyCode.ENTER: case $.ui.keyCode.TAB: - menu.select(); menu.widget().hide(); - event.preventDefault(); break; case $.ui.keyCode.ESCAPE: menu.widget().hide(); @@ -111,7 +96,6 @@ <body> <button id="1">Show context menu 1</button> - <ul id="menu1"> <li><a href="#">Amsterdam</a></li> <li><a href="#">Anaheim</a></li> @@ -123,6 +107,12 @@ <li><a href="#">Zurich</a></li> </ul> +<div class="ui-widget" style="margin-top:2em; font-family:Arial"> + Log: + <div id="log" style="height: 400px; width: 300px; overflow: auto;" class="ui-widget-content"></div> +</div> + +<button id="2">Show context menu 2</button> <ul id="menu2"> <li><a href="#">Aberdeen</a></li> <li><a href="#">Ada</a></li> @@ -164,12 +154,5 @@ <li><a href="#">Amesville</a></li> </ul> -<div class="ui-widget" style="margin-top:2em; font-family:Arial"> - Log: - <div id="log" style="height: 400px; width: 300px; overflow: auto;" class="ui-widget-content"></div> -</div> - -<button id="2">Show context menu 2</button> - </body> </html> diff --git a/tests/visual/menu/drilldown.html b/tests/visual/menu/drilldown.html index 8a6fd6b80..e9572db6c 100644 --- a/tests/visual/menu/drilldown.html +++ b/tests/visual/menu/drilldown.html @@ -28,6 +28,8 @@ this.element.find("ul").hide().prev("a").prepend('<span class="ui-icon ui-icon-carat-1-e"></span>').end().filter(":first").show(); this.element.find("ul").menu({ + // disable built-in key handling + input: $(), focus: function(event, ui) { self.activeItem = ui.item; }, diff --git a/tests/visual/menu/menu.html b/tests/visual/menu/menu.html index efae8b1ae..0f3dadae0 100644 --- a/tests/visual/menu/menu.html +++ b/tests/visual/menu/menu.html @@ -17,37 +17,10 @@ top: 10 }).appendTo(document.body).themeswitcher(); - var menus = $("#menu1, #menu2").menu({ + $("#menu1, #menu2").menu({ selected: function(event, ui) { $("<div/>").text("Selected: " + ui.item.text()).appendTo("#log"); } - }).keydown(function(event) { - var menu = $(this).data("menu"); - if (menu.widget().is(":hidden")) - return; - event.stopPropagation(); - switch (event.keyCode) { - case $.ui.keyCode.PAGE_UP: - menu.previousPage(); - event.preventDefault(); - break; - case $.ui.keyCode.PAGE_DOWN: - menu.nextPage(); - event.preventDefault(); - break; - case $.ui.keyCode.UP: - menu.previous(); - event.preventDefault(); - break; - case $.ui.keyCode.DOWN: - menu.next(); - event.preventDefault(); - break; - case $.ui.keyCode.ENTER: - menu.select(); - event.preventDefault(); - break; - } }); }); @@ -60,7 +33,7 @@ </head> <body> -<ul id="menu1" tabindex="0"> +<ul id="menu1"> <li><a href="#">Aberdeen</a></li> <li><a href="#">Ada</a></li> <li><a href="#">Adamsville</a></li> @@ -68,7 +41,7 @@ <li><a href="#">Adelphi</a></li> </ul> -<ul id="menu2" tabindex="0"> +<ul id="menu2"> <li><a href="#">Aberdeen</a></li> <li><a href="#">Ada</a></li> <li><a href="#">Adamsville</a></li> diff --git a/tests/visual/menu/nested.html b/tests/visual/menu/nested.html index 6e0f5fbff..1d840f8c9 100644 --- a/tests/visual/menu/nested.html +++ b/tests/visual/menu/nested.html @@ -28,6 +28,8 @@ this.element.find("ul").hide().prev("a").prepend('<span class="ui-icon ui-icon-carat-1-e"></span>'); this.element.find("ul").andSelf().menu({ + // disable built-in key handling + input: $(), selected: this.options.selected, focus: function(event, ui) { self.active = ui.item.parent(); diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 62e99cff3..b4176c038 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -104,6 +104,8 @@ $.widget( "ui.autocomplete", { .addClass( "ui-autocomplete" ) .appendTo( "body", doc ) .menu({ + // custom key handling for now + input: $(), focus: function( event, ui ) { var item = ui.item.data( "item.autocomplete" ); if ( false !== self._trigger( "focus", null, { item: item } ) ) { diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 3ea98677e..b8e1fd410 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -31,6 +31,39 @@ $.widget("ui.menu", { self.select( event ); }); this.refresh(); + + if (!this.options.input) { + this.options.input = this.element.attr("tabindex", 0); + } + this.options.input.bind("keydown.menu", function(event) { + switch (event.keyCode) { + case $.ui.keyCode.PAGE_UP: + self.previousPage(); + event.preventDefault(); + event.stopImmediatePropagation(); + break; + case $.ui.keyCode.PAGE_DOWN: + self.nextPage(); + event.preventDefault(); + event.stopImmediatePropagation(); + break; + case $.ui.keyCode.UP: + self.previous(); + event.preventDefault(); + event.stopImmediatePropagation(); + break; + case $.ui.keyCode.DOWN: + self.next(); + event.preventDefault(); + event.stopImmediatePropagation(); + break; + case $.ui.keyCode.ENTER: + self.select(); + event.preventDefault(); + event.stopImmediatePropagation(); + break; + } + }); }, destroy: function() { |