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

Commit 4abd53b

Browse files
committed
internal baseURI implementation
1 parent 39a20a3 commit 4abd53b

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/system.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@ var System;
1515
function SystemLoader() {
1616
Loader.call(this);
1717

18+
var baseURI;
19+
// environent baseURI detection
20+
if (typeof document != 'undefined' && document.getElementsByTagName) {
21+
baseURI = document.baseURI;
22+
23+
if (!baseURI) {
24+
var bases = document.getElementsByTagName('base');
25+
baseURI = bases[0] && bases[0].href || window.location.href;
26+
}
27+
28+
// sanitize out the hash and querystring
29+
baseURI = baseURI.split('#')[0].split('?')[0];
30+
baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
31+
}
32+
else if (typeof process != 'undefined' && process.cwd) {
33+
baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
34+
if (isWindows)
35+
baseURI = baseURI.replace(/\\/g, '/');
36+
}
37+
else if (typeof location != 'undefined') {
38+
baseURI = __global.location.href;
39+
}
40+
else {
41+
throw new TypeError('No environment baseURI');
42+
}
43+
1844
this.baseURL = baseURI;
1945
this.paths = {};
2046
}

src/wrapper-start.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,3 @@
5757
}
5858

5959
var URL = __global.URL || URLPolyfill;
60-
61-
var baseURI;
62-
63-
// environent baseURI detection
64-
if (typeof document != 'undefined' && document.getElementsByTagName) {
65-
baseURI = document.baseURI;
66-
67-
if (!baseURI) {
68-
var bases = document.getElementsByTagName('base');
69-
baseURI = bases[0] && bases[0].href || window.location.href;
70-
}
71-
72-
// sanitize out the hash and querystring
73-
baseURI = baseURI.split('#')[0].split('?')[0];
74-
baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
75-
}
76-
else if (typeof process != 'undefined' && process.cwd) {
77-
baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
78-
if (isWindows)
79-
baseURI = baseURI.replace(/\\/g, '/');
80-
}
81-
else if (typeof location != 'undefined') {
82-
baseURI = __global.location.href;
83-
}
84-
else {
85-
throw new TypeError('No environment baseURI');
86-
}

0 commit comments

Comments
 (0)