Author: pbr
Date: 2007-10-23 13:07:24 -0700 (Tue, 23 Oct 2007)
New Revision: 6976

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzContextMenu.js
Log:
Change 20071018-Philip-0 by [EMAIL PROTECTED] on 2007-10-18 20:23:02 EDT
     in /cygdrive/f/laszlo/svn/src/svn/openlaszlo/trunk
     for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Fix context menu for dhtml (to match swf)

New Features:

Bugs Fixed: LPP-4213

Technical Reviewer: max
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
The context menu worked differently in swf and dhtml. In swf, duplicate captions
  are not displayed. I added this behavior to dhtml. swf is only sensitive to 
the
  caption name, and not the method name called.


Tests:
Run the following test in swf and dhtml. When you right click on the canvas you 
should see:

swf
---
   About OpenLaszlo...
   View Source
   My Function
   box4
   box5
   box6
   ------
   Settings
   ------
   About Adobe Flash Player 9...

dhtml
-----
   About OpenLaszlo...
   View Source
   My Function
   box4
   box5
   box6



<canvas debug="true">

   <class name="box">
     <handler name="oninit">
       var cm = canvas.getContextMenu();
       var del = new LzDelegate (this, 'cmHandler');
       cm.addItem(cm.makeMenuItem('My Function', del));
     </handler>

     <method name="cmHandler">
       Debug.write("cmHandler", this);
     </method>
   </class>

   <class name="uniquebox">
     <handler name="oninit">
       var cm = canvas.getContextMenu();
       var del = new LzDelegate (this, 'cmHandler');
       cm.addItem(cm.makeMenuItem(this.id, del));
     </handler>

     <method name="cmHandler">
       Debug.write("cmHandler", this);
     </method>
   </class>

   <handler name="oninit">
     var cm = canvas.getContextMenu();
     var del = new LzDelegate (this, 'cmHandler');
     cm.addItem(cm.makeMenuItem('My Function', del));
   </handler>

   <method name="cmHandler">
     Debug.write("cmHandler", this);
   </method>

   <simplelayout axis="x" spacing="10"/>
   <box width="50" height="50" name="box1" bgcolor="red"/>
   <box width="50" height="50" name="box2" bgcolor="green"/>
   <box width="50" height="50" name="box3" bgcolor="blue"/>
   <uniquebox width="50" height="50" name="box4" bgcolor="red"/>
   <uniquebox width="50" height="50" name="box5" bgcolor="green"/>
   <uniquebox width="50" height="50" name="box6" bgcolor="blue"/> </canvas>



Files:
M      WEB-INF/lps/lfc/kernel/dhtml/LzContextMenu.js

Changeset: http://svn.openlaszlo.org/openlaszlo/patches/20071018-Philip-0.tar



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzContextMenu.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzContextMenu.js      
2007-10-23 20:05:36 UTC (rev 6975)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzContextMenu.js      
2007-10-23 20:07:24 UTC (rev 6976)
@@ -65,9 +65,22 @@
 
     var o = '';
     for (var i = 0; i < this.items.length; i++) {
-        var v = this.items[i].cmenuitem;
+        var cm = this.items[i];
+        var v = cm.cmenuitem;
         if (v.visible != true) continue; 
         if (v.separatorBefore) o += '<br/>';
+
+        // Don't display the same item twice (matches swf behavior)
+        var duplicate = false;
+        for (var j=0; j<i; j++) {
+            if (cm._equals(this.items[j])) {
+              duplicate = true;
+              break;
+            }
+        }
+        if (duplicate)
+            continue;
+
         if (v.enabled) {
             o += '<a 
onmousedown="javascript:LzMouseKernel.__showncontextmenu.__select(' + i + 
');return false;"'
             o +='>' + v.caption + '</a>';
@@ -187,6 +200,13 @@
     }
 }
 
+/** @access private */
+// Must match the behavior of swf (only the caption is matched)
+function _equals (cm) {
+  return (cm != null) && (this.cmenuitem.caption == cm.cmenuitem.caption);
+}
+
+
 /**
   * LzContextMenuItem.setCaption
   * Sets the text string which is displayed for the menu item


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to