You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2008/06/02 11:14:14 UTC

svn commit: r662371 - in /wicket/trunk: wicket-extensions/ wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/ wicket/ wicket/src/main/java/org/apache/wicket/ajax/ wicket/src/main/java/org/apache/wicket/request/t...

Author: jcompagner
Date: Mon Jun  2 02:14:13 2008
New Revision: 662371

URL: http://svn.apache.org/viewvc?rev=662371&view=rev
Log:
merged various checkings until: 662360

Modified:
    wicket/trunk/wicket/   (props changed)
    wicket/trunk/wicket-extensions/   (props changed)
    wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
    wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
    wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/StringRequestTarget.java

Propchange: wicket/trunk/wicket/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jun  2 02:14:13 2008
@@ -1 +1 @@
-/wicket/branches/wicket-1.3.x/jdk-1.4/wicket:653208,653212,653215,653226,653231,654304,655446,655466,655786
+/wicket/branches/wicket-1.3.x/jdk-1.4/wicket:653208,653212,653215,653226,653231,654304,655446,655466,655786,658141,659118,659120,662360

Propchange: wicket/trunk/wicket-extensions/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Jun  2 02:14:13 2008
@@ -0,0 +1 @@
+/wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions:659248,661657,662360

Modified: wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js?rev=662371&r1=662370&r2=662371&view=diff
==============================================================================
--- wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js (original)
+++ wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js Mon Jun  2 02:14:13 2008
@@ -52,8 +52,26 @@
 	var objonkeypress;
 	var objonchange;
 	var objonchangeoriginal;
-
-    function initialize(){    	
+	
+	// holds the eventual margins, padding, etc. of the menu container.
+	// it is computed when the menu is first rendered, and then reused.
+	var initialDelta = -1;
+
+	// holds a throttler, for not sending many requests if the user types
+	// too quickly.
+	var localThrottler = new Wicket.Throttler(true);
+	var throttleDelay = 300;
+
+    function initialize(){
+		// Remove the autocompletion menu if still present from
+		// a previous call. This is required to properly register
+		// the mouse event handler again (using the new stateful 'mouseactive'
+		// variable which just gets created)
+        var choiceDiv=document.getElementById(getMenuId());
+        if (choiceDiv != null) {
+            choiceDiv.parentNode.parentNode.removeChild(choiceDiv.parentNode);
+        } 
+        	
         var obj=wicketGet(elementId);
 
         objonkeydown=obj.onkeydown;
@@ -223,6 +241,11 @@
         else{
         	selected=-1;
         }
+        localThrottler.throttle(getMenuId(), throttleDelay, actualUpdateChoices);
+    }
+
+    function actualUpdateChoices()
+    {
         var value = wicketGet(elementId).value;
        	var request = new Wicket.Ajax.Request(callbackUrl+"&q="+processValue(value), doUpdateChoices, false, true, false, "wicket-autocomplete|d");
        	request.get();
@@ -279,23 +302,26 @@
         var element = getAutocompleteMenu();
         element.innerHTML=resp;
         if(element.firstChild && element.firstChild.childNodes) {
-            elementCount=element.firstChild.childNodes.length;
+		elementCount=element.firstChild.childNodes.length;
 
-            for(var i=0;i<elementCount;i++){
-	            var node=element.firstChild.childNodes[i];
-
-				node.onclick = function(event){
-					mouseactive=0;
-					wicketGet(elementId).value=getSelectedValue();
-					if(typeof objonchange=="function")objonchange();
-					hideAutoComplete();
-       			}
-
-				node.onmouseover = function(event){					
-					selected = getElementIndex(this);
-					render();
-				 	showAutoComplete();
-				}
+		var clickFunc = function(event){
+			mouseactive=0;
+			wicketGet(elementId).value=getSelectedValue();
+			if(typeof objonchange=="function")objonchange();
+				hideAutoComplete();
+		};
+			
+		var mouseOverFunc = function(event){
+			selected = getElementIndex(this);
+			render();
+		 	showAutoComplete();
+		};
+
+		var node=element.firstChild.childNodes[0];
+		for(var i=0;i<elementCount;i++){
+			node.onclick = clickFunc;
+			node.onmouseover = mouseOverFunc;
+			node = node.nextSibling;
        		}
         } else {
             elementCount=0;
@@ -360,26 +386,30 @@
     function render(){
         var menu=getAutocompleteMenu();
         var height=0;
-        for(var i=0;i<elementCount;i++){
-            var node=menu.firstChild.childNodes[i];
-
-            var classNames=node.className.split(" ");
-            for (var j=0; j<classNames.length; j++) {
-                if (classNames[j]=='selected') {
-                    classNames[j]='';
-                }
-            }
-
-            if(selected==i){
-                classNames.push('selected');
-                adjustScrollOffset(menu.parentNode, node);
-            }
-            
-            node.className=classNames.join(" ");
-            height+=node.offsetHeight;
-        }
+		var node=menu.firstChild.childNodes[0];
+		var re = /\bselected\b/gi;
+        for(var i=0;i<elementCount;i++)
+		{
+            var origClassNames = node.className;
+			var classNames = origClassNames.replace(re, "");
+			if(selected==i){
+				classNames += " selected";
+				adjustScrollOffset(menu.parentNode, node);
+			}
+			if (classNames != origClassNames)
+                node.className = classNames;
+	
+			if ((cfg.maxHeight > -1) && (height < cfg.maxHeight))
+				height+=node.offsetHeight;
+	
+			node = node.nextSibling;
+		}
         if (cfg.maxHeight > -1) {
-        	height = height<cfg.maxHeight?height:cfg.maxHeight;
+			// If we don't exceed the maximum size, we add the extra space 
+			// that may be there due to padding, margins, etc.
+			if (initialDelta == -1)
+				initialDelta = menu.parentNode.offsetHeight - height;
+        	height = height<cfg.maxHeight ? height+initialDelta : cfg.maxHeight;
         	menu.parentNode.style.height=height+"px";
         }
     }
@@ -464,4 +494,4 @@
     }
 
     initialize();
-}
\ No newline at end of file
+}

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java?rev=662371&r1=662370&r2=662371&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java Mon Jun  2 02:14:13 2008
@@ -732,7 +732,7 @@
 		RequestCycle.get().setResponse(encodingBodyResponse);
 
 		// Initialize temporary variables
-		final Page<?> page = component.getPage();
+		final Page page = (Page)component.findParent(Page.class);
 		if (page == null)
 		{
 			// dont throw an exception but just ignore this component, somehow

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js?rev=662371&r1=662370&r2=662371&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js Mon Jun  2 02:14:13 2008
@@ -1561,6 +1561,7 @@
 	initialize: function(func) {
 		this.func = func;
 		this.timestamp = new Date().getTime();
+		this.timeoutVar = undefined;
 	},
 	
 	getTimestamp: function() {
@@ -1573,13 +1574,30 @@
 	
 	setFunc: function(func) {
 		this.func = func;
+	},
+
+	getTimeoutVar: function() {
+        return this.timeoutVar;
+	},
+
+	setTimeoutVar: function(timeoutVar) {
+        this.timeoutVar = timeoutVar;
 	}
 };
 
 Wicket.Throttler = Wicket.Class.create();
 Wicket.Throttler.prototype = {
-	initialize: function() {
+
+    /* "postponeTimerOnUpdate" is an optional parameter. If it is set to true, then the timer is
+       reset each time the throttle function gets called. Use this behaviour if you want something
+       to happen at X milliseconds after the *last* call to throttle.
+       If the parameter is not set, or set to false, then the timer is not reset. */
+	initialize: function(postponeTimerOnUpdate) {
 		this.entries = new Array();
+		if (postponeTimerOnUpdate != undefined)
+            this.postponeTimerOnUpdate = postponeTimerOnUpdate;
+        else
+            this.postponeTimerOnUpdate = false;
 	},
 	
 	throttle: function(id, millis, func) {
@@ -1587,10 +1605,15 @@
 		var me = this;
 		if (entry == undefined) {
 			entry = new Wicket.ThrottlerEntry(func);
+			entry.setTimeoutVar(window.setTimeout(function() { me.execute(id); }, millis));
 			this.entries[id] = entry;
-			window.setTimeout(function() { me.execute(id); }, millis);
 		} else {
 			entry.setFunc(func);
+            if (this.postponeTimerOnUpdate == true)
+            {
+                window.clearTimeout(entry.getTimeoutVar());
+                entry.setTimeoutVar(window.setTimeout(function() { me.execute(id); }, millis));
+            }
 		}	
 	},
 	
@@ -1598,10 +1621,9 @@
 		var entry = this.entries[id];
 		if (entry != undefined) {
 			var func = entry.getFunc();
+            this.entries[id] = undefined;	
 			var tmp = func();
 		}
-		
-		this.entries[id] = undefined;	
 	}
 };
 
@@ -2074,4 +2096,4 @@
 	if (e!=null) {
 	    e.style.display = "none";
 	}
-}
\ No newline at end of file
+}

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/StringRequestTarget.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/StringRequestTarget.java?rev=662371&r1=662370&r2=662371&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/StringRequestTarget.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/basic/StringRequestTarget.java Mon Jun  2 02:14:13 2008
@@ -48,7 +48,7 @@
 	 */
 	public StringRequestTarget(String string)
 	{
-		this("text", string);
+		this("text/plain", string);
 	}
 
 	/**
@@ -84,6 +84,7 @@
 	{
 		// Get servlet response to use when responding with resource
 		final Response response = requestCycle.getResponse();
+		response.setContentType(contentType);
 		final StringBufferResourceStream stream = new StringBufferResourceStream(contentType);
 		stream.append(string);