Make the order of "elementAppended" slightly more correct in the presence of resizable toolbars
authorPatrick Walton <pwalton@mozilla.com>
Fri, 24 Sep 2010 16:48:03 +0200
changeset 2046 675c99acdf513325fbd200458e51539fe59a660c
parent 2045 195674fd2f938d8a5ceac5c0b3f0fbd779257afb
child 2047 e76cf0e214f1086e605856ac050bc4543dc5e5b6
push id923
push userpwalton@mozilla.com
push dateFri, 24 Sep 2010 14:48:12 +0000
Make the order of "elementAppended" slightly more correct in the presence of resizable toolbars
plugins/supported/appconfig/index.js
--- a/plugins/supported/appconfig/index.js
+++ b/plugins/supported/appconfig/index.js
@@ -332,58 +332,63 @@ var generateGUI = function(catalog, conf
     centerContainer.setAttribute('class', 'center-container');
     var centerAdded = false;
 
     var element = config.element || document.body;
     // Add the 'bespin' class to the element in case it doesn't have this already.
     util.addClass(element, 'bespin');
     element.appendChild(container);
 
-    var elementAppendedQueue = [];
+    try {
+        // this shouldn't be necessary, but it looks like Firefox has an issue
+        // with the box-ordinal-group CSS property
+        ['north', 'west', 'center', 'east', 'south'].forEach(function(place) {
+            var descriptor = config.gui[place];
+            if (!descriptor) {
+                return;
+            }
 
-    // this shouldn't be necessary, but it looks like Firefox has an issue
-    // with the box-ordinal-group CSS property
-    ['north', 'west', 'center', 'east', 'south'].forEach(function(place) {
-        var descriptor = config.gui[place];
-        if (!descriptor) {
-            return;
-        }
+            var component = catalog.getObject(descriptor.component);
+            if (!component) {
+                throw 'Cannot find object ' + descriptor.component +
+                                ' to attach to the Bespin UI';
+            }
 
-        var component = catalog.getObject(descriptor.component);
-        if (!component) {
-            error = 'Cannot find object ' + descriptor.component +
-                            ' to attach to the Bespin UI';
-            console.error(error);
-            pr.reject(error);
-            return;
-        }
+            element = component.element;
+            if (!element) {
+                throw 'Component ' + descriptor.component + ' does not ' +
+                            'have an "element" attribute to attach to the ' +
+                            'Bespin UI';
+            }
+
+            $(element).addClass(place);
 
-        element = component.element;
-        if (!element) {
-            error = 'Component ' + descriptor.component + ' does not have' +
-                          ' an "element" attribute to attach to the Bespin UI';
-            console.error(error);
-            pr.reject(error);
-            return;
-        }
-
-        $(element).addClass(place);
-
-        if (place == 'west' || place == 'east' || place == 'center') {
-            if (!centerAdded) {
-                container.appendChild(centerContainer);
-                centerAdded = true;
+            if (place == 'west' || place == 'east' || place == 'center') {
+                if (!centerAdded) {
+                    container.appendChild(centerContainer);
+                    centerAdded = true;
+                }
+                centerContainer.appendChild(element);
+            } else {
+                container.appendChild(element);
             }
-            centerContainer.appendChild(element);
-        } else {
-            container.appendChild(element);
-        }
+        });
+
+        // Call the "elementAppended" callbacks.
+        ['north', 'west', 'east', 'south', 'center'].forEach(function(place) {
+            var descriptor = config.gui[place];
+            if (!descriptor) {
+                return;
+            }
 
-        // Queue up the "elementAppended" event, if the component has one.
-        if (component.elementAppended != null) {
-            elementAppendedQueue.push(component);
-        }
-    });
+            var component = catalog.getObject(descriptor.component);
+            if (component.elementAppended != null) {
+                component.elementAppended();
+            }
+        });
 
-    _(elementAppendedQueue).invoke('elementAppended');
+        pr.resolve();
+    } catch (e) {
+        console.error(e);
+        pr.reject(e);
+    }
 
-    pr.resolve();
 };