Skip to content
This repository

Fix for #2531093 #25

Closed
wants to merge 2 commits into from

4 participants

andreas.karlsson Eric Ferraiuolo Satyen Desai Ryan Grove
andreas.karlsson

Made _uiAddChild always append the child's bb to the parent node which fixes #2531093
Added a test for the issue.

Eric Ferraiuolo
Owner

@andreas-karlsson could you please sign the YUI CLA?

The CLA ensures that everyone who submits a work of authorship to the YUI Library is contributing work that is their own or for which they can authoritatively speak. This protects the tens of thousands of developers who use YUI in their daily work, all of whom rely on YUI's BSD license to appropriately cover their use of the library.

The CLA does not transfer title or copyright of your contributed work to Yahoo!. It merely guarantees that you approve the use of your work within YUI and by those who use the library under the terms of its license.

Thanks!

andreas.karlsson

Cool, the CLA is signed.

Satyen Desai
Collaborator

Hey Andreas, thanks for the pull request. There are a couple of small changes which I think are worth making:

a) Refactor the method to have a single return (just a readability/maintainability thing).

b) Add a check around the parentNode.appendChild(childBB). We don't want to append a child which already may be added to parentNode in it's correct position.

If you want, I'm happy to make these changes locally since they are pretty small, and give you credit for it, or if you want to send in another pull request I can pull it in.

andreas.karlsson
Satyen Desai
Collaborator

Cool. Fixed locally, with References to this pull request.

andreas.karlsson
Ryan Grove rgrove closed this October 12, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Sep 14, 2011
andreas.karlsson Made _uiAddChild always append the child's bb to the parent node whic…
…h fixes #2531093

Added a test for the issue.
7816d52
andreas.karlsson Fixed some accidental tab indentation c2a0549
This page is out of date. Refresh to see the latest.
22  src/widget-parent/js/Widget-Parent.js
@@ -731,14 +731,20 @@ Parent.prototype = {
731 731
         if (nextSibling && nextSibling.get(RENDERED)) {
732 732
             siblingBB = nextSibling.get(BOUNDING_BOX);
733 733
             siblingBB.insert(childBB, "before");
734  
-        } else {
735  
-            prevSibling = child.previous(false);
736  
-    
737  
-            if (prevSibling && prevSibling.get(RENDERED)) {
738  
-                siblingBB = prevSibling.get(BOUNDING_BOX);
739  
-                siblingBB.insert(childBB, "after");
740  
-            }
741  
-        }        
  734
+            return;
  735
+        }
  736
+        
  737
+        prevSibling = child.previous(false);
  738
+        if (prevSibling && prevSibling.get(RENDERED)) {
  739
+            siblingBB = prevSibling.get(BOUNDING_BOX);
  740
+            siblingBB.insert(childBB, "after");
  741
+            return;
  742
+        }
  743
+        
  744
+        // In all other cases, make sure childBB is contained
  745
+        // by the childrenContainer since it might have been
  746
+        // previously rendered elsewhere
  747
+        parentNode.append(childBB);
742 748
 
743 749
     },
744 750
 
25  src/widget-parent/tests/parent-child.html
@@ -239,6 +239,31 @@
239 239
                     widget.destroy();
240 240
                 },
241 241
 
  242
+                testAddWidgetToEmptyParent : function() {
  243
+                    var widget = new Y.ParentWidget({
  244
+                        id:"widget-1"
  245
+                    });
  246
+                    
  247
+                    widget.render();
  248
+
  249
+                    var child = new Y.ChildWidget({
  250
+                        id:"child-1"
  251
+                    });
  252
+                    
  253
+                    child.render();
  254
+                    
  255
+                    widget.add(child);
  256
+                    
  257
+                    Y.Assert.areEqual(widget.size(1), 1, "expected one child");
  258
+
  259
+                    var renderedChildren = widget.get("contentBox").get("children");
  260
+
  261
+                    Y.Assert.areEqual(renderedChildren.size(), 1, "expected one child node");
  262
+
  263
+                    widget.destroy();
  264
+                    child.destroy();
  265
+                },
  266
+                
242 267
                 testRemove: function () {
243 268
 
244 269
                     var widget = new Y.ParentWidget({
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.