r3402 committed - menu: only activate a single item; simplified paging code, always scro...
Revision: 3402
Author: joern.zaefferer
Date: Mon Nov 2 11:56:26 2009
Log: menu: only activate a single item; simplified paging code, always
scroll a full page
http://code.google.com/p/jquery-ui/source/detail?r=3402
Modified:
/branches/dev/ui/jquery.ui.menu.js
=======================================
--- /branches/dev/ui/jquery.ui.menu.js Sun Nov 1 03:07:21 2009
+++ /branches/dev/ui/jquery.ui.menu.js Mon Nov 2 11:56:26 2009
@@ -34,7 +34,7 @@
activate: function(item) {
this.deactivate();
- this.active =
item.children("a").addClass("ui-state-hover").attr("id", "ui-active-menuitem").end();
+ this.active =
item.eq(0).children("a").addClass("ui-state-hover").attr("id", "ui-active-menuitem").end();
this._trigger("focus", null, { item: item });
if (this.hasScroll()) {
var offset = item.offset().top - this.element.offset().top,
@@ -92,31 +92,17 @@
this.activate(this.element.children(":first"));
return;
}
- // last item on page, then scroll one page down, otherwise select last
item on page
- if (this.active && this.active.offset().top - this.element.offset().top
+ this.active.height() > this.element.height()) {
- // last
- var offsetBase = this.element.offset().top,
- height = this.element.height();
- var result = this.element.children("li").filter(function() {
- var close = $(this).offset().top - offsetBase - height * 2 +
$(this).height() * 2;
- // TODO improve approximation
- return close < 10 && close > -10;
- })
- // TODO try to catch this earlier when scrollTop indicates the last
page anyway
- if (!result.length)
- result = this.element.children(":last")
- this.activate(result);
- } else {
- // not last
- var offsetBase = this.element.offset().top,
- height = this.element.height();
- var result = this.element.children("li").filter(function() {
- var close = $(this).offset().top - offsetBase + $(this).height() -
height;
- // TODO improve approximation
- return close < 10 && close > -10;
- })
- this.activate(result);
- }
+ var base = this.active.offset().top,
+ height = this.element.height();
+ var result = this.element.children("li").filter(function() {
+ var close = $(this).offset().top - base - height + $(this).height();
+ // TODO improve approximation
+ return close < 10 && close > -10;
+ });
+ // TODO try to catch this earlier when scrollTop indicates the last
page anyway
+ if (!result.length)
+ result = this.element.children(":last")
+ this.activate(result);
} else {
this.activate(this.element.children(!this.active ||
this.last() ? ":first" : ":last"));
}
@@ -130,31 +116,18 @@
this.activate(this.element.children(":last"));
return;
}
- // first item on page, then scroll one page up, otherwise select first
item on page
- if (this.active && this.active.offset().top - this.element.offset().top
<= 1) {
- // first
- var offsetBase = this.element.offset().top,
- height = this.element.height();
- var result = this.element.children("li").filter(function() {
- var close = $(this).offset().top - offsetBase + height -
$(this).height();
- // TODO improve approximation
- return close < 10 && close > -10;
- })
- // TODO try to catch this earlier when scrollTop indicates the first
page anyway
- if (!result.length)
- result = this.element.children(":first")
- this.activate(result);
- } else {
- // not first
- var offsetBase = this.element.offset().top,
- height = this.element.height();
- var result = this.element.children("li").filter(function() {
- var close = $(this).offset().top - offsetBase;
- // TODO improve approximation
- return close < 10 && close > -10;
- })
- this.activate(result);
- }
+
+ var base = this.active.offset().top,
+ height = this.element.height();
+ var result = this.element.children("li").filter(function() {
+ var close = $(this).offset().top - base + height - $(this).height();
+ // TODO improve approximation
+ return close < 10 && close > -10;
+ });
+ // TODO try to catch this earlier when scrollTop indicates the last
page anyway
+ if (!result.length)
+ result = this.element.children(":first")
+ this.activate(result);
} else {
this.activate(this.element.children(!this.active ||
this.first() ? ":last" : ":first"));
}