Author: jmorliaguet
Date: Sun Dec 25 19:05:23 2005
New Revision: 2078

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
Log:

- simpler code using prototype.js' Position.within(node, x, y)

- the menu width is evaluated when the menu is created.



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 Dec 25 
19:05:23 2005
@@ -102,6 +102,7 @@
 
   initialize: function(menu, area, actions, options) {
     this.menu = menu;
+    this.area = area;
     this.menunode = $(menu);
     this.actions = actions;
     this.setOptions(options || {});
@@ -112,26 +113,30 @@
     this.browseEvent = this.browse.bindAsEventListener(this);
     this.clickEvent = this.click.bindAsEventListener(this);
 
-    var area = area || document;
-    Event.observe(area, 'click', this.clickEvent);
+    Event.observe(document, 'click', this.clickEvent);
+    Event.observe(this.menunode, 'mouseover', this.browseEvent);
   },
 
   setOptions: function(options) {
     this.options = Object.extend({
-      width:    120,
       maxwidth: 250
     }, options || {});
   },
 
   click: function(e) {
-    var node = Event.element(e);
+    var  node = Event.element(e);
     if (this.active) {
-      this.call(node);
       this.hide();
+      if (Position.within($(this.menunode), x, y)) {
+        this.call(node);
+      }
     } else {
-      this.selected = this.getIdentifiableElement(node);
-      Event.observe(this.menunode, 'mouseover', this.browseEvent);
-      this.show(e);
+      this.selected = Identifiable.getIdentifiable(node);
+      var x = Event.pointerX(e);
+      var y = Event.pointerY(e);
+      if (Position.within($(this.area), x, y)) {
+        this.show(x, y);
+      }
     }
   },
 
@@ -139,7 +144,7 @@
     node = Event.element(e);
     if (Element.hasClassName(node, 'submenu')) {
       this.submenunode = document.getElementsByClassName('items', node)[0];
-      var xpos = this.options.width -5;
+      var xpos = Element.getDimensions(this.menunode)['width'] -5;
       if (!document.all)
         xpos += parseInt(this.menunode.style.left);
       Element.setStyle(this.submenunode, 'left', xpos + 'px');
@@ -149,7 +154,7 @@
 
   call: function(item) {
     if (!item) { return; }
-    var action = item.getAttribute('id');
+    var action = item.getAttribute('action');
     if (!action) { return; }
     var confirm = item.getAttribute("confirm");
     if (confirm) {
@@ -163,26 +168,23 @@
 
   hide: function() {
     Element.hide(this.menunode);
-    Event.stopObserving(this.menunode, 'mouseover', this.browseEvent);
     this.active = false;
   },
 
-  show: function(e) {
+  show: function(x, y) {
     var menunode = this.menunode;
     var dimensions = Element.getDimensions(menunode);
     var menuWidth = dimensions['width'];
     var menuHeight = dimensions['height'];
     var page_w = window.innerWidth || document.body.clientWidth;
     var page_h = window.innerHeight || document.body.clientHeight;
-    var x = Event.pointerX(e);
-    var y = Event.pointerY(e);
 
     var menuX = (x + menuWidth > page_w) ? x - menuWidth -1 : x + 1;
     var menuY = (y + menuHeight > page_h) ? y - menuHeight -1 : y + 1;
     menunode.style.left = menuX + 'px';
     menunode.style.top =  menuY + 'px';
 
-    var width = this.options.width;
+    var width = this.width;
     if (menuWidth >= this.options.maxwidth) {
       width = this.options.maxwidth;
     }
@@ -199,9 +201,9 @@
     if (!selected) { return; }
 
     if (!node.getAttribute) { return; }
-    var actionid = node.getAttribute("id");
-    if (actionid && actionid != this.menu) {
-      var action_info = this.actions[actionid];
+    var action = node.getAttribute(action);
+    if (action && action != this.menu) {
+      var action_info = this.actions[action];
 
       var visible = true;
       var visibility = action_info['visibility'];
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to