[fusion-commits] r1692 - trunk/lib

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Nov 27 10:41:43 EST 2008


Author: pagameba
Date: 2008-11-27 10:41:43 -0500 (Thu, 27 Nov 2008)
New Revision: 1692

Modified:
   trunk/lib/jxlib.uncompressed.js
Log:
Fixes #173.  Remove recursive calls in eventInMenu, descendantOf and findElement to avoid stack overflow errors when closing menus from a mouse click in deeply nested HTML structures.  This fix will be bundled in jxlib beta 5 which needs to be released in sync with changes to the mapguide templates (for fusion) so I have manually applied the fixes to this version of jxlib for now.

Modified: trunk/lib/jxlib.uncompressed.js
===================================================================
--- trunk/lib/jxlib.uncompressed.js	2008-11-27 14:18:34 UTC (rev 1691)
+++ trunk/lib/jxlib.uncompressed.js	2008-11-27 15:41:43 UTC (rev 1692)
@@ -5895,33 +5895,21 @@
     
     descendantOf: function(node) {
         var parent = $(this.parentNode);
-        if (parent == node) {
-            return true;
-        } else if (!parent || !parent.parentNode) {
-            return null;
-        } else if (parent.parentNode === parent) {
-            return null;
-        } else {
-            return parent.descendantOf(node);
+        while (parent != node && parent && parent.parentNode && parent.parentNode != parent) {
+            parent = $(parent.parentNode);
         }
+        return parent == node;
+
     },
     
     findElement: function(type) {
-        if (this.tagName == type) {
-            return this;
+        var o = this;
+        var tagName = o.tagName;
+        while (o.tagName != type && o && o.parentNode && o.parentNode != o) {
+            o = $(o.parentNode);
         }
-        var parent = $(this.parentNode);
-        if (parent) {
-            if (parent.tagName == type) {
-                return parent;
-            } else if (!parent.parentNode || parent.parentNode == parent) {
-                return null;
-            } else {
-                return parent.findElement(type);
-            }
-        } else {
-            return null;
-        }
+        return o.tagName == type;
+
     }
 } );
 
@@ -9246,7 +9234,7 @@
         this.subDomObj = new Element('ul',{
             'class':'jxMenu'
         });
-        
+        this.subDomObj.store('jxMenu', this);
         this.contentContainer.adopt(this.subDomObj);
         
         /* if options are passed, make a button inside an LI so the
@@ -9305,14 +9293,26 @@
     },
     
     eventInMenu: function(e) {
-        return $(e.target).descendantOf(this.domObj) ||
-               $(e.target).descendantOf(this.subDomObj) ||
-               this.items.some(
-                   function(item) {
-                       return item instanceof Jx.Menu.SubMenu && 
-                              item.eventInMenu(e);
-                   }
-               );
+        var target = $(e.target);
+        if (target.descendantOf(this.domObj) ||
+            target.descendantOf(this.subDomObj)) {
+            return true;
+        } else {
+            var ul = target.findElement('ul');
+            if (ul) {
+                var sm = ul.retrieve('jxSubMenu');
+                if (sm) {
+                    var owner = sm.owner;
+                    while (owner) {
+                        if (owner == this) {
+                            return true;
+                        }
+                        owner = owner.owner;
+                    }
+                }
+            }
+            return false;
+        }
     },
     
     /**
@@ -9334,7 +9334,7 @@
         if (this.button && this.button.domA) {
             this.button.domA.removeClass('jx'+this.button.options.type+'Active');            
         }
-        this.items.each(function(item){item.hide(e);});
+        this.items.each(function(item){item.hide.delay(0,item,e);});
         document.removeEvent('mousedown', this.hideWatcher);
         document.removeEvent('keyup', this.keypressWatcher);
         this.contentContainer.dispose();
@@ -9646,6 +9646,7 @@
         this.subDomObj = new Element('ul', {
             'class':'jxSubMenu'
         });
+        this.subDomObj.store('jxSubMenu', this);
         this.contentContainer.adopt(this.subDomObj);
     },
     /**
@@ -9708,7 +9709,7 @@
             return;
         }
         this.open = false;
-        this.items.each(function(item){item.hide();});
+        this.items.each(function(item){item.hide.delay(0,item);});
         this.contentContainer.dispose();
         this.visibleItem = null;
     },



More information about the fusion-commits mailing list