[richfaces-svn-commits] JBoss Rich Faces SVN: r468 - trunk/richfaces/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Apr 20 10:24:35 EDT 2007


Author: A.Skokov
Date: 2007-04-20 10:24:34 -0400 (Fri, 20 Apr 2007)
New Revision: 468

Modified:
   trunk/richfaces/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
http://jira.jboss.com/jira/browse/RF-58 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-04-20 12:46:59 UTC (rev 467)
+++ trunk/richfaces/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js	2007-04-20 14:24:34 UTC (rev 468)
@@ -4,7 +4,7 @@
 };
 Suggestion.Base.prototype = {
     baseInitialize: function(element, update, options) {
-    	this.isOpera = (RichFaces.navigatorType() =="OPERA"?true:false);
+        this.isOpera = (RichFaces.navigatorType() == "OPERA"?true:false);
         this.element = $(element);
         this.update = $(update);
         this.hasFocus = false;
@@ -27,13 +27,16 @@
             this.options = options || {};
 
         this.options.param = this.options.param || this.element.name;
-        this.options.selectedClass = this.options.selectedClass || "dr-sb-int-sel";
+        this.options.selectedClass = this.options.selectedClass
+                || "dr-sb-int-sel";
         this.options.tokens = $A(options.tokens) || [];
         this.options.frequency = this.options.frequency || 0.4;
         this.options.minChars = parseInt(this.options.minChars) || 1;
         this.options.onShow = this.options.onShow ||
                               function(element, update, options) {
-                                  if (!update.style.position || update.style.position == 'absolute') {
+                                  if (!update.style.position
+                                          || update.style.position
+                                          == 'absolute') {
                                       update.style.position = 'absolute';
                                       Exadel.Position.smartClone(element, update, options);
                                   }
@@ -73,64 +76,68 @@
         Event.observe(this.element, "keypress", this.onKeyPressListener);
 
         if (this.isOpera) {
-	        this.onKeyUpListener = this.onKeyUp.bindAsEventListener(this);
-	        Event.observe(this.element, "keyup", this.onKeyUpListener);
-	        this.upDown = 0;
+            this.onKeyUpListener = this.onKeyUp.bindAsEventListener(this);
+            Event.observe(this.element, "keyup", this.onKeyUpListener);
+            this.upDown = 0;
         }
     },
 
-	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();
-		}
-	},
+    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();
+        }
+    },
 
-	cancelSubmit: function(event) {
-		Event.stop(event);
-	},
+    cancelSubmit: function(event) {
+        Event.stop(event);
+    },
 
-	disableSubmit: function() {
-		if (this.isOpera) {
-		    var el = this.element;
-		    while (el.parentNode && (!el.tagName || (el.tagName.toUpperCase() != 'FORM')))
-		      el = el.parentNode;
-		    if (el.tagName && (el.tagName.toUpperCase() == 'FORM')) {
-		    	this.parentForm = el;
-		        this.onSubmitListener = this.cancelSubmit.bindAsEventListener(this);
-		        Event.observe(el, "submit", this.onSubmitListener);
-		    }
-		}
-	},
+    disableSubmit: function() {
+        if (this.isOpera) {
+            var el = this.element;
+            while (el.parentNode && (!el.tagName || (el.tagName.toUpperCase()
+                    != 'FORM')))
+                el = el.parentNode;
+            if (el.tagName && (el.tagName.toUpperCase() == 'FORM')) {
+                this.parentForm = el;
+                this.onSubmitListener
+                        = this.cancelSubmit.bindAsEventListener(this);
+                Event.observe(el, "submit", this.onSubmitListener);
+            }
+        }
+    },
 
-	enableSubmit: function() {
-		if (this.isOpera) {
-			if (this.parentForm) {
-			    Event.stopObserving(this.parentForm, "submit", this.onSubmitListener);
-			}
-		}
-	},
+    enableSubmit: function() {
+        if (this.isOpera) {
+            if (this.parentForm) {
+                Event.stopObserving(this.parentForm, "submit", this.onSubmitListener);
+            }
+        }
+    },
 
-	onKeyUp: function(event) {
-		if (this.upDown > 0) {
-			this.element.onkeypress=this.prevOnKeyPress;
-		}
-		this.upDown = 0;
-	},
+    onKeyUp: function(event) {
+        if (this.upDown > 0) {
+            this.element.onkeypress = this.prevOnKeyPress;
+        }
+        this.upDown = 0;
+    },
 
     show: function() {
-        if (Element.getStyle(this.update, 'display') == 'none') this.options.onShow(this.element, this.update, this.options);
+        if (Element.getStyle(this.update, 'display')
+                == 'none') this.options.onShow(this.element, this.update, this.options);
         this.disableSubmit();
     },
 
     hide: function() {
         this.stopIndicator();
-        if (Element.getStyle(this.update, 'display') != 'none') this.options.onHide(this.element, this.update, this.options);
+        if (Element.getStyle(this.update, 'display')
+                != 'none') this.options.onHide(this.element, this.update, this.options);
         this.enableSubmit();
     },
 
@@ -169,7 +176,7 @@
             document.body.insertBefore(this.update, document.body.firstChild);
             this.initialized = true;
         }
-        if (this.active)
+        if (this.active) {
             switch (event.keyCode) {
                 case Event.KEY_TAB:
                 case Event.KEY_RETURN:
@@ -187,28 +194,34 @@
                     this.keyEvent = true;
                     this.markPrevious();
                     this.render();
-                    if (navigator.appVersion.indexOf('AppleWebKit') > 0) Event.stop(event);
-                	if (this.isOpera) {
-	                	this.upDown = 1;
-	                	this.prevOnKeyPress = this.element.onkeypress;
-	                	this.element.onkeypress = this.onBoxKeyPress.bindAsEventListener(this);
-                	}
+                    if (navigator.appVersion.indexOf('AppleWebKit')
+                            > 0) Event.stop(event);
+                    if (this.isOpera) {
+                        this.upDown = 1;
+                        this.prevOnKeyPress = this.element.onkeypress;
+                        this.element.onkeypress
+                                = this.onBoxKeyPress.bindAsEventListener(this);
+                    }
                     return;
                 case Event.KEY_DOWN:
                     this.keyEvent = true;
                     this.markNext();
                     this.render();
-                    if (navigator.appVersion.indexOf('AppleWebKit') > 0) Event.stop(event);
-                	if (this.isOpera) {
-	                	this.upDown = 2;
-	                	this.prevOnKeyPress = this.element.onkeypress;
-	                	this.element.onkeypress = this.onBoxKeyPress.bindAsEventListener(this);
-                	}
+                    if (navigator.appVersion.indexOf('AppleWebKit')
+                            > 0) Event.stop(event);
+                    if (this.isOpera) {
+                        this.upDown = 2;
+                        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)
+        } else if (event.keyCode == Event.KEY_TAB
+                || event.keyCode  == Event.KEY_RETURN
+                || event.keyCode  == Event.KEY_ESC) {
                 return;
+        }
 
         this.changed = true;
         this.hasFocus = true;
@@ -242,7 +255,8 @@
             LOG.warn("Exception on clone event");
         }
         this.observerHandle =
-        window.setTimeout(this.onObserverEvent.bind(this, domEvt), this.options.frequency * 1000);
+        window.setTimeout(this.onObserverEvent.bind(this, domEvt), this.options.frequency
+                * 1000);
     },
 
     onHover: function(event) {
@@ -269,8 +283,10 @@
             offsets["x"] = 0;
             offsets["y"] = 0;
         }
-        if (event.clientX > offsets["x"] && event.clientX < (this.update.clientWidth + offsets["x"])) {
-            if (event.clientY > (offsets["y"] - this.update.clientHeight) && event.clientY < offsets["y"]) {
+        if (event.clientX > offsets["x"] && event.clientX
+                < (this.update.clientWidth + offsets["x"])) {
+            if (event.clientY > (offsets["y"] - this.update.clientHeight)
+                    && event.clientY < offsets["y"]) {
                 this.element.focus();
                 return;
             }
@@ -283,12 +299,14 @@
 
     render: function() {
         if (this.entryCount > 0) {
-            LOG.debug('render for index ' + this.index + " and old index " + this.prevIndex);
+            LOG.debug('render for index ' + this.index + " and old index "
+                    + this.prevIndex);
             if (this.prevIndex != this.index) {
                 var entry = this.getEntry(this.index);
                 Element.addClassName(entry, this.options.selectedClass);
                 // Calc scroll position :
-                var scroll = document.getElementsByClassName("_suggestion_size_", this.update)[0] || this.update;
+                var scroll = document.getElementsByClassName("_suggestion_size_", this.update)[0]
+                        || this.update;
                 var item = entry;
                 var realOffset = 0;
                 while (item && (item != scroll)) {
@@ -298,9 +316,14 @@
                 }
                 if (this.keyEvent) {
                     this.keyEvent = false;
-                    LOG.debug("Scroll = " + scroll.scrollTop + " , reallOffset= " + realOffset + " scrollHeight= " + scroll.offsetHeight);
-                    var minScroll = realOffset - (scroll.clientHeight / 2) - (scroll.clientHeight / 2) % entry.offsetHeight;
-                    var maxScroll = realOffset - (scroll.clientHeight * 2 / 3) + (scroll.clientHeight * 2 / 3) % (entry.offsetHeight) ;
+                    LOG.debug("Scroll = " + scroll.scrollTop
+                            + " , reallOffset= " + realOffset
+                            + " scrollHeight= " + scroll.offsetHeight);
+                    var minScroll = realOffset - (scroll.clientHeight / 2)
+                            - (scroll.clientHeight / 2) % entry.offsetHeight;
+                    var maxScroll = realOffset - (scroll.clientHeight * 2 / 3)
+                            + (scroll.clientHeight * 2 / 3)
+                            % (entry.offsetHeight) ;
                     if (scroll.scrollTop > minScroll) {
                         scroll.scrollTop = minScroll;
                     } else if (scroll.scrollTop < maxScroll) {
@@ -366,15 +389,18 @@
         }
         var value = '';
         if (this.options.select) {
-            var nodes = document.getElementsByClassName(this.options.select, selectedElement) || [];
-            if (nodes.length > 0) value = Element.collectTextNodes(nodes[0], this.options.select);
+            var nodes = document.getElementsByClassName(this.options.select, selectedElement)
+                    || [];
+            if (nodes.length > 0) value
+                    = Element.collectTextNodes(nodes[0], this.options.select);
         } else
             value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
 
         var lastTokenPos = this.findLastToken();
         if (lastTokenPos != -1) {
             var newValue = this.element.value.substr(0, lastTokenPos + 1);
-            var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/);
+            var whitespace = this.element.value.substr(lastTokenPos
+                    + 1).match(/^\s+/);
             if (whitespace)
                 newValue += whitespace[0];
             this.element.value = newValue + value;
@@ -395,8 +421,11 @@
             // TODO - get entry elements by tag name or class
             var entryes = [];
             if (this.options.entryClass) {
-                entryes = document.getElementsByClassName(this.options.entryClass, this.update) || [];
-            } else if (this.update.firstChild && this.update.firstChild.firstChild && this.update.firstChild.firstChild.childNodes) {
+                entryes = document.getElementsByClassName(this.options.entryClass, this.update)
+                        || [];
+            } else if (this.update.firstChild
+                    && this.update.firstChild.firstChild
+                    && this.update.firstChild.firstChild.childNodes) {
                 Element.cleanWhitespace(this.update);
                 Element.cleanWhitespace(this.update.firstChild);
                 Element.cleanWhitespace(this.update.firstChild.firstChild);
@@ -408,12 +437,13 @@
                 //          var entry = this.getEntry(i);
                 entry.autocompleteIndex = i;
                 this.addObservers(entry);
-//                if (this.options.cellpadding)
-//                entry.lastChild.style.padding=this.options.cellpadding;
+                //                if (this.options.cellpadding)
+                //                entry.lastChild.style.padding=this.options.cellpadding;
             }
 
             this.stopIndicator();
-            var scroll = document.getElementsByClassName("_suggestion_size_", this.update)[0] || this.update;
+            var scroll = document.getElementsByClassName("_suggestion_size_", this.update)[0]
+                    || this.update;
             scroll.scrollTop = -1;
             scroll.scrollLeft = -1;
             this.index = 0;
@@ -444,7 +474,8 @@
     getToken: function() {
         var tokenPos = this.findLastToken();
         if (tokenPos != -1)
-            var ret = this.element.value.substr(tokenPos + 1).replace(/^\s+/, '').replace(/\s+$/, '');
+            var ret = this.element.value.substr(tokenPos
+                    + 1).replace(/^\s+/, '').replace(/\s+$/, '');
         else
             var ret = this.element.value;
 
@@ -490,7 +521,8 @@
     onComplete: function(request, event) {
         LOG.debug("AJAX response  complete - updateChoices");
         // Calculate height of choices window
-        if (!this.update.style.position || this.update.style.position == 'absolute') {
+        if (!this.update.style.position || this.update.style.position
+                == 'absolute') {
             this.update.style.position = 'absolute';
             Exadel.Position.smartClone(this.element, this.update, this.options);
         }
@@ -503,10 +535,13 @@
 
     create: function(element, suggestion, content, options) {
         if (!$(element)) return;
-        var style = "display:none;" + ( options.popupStyle || "border:1px solid black;position:absolute; background-color:white;");
-        var styleClass = options.popupClass ? ' class="' + options.popupClass + '" ':'';
+        var style = "display:none;" + ( options.popupStyle
+                || "border:1px solid black;position:absolute; background-color:white;");
+        var styleClass = options.popupClass ? ' class="' + options.popupClass
+                + '" ':'';
         new Insertion.Top($(element).ownerDocument.body,
-                '<div id="' + suggestion + '"' + styleClass + ' style="' + style + '">' +
+                '<div id="' + suggestion + '"' + styleClass + ' style="' + style
+                        + '">' +
                 '<table id="' + content + '" cellspacing="0" cellpadding="0">' +
                 '<tbody></tbody>' +
                 '</table>' +
@@ -541,7 +576,8 @@
         }
         */
         var offsets = this.calcOffsets(this.source);
-        Element.setStyle(this.target, Object.extend({"left": offsets["x"] + "px", "top": offsets["y"] + "px"}, targetStyle));
+        Element.setStyle(this.target, Object.extend({"left": offsets["x"]
+                + "px", "top": offsets["y"] + "px"}, targetStyle));
 
         if (options.iframeId) {
             var iframe = $(options.iframeId);
@@ -559,15 +595,16 @@
 
     calcOffsets : function(element) {
         var ret = new Object(), height = 0;
-		var left = element.offsetLeft;
-		var top = element.offsetTop;
-		for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
-			left += parent.offsetLeft;
-			top += parent.offsetTop;
-		}
+        var left = element.offsetLeft;
+        var top = element.offsetTop;
+        for (var parent = element.offsetParent; parent;
+             parent = parent.offsetParent) {
+            left += parent.offsetLeft;
+            top += parent.offsetTop;
+        }
 
-		ret["x"] = left;
-		ret["y"] = top + element.clientHeight;
+        ret["x"] = left;
+        ret["y"] = top + element.clientHeight;
 
         return ret;
     },
@@ -600,7 +637,8 @@
             if (this.options.width.indexOf("%") >= 0) {
                 // Count persents to pixels
                 var percent = parseInt(this.options.width.substring(0, this.options.width.indexOf("%")));
-                var sizeInPixels = parseInt(this.source.offsetWidth) * percent / 100;
+                var sizeInPixels = parseInt(this.source.offsetWidth) * percent
+                        / 100;
                 this.options.width = sizeInPixels + "px";
             }
 
@@ -615,7 +653,8 @@
         var sourceLeft = sourceOffset[0];
         var sourceWidth = this.source.offsetWidth;
         var body = this.getBody();
-        var width = parseInt(sourceLeft) + parseInt(sourceWidth) + parseInt(targetWidth);
+        var width = parseInt(sourceLeft) + parseInt(sourceWidth)
+                + parseInt(targetWidth);
         if (width <= parseInt(body.clientWidth)) {
             return sourceLeft;
         } else {




More information about the richfaces-svn-commits mailing list