Author: nbelaevski
Date: 2008-09-16 15:37:07 -0400 (Tue, 16 Sep 2008)
New Revision: 10456
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
https://jira.jboss.org/jira/browse/RF-4339
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
===================================================================
---
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-09-16
16:42:09 UTC (rev 10455)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-09-16
19:37:07 UTC (rev 10456)
@@ -142,7 +142,10 @@
Event.observe(this.element, "keydown", this.onKeyDownListener);
if (this.isOpera) {
- this.onKeyUpListener = this.onKeyUp.bindAsEventListener(this);
+ this.onKeyPressListener = this.onKeyPress.bindAsEventListener(this);
+ Event.observe(this.element, "keypress", this.onKeyPressListener);
+
+ this.onKeyUpListener = this.onKeyUp.bindAsEventListener(this);
Event.observe(this.element, "keyup", this.onKeyUpListener);
this.upDown = 0;
}
@@ -155,26 +158,6 @@
this.onNothingLabelClick = this.hideNLabel.bindAsEventListener(this);
},
- onBoxKeyPress: function(event) {
- if (this.upDown == 1) {
- this.keyEvent = true;
- this.markPrevious();
- this.render();
- } else if (this.upDown == 2) {
- 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();
- }
- },
-
cancelSubmit: function(event) {
Event.stop(event);
},
@@ -203,11 +186,37 @@
}
},
+ onKeyPress: function(event) {
+ if (this.upDown != 0) {
+ if (this.upDownMark) {
+ //Opera produces keydown keypress keypress ... keypress for pressed arrow button
+ //so we should skip the first keypress that follows keydown
+ this.upDownMark = false;
+ } else {
+ if (this.upDown == 1) {
+ this.keyEvent = true;
+ this.markPrevious();
+ this.render();
+ } else if (this.upDown == 2) {
+ 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();
+ }
+ }
+ }
+ },
+
onKeyUp: function(event) {
- if (this.upDown > 0) {
- this.element.onkeypress = this.prevOnKeyPress;
- }
- this.upDown = 0;
+ this.upDownMark = false;
+ this.upDown = 0;
},
show: function() {
@@ -265,6 +274,16 @@
if (this.element) {
Event.stopObserving(this.element, "blur", this.onBlurListener);
Event.stopObserving(this.element, "keydown",
this.onKeyDownListener);
+
+ if (this.onKeyPressListener) {
+ Event.stopObserving(this.element, "keypress",
this.onKeyPressListener);
+ this.onKeyPressListener = undefined;
+ }
+
+ if (this.onKeyUpListener) {
+ Event.stopObserving(this.element, "keyup",
this.onKeyUpListener);
+ this.onKeyUpListener = undefined;
+ }
}
return true;
},
@@ -298,6 +317,9 @@
this.wasBlur = false;
if (this.active) {
this.wasScroll = false;
+
+ var surrogateEvent = (event.rich && event.rich.isCallSuggestion);
+
switch (event.keyCode) {
case Event.KEY_TAB:
case Event.KEY_RETURN:
@@ -320,11 +342,9 @@
this.render();
if (navigator.appVersion.indexOf('AppleWebKit')
0) Event.stop(event);
- if (this.isOpera) {
+ if (this.isOpera && !surrogateEvent) {
this.upDown = 1;
- this.prevOnKeyPress = this.element.onkeypress;
- this.element.onkeypress
- = this.onBoxKeyPress.bindAsEventListener(this);
+ this.upDownMark = true;
}
return;
case Event.KEY_DOWN:
@@ -333,11 +353,9 @@
this.render();
if (navigator.appVersion.indexOf('AppleWebKit')
0) Event.stop(event);
- if (this.isOpera) {
+ if (this.isOpera && !surrogateEvent) {
this.upDown = 2;
- this.prevOnKeyPress = this.element.onkeypress;
- this.element.onkeypress
- = this.onBoxKeyPress.bindAsEventListener(this);
+ this.upDownMark = true;
}
return;
case 33:
@@ -346,11 +364,9 @@
this.render();
if (navigator.appVersion.indexOf('AppleWebKit')
0) Event.stop(event);
- if (this.isOpera) {
+ if (this.isOpera && !surrogateEvent) {
this.upDown = 3;
- this.prevOnKeyPress = this.element.onkeypress;
- this.element.onkeypress
- = this.onBoxKeyPress.bindAsEventListener(this);
+ this.upDownMark = true;
}
return;
case 34:
@@ -359,11 +375,9 @@
this.render();
if (navigator.appVersion.indexOf('AppleWebKit')
0) Event.stop(event);
- if (this.isOpera) {
+ if (this.isOpera && !surrogateEvent) {
this.upDown = 4;
- this.prevOnKeyPress = this.element.onkeypress;
- this.element.onkeypress
- = this.onBoxKeyPress.bindAsEventListener(this);
+ this.upDownMark = true;
}
return;
}
@@ -761,6 +775,7 @@
domEvt.screenY = 0;
domEvt.shiftKey = false;
domEvt.which = 40;
+ //this hash is used in keydown handler - modify with care
domEvt.rich = {"isCallSuggestion":true, "ignoreMinChars":
ignoreMinChars};
this.onKeyDownListener(domEvt);