02646d7ea3d38d8e6dfd0584894dcf77b334447c
tdreszer
Tue Nov 19 10:57:26 2013 -0800
Adding back-button suppoirt through jquery.history.js API. At this time back-button support is only for position. At all times the image should agree with the cart. This means that moving forward, the image must be stacked in window.History.state and moving back, the image must be refreshed using the old location. Note that full page refreshes complicate the picure. Back-button will recall a client side cached page which may be greatly out of sync with cart. Stretegy is to use image only update, but if all else fails, a full page reload is used. This means, that image only update is preferred going forward. To that end, several previous places that required full page refresh can now be done with image only rtefresh. At this time, anytime the chrom changes, the page will be fully refreshed. Redmine #7473.
diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index e138b69..db5d5d6 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -172,30 +172,31 @@
$('#wormbaseLink').attr('href', a[1] + pos.start + "-" + pos.end);
}
}
// Fixup DNA link; e.g.: hgc?hgsid=2999470&o=114385768&g=getDna&i=mixed&c=chr7&l=114385768&r=114651696&db=panTro2&hgsid=2999470
if($('#dnaLink').length) {
var link = $('#dnaLink').attr('href');
var reg = new RegExp("(.+&o=)[0-9]+.+&db=[^&]+(.*)");
var a = reg.exec(link);
if(a && a[1]) {
var url = a[1] + (pos.start - 1) + "&g=getDna&i=mixed&c=" + pos.chrom;
url += "&l=" + (pos.start - 1) + "&r=" + pos.end + "&db=" + getDb() + a[2];
$('#dnaLink').attr('href', url);
}
}
}
+ if (!imageV2.backSupport)
imageV2.markAsDirtyPage();
},
check: function (img, selection)
{ // return true if user's selection is still w/n the img (including some slop).
var imgWidth = jQuery(img).width();
var imgHeight = jQuery(img).height();
var imgOfs = jQuery(img).offset();
var slop = 10;
// We ignore clicks in the gray tab and track title column
// (we really should suppress all drag activity there,
// but I don't know how to do that with imgAreaSelect).
var leftX = hgTracks.revCmplDisp ? imgOfs.left - slop :
imgOfs.left + hgTracks.insideX - slop;
@@ -495,30 +496,58 @@
imageV2.markAsDirtyPage();
if(arguments.length > 2)
return setTableRowVisibility(button, prefix, "hgtgroup", "group",false,arguments[2]);
else
return setTableRowVisibility(button, prefix, "hgtgroup", "group",false);
},
expandAllGroups: function (newState)
{ // Set visibility of all track groups to newState (true means expanded).
// This code also modifies the corresponding hidden fields and the gif's of the +/- img tag.
imageV2.markAsDirtyPage();
$(".toggleButton[id$='_button']").each( function (i) { // works for old img type AND new BUTTONS_BY_CSS
vis.toggleForGroup(this,this.id.substring(0,this.id.length - 7),newState); // clip '_button' suffix
});
return false;
+ },
+
+ initForAjax: function()
+ { // To better support the back-button, it is good to eliminate extraneous form puts
+ // Towards that end, we support visBoxes making ajax calls to update cart.
+ var sels = $('select.normalText,select.hiddenText');
+ $(sels).change(function() {
+ var track = $(this).attr('name');
+ if ($(this).val() == 'hide') {
+ var rec = hgTracks.trackDb[track];
+ if(rec)
+ rec.visibility = 0;
+ // else Would be nice to hide subtracks as well but that may be overkill
+ $(document.getElementById('tr_' + track)).remove();
+ $(this).attr('class', 'hiddenText');
+ } else
+ $(this).attr('class', 'normalText');
+
+ setCartVar(track,$(this).val());
+ return false;
+ });
+ // Now we can rid the submt of the burden of all those vis boxes
+ var form = $('form#TrackForm');
+ $(form).submit(function () {
+ $('select.normalText,select.hiddenText').attr('disabled',true);
+ });
+ $(form).attr('method','get');
+
}
}
////////////////////////////////////////////////////////////
// dragSelect is also known as dragZoom or shift-dragZoom //
////////////////////////////////////////////////////////////
var dragSelect = {
areaSelector: null, // formerly "imgAreaSelect". jQuery element used for imgAreaSelect
autoHideSetting: true, // Current state of imgAreaSelect autoHide setting
originalCursor: null,
startTime: null,
rulerModeToggle: function (ele) // UNUSED?
{
@@ -620,43 +649,44 @@
jQuery.fn.chromDrag = function(){
this.each(function(){
// Plan:
// mouseDown: determine where in map: convert to img location: pxDown
// mouseMove: flag drag
// mouseUp: if no drag, then create href centered on bpDown loc with current span
// if drag, then create href from bpDown to bpUp
// if ctrlKey then expand selection to containing cytoBand(s)
var img = { top: -1, scrolledTop: -1, height: -1, left: -1, scrolledLeft: -1, width: -1 }; // Image dimensions all in pix
var chr = { name: "", reverse: false, beg: -1, end: -1, size: -1,
top: -1, bottom: -1, left: -1, right: -1, width: -1 }; // chrom Dimenaions beg,end,size in bases, rest in pix
var pxDown = 0; // pix X location of mouseDown
var chrImg = $(this);
var mouseIsDown = false;
var mouseHasMoved = false;
- var hilite = jQuery('
');
+ var hilite = null;
initialize();
function initialize(){
findDimensions();
if(chr.top == -1)
warn("chromIdeo(): failed to register "+this.id);
else {
hiliteSetup();
+ $('area.cytoBand').unbind('mousedown'); // Make sure this is only bound once
$('area.cytoBand').mousedown( function(e)
{ // mousedown on chrom portion of image only (map items)
updateImgOffsets();
pxDown = e.clientX - img.scrolledLeft;
var pxY = e.clientY - img.scrolledTop;
if(mouseIsDown == false
&& isWithin(chr.left,pxDown,chr.right) && isWithin(chr.top,pxY,chr.bottom)) {
mouseIsDown = true;
mouseHasMoved = false;
$(document).bind('mousemove',chromMove);
$(document).bind( 'mouseup', chromUp);
hiliteShow(pxDown,pxDown);
return false;
}
@@ -735,30 +765,35 @@
if(selRange.end > -1) {
// prompt, then submit for new position
selRange = rangeNormalizeToChrom(selRange,chr);
if(mouseHasMoved == false) { // Update highlight by converting bp back to pix
pxDown = convertFromBases(selRange.beg)
pxUp = convertFromBases(selRange.end)
hiliteShow(pxDown,pxUp);
}
//if ((selRange.end - selRange.beg) < 50000)
// dontAsk = true;
if (dontAsk
|| confirm("Jump to new position:\n\n"+chr.name+":"+commify(selRange.beg)+
"-"+commify(selRange.end)+" size:"+commify(selRange.width)) ) {
genomePos.setByCoordinates(chr.name, selRange.beg, selRange.end)
$('area.cytoBand').mousedown( function(e) { return false; }); // Stop the presses :0)
+ if (imageV2.backSupport) {
+ imageV2.navigateInPlace("position=" +
+ encodeURIComponent(genomePos.get().replace(/,/g,'')), null, true);
+ hiliteCancel();
+ } else
document.TrackHeaderForm.submit();
return true; // Make sure the setTimeout below is not called.
}
}
}
//else warn("chromIdeo("+chr.name+") NOT WITHIN VERTICAL RANGE\n selected range (pix):"+pxDown+"-"+pxUp+" chrom range (pix):"+chr.left+"-"+chr.right+"\n cytoTop-Bottom:"+chr.top +"-"+chr.bottom);
hiliteCancel();
setTimeout('posting.allowMapClicks();',50);
}
mouseIsDown = false;
mouseHasMoved = false;
}
function isWithin(beg,here,end)
{ // Simple utility
@@ -898,34 +933,37 @@
begX = down + img.left;
wide = (cur - down);
}
$(hilite).css({ left: begX + 'px', width: wide + 'px', top: topY + 'px',
height: high + 'px', display:'' });
$(hilite).show();
}
function hiliteCancel(left,width,top,height)
{ // Called on mouseup: Make green drag hilite disappear when no longer wanted
$(hilite).hide();
$(hilite).css({ left: '0px', width: '0px', top: '0px', height: '0px' });
}
function hiliteSetup()
{ // Called on init: setup of drag region hilite (but don't show yet)
+ if (hilite == null) { // setup only once
+ hilite = jQuery("");
$(hilite).css({ backgroundColor: 'green', opacity: 0.4, borderStyle: 'solid',
borderWidth: '1px', bordercolor: '#0000FF' });
$(hilite).css({ display: 'none', position: 'absolute', overflow: 'hidden', zIndex: 1 });
jQuery($(chrImg).parents('body')).append($(hilite));
+ }
return hilite;
}
function updateImgOffsets()
{ // Called on mousedown: Gets the current offsets
var offs = $(chrImg).offset();
img.top = Math.round(offs.top );
img.left = Math.round(offs.left);
img.scrolledTop = img.top - $("body").scrollTop();
img.scrolledLeft = img.left - $("body").scrollLeft();
if($.browser.msie) {
img.height = $(chrImg).outerHeight();
img.width = $(chrImg).outerWidth();
} else {
img.height = $(chrImg).height();
@@ -947,30 +985,64 @@
var values = [];
$("tr.imgOrd").each(function (i) {
if ($(this).attr('abbr') != $(this).attr('rowIndex').toString()) {
$(this).attr('abbr',$(this).attr('rowIndex').toString());
var name = this.id.substring('tr_'.length) + '_imgOrd';
names.push(name);
values.push($(this).attr('abbr'));
}
});
if(names.length > 0) {
setCartVars(names,values);
imageV2.markAsDirtyPage();
}
},
+ sort: function (table)
+ { // Sets the table row order to match the order of the abbr attribute.
+ // This is needed for back-button, and for visBox changes combined with refresh.
+ var tbody = $(table).find('tbody')[0];
+ if(tbody == undefined)
+ tbody = table;
+
+ // Do we need to sort?
+ var trs = tbody.rows;
+ var needToSort = false;
+ $(trs).each(function(ix) {
+ if ($(this).attr('abbr') != $(this).attr('rowIndex').toString()) {
+ needToSort = true;
+ return false; // break for each() loops
+ }
+ });
+ if (!needToSort)
+ return false;
+
+ // Create array of tr holders to sort
+ var ary = new Array();
+ $(trs).each(function(ix) { // using sortTable found in utils.js
+ ary.push(new sortTable.field($(this).attr('abbr'),false,this));
+ });
+
+ // Sort the array
+ ary.sort(sortTable.fieldCmp);
+
+ // most efficient reload of sorted rows I have found
+ var sortedRows = jQuery.map(ary, function(ary, i) { return ary.row; });
+ $(tbody).append( sortedRows ); // removes tr from current position and adds to end.
+ return true;
+ },
+
showCenterLabel: function (tr, show)
{ // Will show or hide centerlabel as requested
// adjust button, sideLabel height, sideLabelOffset and centerlabel display
if (!$(tr).hasClass('clOpt'))
return;
var center = $(tr).find(".sliceDiv.cntrLab");
if($(center) == undefined)
return;
seen = ($(center).css('display') != 'none');
if(show == seen)
return;
var centerHeight = $(center).height();
@@ -2508,36 +2580,43 @@
}
}
///////////////////////////////
//// imageV2 (aka imgTbl) ////
///////////////////////////////
var imageV2 = {
enabled: false, // Will be set to true unless advancedJavascriptFeatures is turned off OR if track search of config page
imgTbl: null, // formerly "trackImgTbl" The imgTbl or null if non-imageV2.
inPlaceUpdate: false, // modified based on value of hgTracks.inPlaceUpdate and mapIsUpdateable
mapIsUpdateable:true,
lastTrack: null, // formerly (lastMapItem) this is used to try to keep what the last track the cursor passed.
markAsDirtyPage: function ()
- { // Page is marked as dirty so that the backbutton can be overridden
+ { // Page is marked as dirty so that the back-button knows page doesn't match cart
var dirty = $('#dirty');
if (dirty != undefined && dirty.length != 0)
$(dirty).val('true');
},
+ markAsCleanPage: function ()
+ { // Clears signal that history may be out of sync with cart.
+ var dirty = $('#dirty');
+ if (dirty != undefined && dirty.length != 0)
+ $(dirty).val('false');
+ },
+
isDirtyPage: function ()
{ // returns true if page was marked as dirty
// This will allow the backbutton to be overridden
var dirty = $('#dirty');
if (dirty != undefined && dirty.length > 0) {
if ($(dirty).val() == 'true')
return true;
}
return false;
},
updateTiming: function (response)
{ // update measureTiming text on current page based on what's in the response
var reg = new RegExp("(.+?)", "g");
@@ -2567,50 +2646,62 @@
},
function (position) {
genomePos.set(position, commify(getSizeFromCoordinates(position)));
});
// Make sure suggestTrack is visible when user chooses something via gene select (#3484).
if($("#suggestTrack").length) {
$(document.TrackForm || document.TrackHeaderForm).submit(function(event) {
if($('#hgFindMatches').length) {
vis.makeTrackVisible($("#suggestTrack").val());
}
});
}
}
},
- afterReload: function ()
+ afterReload: function (id)
{ // Reload various UI widgets after updating imgTbl map.
dragReorder.init();
dragSelect.load(false);
// Do NOT reload context menu (otherwise we get the "context menu sticks" problem).
// rightClick.load($('#tr_' + id));
if(imageV2.imgTbl.tableDnDUpdate)
imageV2.imgTbl.tableDnDUpdate();
rightClick.reloadFloatingItem();
// Turn on drag scrolling.
if(hgTracks.imgBoxPortal) {
$("div.scroller").panImages();
}
+ if (imageV2.backSupport) {
+ if (id) { // The remainder is only needed for full reload
+ imageV2.markAsDirtyPage(); // vis of cfg change
+ return;
+ }
+ }
+
imageV2.loadRemoteTracks();
makeItemsByDrag.load();
- imageV2.markAsDirtyPage();
imageV2.loadSuggestBox();
+
+ if (imageV2.backSupport) {
+ imageV2.setInHistory(false); // Set this new position into History stack
+ } else {
+ imageV2.markAsDirtyPage();
+ }
},
- updateImgForId: function (html, id)
+ updateImgForId: function (html, id, fullImageReload, newJsonRec)
{ // update row in imgTbl for given id.
// return true if we successfully pull slice for id and update it in imgTrack.
var str = "]*>([\\s\\S]+?)
";
var reg = new RegExp(str);
var a = reg.exec(html);
if(a && a[1]) {
var tr = $(document.getElementById("tr_" + id));
if (tr.length > 0) {
$(tr).html(a[1]);
// Need to update tr class list too
str = "";
reg = new RegExp(str);
var classes = reg.exec(html);
if(classes && classes[1] && classes[1].length > 0) {
@@ -2618,36 +2709,113 @@
$(tr).addClass(classes[1]);
}
// NOTE: Want to examine the png? Uncomment:
//var img = $('#tr_' + id).find("img[id^='img_data_']").attr('src');
//warn("Just parsed image:
"+img);
// >1x dragScrolling needs some extra care.
if(hgTracks.imgBoxPortal && (hgTracks.imgBoxWidth > hgTracks.imgBoxPortalWidth)) {
if (hgTracks.imgBoxPortalLeft != undefined) {
$(tr).find('.panImg').css({'left': hgTracks.imgBoxPortalLeft });
$(tr).find('.tdData').css(
{'backgroundPosition': hgTracks.imgBoxPortalLeft});
}
}
+
+ // Need to update vis box (in case this is reached via back-button)
+ if (imageV2.backSupport && fullImageReload) {
+ // Update abbr so that rows can be resorted properly
+ str = "
0) {
+ $(tr).attr('abbr',abbr[1]);
+ }
+
+ if (newJsonRec)
+ vis.update(id, vis.enumOrder[newJsonRec.visibility]);
+ }
+
return true;
}
}
return false;
},
+ updateImgForAllIds: function (response, oldJson, newJson)
+ { // update all rows in imgTbl based upon navigateInPlace response.
+ var imgTbl = $('#imgTbl');
+
+ // We update rows one at a time
+ // (b/c updating the whole imgTbl at one time doesn't work in IE).
+ for (var id in newJson.trackDb) {
+ var newJsonRec = newJson.trackDb[id];
+ var oldJsonRec = oldJson.trackDb[id];
+
+ if (newJsonRec.type == "remote")
+ continue;
+ if (oldJsonRec != undefined && oldJsonRec.visibility != 0) {
+ // New track replacing old:
+ if (!imageV2.updateImgForId(response, id, true, newJsonRec))
+ warn("Couldn't parse out new image for id: " + id);
+ } else { //if (oldJsonRec == undefined || oldJsonRec.visibility == 0)
+ // New track seen for the first time
+ if (imageV2.backSupport) {
+ $(imgTbl).append("
");
+ if (!imageV2.updateImgForId(response, id, true, newJsonRec))
+ warn("Couldn't insert new image for id: " + id);
+ }
+ }
+ }
+ if (imageV2.backSupport) {
+ // Removes OLD: those in oldJson but not in newJson
+ for (var id in oldJson.trackDb) {
+ if(newJson.trackDb[id] == undefined)
+ $(document.getElementById('tr_' + id)).remove();
+ }
+
+ // Need to reorder the rows based upon abbr
+ dragReorder.sort($(imgTbl));
+ }
+ },
+
+ updateChromImg: function (response)
+ { // Parse out new chrom 'ideoGram' (if available)
+ // e.g.:
+ // Larry's regex voodoo:
+ var a = /
]+SRC[^>]+id='chrom'[^>]*)>/.exec(response);
+ if (a && a[1]) {
+ var b = /SRC\s*=\s*"([^")]+)"/.exec(a[1]);
+ if (b && b[1]) {
+ $('#chrom').attr('src', b[1]);
+ // ideoMap? Not needed if the chrom has not changed.
+ //a = /