[richfaces-svn-commits] JBoss Rich Faces SVN: r5273 - trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Jan 10 11:14:39 EST 2008


Author: vmolotkov
Date: 2008-01-10 11:14:39 -0500 (Thu, 10 Jan 2008)
New Revision: 5273

Modified:
   trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
Log:
selection functionality was corrected

Modified: trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
===================================================================
--- trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js	2008-01-10 15:17:54 UTC (rev 5272)
+++ trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js	2008-01-10 16:14:39 UTC (rev 5273)
@@ -57,6 +57,9 @@
 		} else {
 			this.comboList.createDefaultList();
 			this.comboList.show();
+			if (this.comboList.selectedItem) {
+				this.comboList.scrollingUpToItem(this.comboList.selectedItem);
+			}
 			this.comboList.isList = false;
 		}
 		this.field.focus();
@@ -66,7 +69,7 @@
 		//changes item's decoration
 		var item = this.comboList.getEventItem(event);
 		if (item) {
-			this.comboList.selectItem(this.comboList.getEventItem(event));			
+			this.comboList.doActiveItem(this.comboList.getEventItem(event));			
 		}
 	},
 	
@@ -94,10 +97,10 @@
 	},
 	
 	setValue : function(toSetOnly) {
-		if (!this.comboList.selectedItem) {
+		if (!this.comboList.activeItem) {
 			return;
 		}
-		var value = this.comboList.selectedItem.innerHTML;
+		var value = this.comboList.activeItem.innerHTML;
 		if (toSetOnly) {
 			var oV = this.field.value; 
 			if (oV == value) {
@@ -106,6 +109,7 @@
 				}
 			}
 			this.field.value = value;
+			this.comboList.doSelectItem(this.comboList.activeItem);
 			this.combobox.fire("rich:onitemselected", {});
 			if (oV != value) {
 				this.combobox.fire("rich:onchange", {});
@@ -131,10 +135,10 @@
 				this.comboList.hide();
 				break;
 			case Event.KEY_DOWN : 
-				this.comboList.moveSelectedItem(event);
+				this.comboList.moveActiveItem(event);
 				break;
 			case Event.KEY_UP :
-				this.comboList.moveSelectedItem(event);
+				this.comboList.moveActiveItem(event);
 				break; 
 			default : 
 				//this.dataUpdating(event);
@@ -146,6 +150,11 @@
 			var value = this.field.value; 
 			if (value.length == 0) {
 				this.applyDefaultText();
+			} else {
+				var item = this.comboList.findItemBySubstr(value);
+				if (item) {
+					this.comboList.doSelectItem(item);
+				}
 			}
 			this.comboList.hide();
 			this.doDisable();
@@ -171,10 +180,10 @@
 				if (!this.comboList.visible()) {
 					this.comboList.show();
 				}
-				var item = this.comboList.findItemByText(this.field.value);
+				var item = this.comboList.findItemBySubstr(this.field.value);
 				if (item) {
-					this.comboList.selectItem(this.comboList.findItemByText(this.field.value));
-					this.comboList.scrollingUpToSdItem();
+					this.comboList.doActiveItem(item);
+					this.comboList.scrollingUpToItem(this.comboList.activeItem);
 				}
 			}
 			
@@ -217,7 +226,9 @@
 		this.defaultRowsAmount = 15; 
 		
 		this.selectedItem = null;
+		this.activeItem = null;
 		
+		
 		this.width = width;
 		this.height = height;
 		this.fieldDimensions = fieldXY;
@@ -253,10 +264,19 @@
 		this.setSize();
 		this.setPosition(this.fieldDimensions.top, this.fieldDimensions.left, this.fieldDimensions.height);
 		
-		var curItems = this.getItems();
+		if (this.selectedItem) {
+			//was created new item list, so necessary to recreate selectedItem
+			this.doSelectItem(this.findItemBySubstr(this.selectedItem.innerHTML));
+		}
+		
 		if (this.selectFirstOnUpdate) {
+			var curItems = this.getItems();
 			if (curItems.length != 0) {
-				this.selectItem(curItems[0]);
+				if (this.selectedItem) {
+					this.doActiveItem(this.selectedItem);
+				} else {
+					this.doActiveItem(curItems[0]);	
+				}
 			}
 		}
 		this.listParent.show();
@@ -339,7 +359,7 @@
 		var increment;
 		var listTop = Richfaces.ComboBoxList.getElemXY(this.listParent).top;
 		var scrollTop = this.listParent.scrollTop;
-		var itemTop = Richfaces.ComboBoxList.getElemXY(this.selectedItem).top;
+		var itemTop = Richfaces.ComboBoxList.getElemXY(this.activeItem).top;
 		
 		if ((event.keyCode == Event.KEY_UP) || (event.keyCode == 33)) {
 			increment = (itemTop - scrollTop) - listTop;
@@ -347,7 +367,7 @@
 				this.listParent.scrollTop += increment;			
 			}
 		} else if ((event.keyCode == Event.KEY_DOWN) || (event.keyCode == 34)) {
-			var itemBottom = itemTop + this.selectedItem.offsetHeight;
+			var itemBottom = itemTop + this.activeItem.offsetHeight;
 			var increment = (itemBottom - scrollTop) - (listTop + this.listParent.clientHeight);
 			if (increment > 0) {
 				this.listParent.scrollTop += increment;			
@@ -356,26 +376,30 @@
 		Event.stop(event);
 	},
 	
-	scrollingUpToSdItem : function() {
-		var increment = (Richfaces.ComboBoxList.getElemXY(this.selectedItem).top - this.listParent.scrollTop) - Richfaces.ComboBoxList.getElemXY(this.listParent).top;
+	scrollingUpToItem : function(item) {
+		var increment = (Richfaces.ComboBoxList.getElemXY(item).top - this.listParent.scrollTop) - Richfaces.ComboBoxList.getElemXY(this.listParent).top;
 		this.listParent.scrollTop += increment;
 	},
 	
 	/* items library*/
-	selectItem : function(item) {
-		if (this.selectedItem) {
-			this.normalizeItem(this.selectedItem);			
+	doActiveItem : function(item) {
+		if (this.activeItem) {
+			this.doNormalItem(this.activeItem);			
 		}
 		
-		this.selectedItem = item;
+		this.activeItem = item;
 		this.changeItem(item, this.classes.ITEM.SELECTED);
 	},
 	
-	normalizeItem : function(item) {
-		this.selectedItem = null;
+	doNormalItem : function(item) {
+		this.activeItem = null;
 		this.changeItem(item, this.classes.ITEM.NORMAL);
 	},
 	
+	doSelectItem : function(item) {
+		this.selectedItem = item;
+	},
+	
 	changeItem : function(item, className) {
 		item.className = className;
 	},
@@ -388,9 +412,9 @@
 		return item;
 	},
 	
-	moveSelectedItem : function(event) {
-		var item = this.selectedItem;
-		if (!this.selectedItem) {
+	moveActiveItem : function(event) {
+		var item = this.activeItem;
+		if (!this.activeItem) {
 			return;
 		}
 		if (event.keyCode == Event.KEY_UP) {
@@ -408,15 +432,15 @@
 	},
 	
 	itemsRearrangement : function(item, newItem) {
-		//this.normalizeItem(item);
-		this.selectItem(newItem);
+		//this.doNormalItem(item);
+		this.doActiveItem(newItem);
 	},
 	
 	resetState : function() {
 		var tempList = this.list.cloneNode(false);
 		this.listParent.replaceChild(tempList, this.listParent.firstChild);
 		this.list = this.listParent.firstChild;
-		this.selectedItem = null;
+		this.activeItem = null;
 		this.isList = false;
 	},
 	
@@ -435,15 +459,24 @@
 		return items;
 	},
 	
-	findItemByText : function(text) {
-		for (var i = 0; i < this.itemsText.length; i++) {
-			var itText = this.itemsText[i];
-			if (itText.substr(0, text.length).toLowerCase() == text.toLowerCase()) { //FIXME: to optimaize
-				return this.list.childNodes[i];
+	findItemBySubstr : function(substr) {
+		var items = this.getItems();
+		for (var i = 0; i < items.length; i++) {
+			var item = items[i]
+			var itText = item.innerHTML;
+			if (itText.substr(0, substr.length).toLowerCase() == substr.toLowerCase()) { //FIXME: to optimaize
+				return item;
 			}
 		}
 	},
 	
+	/*findItemByText : function(text) {
+		var id = this.itemsText.indexOf(text);
+		if (id != -1) {
+			return this.getItems()[this.itemsText.indexOf(text)];
+		}
+	},*/
+	
 	createNewList : function(items) {
 		//FIX for FF
 		this.list.innerHTML = items.join("");




More information about the richfaces-svn-commits mailing list