MediaWiki:JBrowse.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
var baseUrl = "/jbrowse/JBrowse/";

// 最初にdojo.jsを属性付きで読み込む
var dojoScript  = document.createElement('script');
dojoScript.type = 'text/javascript';
dojoScript.src  = baseUrl+'/src/dojo/dojo.js'
dojoScript.setAttribute("data-dojo-config", "async: 1, baseUrl: baseUrl+'src'");
var css = document.getElementsByTagName( 'link' )[0];
css.parentNode.appendChild(dojoScript, css);

// dojo.jsの読み込み完了後、init.jsを読み込む
dojoScript.onload = function(){
	var initScript  = document.createElement('script');
	initScript.type = 'text/javascript';
	initScript.src  = baseUrl+'/src/JBrowse/init.js';
	dojoScript.parentNode.appendChild(initScript, dojoScript);


	// init.jsの読み込み完了後、初期化を行う
	initScript.onload = function(){
		window.onerror=function(msg){
		    if( document.body )
		        document.body.setAttribute("JSError",msg);
		}

		// puts the main Browser object in this for convenience.  feel
		// free to move it into function scope if you want to keep it
		// out of the global namespace
		var JBrowse;
		require(['JBrowse/Browser', 'dojo/io-query', 'dojo/json' ],
		     function (Browser,ioQuery,JSON) {
		           // the initial configuration of this JBrowse
		           // instance

		           // NOTE: this initial config is the same as any
		           // other JBrowse config in any other file.  this
		           // one just sets defaults from URL query params.
		           // If you are embedding JBrowse in some other app,
		           // you might as well just set this initial config
		           // to something like { include: '../my/dynamic/conf.json' },
		           // or you could put the entire
		           // dynamically-generated JBrowse config here.

		           // parse the query vars in the page URL
		           var queryParams = ioQuery.queryToObject( window.location.search.slice(1) );

		           var config = {
		               containerID:      "GenomeBrowser",
                               sourceUrl:        baseUrl,
                               browserRoot:      baseUrl, 
		               dataRoot:         queryParams.data,
		               queryParams:      queryParams,
		               location:         queryParams.loc,
		               forceTracks:      queryParams.tracks,
		               initialHighlight: queryParams.highlight,
		               show_nav:         queryParams.nav,
		               show_tracklist:   queryParams.tracklist,
		               show_overview:    queryParams.overview,
		               stores: { url: { type: "JBrowse/Store/SeqFeature/FromConfig", features: [] } },
		               makeFullViewURL: function( browser ) {

		                   // the URL for the 'Full view' link
		                   // in embedded mode should be the current
		                   // view URL, except with 'nav', 'tracklist',
		                   // and 'overview' parameters forced to 1.

		                   return browser.makeCurrentViewURL({ nav: 1, tracklist: 1, overview: 1 });
		               },
		               updateBrowserURL: true
		           };

		           //if there is ?addFeatures in the query params,
		           //define a store for data from the URL
		           if( queryParams.addFeatures ) {
		               config.stores.url.features = JSON.parse( queryParams.addFeatures );
		           }

		           // if there is ?addTracks in the query params, add
		           // those track configurations to our initial
		           // configuration
		           if( queryParams.addTracks ) {
		               config.tracks = JSON.parse( queryParams.addTracks );
		           }

		           // if there is ?addStores in the query params, add
		           // those store configurations to our initial
		           // configuration
		           if( queryParams.addStores ) {
		               config.stores = JSON.parse( queryParams.addStores );
		           }
		           // create a JBrowse global variable holding the JBrowse instance
		           JBrowse = new Browser( config );
		});
	}
}