forked from ibm-js/dworklight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequire.js
90 lines (78 loc) · 2.85 KB
/
require.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
//-------------------------------------------------------------------------
// Module: dworklight/require
//-------------------------------------------------------------------------
define([
"module",
"dojo/_base/array",
"dojo/_base/lang",
"dojo/has",
"./sniff",
], function(array, lang, has ) {
//--------------------------------------------------------------------
var MODULE = module.id;
//console.log("Worklight - Env setup");
//--------------------------------------------------------------------
function require(){
//--------------------------------------------------------------------
getHostUrl: function(/*bool*/ fullWebApp) {
// summary:
// Returns the Worklight server URL
// description:
// Note: The worklight server is not defined until after WL.init() has completed!
// fullWebApp: bool
// Returns the fully qualified mobilewebapp url
var F = MODULE+".getHostUrl:";
var host;
if ( has("worklight") ) {
//-- We need to get the app name based on the api
//-- Get the next path segment after ".../api/{appName}/...."
//-- ex: "/api/MyApp/ipad/0/" == "MyApp"
if ( WL.mock ) {
host = "../mobilewebapp/";
} else {
// http://{host}:8080/apps/services/www/Main/mobilewebapp/
host = WL.Client.getAppProperty(WL.AppProperty.APP_SERVICES_URL);
if ( fullWebApp ) {
var appName = WL.Client.getAppProperty(WL.AppProperty.WORKLIGHT_ROOT_URL).match(/\/api\/([^\/]*)\/.*$/)[1];
host += "www/" + appName + "/mobilewebapp/default/";
}
}
} else {
host = "/";
}
//console.debug(F,"Host:",host);
return host;
},
//--------------------------------------------------------------------
require : function( packages, modules, callback) {
// summary:
// Special require loader to retrieve on demand modules from WL mobilewebapp deployment
// description:
// Allows dynamic loading of dojo modules when the package name is not known at
// build or deployment time. It assumes that the package is at the top level of
// the mobilewebapp tree.
// example:
// | wl.require( ["rapp"],
// | ["rapp/investment/InvestmentBijit"],
// | lang.hitch(this, function(InvestmentBijit) {
// | this.widget = new InvestmentBijit({}, "InvestmentViewContent");
// | }
// | ));
var F = MODULE+".require(): ";
var host = null, MODULEs = [];
packages = lang.isArray(packages) ? packages : [packages];
modules = lang.isArray(modules) ? modules : [modules];
//-- WL defined by injected scripts at build time.
host = this.getHostUrl(true);
//-- build up packages array / map
array.forEach(packages, function(MODULE) {
MODULEs.push( {name:MODULE, location:host+MODULE} );
});
//console.log(F,"Loading modules from:",MODULEs );
require({
packages : MODULEs
}, modules, callback);
}
};
return require;
});