r3396 committed - menu: some actual page up/down scrolling, still in dire need for refac...
Revision: 3396
Author: joern.zaefferer
Date: Mon Oct 26 15:16:57 2009
Log: menu: some actual page up/down scrolling, still in dire need for
refactoring
http://code.google.com/p/jquery-ui/source/detail?r=3396
Modified:
/branches/dev/ui/jquery.ui.menu.js
=======================================
--- /branches/dev/ui/jquery.ui.menu.js Mon Oct 26 14:35:43 2009
+++ /branches/dev/ui/jquery.ui.menu.js Mon Oct 26 15:16:57 2009
@@ -84,26 +84,74 @@
}
},
+ // TODO merge with previousPage
nextPage: function() {
if (this.hasScroll()) {
- // TODO last item on page, then scroll one page down, otherwise select
last item on page
+ // TODO merge with no-scroll-else
+ if (!this.active || this.last()) {
+ 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()) {
- console.log("last");
+ // 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 * 1.5 -
$(this).height() / 2;
+ // TODO improve approximation
+ return close < 10 && close > -10;
+ })
+ if (!result.length)
+ result = this.element.children(":last")
+ this.activate(result);
} else {
- console.log("not last");
+ // 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);
}
} else {
this.activate(this.element.children(!this.active ||
this.last() ? ":first" : ":last"));
}
},
+ // TODO merge with nextPage
previousPage: function() {
if (this.hasScroll()) {
- // TODO first item on page, then scroll one page up, otherwise select
first item on page
+ // TODO merge with no-scroll-else
+ if (!this.active || this.first()) {
+ 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) {
- console.log("first");
+ // 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 / 2 +
$(this).height() / 2;
+ // TODO improve approximation
+ return close < 10 && close > -10;
+ })
+ if (!result.length)
+ result = this.element.children(":first")
+ this.activate(result);
} else {
- console.log("not first");
+ // 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);
}
} else {
this.activate(this.element.children(!this.active ||
this.first() ? ":last" : ":first"));