Index: src/main/java/info/magnolia/cms/taglibs/util/SimpleNavigationTag.java
===================================================================
--- src/main/java/info/magnolia/cms/taglibs/util/SimpleNavigationTag.java (revision 19163)
+++ src/main/java/info/magnolia/cms/taglibs/util/SimpleNavigationTag.java (working copy)
@@ -117,6 +117,16 @@
private static final String CSS_LI_OPEN = "open"; //$NON-NLS-1$
/**
+ * Css class added to first li in ul.
+ */
+ private static final String CSS_LI_FIRST = "first"; //$NON-NLS-1$
+
+ /**
+ * Css class added to last li in ul.
+ */
+ private static final String CSS_LI_LAST = "last"; //$NON-NLS-1$
+
+ /**
* Page property: navigation title.
*/
private static final String NODEDATA_NAVIGATIONTITLE = "navTitle"; //$NON-NLS-1$
@@ -221,6 +231,11 @@
private String contentFilter = "";
+ /**
+ * Flag to set if the first and last li in each ul should be marked with a special css class
+ */
+ private boolean markFirstAndLastElement = false;
+
/**
* The start level for navigation, defaults to 0.
* @jsp.attribute required="false" rtexprvalue="true" type="int"
@@ -323,6 +338,15 @@
}
/**
+ * If set to true, a "first" or "last" css class will be added to the list of css classes of the
+ * first and the last li in each ul.
+ */
+ public void setMarkFirstAndLastElement(boolean flag) {
+ System.out.println("setMarkFirstAndLastElement(): "+flag);
+ markFirstAndLastElement = flag;
+ }
+
+ /**
* @see javax.servlet.jsp.tagext.Tag#doEndTag()
*/
public int doEndTag() throws JspException {
@@ -404,7 +428,6 @@
if (children.size() == 0) {
return;
}
-
out.print("
"); //$NON-NLS-1$
+ ArrayList visibleChildren = new ArrayList(children);
Iterator it = children.iterator();
+ Content child;
while (it.hasNext()) {
- Content child = (Content) it.next();
+ child = (Content) it.next();
if (expandAll.equalsIgnoreCase(EXPAND_NONE) || expandAll.equalsIgnoreCase(EXPAND_SHOW)) {
if (child
.getNodeData(StringUtils.defaultString(this.hideInNav, DEFAULT_HIDEINNAV_NODEDATA))
.getBoolean()) {
+ visibleChildren.remove(child);
continue;
}
// use a filter
if (filter != null) {
if (!filter.accept(child)) {
+ visibleChildren.remove(child);
continue;
}
}
}
+ }
+
+ it = visibleChildren.iterator();
+ boolean isFirst = true;
+ while (it.hasNext()) {
+ child = (Content) it.next();
+ List cssClasses = new ArrayList(4);
- List cssClasses = new ArrayList(3);
-
NodeData nodeData = I18nContentSupportFactory.getI18nSupport().getNodeData(child, NODEDATA_NAVIGATIONTITLE);
String title = nodeData.getString(StringUtils.EMPTY);
@@ -486,6 +518,15 @@
cssClasses.add(child.getNodeData(classProperty).getString(StringUtils.EMPTY));
}
+ if (markFirstAndLastElement && isFirst) {
+ cssClasses.add(CSS_LI_FIRST);
+ isFirst = false;
+ }
+
+ if (markFirstAndLastElement && !it.hasNext()) {
+ cssClasses.add(CSS_LI_LAST);
+ }
+
StringBuffer css = new StringBuffer(cssClasses.size() * 10);
Iterator iterator = cssClasses.iterator();
while (iterator.hasNext()) {
Index: src/main/resources/META-INF/cms-util-taglib.tld
===================================================================
--- src/main/resources/META-INF/cms-util-taglib.tld (revision 19163)
+++ src/main/resources/META-INF/cms-util-taglib.tld (working copy)
@@ -326,6 +326,13 @@
true
boolean
+
+ If set to true, the first and last element of each level will be marked with the css classes "first" and "last"
+ markFirstAndLastElement
+ false
+ true
+ boolean
+