Index: src/hg/js/hgTracks.js
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/js/hgTracks.js,v
retrieving revision 1.49
retrieving revision 1.50
diff -b -B -U 4 -r1.49 -r1.50
--- src/hg/js/hgTracks.js	29 Dec 2009 20:24:53 -0000	1.49
+++ src/hg/js/hgTracks.js	30 Dec 2009 04:14:21 -0000	1.50
@@ -1286,9 +1286,22 @@
         autoHideSetting = false;
         var obj = imgAreaSelect.data('imgAreaSelect');
         obj.setOptions({autoHide : false, movable: true});
     } else if (cmd == 'viewImg') {
-        window.open(trackImg.attr('src'));
+        // Fetch a new copy of track img and show it to the user in another window. This code assume we have updated
+        // remote cart with all relevant chages (e.g. drag-reorder).
+        var data = "hgt.trackImgOnly=1&hgsid=" + getHgsid();
+        jQuery('body').css('cursor', 'wait');
+        $.ajax({
+                   type: "GET",
+                   url: "../cgi-bin/hgTracks",
+                   data: data,
+                   dataType: "html",
+                   trueSuccess: handleViewImg,
+                   success: catchErrorOrDispatch,
+                   cmd: cmd,
+                   cache: false
+               });
     } else if (cmd == 'openLink') {
         // XXXX This is blocked by Safari's popup blocker (without any warning message).
         window.open(selectedMenuItem.href);
     } else {
@@ -1611,4 +1624,21 @@
         }
     }
     jQuery('body').css('cursor', '');
 }
+
+function handleViewImg(response, status)
+{
+    jQuery('body').css('cursor', '');
+    for (var id in trackDbJson) {
+        // Use an arbitrary id to pull out a src from the track image table;
+        // e.g.: <IMG id='img_data_knownGene' src='../trash/hgt/hgt_hgwdev_larrym_479c_abde90.png' ...>
+        var str = "<IMG[^>]*id='img_data_" + id + "'[^>]*src='([^']+)'";
+        var reg = new RegExp(str);
+        a = reg.exec(response);
+        if(a && a[1]) {
+            window.open(a[1]);
+            return;
+        }
+    }
+    showWarning("Couldn't parse out img src");
+}

