Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Improved scrolling on Autocompleter when necessary #34

Open
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+16 −3
Split
View
@@ -211,13 +211,13 @@ Autocompleter.Base = Class.create({
markPrevious: function() {
if(this.index > 0) this.index--;
else this.index = this.entryCount-1;
- this.getEntry(this.index).scrollIntoView(true);
+ this.getEntry(this.index).scrollIntoViewIfNecessary(true);
},
markNext: function() {
if(this.index < this.entryCount-1) this.index++;
else this.index = 0;
- this.getEntry(this.index).scrollIntoView(false);
+ this.getEntry(this.index).scrollIntoViewIfNecessary(false);
},
getEntry: function(index) {
@@ -960,4 +960,17 @@ Form.Element.DelayedObserver = Class.create({
this.timer = null;
this.callback(this.element, $F(this.element));
}
-});
+});
+
+Element.addMethods({
+ scrollIntoViewIfNecessary: function(element, showAtTop) {
+ element = $(element);
+ var parent = element.getOffsetParent(), y = element.offsetTop;
+ if (parent.scrollTop > element.offsetTop || parent.scrollTop < (element.offsetTop - parent.offsetHeight + element.offsetHeight)) {
+ parent.scrollTop = (showAtTop || typeof(showAtTop) == 'undefined')
+ ? element.offsetTop
+ : element.offsetTop - parent.offsetHeight + element.offsetHeight;
+ }
+ return element;
+ }
+});