You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2015/05/06 10:11:36 UTC

svn commit: r1677946 - in /myfaces/tobago/branches/tobago-3.0.x: tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/ tobago-theme/tobago-theme-st...

Author: lofwyr
Date: Wed May  6 08:11:36 2015
New Revision: 1677946

URL: http://svn.apache.org/r1677946
Log:
TOBAGO-1368: Create a new theme which uses Bootstrap
 - nav -> collapse

Added:
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java
Modified:
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/NavRenderer.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRenderer.java

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java?rev=1677946&r1=1677945&r2=1677946&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java Wed May  6 08:11:36 2015
@@ -231,6 +231,8 @@ public final class DataAttributes {
 
   public static final String SUGGEST_UPDATE = "data-tobago-suggest-update";
 
+  public static final String TARGET = "data-target";
+
   public static final String TO_PAGE = "data-tobago-to-page";
 
   public static final String TOGGLE = "data-toggle";

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.java?rev=1677946&r1=1677945&r2=1677946&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.java Wed May  6 08:11:36 2015
@@ -35,6 +35,7 @@ public enum BootstrapClass implements Cs
   ALERT_INFO("alert-info"),
   CHECKBOX("checkbox"),
   COLLAPSE("collapse"),
+  COLLAPSED("collapsed"),
   CONTAINER("container"),
   CONTAINER_FLUID("container-fluid"),
   DISABLED("disabled"),

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/NavRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/NavRenderer.java?rev=1677946&r1=1677945&r2=1677946&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/NavRenderer.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/NavRenderer.java Wed May  6 08:11:36 2015
@@ -22,10 +22,13 @@ package org.apache.myfaces.tobago.render
 import org.apache.myfaces.tobago.internal.component.AbstractUIForm;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
 import org.apache.myfaces.tobago.renderkit.html.BootstrapClass;
+import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlButtonTypes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
 import org.apache.myfaces.tobago.renderkit.html.HtmlRoleValues;
 import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.renderkit.util.JQueryUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 
 import javax.faces.component.UIComponent;
@@ -38,14 +41,20 @@ public class NavRenderer extends Rendere
   public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
     final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
 
+    final String clientId = component.getClientId(facesContext);
+    final String navbarId = clientId + "::navbar";
+
     writer.startElement(HtmlElements.NAV, null);
-    writer.writeIdAttribute(component.getClientId(facesContext));
+    writer.writeIdAttribute(clientId);
     writer.writeAttribute(HtmlAttributes.ROLE, HtmlRoleValues.NAVIGATION.toString(), false);
 
     writer.startElement(HtmlElements.DIV, null);
     writer.writeClassAttribute(BootstrapClass.CONTAINER_FLUID);
 
+    encodeOpener(writer, navbarId);
+
     writer.startElement(HtmlElements.DIV, null);
+    writer.writeIdAttribute(navbarId);
     writer.writeClassAttribute(BootstrapClass.COLLAPSE, BootstrapClass.NAVBAR_COLLAPSE);
 // XXX   writer.writeClassAttribute(BootstrapClass.COLLAPSE, BootstrapClass.NAVBAR_COLLAPSE, BootstrapClass.NAVBAR_TEXT);
 
@@ -83,4 +92,36 @@ public class NavRenderer extends Rendere
     writer.endElement(HtmlElements.DIV);
     writer.endElement(HtmlElements.NAV);
   }
+
+  private void encodeOpener(TobagoResponseWriter writer, String navbarId) throws IOException {
+
+    // todo: consolidate this rendering with ToolBarRenderer
+
+    writer.startElement(HtmlElements.DIV, null);
+    writer.writeClassAttribute(BootstrapClass.NAVBAR_HEADER);
+
+    writer.startElement(HtmlElements.BUTTON, null);
+    writer.writeAttribute(HtmlAttributes.TYPE, HtmlButtonTypes.BUTTON, false);
+    writer.writeClassAttribute(BootstrapClass.NAVBAR_TOGGLE, BootstrapClass.COLLAPSED);
+    writer.writeAttribute(DataAttributes.TOGGLE, "collapse", false);
+    writer.writeAttribute(DataAttributes.TARGET, JQueryUtils.escapeIdForHtml(navbarId), true);
+    writer.writeAttribute("aria-expanded", "false", false);
+    writer.writeAttribute("aria-controls", navbarId, false);
+
+    writer.startElement(HtmlElements.SPAN, null);
+    writer.writeClassAttribute(BootstrapClass.SR_ONLY);
+    writer.writeText("Toggle navigation"); // todo: i18n
+    writer.endElement(HtmlElements.SPAN);
+
+    for (int i = 0; i < 3; i++) {
+      writer.startElement(HtmlElements.SPAN, null);
+      writer.writeClassAttribute(BootstrapClass.ICON_BAR);
+      writer.endElement(HtmlElements.SPAN);
+    }
+
+    writer.endElement(HtmlElements.BUTTON);
+
+    writer.endElement(HtmlElements.DIV);
+  }
+
 }

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRenderer.java?rev=1677946&r1=1677945&r2=1677946&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRenderer.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRenderer.java Wed May  6 08:11:36 2015
@@ -21,12 +21,14 @@ package org.apache.myfaces.tobago.render
 
 import org.apache.myfaces.tobago.component.UIToolBar;
 import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
+import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlButtonTypes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
 import org.apache.myfaces.tobago.renderkit.html.HtmlRoleValues;
 import org.apache.myfaces.tobago.renderkit.html.BootstrapClass;
 import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.renderkit.util.JQueryUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,12 +60,12 @@ public class ToolBarRenderer extends Lay
     writer.startElement(HtmlElements.BUTTON, null);
     writer.writeAttribute(HtmlAttributes.TYPE, HtmlButtonTypes.BUTTON, false);
     writer.writeClassAttribute(BootstrapClass.NAVBAR_TOGGLE);
-    writer.writeAttribute("data-toggle", "collapse", false);
-    writer.writeAttribute("data-target", "#" + toolBar.getClientId(facesContext).replace(":", "\\:"), true);
+    writer.writeAttribute(DataAttributes.TOGGLE, "collapse", false);
+    writer.writeAttribute("data-target", JQueryUtils.escapeIdForHtml(toolBar.getClientId(facesContext)), true);
 
     writer.startElement(HtmlElements.SPAN, null);
     writer.writeClassAttribute(BootstrapClass.SR_ONLY);
-    writer.writeText("Toggle navigation");
+    writer.writeText("Toggle navigation"); // todo i18n
     writer.endElement(HtmlElements.SPAN);
 
     for (int i = 0; i < 3; i++) {
@@ -91,7 +93,8 @@ public class ToolBarRenderer extends Lay
       <div class="container-fluid">
         <!-- Brand and toggle get grouped for better mobile display -->
         <div class="navbar-header">
-          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
+          <button type="button" class="navbar-toggle"
+              data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
             <span class="sr-only">Toggle navigation</span>
             <span class="icon-bar"></span>
             <span class="icon-bar"></span>

Added: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java?rev=1677946&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java (added)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java Wed May  6 08:11:36 2015
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.renderkit.util;
+
+public class JQueryUtils {
+
+  public static String escapeIdForHtml(String id) {
+    return "#" + id.replaceAll("([\\:\\.\\[\\]\\,])", "\\\\$1" );
+  }
+
+  public static String escapeIdForJavaScript(String id) {
+    return "#" + id.replaceAll("([\\:\\.\\[\\]\\,])", "\\\\\\\\$1" );
+  }
+
+}