e25c65911f8d384574f9ebb8178956a6af671a96
tdreszer
  Fri May 16 13:27:57 2014 -0700
Fixed setTimeout (thanks Angie) and retooled where the output of a bug that was fixed yesterday was relied upon downstream.
diff --git src/hg/js/ddcl.js src/hg/js/ddcl.js
index ced070e..5d93020 100644
--- src/hg/js/ddcl.js
+++ src/hg/js/ddcl.js
@@ -161,40 +161,46 @@
     },
 
     reinit: function (filterBys,force) {
         // ReInitialize the DDCLs (drop-down checkbox-list)
         // This is done when the track search with tabs gets switched to advanced tab
         // because the DDCLs were setup on hidden filterBys and dimensiuons are wrong.
         // if not force, then only reinit when the dimensions are suspect
 
         if (filterBys.length < 1)
             return;
 
         $(filterBys).each( function(i) { // Do this by 'each' to set noneIsAll individually
             var multiSelect = this;
             if (!force) { // condition on bad dimensions
                 var id = $(multiSelect).attr('id');
-                control = normed($('#ddcl-' + id));
-                if (!control)
-                    return;                            // This is being called before normal init
+                var control = normed($('#ddcl-' + id));
+                if (!control) {
+                    // Object never initialized so do it now.
+                    //$(multiSelect).show(); // necessary to get dimensions
+                    ddcl.setup(multiSelect,'noneIsAll');
+                } else {
+                    // This is being called before normal init
                     var controlSelector = $(control).find(".ui-dropdownchecklist-selector");
-                if ($(controlSelector).width() > 20)
-                    return;  // Dimensions look okay
-            }
+                    if ($(controlSelector).width() <= 20) {
+                        // Initialized before fully visible so do it again.
                         $(multiSelect).dropdownchecklist("destroy");
                         $(multiSelect).show(); // necessary to get dimensions
                         ddcl.setup(multiSelect,'noneIsAll');
+                    } // else dimensions look okay
+                }
+            }
         });
     },
 
     setup: function (obj) {
         // Initialize the multiselect as a DDCL (drop-down checkbox-list)
         //mySelf = this; // There is no need for a "mySelf" unless this object is being instantiated
 
         // Defaults
         var myFirstIsAll = true;
         var myNoneIsAll  = false;
         var myIcon       = null;
         var myEmptyText  = 'Select...';
         var myClose      = 'close&nbsp;&nbsp;';
         var myDropHeight = filterByMaxHeight(obj);
         // parse optional args
@@ -217,34 +223,39 @@
             }
         }
         if (myFirstIsAll === false)
             myNoneIsAll  = false;
 
         // Make sure there is an id!
         var id = $(obj).attr('id');
         if (!id || id.length === 0) {
             var name = $(obj).attr('name');
             if (name && name.length > 0)
                 id = 'dd-' + name;
             else {
                 id = 'ix' +  $('select').index(obj);
             }
             $(obj).attr('id',id);
+        } else {
+            if (normed($('#ddcl-' + id)))    // Don't set up twice!
+                return;
         }
 
         // These values can only be taken from the select before it becomes a DDCL
         var maxWidth = $(obj).width();
+        if (maxWidth === 0) // currently hidden so wait for a reinit();
+            return;
         var minWidth = $(obj).css('min-width');
         if (minWidth && minWidth.length > 0) { // Is a string, so convert and compare
             minWidth = parseInt(minWidth);
             if (maxWidth < minWidth)
                 maxWidth = minWidth;
         }
         maxWidth = (Math.ceil(maxWidth / 10) * 10) + 10; // Makes for more even boxes
         var style = $(obj).attr('style');
 
         // The magic starts here:
         $(obj).dropdownchecklist({
                             firstItemChecksAll: true,
                             noneIsAll: myNoneIsAll,
                             maxDropHeight: myDropHeight,
                             icon: myIcon,
@@ -526,18 +537,18 @@
         });
 
         // If all options except "all" are included then all should nt be excluded
         var excluded = $(filter).children('option.excluded');
         if (excluded.length === 1) {
             var text = $(excluded[0]).text();
             if (text === 'All' || text === 'Any')
                 $(excluded[0]).removeClass('excluded');
         }
         return true;
     }
 };
 
 $(document).ready(function() {
 
-    setTimeout(ddcl.start(),2);  // necessary to delay startup till all selects get ids.
+    setTimeout(ddcl.start,2);  // necessary to delay startup till all selects get ids.
 });