Do everything on dom:load
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Oct 2009 18:02:57 +0000 (12:02 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sat, 24 Oct 2009 23:57:35 +0000 (17:57 -0600)
imp/js/compose.js

index f1de0af..28ddccb 100644 (file)
@@ -399,21 +399,27 @@ var ImpCompose = {
                 }
             }
         }
+
+        document.observe('click', this.clickHandler.bindAsEventListener(this));
+        document.observe('change', this.changeHandler.bindAsEventListener(this));
+
+        this.resize();
     },
 
-    onLoad: function()
+    resize: function()
     {
         var d, e = this.redirect ? $('redirect') : $('compose');
 
         if (this.popup && !this.reloaded) {
+            e = e.getHeight();
+            if (!e) {
+                return this.resize.bind(this).defer();
+            }
             d = Math.min(e.getHeight(), screen.height - 100) - document.viewport.getHeight();
             if (d > 0) {
                 window.resizeBy(0, d);
             }
         }
-
-        document.observe('click', this.clickHandler.bindAsEventListener(this));
-        document.observe('change', this.changeHandler.bindAsEventListener(this));
     },
 
     onBeforeUnload: function()
@@ -427,7 +433,6 @@ var ImpCompose = {
 
 /* Code to run on window load. */
 document.observe('dom:loaded', ImpCompose.onDomLoad.bind(ImpCompose));
-Event.observe(window, 'load', ImpCompose.onLoad.bind(ImpCompose));
 
 /* Warn before closing the window. */
 Event.observe(window, 'beforeunload', ImpCompose.onBeforeUnload.bind(ImpCompose));