-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.js
205 lines (178 loc) · 6.71 KB
/
boot.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Copyright (C) 2012-2013 CloudJee, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Don't touch djConfig.locale if the user isn't overriding its behavior via the URL; leave it to system default behavior */
try {
if (location.search.indexOf("dojo.locale=") != -1) {
djConfig.locale = location.search.indexOf("dojo.locale=") + "dojo.locale=".length; // avoid unlocalized variables
djConfig.locale = location.search.substr(djConfig.locale);
if (djConfig.locale.indexOf("&") != -1) {
djConfig.locale = djConfig.locale.substring(0, djConfig.locale.indexOf("&"));
}
} else if (wm.preferredLanguage) {
djConfig.locale = wm.preferredLanguage.toLowerCase(); // wm.language is provided so that developers can override wm.localeString by putting it in config.js
} else if (wm.localeString) {
djConfig.locale = wm.localeString.toLowerCase(); // wm.localeString is added to config.js by FileController.java using the "accept-language" header.
}
} catch(e) {}
wm = window["wm"] || {};
wm.version = '6.7.0.RELEASE';
wm.isMobile = navigator.userAgent.match(/mobile|android/i) || "onorientationchange" in window || navigator.msMaxTouchPoints > 0;
if (location.search.match(/(\?|\&)wmmobile=(.)/)) {
wm.device = location.search.match(/(\?|\&)wmmobile=([^&]*)/)[2] || "desktop";
wm.device = wm.device.replace(/\&.*$/,"");
wm.isFakeMobile = !wm.isMobile && wm.device != "desktop";
wm.isMobile = wm.device != "desktop";
} else {
if (!wm.isMobile) {
wm.device = "desktop";
} else {
wm.device = (window.screen && (window.screen.width > 450 && window.screen.height > 450)) ? "tablet" : "phone";
}
}
var matches = navigator.userAgent.match(/(iphone|ipad).* OS (\d+)/i);
if (matches) {
wm.isIOS = parseInt(matches[2]);
} else {
var matches = navigator.userAgent.match(/Android (2|3|4|5|6|7|8|9)\./);
if (matches) {
wm.isAndroid = Number(matches[1]);
}
if (wm.isAndroid && navigator.userAgent.match(/ CrMo\//)) {
wm.isAndroid = "chrome";
}
}
if (location.search.match(/(\?|\&)wmdevicesize=(\d+)/)) {
wm.deviceSize = location.search.match(/(\?|\&)wmdevicesize=(\d+)/)[2];
}
// loading via append element
wm.createElement = function(inTag, inAttrs) {
var tag = document.createElement(inTag);
for (var i in inAttrs) {
if (!(0)[i])
tag[i] = inAttrs[i];
}
return tag;
};
wm.headAppend = function(inElement) {
var head= document.getElementsByTagName("head")[0];
head.appendChild(inElement);
};
wm.addStyleSheet = function(inPath) {
var link = document.createElement("link");
dojo.attr(link, "rel", "stylesheet");
dojo.attr(link, "href", inPath);
wm.headAppend(link);
};
// loading via document.write
wm.tags = {
js: [ '<scrip', 't type="text/javascript" src="', '', '"></scrip', 't>' ],
css: [ '<link', ' rel="stylesheet" href="', '', '" />' ]
};
wm.writeTag = function(inTag, inUrl) {
inTag[2] = inUrl;
document.write(inTag.join(""));
};
wm.writeJsTag = function(inUrl) {
wm.writeTag(wm.tags.js, inUrl);
};
wm.writeCssTag = function(inUrl) {
wm.writeTag(wm.tags.css, inUrl);
};
// load JS
wm.loadScript = function(inUrl, inPreferHeadLoad) {
// FIXME: FF 3 appears to load script tags appended to head asynchronously
// and potentially after dojo.addOnLoad is fired. Therefore not using this method for FF3.
// NOTE: argh! FF3 requires head mode for files that rely on script tag inspection (EditArea)
if (wm.isMoz && wm.isFF < 3 || inPreferHeadLoad)
wm.headAppend(wm.createElement("script", { type: "text/javascript", src: inUrl }));
else
wm.writeJsTag(inUrl);
};
// start up
wm.showLoading = function() {
var e = wm.createElement("div", {
id: "_wm_loading",
innerHTML: '<div style="position: absolute; top: 40%; left: 40%;"><img alt="loading" style="vertical-align: middle" src="images/loadingThrobber.gif" /> Loading...</div>'
});
e.style.cssText = "position: absolute; zIndex: 100; width: 80%; height: 80%;"
document.body.appendChild(e);
};
// library loading (need Dojo to execute these)
wm.buildLibPath = function(inLib) {
var n = inLib.pop();
return dojo.moduleUrl(inLib.join(".")) + n;
};
wm.loadScripts = function(inUrls) {
dojo.forEach(inUrls, function(url) {
wm.loadScript(url);
});
};
wm.loadLib = function(inLib) {
var split = (inLib || "").split(".");
var tail = split[split.length-1];
if (split[0] == "css") {
split.shift();
wm.writeCssTag(wm.buildLibPath(split) + ".css");
} else if (djConfig.debugBoot && (tail != "manifest")) {
wm.loadScript(wm.buildLibPath(split) + ".js");
} else {
dojo.require(inLib, true);
}
};
wm.loadDojoModules = function(inLib) {
var split = (inLib || "").split(".");
var tail = split[split.length-1];
if (split[0] == "css") {
split.shift();
wm.writeCssTag(wm.buildLibPath(split) + ".css");
} else {
dojo.require(inLib, true);
}
};
wm.loadLibs = function(inLibs) {
dojo.forEach(inLibs, function(l) { if (l) wm.loadLib(l)});
};
wm.registerPaths = function() {
// variable argument list of arrays of parameters to registerModulePath
for (var i=0, a; a=arguments[i]; i++) {
dojo.registerModulePath.apply(dojo, a);
}
}
wm.registerPackage = registerPackage = function() {
// stub
};
/* Load theme before loading page */
if (!djConfig.isDebug) {
wm.writeCssTag(wm.relativeLibPath + "dojo/dijit/themes/tundra/" + (wm.isMobile ? "tmobile.css" : "t.css"));
}
if (window["wmThemeUrl"]) {
wm.writeCssTag(wm.device == "desktop" ? wmThemeUrl : wmThemeUrl.replace(/theme\.css/,"mtheme.css"));
}
(function(){
if (window["wmChromeFramePath"]) return;
// early browser sniff
var n = navigator, ua = n.userAgent, av = n.appVersion;
wm.isMoz = (ua.indexOf("Gecko")>=0 && av.indexOf("WebKit")<0 && av.indexOf("Safari")<0 && av.indexOf("Konqueror")<0);
wm.isFF = parseFloat(ua.split("Firefox/")[1]);
// force cache revalidation in debug mode
// FIXME: test on multiple platforms
if (djConfig.debugBoot) {
wm.headAppend(wm.createElement("meta", { "httpEquiv": "cache-control", content: "must-revalidate" }));
}
// bootstrap dojo
//var d = djConfig.debugBoot ? "dojo/dojo/dojo.js" : "build/dojo.js";
var d = djConfig.debugBoot ? "dojo/dojo/dojo.js" : "dojo/dojo/dojo_build.js";
djConfig.baseUrl = wm.relativeLibPath + "dojo/dojo/";
wm.writeJsTag(wm.relativeLibPath + d);
})();