Author: jmorliaguet
Date: Sun Jan  1 23:00:32 2006
New Revision: 2112

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
Log:

- more robust submenus



Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Jan  1 
23:00:32 2006
@@ -325,8 +325,16 @@
   },
 
   _getSubmenu: function(e) {
-    var nodes = document.getElementsByClassName("submenu", Event.element(e))
-    return (nodes.length > 0) ? nodes[0] : null;
+    var start = Event.element(e);
+    if (!start) return null;
+    var nodes = start.childNodes;
+    for (var i=0;i<nodes.length;i++) {
+      var node = nodes[i]; 
+      if (node.nodeType != 1) continue;
+      if (!Element.hasClassName(node, "submenu")) continue;
+      return node;
+    }
+    return null;
   },
 
   show: function(x, y) {
@@ -353,7 +361,7 @@
       v.parentNode.removeChild(v);
     });
 
-    this._drawNode(widget, view);
+    this._renderNode(widget, view);
 
     new CPSSkins.Effect(widget, {
       action: function(value) {
@@ -366,7 +374,7 @@
 
   },
 
-  _drawNode: function(container, fragment) {
+  _renderNode: function(container, fragment) {
     var data = Canvas.getNodeData(this.selected);
     var tags = fragment.childNodes;
 
@@ -443,22 +451,21 @@
 
           var mouseOverEvent = function(e) {
             var menu = this._getSubmenu(e);
-            if (menu) {
-
-              new CPSSkins.Effect(menu, {
-                action: function(value) {
-                  Canvas.setOpacity(menu, value);
-                },
-                onComplete: function() {
-                  Element.show(menu);
-                }
-              });
-            }
+            if (!menu) return;
+            new CPSSkins.Effect(menu, {
+              action: function(value) {
+                Canvas.setOpacity(menu, value);
+              },
+              onComplete: function() {
+                Element.show(menu);
+              }
+            });
           }.bindAsEventListener(this);
           Event.observe(item, "mouseover", mouseOverEvent);
 
           var mouseOutEvent = function(e) {
             var menu = this._getSubmenu(e);
+            if (!menu) return;
             if (!Position.within(menu, Event.pointerX(e), Event.pointerY(e))) {
               new CPSSkins.Effect(menu, {
                 action: function(value) {
@@ -472,7 +479,7 @@
           }.bindAsEventListener(this);
           Event.observe(item, "mouseout", mouseOutEvent);
 
-          this._drawNode(submenu, tag);
+          this._renderNode(submenu, tag);
 
           break;
         };

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
  (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
  Sun Jan  1 23:00:32 2006
@@ -20,7 +20,8 @@
 
   <div style="float: left; margin: 1em">
 
-    <!-- Contextual menu widget -->
+    <!-- View: contextual menu widget -->
+
     <cpsskins:contextmenu controller="controller">
       <item label="Edit" icon="edit.png" action="edit"
             visible="editable"></item>
@@ -37,10 +38,17 @@
         </submenu>
       </submenu>
 
+      <submenu label="Size" visible="sizable">
+        <items action="size" choices="sizes"></items>
+      </submenu>
+
       <item label="Delete" icon="delete.png" action="delete"
             visible="editable" confirm="Deleting, are you sure?"></item>
     </cpsskins:contextmenu>
 
+
+    <!-- Model: data provider -->
+
     <!-- json-data: {"copyable":true} -->
     <div id="area1" class="pad">area1</div>
 
@@ -56,7 +64,8 @@
     <div id="area3" class="pad">area3</div>
 
     <!-- json-data:
-    {"formattable":true,
+    {"editable":true,
+     "formattable":true,
      "formats":[
       {"choice":"style","label":"Style"},
       {"choice":"widget","label":"Widget"},
@@ -66,7 +75,8 @@
      "sizes":[
       {"choice":"small","label":"Small"},
       {"choice":"medium","label":"Medium"},
-      {"choice":"large","label":"Large"}
+      {"choice":"large","label":"Large"},
+      {"choice":"x-large","label":"Extra large"}
      ]}
     -->
     <div id="area4" class="pad">area4
@@ -93,6 +103,8 @@
 
   </script>
 
+  <div id="message"></div>
+
 </body>
 
 </html>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to