1 var ConfigAdaptor; if( !ConfigAdaptor ) ConfigAdaptor = {};
  2 
  3 /**
  4  * Configuration adaptor for JBrowse JSON version 1 configuration
  5  * files (formerly known as trackList.json files).
  6  * @class
  7  */
  8 ConfigAdaptor.JB_json_v1 = function() {
  9 };
 10 
 11 ConfigAdaptor.JB_json_v1.prototype.load = function( args ) {
 12     var that = this;
 13     dojo.xhrGet({
 14         url: args.config.url,
 15         handleAs: 'text',
 16         load: function( o ) {
 17             o = that.parse_conf( o, args );
 18             o = that.regularize_conf( o, args );
 19             args.onSuccess.call( args.context || this, o );
 20         },
 21         error: function( i ) {
 22             console.error( ''+i );
 23             if( args.onFailure )
 24                 args.onFailure.call( args.context || this, i);
 25         }
 26     });
 27 };
 28 
 29 /**
 30  * In this adaptor, just evals the conf text to parse the JSON, but
 31  * other conf adaptors might want to inherit and override this.
 32  * @param {String} conf_text the configuration text
 33  * @param {Object} load_args the arguments that were passed to <code>load()</code>
 34  * @returns {Object} the parsed JSON
 35  */
 36 ConfigAdaptor.JB_json_v1.prototype.parse_conf = function( conf_text, load_args ) {
 37     var conf;
 38     return eval( 'conf = ' + conf_text );
 39 };
 40 
 41 /**
 42  * Applies defaults and any other necessary tweaks to the loaded JSON
 43  * configuration.  Called by <code>load()</code> on the JSON
 44  * configuration before it calls the <code>onSuccess</code> callback.
 45  * @param {Object} o the object containing the configuration, which it
 46  *                   modifies in-place
 47  * @param {Object} load_args the arguments that were passed to <code>load()</code>
 48  * @returns the same object it was passed
 49  */
 50 ConfigAdaptor.JB_json_v1.prototype.regularize_conf = function( o, load_args ) {
 51     o.sourceUrl = o.sourceUrl || load_args.config.url;
 52     o.baseUrl   = o.baseUrl || Util.resolveUrl( o.sourceUrl, '.' );
 53     if( ! /\/$/.test( o.baseUrl ) )
 54         o.baseUrl += "/";
 55     return o;
 56 };
 57