rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject svn commit: r1141646 - in /incubator/rave/trunk/rave-portal/src/main: java/org/apache/rave/provider/opensocial/web/renderer/ java/org/apache/rave/provider/w3c/web/renderer/ webapp/WEB-INF/views/ webapp/script/
Date Thu, 30 Jun 2011 18:15:17 GMT
Author: jasha
Date: Thu Jun 30 18:15:17 2011
New Revision: 1141646

URL: http://svn.apache.org/viewvc?rev=1141646&view=rev
Log:
RAVE-79 Move the (inline) scripts for rendering the gadgets to the bottom of the HTML

Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/w3c/web/renderer/W3cWidgetRenderer.java
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java?rev=1141646&r1=1141645&r2=1141646&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java
Thu Jun 30 18:15:17 2011
@@ -43,13 +43,12 @@ public class OpenSocialWidgetRenderer im
 
     //Note the widgets.push() call.  This defines the widget objects, which are
     //added to the widgets[] array in home.jsp.   
-    private static final String IFRAME_MARKUP = "<script type=\"text/javascript\">"
+
+    private static final String IFRAME_MARKUP =
             "widgets.push({type: '%1$s'," +
             " regionWidgetId: %2$s," +
             " widgetUrl: '%3$s', " +
             " metadata: %4$s," +
-            " userPrefs: {}});" +
-            "</script>";
+            " userPrefs: {}});";
 
     @Override
     public String getSupportedContext() {
@@ -72,4 +71,4 @@ public class OpenSocialWidgetRenderer im
         return String.format(IFRAME_MARKUP, Constants.WIDGET_TYPE, item.getId(), item.getWidget().getUrl(),
                 openSocialService.getGadgetMetadata(item.getWidget().getUrl()));
     }
-}
\ No newline at end of file
+}

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/w3c/web/renderer/W3cWidgetRenderer.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/w3c/web/renderer/W3cWidgetRenderer.java?rev=1141646&r1=1141645&r2=1141646&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/w3c/web/renderer/W3cWidgetRenderer.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/w3c/web/renderer/W3cWidgetRenderer.java
Thu Jun 30 18:15:17 2011
@@ -19,8 +19,6 @@
 
 package org.apache.rave.provider.w3c.web.renderer;
 
-import static org.apache.rave.provider.w3c.Constants.WIDGET_TYPE;
-
 import org.apache.rave.exception.NotSupportedException;
 import org.apache.rave.portal.model.RegionWidget;
 import org.apache.rave.portal.model.Widget;
@@ -30,6 +28,8 @@ import org.springframework.beans.factory
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 
+import static org.apache.rave.provider.w3c.Constants.WIDGET_TYPE;
+
 /**
  * Creates the appropriate markup to represent a W3C widget
  */
@@ -37,11 +37,9 @@ import org.springframework.stereotype.Co
 public class W3cWidgetRenderer implements RegionWidgetRenderer {
 
 
-    private static final String IFRAME_MARKUP = "<script>" +
-                                                    "widgets.push({type: '%1$s'," +
-                                                                 " regionWidgetId: %2$s,"
+
-                                                                 " widgetUrl: '%3$s'});"
+
-                                                "</script>";
+    private static final String IFRAME_MARKUP = "widgets.push({type: '%1$s'," +
+                                                " regionWidgetId: %2$s," +
+                                                " widgetUrl: '%3$s'});";
 
     private static final String INLINE_MARKUP = "";
 

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp?rev=1141646&r1=1141645&r2=1141646&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp Thu Jun 30 18:15:17
2011
@@ -36,28 +36,16 @@
     <a href="<spring:url value="/app/store?referringPageId=${defaultPage.id}" />">Widget
Store</a>
 </div>
 
-<script src="${opensocial_engine_url}/js/container.js?c=1&container=default&debug=1"></script>
-<script src="<spring:url value="/script/rave.js"/>"></script>
-<script src="<spring:url value="/script/rave_api.js"/>"></script>
-<script src="<spring:url value="/script/rave_opensocial.js"/>"></script>
-<script src="<spring:url value="/script/rave_wookie.js"/>"></script>
-<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
-<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
 
 <h1>Hello ${defaultPage.owner.username}, welcome to Rave!</h1>
-<script>
-    //Define the global widgets variable
-     //This array will be populated by RegionWidgetRender providers.
-    var widgets = [];
-</script>
 <c:forEach var="region" items="${defaultPage.regions}">
 <div class="region" id="region-${region.id}-id" >
     <c:forEach var="regionWidget" items="${region.regionWidgets}">
-    <!-- FIXME: whether region.id should be included in the id. 
+    <%-- FIXME: whether region.id should be included in the id.
          I am not sure whether id's of widgets in different regions can be the same.
          If so, region.id must be included. When a gadget is moved, region id must be updated.

          Otherwise, it is not needed.
-    -->
+    --%>
     <div class="widget-wrapper" id="widget-wrapper-${regionWidget.id}">
         <div class="widget-title-bar" >
             <span id="widget-${regionWidget.id}-title">${regionWidget.widget.title}</span>
@@ -72,43 +60,40 @@
                              class="widget-toolbar-btn"
                              onclick="rave.toolbarDelete(this,{myRegionWidgetId:${regionWidget.id},myRegionId:${region.id},myPageId:${defaultPage.id}})">
                   </button>
-                  <script>
-                     //This decorates the toolbar buttons.  As currently written,
-                     //it needs to be in the forEach loop.
-                     $("#widget-${regionWidget.id}-max").button({
-                     text: false,
-                     icons: {
-                     primary: "ui-icon-arrow-4-diag"
-                     }
-                     });
-
-                     $("#widget-${regionWidget.id}-remove").button({
-                     text: false,
-                     icons: {
-                     primary: "ui-icon-close"
-                     }
-                     });
-                     rave.mapGadgetToRegion("${regionWidget.id}", "${region.id}");
-                  </script>
-
                 </span>
           </div>
         <div class="widget" id="widget-${regionWidget.id}-body">
-             <!-- 
-                    Among other things, the render-widget tag will populate the widgets[]
array.  
-                    See the markup text in OpenSocialWidgetRenderer.java, for example.
-             -->
-            <portal:render-widget regionWidget="${regionWidget}" />
+            <%-- Widget will be rendered here --%>
         </div>
     </div>
     </c:forEach>
 </div>
 </c:forEach>
 <div class="clear-float">&nbsp;</div>
-
+<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
+<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
+<script src="${opensocial_engine_url}/js/container.js?c=1&container=default&debug=1"></script>
+<script src="<spring:url value="/script/rave.js"/>"></script>
+<script src="<spring:url value="/script/rave_api.js"/>"></script>
+<script src="<spring:url value="/script/rave_opensocial.js"/>"></script>
+<script src="<spring:url value="/script/rave_wookie.js"/>"></script>
 <script>
-    $(function(){
+    //Define the global widgets variable
+    //This array will be populated by RegionWidgetRender providers.
+    var widgets = [];
+    <%--
+        Among other things, the render-widget tag will populate the widgets[] array.
+        See the markup text in OpenSocialWidgetRenderer.java, for example.
+     --%>
+    <c:forEach var="region" items="${defaultPage.regions}">
+    <c:forEach var="regionWidget" items="${region.regionWidgets}">
+    <portal:render-widget regionWidget="${regionWidget}" />
+    </c:forEach>
+    </c:forEach>
+
+    $(function() {
         rave.setContext("<spring:url value="/app/" />");
+        rave.initGadgetUI(widgets);
         rave.initProviders();
         rave.initWidgets(rave.createWidgetMap(widgets));
         rave.initDragAndDrop();

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js?rev=1141646&r1=1141645&r2=1141646&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js Thu Jun 30 18:15:17 2011
@@ -187,8 +187,26 @@ var rave = rave || (function() {
     function getContext() {
         return context;
     }
-	 
-	 /**
+
+    /**
+     * Takes care of the UI part of the widget rendering. Depends heavily on the HTML structure
+     * @param widgets array of widgets
+     */
+    function initGadgetUI(widgets) {
+        $("div[id^='region-']").each(function(regionIndex) {
+            var regionElement = $(this);
+            var regionId = regionElement.attr("id");
+            regionId = regionId.substring("region-".length, regionId.lastIndexOf('-'));
+            regionElement.children("div[id^='widget-wrapper-']").each(function(wrapperIndex)
{
+                var widgetElement = $(this);
+                var widgetId = widgetElement.attr("id").substr("widget-wrapper-".length);
+                mapGadgetToRegion(widgetId, regionId);
+                styleGadgetButtons(widgetId);
+            });
+        });
+    }
+
+    /**
 	  * Map a widget to the region where it is located.
 	  * 
 	  * @param widgetId: id of the widget (not DOM id)
@@ -210,6 +228,27 @@ var rave = rave || (function() {
      }
 
     /**
+     * Applies styling to the several buttons in the widget / gadget toolbar
+     * @param widgetId identifier of the widget / gadget
+     */
+    function styleGadgetButtons(widgetId) {
+        $("#widget-" + widgetId + "-max").button({
+                    text: false,
+                    icons: {
+                        primary: "ui-icon-arrow-4-diag"
+                    }
+                });
+
+        $("#widget-" + widgetId + "-remove").button({
+                    text: false,
+                    icons: {
+                        primary: "ui-icon-close"
+                    }
+                });
+    }
+
+
+    /**
      * Public API
      */
     return {
@@ -269,6 +308,8 @@ var rave = rave || (function() {
          */
         getContext: getContext,
 
+        initGadgetUI : initGadgetUI,
+
 
     	/**
     	 * Change or delete gadget to region map entry.
@@ -286,4 +327,4 @@ var rave = rave || (function() {
 		  toolbarMaximize : toolbar.maximizeAction,
 		  toolbarDelete : toolbar.deleteAction
     }
-})();
\ No newline at end of file
+})();



Mime
View raw message