Author: ivaynberg
Date: Thu Jun 26 09:49:29 2008
New Revision: 671945

URL: http://svn.apache.org/viewvc?rev=671945&view=rev
Log:
WICKET-1716 make autocompleter more customizable

Modified:
    
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
    
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
    
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js

Modified: 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java?rev=671945&r1=671944&r2=671945&view=diff
==============================================================================
--- 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
 (original)
+++ 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
 Thu Jun 26 09:49:29 2008
@@ -56,10 +56,16 @@
 
        protected final String constructSettingsJS()
        {
-               return 
String.format("{preselect:%b,maxHeight:%d,showListOnEmptyInput:%b}",
-                       settings.getPreselect(), settings.getMaxHeightInPx(),
-                       settings.getShowListOnEmptyInput());
-       }
+        final StringBuilder sb = new StringBuilder();
+        sb.append("{preselect: ").append(settings.getPreselect());
+        sb.append(",maxHeight: ").append(settings.getMaxHeightInPx());
+        sb.append(",adjustInputWidth: ").append(settings.isAdjustInputWidth());
+        sb.append(",showListOnEmptyInput: 
").append(settings.getShowListOnEmptyInput());
+        if(settings.getCssClassName() != null)
+            sb.append(",className: 
'").append(settings.getCssClassName()).append('\'');
+        sb.append('}');
+        return sb.toString();
+    }
 
        /**
         * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind()

Modified: 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java?rev=671945&r1=671944&r2=671945&view=diff
==============================================================================
--- 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
 (original)
+++ 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
 Thu Jun 26 09:49:29 2008
@@ -54,7 +54,11 @@
 
        private boolean showListOnEmptyInput = false;
 
-       /**
+    private String cssClassName = null;
+
+    private boolean adjustInputWidth = true;
+
+  /**
         * Indicates whether the first item in the list is automatically 
selected when the autocomplete
         * list is shown.
         * 
@@ -136,4 +140,52 @@
                this.showListOnEmptyInput = showListOnEmptyInput;
                return this;
        }
+
+    /**
+     * Get CSS class name to add to the autocompleter markup container
+     *
+     * @return CSS class name, or <code>null</code> if not used
+     */
+    public String getCssClassName()
+    {
+        return cssClassName;
+    }
+
+    /**
+     * Sets an CSS class name to add to the autocompleter markup container
+     * <p/>
+     * This makes it easier to have multiple autocompleters in your application
+     * with different style and layout.
+     *
+     * @param cssClassName valid CSS class name
+     */
+    public void setCssClassName(final String cssClassName)
+    {
+        this.cssClassName = cssClassName;
+    }
+
+    /**
+     * Tells if wicket should adjust the width of the autocompleter selection 
window
+     * to the width of the related input field.
+     *
+     * @return   <code>true</code> if the autocompleter should have the same 
size as
+     *             the input field, <code>false</code> for default browser 
behavior
+     */
+    public boolean isAdjustInputWidth()
+    {
+        return adjustInputWidth;
+    }
+
+  /**
+   * Adjust the width of the autocompleter selection window to the width of 
the related input field.
+   * <p/>
+   * Otherwise the size will depend on the default browser behavior and CSS.
+   *
+    * @param adjustInputWidth  <code>true</code> if the autocompleter should 
have the same size  as
+   *                           the input field, <code>false</code> for default 
browser behavior
+   */
+    public void setAdjustInputWidth(final boolean adjustInputWidth)
+    {
+        this.adjustInputWidth = adjustInputWidth;
+    }
 }
\ No newline at end of file

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=671945&r1=671944&r2=671945&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
 Thu Jun 26 09:49:29 2008
@@ -194,8 +194,10 @@
         var choiceDiv=document.getElementById(getMenuId());
         if (choiceDiv==null) {
                var container = document.createElement("div");
-               container.className="wicket-aa-container";
-               document.body.appendChild(container);
+            container.className ="wicket-aa-container";
+            if(cfg.className)
+              container.className += ' ' + cfg.className;
+            document.body.appendChild(container);
                container.style.display="none";
                container.style.overflow="auto";
             container.style.position="absolute";            
@@ -273,7 +275,8 @@
         
container.style.zIndex=(Number(index)!=Number.NaN?Number(index)+1:index);
         container.style.left=position[0]+'px'
         container.style.top=(input.offsetHeight+position[1])+'px';
-        container.style.width=input.offsetWidth+'px';
+        if(cfg.adjustInputWidth)
+          container.style.width=input.offsetWidth+'px';
         visible=1;
         hideShowCovered();
     }


Reply via email to