Author: pyaschenko
Date: 2008-09-12 08:51:43 -0400 (Fri, 12 Sep 2008)
New Revision: 10434
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
https://jira.jboss.org/jira/browse/RF-4339
part 3
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-12
12:48:26 UTC (rev 10433)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-09-12
12:51:43 UTC (rev 10434)
@@ -2,31 +2,38 @@
if (!Richfaces.Selection) Richfaces.Selection = {};
Richfaces.Selection.getStart = function(element)
{
- if (element.createTextRange) {
+ if (element.setSelectionRange) {
+ return element.selectionStart;
+ } else if (document.selection && document.selection.createRange) {
var r = document.selection.createRange().duplicate();
r.moveEnd('character', element.value.length);
if (r.text == '') return element.value.length;
return element.value.lastIndexOf(r.text);
- } else return element.selectionStart;
+ }
}
Richfaces.Selection.getEnd = function(element)
{
- if (element.createTextRange) {
+ if (element.setSelectionRange) {
+ return element.selectionEnd;
+ } else if (document.selection && document.selection.createRange) {
var r = document.selection.createRange().duplicate();
r.moveStart('character', -element.value.length);
return r.text.length;
- } else return element.selectionEnd;
+ }
}
-Richfaces.Selection.setCaretTo = function (element, pos) {
- if(element.createTextRange) {
- var range = element.createTextRange();
- range.move("character", pos);
- range.select();
- } else if(element.selectionStart) {
- element.focus();
- element.setSelectionRange(pos, pos);
- }
+Richfaces.Selection.setCaretTo = function (element, pos)
+{
+ if(element.setSelectionRange) {
+ element.focus();
+ element.setSelectionRange(pos,pos);
+ } else if (element.createTextRange){
+ var range = element.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character', pos);
+ range.moveStart('character', pos);
+ range.select();
+ }
}
var Suggestion = {};
@@ -858,6 +865,10 @@
if (whitespace) endStr = whitespace[0] + endStr;
this.element.value = startStr + value + endStr;
Richfaces.Selection.setCaretTo(this.element, (startStr + value).length);
+ //alert(Richfaces.Selection.getEnd(this.element));
+ // partial fix for new bag with keyDown insertion
+ // TODO: create & fix bug
+ this.endPosition = this.startPosition + value.length;
if (this.options.usingSuggestObjects)
{