Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Commit

Permalink
make baseURL a loader constructor option
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed May 16, 2015
1 parent 80c2119 commit 9ae32c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
13 changes: 0 additions & 13 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@

function Module() {}
function Loader(options) {
options = options || {};

if (options.normalize)
this.normalize = options.normalize;
if (options.locate)
this.locate = options.locate;
if (options.fetch)
this.fetch = options.fetch;
if (options.translate)
this.translate = options.translate;
if (options.instantiate)
this.instantiate = options.instantiate;

this._loader = {
loaderObj: this,
loads: [],
Expand Down
47 changes: 24 additions & 23 deletions src/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,34 @@

var System;

function SystemLoader(options) {
Loader.call(this, options || {});
function SystemLoader(baseURL) {
Loader.call(this);

var baseURL;
// Set default baseURL and paths
if (typeof document != 'undefined' && document.getElementsByTagName) {
baseURL = document.baseURI;
if (!baseURL) {
if (typeof document != 'undefined' && document.getElementsByTagName) {
baseURL = document.baseURI;

if (!baseURL) {
var bases = document.getElementsByTagName('base');
baseURL = bases[0] && bases[0].href || window.location.href;
}
if (!baseURL) {
var bases = document.getElementsByTagName('base');
baseURL = bases[0] && bases[0].href || window.location.href;
}

// sanitize out the hash and querystring
baseURL = baseURL.split('#')[0].split('?')[0];
baseURL = baseURL.substr(0, baseURL.lastIndexOf('/') + 1);
}
else if (typeof process != 'undefined' && process.cwd) {
baseURL = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
if (isWindows)
baseURL = baseURL.replace(/\\/g, '/');
}
else if (typeof location != 'undefined') {
baseURL = __global.location.href;
}
else {
throw new TypeError('No environment baseURL');
// sanitize out the hash and querystring
baseURL = baseURL.split('#')[0].split('?')[0];
baseURL = baseURL.substr(0, baseURL.lastIndexOf('/') + 1);
}
else if (typeof process != 'undefined' && process.cwd) {
baseURL = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
if (isWindows)
baseURL = baseURL.replace(/\\/g, '/');
}
else if (typeof location != 'undefined') {
baseURL = __global.location.href;
}
else {
throw new TypeError('No environment baseURL');
}
}

this.baseURL = baseURL;
Expand Down

0 comments on commit 9ae32c4

Please sign in to comment.