-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.js
78 lines (72 loc) · 2.51 KB
/
loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Loader to add ol.css, ol.js and the example-specific js file to the
* documents.
*
* This loader is used for the hosted examples. It is used in place of the
* development loader (examples/loader.js).
*
* ol.js, ol-simple.js, ol-whitespace.js, and ol-deps.js are built
* by OL3's build.py script. They are located in the ../build/ directory,
* relatively to this script.
*
* The script must be named loader.js.
*
* Usage:
*
* <script src="../loader.js?id=my-demo"></script>
*/
(function() {
var i, pair;
var href = window.location.href, start, end, paramsString, pairs,
pageParams = {};
if (href.indexOf('?') > 0) {
start = href.indexOf('?') + 1;
end = href.indexOf('#') > 0 ? href.indexOf('#') : href.length;
paramsString = href.substring(start, end);
pairs = paramsString.split(/[&;]/);
for (i = 0; i < pairs.length; ++i) {
pair = pairs[i].split('=');
if (pair[0]) {
pageParams[decodeURIComponent(pair[0])] =
decodeURIComponent(pair[1]);
}
}
}
var scripts = document.getElementsByTagName('script');
var src, index, search, chunks, scriptParams = {};
for (i = scripts.length - 1; i >= 0; --i) {
src = scripts[i].getAttribute('src');
if (~(index = src.indexOf('loader.js?'))) {
search = src.substr(index + 10);
chunks = search ? search.split('&') : [];
for (i = chunks.length - 1; i >= 0; --i) {
pair = chunks[i].split('=');
if (pair[0]) {
scriptParams[decodeURIComponent(pair[0])] =
decodeURIComponent(pair[1]);
}
}
break;
}
}
var oljs = 'ol.js', mode;
if ('mode' in pageParams) {
mode = pageParams.mode.toLowerCase();
if (mode == 'debug') {
mode = 'raw';
}
if (mode != 'advanced' && mode != 'raw') {
oljs = 'ol-' + mode + '.js';
}
}
var scriptId = encodeURIComponent(scriptParams.id);
if (mode != 'raw') {
document.write('<scr' + 'ipt type="text/javascript" src="./build/' + oljs + '"></scr' + 'ipt>');
} else {
window.CLOSURE_NO_DEPS = true; // we've got our own deps file
document.write('<scr' + 'ipt type="text/javascript" src="../closure-library/closure/goog/base.js"></scr' + 'ipt>');
document.write('<scr' + 'ipt type="text/javascript" src="../build/ol-deps.js"></scr' + 'ipt>');
document.write('<scr' + 'ipt type="text/javascript" src="' + scriptId + '-require.js"></scr' + 'ipt>');
}
document.write('<scr' + 'ipt type="text/javascript" src="' + scriptId + '.js"></scr' + 'ipt>');
}());