From f8091f761cf3705087efc90cc09f74e5f83744bb Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Tue, 22 Feb 2011 15:14:12 +0100 Subject: [PATCH] Menu: Overhauled menubar, again starting with Michael Lang's fork. Added working keyboard navigation, including nested menus. Still need to properly style the menu buttons, e.g. highlight the button of the currently open menu. --- tests/visual/menu/flyoutmenu.js | 22 +++----- tests/visual/menu/menubar.html | 64 ++++++++++------------- tests/visual/menu/menubar.js | 93 +++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 50 deletions(-) create mode 100644 tests/visual/menu/menubar.js diff --git a/tests/visual/menu/flyoutmenu.js b/tests/visual/menu/flyoutmenu.js index 8534c9462..54ee8bb67 100644 --- a/tests/visual/menu/flyoutmenu.js +++ b/tests/visual/menu/flyoutmenu.js @@ -34,14 +34,17 @@ $.widget("ui.flyoutmenu", { }).keydown(function(event) { if (self.element.is(":hidden")) return; - event.stopPropagation(); switch (event.keyCode) { case $.ui.keyCode.LEFT: - self.left(event); + if (self.left(event)) { + event.stopImmediatePropagation(); + } event.preventDefault(); break; case $.ui.keyCode.RIGHT: - self.right(event); + if (self.right(event)) { + event.stopImmediatePropagation(); + } event.preventDefault(); break; case $.ui.keyCode.ESCAPE: @@ -98,22 +101,18 @@ $.widget("ui.flyoutmenu", { at: "right top", of: this.activeItem }); - $(document).one("click", function() { - //clicking outside menu flyouts should close all flyouts - //$(document).find(".ui-menu-flyout").hide(); - }) }, _select: function(event) { event.stopPropagation(); // TODO make _select cancelable? this._trigger( "select", event, { item: this.activeItem } ); - //this.activate(event, this.element.children("li").first()); this.hide(); }, left: function(event) { var newItem = this.activeItem.parents("li").first(); if (newItem.length) { this.activate(event, newItem); + return true; } }, right: function(event) { @@ -121,6 +120,7 @@ $.widget("ui.flyoutmenu", { if (newItem.length) { this._open(newItem.parent()); this.activate(event, newItem); + return true; } }, activate: function(event, item) { @@ -135,12 +135,6 @@ $.widget("ui.flyoutmenu", { show: function() { this.active = this.element; this.element.show(); - if (this.element.hasClass("ui-menu-flyout")) { - $(document).one("click", function() { - //clicking outside menu flyouts should close all flyouts - //$(document).find(".ui-menu-flyout").hide(); - }) - } }, hide: function() { this.activeItem = this.element.children("li").first(); diff --git a/tests/visual/menu/menubar.html b/tests/visual/menu/menubar.html index d1fc58fa7..c49abb2da 100644 --- a/tests/visual/menu/menubar.html +++ b/tests/visual/menu/menubar.html @@ -10,7 +10,11 @@ + + + @@ -66,6 +49,7 @@ File