Author: ivaynberg
Date: Thu Jun 26 09:48:22 2008
New Revision: 671942
URL: http://svn.apache.org/viewvc?rev=671942&view=rev
Log:
WICKET-1716 make autocompleter more customizable
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java?rev=671942&r1=671941&r2=671942&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
Thu Jun 26 09:48:22 2008
@@ -68,10 +68,14 @@
protected final String constructSettingsJS()
{
- StringBuffer sb = new StringBuffer();
-
sb.append("{preselect:").append(settings.getPreselect()).append(",maxHeight:").append(
-
settings.getMaxHeightInPx()).append(",showListOnEmptyInput:").append(
- settings.getShowListOnEmptyInput()).append("}");
+ final StringBuffer sb = new StringBuffer();
+ 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();
}
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java?rev=671942&r1=671941&r2=671942&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
Thu Jun 26 09:48:22 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/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js?rev=671942&r1=671941&r2=671942&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
Thu Jun 26 09:48:22 2008
@@ -190,8 +190,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";
@@ -269,7 +271,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();
}