Author: a.izobov
Date: 2007-06-21 07:38:04 -0400 (Thu, 21 Jun 2007)
New Revision: 1247
Modified:
trunk/richfaces/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
http://jira.jboss.com/jira/browse/RF-55 fixed
Modified:
trunk/richfaces/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
===================================================================
---
trunk/richfaces/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2007-06-20
23:08:10 UTC (rev 1246)
+++
trunk/richfaces/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2007-06-21
11:38:04 UTC (rev 1247)
@@ -100,6 +100,14 @@
this.keyEvent = true;
this.markNext();
this.render();
+ } else if (this.upDown == 3) {
+ this.keyEvent = true;
+ this.markPreviousPage();
+ this.render();
+ } else if (this.upDown == 4) {
+ this.keyEvent = true;
+ this.markNextPage();
+ this.render();
}
},
@@ -246,6 +254,32 @@
= this.onBoxKeyPress.bindAsEventListener(this);
}
return;
+ case 33:
+ this.keyEvent = true;
+ this.markPreviousPage();
+ this.render();
+ if (navigator.appVersion.indexOf('AppleWebKit')
+ > 0) Event.stop(event);
+ if (this.isOpera) {
+ this.upDown = 3;
+ this.prevOnKeyPress = this.element.onkeypress;
+ this.element.onkeypress
+ = this.onBoxKeyPress.bindAsEventListener(this);
+ }
+ return;
+ case 34:
+ this.keyEvent = true;
+ this.markNextPage();
+ this.render();
+ if (navigator.appVersion.indexOf('AppleWebKit')
+ > 0) Event.stop(event);
+ if (this.isOpera) {
+ this.upDown = 4;
+ this.prevOnKeyPress = this.element.onkeypress;
+ this.element.onkeypress
+ = this.onBoxKeyPress.bindAsEventListener(this);
+ }
+ return;
}
} else if (event.keyCode == Event.KEY_TAB
|| event.keyCode == Event.KEY_RETURN
@@ -351,6 +385,41 @@
}
},
+ calcEntryPosition: function(entry, scroll) {
+ var item = entry;
+ var realOffset = 0;
+ while (item && (item != scroll)) {
+ // Avoid bug in Safari. Details:
http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in...
+ if ("SAFARI" == RichFaces.navigatorType() && "TR" ==
item.tagName.toUpperCase()) {
+ realOffset += document.getElementsByClassName("dr-sb-cell-padding",
item)[0].offsetTop;
+ }
+ else
+ realOffset += item.offsetTop;
+ if (item.parentNode == scroll) break;
+ item = item.offsetParent;
+ }
+
+ var entryOffsetHeight;
+ if ("SAFARI" == RichFaces.navigatorType()) {
+ var tdElement = document.getElementsByClassName("dr-sb-cell-padding",
item)[0];
+ entryOffsetHeight = tdElement.offsetTop + tdElement.offsetHeight;
+ } else
+ entryOffsetHeight = entry.offsetHeight;
+ return {realOffset:realOffset, entryOffsetHeight:entryOffsetHeight};
+ },
+
+ countVisibleEntries: function() {
+ var entry = this.getEntry(this.index);
+ var scroll = document.getElementsByClassName("_suggestion_size_",
this.update)[0]
+ || this.update;
+
+ var entryPosition = this.calcEntryPosition(entry,scroll);
+
+ var countAll = Math.round(scroll.clientHeight/entryPosition.entryOffsetHeight);
+ var current =
Math.round((entryPosition.realOffset-scroll.scrollTop)/entryPosition.entryOffsetHeight);
+ return {current:current,all:countAll};
+ },
+
render: function() {
if (this.entryCount > 0) {
LOG.debug('render for index ' + this.index + " and old index
"
@@ -362,39 +431,19 @@
if (this.keyEvent) {
var scroll =
document.getElementsByClassName("_suggestion_size_", this.update)[0]
|| this.update;
- var item = entry;
- var realOffset = 0;
- while (item && (item != scroll)) {
- // Avoid bug in Safari. Details:
http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in...
- if ("SAFARI" == RichFaces.navigatorType() && "TR" ==
item.tagName.toUpperCase()) {
- realOffset += document.getElementsByClassName("dr-sb-cell-padding",
item)[0].offsetTop;
- }
- else
- realOffset += item.offsetTop;
- if (item.parentNode == scroll) break;
- item = item.offsetParent;
- }
- this.keyEvent = false;
- LOG.debug("Scroll = " + scroll.scrollTop
- + " , reallOffset= " + realOffset
- + " scrollHeight= " + scroll.offsetHeight);
+
+ var entryPosition = this.calcEntryPosition(entry,scroll);
- var entryOffsetHeight;
- if ("SAFARI" == RichFaces.navigatorType()) {
- var tdElement = document.getElementsByClassName("dr-sb-cell-padding",
item)[0];
- entryOffsetHeight = tdElement.offsetTop + tdElement.offsetHeight;
- } else
- entryOffsetHeight = entry.offsetHeight;
-
var oldScrollTop = scroll.scrollTop;
- if (realOffset > scroll.scrollTop + scroll.clientHeight -
entryOffsetHeight) {
- scroll.scrollTop = realOffset - scroll.clientHeight +
entryOffsetHeight;
- } else if (realOffset < scroll.scrollTop) {
- scroll.scrollTop = realOffset;
+ if (entryPosition.realOffset > scroll.scrollTop +
scroll.clientHeight - entryPosition.entryOffsetHeight) {
+ scroll.scrollTop = entryPosition.realOffset - scroll.clientHeight +
entryPosition.entryOffsetHeight;
+ } else if (entryPosition.realOffset < scroll.scrollTop) {
+ scroll.scrollTop = entryPosition.realOffset;
}
if (oldScrollTop != scroll.scrollTop) {
this.skipHover = true;
}
+ this.keyEvent = false;
}
// remove hightliit from inactive entry
if (this.prevIndex >= 0) {
@@ -425,6 +474,24 @@
//else this.index = 0;
},
+ markPreviousPage: function() {
+ var pos = this.countVisibleEntries();
+ if (this.index > 0) {
+ if (pos.current>0) this.index = this.index - Math.min(pos.current,pos.all);
+ else this.index = this.index - pos.all;
+ if (this.index < 0) this.index = 0;
+ }
+ },
+
+ markNextPage: function() {
+ var pos = this.countVisibleEntries();
+ if (this.index < this.entryCount - 1) {
+ if ((pos.current < pos.all - 1) && pos.current>=0) this.index =
this.index + (pos.all - pos.current - 1);
+ else this.index = this.index + pos.all;
+ if (this.index > this.entryCount - 1) this.index = this.entryCount - 1;
+ }
+ },
+
getEntry: function(index) {
if (this.options.entryClass) {
return document.getElementsByClassName(this.options.entryClass,
this.update)[index];