Skip to content

Commit

Permalink
clean up the bookmark-making code, move the default bookmark function…
Browse files Browse the repository at this point in the history
… inside browser.js, making for less code in the index.html file
  • Loading branch information
rbuels committed Mar 5, 2012
1 parent 1855158 commit d004c90
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
12 changes: 2 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@

<script type="text/javascript">
/* <![CDATA[ */
var queryParams = dojo.queryToObject(window.location.search.slice(1));
var bookmarkCallback = function(brwsr) {
return window.location.protocol
+ "//" + window.location.host
+ window.location.pathname
+ "?loc=" + brwsr.visibleRegion()
+ "&tracks=" + brwsr.visibleTracks();
}

var queryParams = dojo.queryToObject( window.location.search.slice(1) );
var dataRoot = queryParams.data || 'data';
var b = new Browser({
containerID: "GenomeBrowser",
Expand All @@ -60,9 +52,9 @@
],
nameUrl: dataRoot + "/names/root.json",
defaultTracks: "DNA,gene,mRNA,noncodingRNA",
queryParams: queryParams,
location: queryParams.loc,
tracks: queryParams.tracks,
bookmark: bookmarkCallback,
show_nav: queryParams.nav,
show_tracklist: queryParams.tracklist,
show_overview: queryParams.overview
Expand Down
75 changes: 46 additions & 29 deletions js/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,14 @@ var Browser = function(params) {
brwsr.container.genomeBrowser = brwsr;
var topPane = document.createElement("div");
brwsr.container.appendChild(topPane);

var overview = document.createElement("div");
overview.className = "overview";
overview.id = "overview";

// controls blue shading in red box
// overview=0 hides the overview, but we still need it to exist
if( params.show_overview == 0 ) overview.style.cssText = "display: none";
topPane.appendChild(overview);

// overview=0 hides overview
if( params.show_overview == 0 ) {
overview.style.cssText="display: none";
};

//try to come up with a good estimate of how big the location box
//actually has to be
var maxBase = 100000000;
Expand Down Expand Up @@ -542,30 +538,51 @@ Browser.prototype.visibleTracks = function() {
return trackLabels.join(",");
};

Browser.prototype.bkmrk = function (params, area) {
var brwsr = this;
if (!this.isInitialized) {
this.deferredFunctions.push(function() { brwsr.bkmrk(params, area); });
Browser.prototype.makeBookmarkLink = function (area) {
// don't make the link if we were explicitly passed a 'bookmark'
// param of 'false'
if( typeof this.params.bookmark != 'undefined' && !this.params.bookmark )
return;
}

if (params.bookmark) {
this.link = document.createElement("a");
if ((params.show_nav != 0) && (params.show_tracklist != 0) && (params.show_overview != 0)) {
this.link.appendChild(document.createTextNode("Link"));
} else {
this.link.appendChild(document.createTextNode("Fullview"));
// if a function was not passed, make a default bookmarking function
if( typeof this.params.bookmark != 'function' )
this.params.bookmark = function( browser_obj ) {
return "".concat(
window.location.protocol,
"//",
window.location.host,
window.location.pathname,
"?",
dojo.objectToQuery({
loc: browser_obj.visibleRegion(),
tracks: browser_obj.visibleTracks(),
data: browser_obj.params.queryParams.data
})
);
};
this.link.href = window.location.href;
dojo.connect(this, "onCoarseMove", function() {
brwsr.link.href = params.bookmark(brwsr);
});
dojo.connect(this, "onVisibleTracksChanged", function() {
brwsr.link.href = params.bookmark(brwsr);
});
this.link.style.cssText = "float: right; clear";
area.appendChild(this.link);
}

// make the bookmark link
this.link = document.createElement("a");
this.link.href = window.location.href;
this.link.appendChild(
document.createTextNode(
this.params.show_nav == 0 || this.params.show_tracklist == 0 || this.params.show_overview == 0
? "Full view"
: "Link"
)
);
this.link.style.cssText = "float: right; clear: both;";

// put it in the DOM
area.appendChild(this.link);

// connect moving events to update it
var update_bookmark = function() {
this.link.href = this.params.bookmark.call( this, this );
};
dojo.connect( this, "onCoarseMove", update_bookmark, this );
dojo.connect( this, "onVisibleTracksChanged", update_bookmark, this );

};

/**
Expand Down Expand Up @@ -615,7 +632,7 @@ Browser.prototype.createNavBox = function(parent, locLength, params) {
navbox.id = "navbox";
parent.appendChild(navbox);
navbox.style.cssText = "text-align: center; padding: 2px; z-index: 10;";
brwsr.bkmrk(params, navbox);
brwsr.makeBookmarkLink( navbox );

var moveLeft = document.createElement("input");
moveLeft.type = "image";
Expand Down

0 comments on commit d004c90

Please sign in to comment.