Skip to content

@jzaefferer /gist:251893
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Index: tests/visual/menu/default.html
===================================================================
--- tests/visual/menu/default.html (revision 3488)
+++ tests/visual/menu/default.html (working copy)
@@ -21,33 +21,6 @@
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>
Index: tests/visual/menu/contextmenu.html
===================================================================
--- tests/visual/menu/contextmenu.html (revision 3487)
+++ tests/visual/menu/contextmenu.html (working copy)
@@ -21,6 +21,10 @@
var menus = $("#menu1, #menu2").menu({
selected: function(event, ui) {
$("#log").append("<div>Selected " + ui.item.text() + "</div>");
+ $(this).hide();
+ },
+ keyHandler: function(element) {
+ return element.prev();
}
}).hide();
@@ -42,23 +46,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:
@@ -74,7 +63,6 @@
} else {
character = prev + character;
}
-
var match = menu.widget().children("li").filter(function() {
return new RegExp("^" + character, "i").test($(this).text());
});
@@ -105,13 +93,12 @@
<style>
body { font-size:62.5%; }
.ui-menu { width: 200px; position: absolute; }
- #menu2 { height: 200px; }
+ #menu2 { height: 200px; overflow: auto; }
</style>
</head>
<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 +110,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 +157,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>
Index: ui/jquery.ui.autocomplete.js
===================================================================
--- ui/jquery.ui.autocomplete.js (revision 3487)
+++ ui/jquery.ui.autocomplete.js (working copy)
@@ -28,6 +28,7 @@
.bind("keydown.autocomplete", function(event) {
var keyCode = $.ui.keyCode;
switch(event.keyCode) {
+ /*
case keyCode.PAGE_UP:
self.move("previousPage");
break;
@@ -43,6 +44,7 @@
event.preventDefault();
break;
case keyCode.ENTER:
+ */
case keyCode.TAB:
if (!self.menu || !self.menu.active) {
return;
@@ -195,7 +197,8 @@
self.previous = data.result;
// TODO only trigger when focus was lost?
self.element.focus();
- }
+ },
+ keyHandler: this.element
})
.removeClass("ui-corner-all").addClass("ui-corner-bottom")
.position({
Index: ui/jquery.ui.menu.js
===================================================================
--- ui/jquery.ui.menu.js (revision 3487)
+++ ui/jquery.ui.menu.js (working copy)
@@ -37,6 +37,34 @@
.mouseenter(function() {
self.activate($(this).parent());
});
+
+ var keyHandler = $.isFunction(this.options.keyHandler) ? this.options.keyHandler(this.element) : this.options.keyHandler;
+ if (!keyHandler) {
+ keyHandler = this.element;
+ this.element.attr("tabindex", 0)
+ }
+ $(keyHandler).keydown(function(event) {
+ var menu = self
+ if (menu.widget().is(":hidden"))
+ return;
+ switch (event.keyCode) {
+ case $.ui.keyCode.PAGE_UP:
+ menu.previousPage();
+ return false;
+ case $.ui.keyCode.PAGE_DOWN:
+ menu.nextPage();
+ return false;
+ case $.ui.keyCode.UP:
+ menu.previous();
+ return false;
+ case $.ui.keyCode.DOWN:
+ menu.next();
+ return false;
+ case $.ui.keyCode.ENTER:
+ menu.select();
+ return false;
+ }
+ });
},
activate: function(item) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.