cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: rev 36594 - cocoon/trunk/src/blocks/forms/samples/resources
Date Thu, 19 Aug 2004 07:28:49 GMT
Author: bruno
Date: Thu Aug 19 00:28:48 2004
New Revision: 36594

Modified:
   cocoon/trunk/src/blocks/forms/samples/resources/forms-lib.js
   cocoon/trunk/src/blocks/forms/samples/resources/forms-page-styling.xsl
Log:
tabbed layout: added the possibility to have some javascript executed
when a tabbed page gets shown.


Modified: cocoon/trunk/src/blocks/forms/samples/resources/forms-lib.js
==============================================================================
--- cocoon/trunk/src/blocks/forms/samples/resources/forms-lib.js	(original)
+++ cocoon/trunk/src/blocks/forms/samples/resources/forms-lib.js	Thu Aug 19 00:28:48 2004
@@ -17,7 +17,7 @@
  * Runtime JavaScript library for Cocoon forms.
  *
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
- * @version CVS $Id: forms-lib.js,v 1.4 2004/05/11 22:50:25 joerg Exp $
+ * @version CVS $Id$
  */
 
 // Handlers that are to be called in the document's "onload" event
@@ -167,6 +167,10 @@
  * @param state (string, optional) name of the input storing the tabgroup state
  */
 function forms_showTab(tabgroup, idx, length, state) {
+    // Change state value
+    if (state.length > 0) {
+        document.forms[0][state].value = idx;
+    }
     for (var i = 0; i < length; i++) {
         // Change tab status (selected/unselected)
         var tab = document.getElementById(tabgroup + "_tab_" + i);
@@ -177,10 +181,13 @@
         var tabitems = document.getElementById(tabgroup + "_items_" + i);
         if (tabitems != null) {
             tabitems.style.display = (i == idx) ? '' : 'none';
+            // execute event handler if any
+            if (i == idx && window.onTabShownHandlers != null) {
+                var onShowHandler = window.onTabShownHandlers[tabgroup][tabgroup + "_items_"
+ i];
+                if (onShowHandler != null) {
+                    eval(onShowHandler);
+                }
+            }
         }
-    }
-    // Change state value
-    if (state.length > 0) {
-        document.forms[0][state].value = idx;
     }
 }

Modified: cocoon/trunk/src/blocks/forms/samples/resources/forms-page-styling.xsl
==============================================================================
--- cocoon/trunk/src/blocks/forms/samples/resources/forms-page-styling.xsl	(original)
+++ cocoon/trunk/src/blocks/forms/samples/resources/forms-page-styling.xsl	Thu Aug 19 00:28:48
2004
@@ -93,6 +93,28 @@
         </div>
       </xsl:for-each>
     </div>
+    <!-- The tabbed elements can have an attribute formsOnShow containing some javascript
to be executed
+         when a tab gets shown. -->
+    <script type="text/javascript">
+      if (window.onTabShownHandlers == undefined)
+        window.onTabShownHandlers = new Object();
+      var currentHandlers = new Object();
+      var initialHandler = null;
+      window.onTabShownHandlers["<xsl:value-of select="$id"/>"] = currentHandlers;
+      <xsl:for-each select="fi:items/fi:*">
+        <xsl:variable name="pos" select="position() - 1"/>
+          <xsl:if test="@formsOnShow">
+            currentHandlers["<xsl:value-of select="concat($id, '_items_', $pos)"/>"]
= "<xsl:value-of select="@formsOnShow"/>";
+            <xsl:if test="$active = $pos">
+               initialHandler = "<xsl:value-of select="@formsOnShow"/>";
+            </xsl:if>
+          </xsl:if>
+      </xsl:for-each>
+      if (initialHandler != null) {
+        eval(initialHandler);
+        initialHandler = null;
+      }
+    </script>
   </xsl:template>
 
   <!--

Mime
View raw message