From f21dc4404ca27a7d0a80a74e72876d67327707e8 Mon Sep 17 00:00:00 2001 From: Rolux Date: Fri, 5 Feb 2010 20:56:23 +0530 Subject: [PATCH] scroll menu on keyboard navigation --- build/js/ox.ui.js | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index 7b93612..9afc849 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -1934,7 +1934,8 @@ requires } function selectNextItem() { - var selected = self.options.selected; + var offset, + selected = self.options.selected; if (!isLastEnabledItem()) { if (selected > -1) { that.items[selected].trigger("mouseleave"); @@ -1943,11 +1944,29 @@ requires selected++; } while (that.items[selected].options("disabled")) that.items[selected].trigger("mouseenter"); + offset = that.items[selected].offset().top + itemHeight - + that.$container.offset().top - that.$container.height(); + if (offset > 0) { + if (that.$scrollbars.up.is(":hidden")) { + that.$scrollbars.up.show(); + that.$container.height(that.$container.height() - itemHeight); + offset += itemHeight; + } + if (selected == that.items.length - 1) { + that.$scrollbars.down.hide(); + that.$container.height(that.$container.height() + itemHeight); + } else { + that.$content.css({ + top: ((parseInt(that.$content.css("top")) || 0) - offset) + "px" + }); + } + } } } function selectPreviousItem() { - var selected = self.options.selected; + var offset, + selected = self.options.selected; if (!isFirstEnabledItem()) { that.items[selected].trigger("mouseleave"); do { @@ -1955,6 +1974,21 @@ requires } while (that.items[selected].options("disabled")) that.items[selected].trigger("mouseenter"); } + offset = that.items[selected].offset().top - that.$container.offset().top; + Ox.print(offset); + if (offset < 0) { + if (that.$scrollbars.down.is(":hidden")) { + that.$scrollbars.down.show(); + that.$container.height(that.$container.height() - itemHeight); + } + if (selected == 0) { + that.$scrollbars.up.hide(); + that.$container.height(that.$container.height() + itemHeight); + } + that.$content.css({ + top: ((parseInt(that.$content.css("top")) || 0) - offset) + "px" + }); + } } function selectSubmenu() { @@ -1996,7 +2030,6 @@ requires return false; } }); - // fixme: scroll menu back up! if (that.$scrollbars.up.is(":visible")) { that.$content.css({ top: "0px"