51ec1e9ef959b36f6ca590f7adf4516d954af846 larrym Thu Aug 25 13:41:07 2011 -0700 fixup coordinates in external links when position is changed diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js index 2c71365..bebd6da 100644 --- src/hg/js/hgTracks.js +++ src/hg/js/hgTracks.js @@ -154,46 +154,81 @@ $(dirty).val('true'); } function isDirtyPage() { // 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; } +function linkFixup(pos, name, reg, endParamName) +{ +// fixup external links (e.g. ensembl) + if($('#' + name).length) { + var link = $('#' + name).attr('href'); + var a = reg.exec(link); + if(a && a[1]) { + $('#' + name).attr('href', a[1] + pos.start + "&" + endParamName + "=" + pos.end); + } + } +} + function setPosition(position, size) { // Set value of position and size (in hiddens and input elements). // We assume size has already been commified. // Either position or size may be null. if(position) { // There are multiple tags with name == "position" (one in TrackHeaderForm and another in TrackForm). var tags = document.getElementsByName("position"); for (var i = 0; i < tags.length; i++) { var ele = tags[i]; ele.value = position; } } if(size) { $('#size').text(size); } + var pos = parsePosition(position); + if(pos) { + // fixup external static links on page' + + // Example ensembl link: http://www.ensembl.org/Homo_sapiens/contigview?chr=21&start=33031934&end=33041241 + linkFixup(pos, "ensemblLink", new RegExp("(.+start=)[0-9]+"), "end"); + + // Example NCBI link: http://www.ncbi.nlm.nih.gov/mapview/maps.cgi?taxid=9606&CHR=21&BEG=33031934&END=33041241 + linkFixup(pos, "ncbiLink", new RegExp("(.+BEG=)[0-9]+"), "END"); + + // Example medaka link: http://utgenome.org/medakabrowser_ens_jump.php?revision=version1.0&chr=chromosome18&start=14435198&end=14444829 + linkFixup(pos, "medakaLink", new RegExp("(.+start=)[0-9]+"), "end"); + + if($('#wormbaseLink').length) { + // e.g. http://www.wormbase.org/db/gb2/gbrowse/c_elegans?name=II:14646301-14667800 + var link = $('#wormbaseLink').attr('href'); + var reg = new RegExp("(.+:)[0-9]+"); + var a = reg.exec(link); + if(a && a[1]) { + $('#wormbaseLink').attr('href', a[1] + pos.start + "-" + pos.end); + } + } + } markAsDirtyPage(); } function checkPosition(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; var rightX = hgTracks.revCmplDisp ? imgOfs.left + imgWidth - hgTracks.insideX + slop : imgOfs.left + imgWidth + slop;