This repository was archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAppStarter.js
253 lines (211 loc) · 9.83 KB
/
AppStarter.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
AppStarter = {
/**
* Initialize the application
* // TODO this pg attr is library dependent, should rather be an url or an RDF document body serialized
* @param pointedGraph the initial pointed graph
* @param currentScriptUrl: required to resolve relative paths of other JS files to load
*/
initialize : function(pointedGraph,currentScriptUrl) {
var self = this
console.debug("Initializing with PG=",pointedGraph);
var appBaseUrl = this.getAppBaseUrl(currentScriptUrl);
console.debug("Will use appBaseUrl=",appBaseUrl);
var requireJsUrl = appBaseUrl+"/js/lib/require/require.js"
this.loadScript(requireJsUrl,function() {
self.startRequire(appBaseUrl,pointedGraph);
})
},
/**
* Triggers the dynamic loading of a new JS file
* @param scriptSrc
* @param callback
*/
loadScript: function(scriptSrc, callback) {
var oHead = document.getElementsByTagName('head')[0];
var oScript = document.createElement('script');
oScript.type = 'text/javascript';
oScript.src = scriptSrc;
// Then bind the event to the callback function.
oScript.onreadystatechange = callback; // IE 6 & 7
oScript.onload = callback;
oHead.appendChild(oScript);
},
/**
* The baseUrl is the absolute path of the folder of the app.
* We can't use the html baseUrl to resolve paths because.
*
* @param scriptUrl
* @return baseUrl (doesn't end with a / )
*/
getAppBaseUrl: function(currentScriptUrl) {
if ( currentScriptUrl && currentScriptUrl.indexOf(".js") != -1 && currentScriptUrl.indexOf("/") != -1 ) {
var scriptFolder = currentScriptUrl.substr( 0 , currentScriptUrl.lastIndexOf("/") );
return scriptFolder;
}
else {
throw new Error("Bad or missing scriptUrl attribute: "+currentScriptUrl + " . " +
"It is required to start the app with AppStarter.initialize(pg,currentScriptUrl)." +
"Note currentScriptUrl should at least contain one / so you can use ./AppStarter.js but not AppStarter.js");
}
},
/**
* Start require
* @param appBaseUrl
* @param pg
*/
startRequire: function(appBaseUrl, pointedGraph) {
require.config({
baseUrl: appBaseUrl,
map: {
"*": {
// doesn't work well if declared with "paths"
"less": "js/lib/require/require-less-0.1.1/less"
}
},
paths: {
/*
* RequireJS Plugins
*/
"jsx": "js/lib/require/require-jsx/jsx",
"JSXTransformer": "js/lib/require/require-jsx/JSXTransformer",
/*
* Libs
*/
"jquery": "js/lib/jquery-2.1.0.min",
"react": "js/lib/react-0.8.0",
"reactAddons": "js/lib/react-with-addons-0.8.0",
"underscore":"js/lib/underscore",
"lodash": "js/lib/lodash.underscore",
"rx": "js/lib/rx",
"rxBinding": "js/lib/rx.binding",
"q": "js/lib/q",
"director": "js/lib/director",
"noty": "js/lib//notifications/jquery-noty",
"notyLayout": "js/lib/notifications/layouts/topcenter",
"notyTheme": "js/lib/notifications/themes/default",
// For now we use the link of github js to be able to stay up to date with the rdflib-stample-pg-extension -->
//"rdflib": "https://rawgithub.com/stample/rdflib-pg-extension/master/releases/0.1.0/rdflib-stample-0.1.0",
//"rdflib-pg-extension": "https://rawgithub.com/stample/rdflib-pg-extension/master/releases/0.1.0/rdflib-stample-pg-extension-0.1.0",
"rdflib": "js/lib/rdflib/rdflib-stample-0.1.1",
"rdflib-pg-extension": "js/lib/rdflib/rdflib-stample-pg-extension-0.1.1",
"globalRdfStore": "js/scripts/globalRdfStore",
/*
* Utils
*/
"foafUtils": "js/scripts/foafUtils",
"PGUtils": "js/scripts/PGUtils",
"notify": "js/scripts/notify",
"mixins": "js/scripts/mixins",
"routing": "js/scripts/routing",
"PGReact": "js/scripts/PGReact",
/*
* REACT Components.
*/
"App": "js/scripts/App",
"Window": "js/scripts/windows/Window",
"FoafWindow": "js/scripts/windows/FoafWindow",
"MainSearchBox": "js/scripts/layout/MainSearchBox",
"ContentSpace": "js/scripts/layout/ContentSpace",
"FooterItem": "js/scripts/layout/FooterItem",
/* COMMON */
"Pix": "js/scripts/common/Pix",
"Name": "js/scripts/common/Name",
"Surname": "js/scripts/common/Surname",
"Company": "js/scripts/common/Company",
/* PERSON PROFILE */
"PersonBasicInfo": "js/scripts/person/PersonBasicInfo",
"PersonNotifications": "js/scripts/person/PersonNotifications",
"PersonMessage": "js/scripts/person/PersonMessage",
"PersonMoreInfo": "js/scripts/person/PersonMoreInfo",
"PersonAddress": "js/scripts/person/PersonAddress",
"PersonWebId": "js/scripts/person/PersonWebId",
"PersonEditProfile": "js/scripts/person/PersonEditProfile",
"Person": "js/scripts/person/Person",
/* CONTACTS */
"PersonContactOnProfileBasicInfo": "js/scripts/contacts/PersonContactOnProfileBasicInfo",
"PersonContactOnProfileMoreInfo": "js/scripts/contacts/PersonContactOnProfileMoreInfo",
"PersonContactOnProfileNotifications": "js/scripts/contacts/PersonContactOnProfileNotifications",
"PersonContactOnProfileMessage": "js/scripts/contacts/PersonContactOnProfileMessage",
"PersonContactOnProfilePix": "js/scripts/contacts/PersonContactOnProfilePix",
"PersonContactOnProfile": "js/scripts/contacts/PersonContactOnProfile",
"PersonContactOnProfileJumpWrapper": "js/scripts/contacts/PersonContactOnProfileJumpWrapper",
"PersonContacts": "js/scripts/contacts/PersonContacts",
"SearchBox": "js/scripts/contacts/SearchBox",
/* CONTACT RECOMMENDATION */
"PersonContactsRecommendation": "js/scripts/contacts/contactsRecommendation/PersonContactsRecommendation",
"PersonContactOnRecommendation": "js/scripts/contacts/contactsRecommendation/PersonContactOnRecommendation",
/*
* Static assets
*/
"appImages": "js/scripts/appImages",
"appDefaultValues": "js/scripts/appDefaultValues",
},
shim: {
JSXTransformer: {
exports: "JSXTransformer"
},
"notyLayout": ["jquery", "noty"],
"notyTheme": ["jquery", "noty"],
"noty": {
"deps": ["jquery"],
"exports": "noty"
},
"rdflib-pg-extension": {
"deps": ["rdflib","q","underscore","rx","rxBinding"],
"exports":"$rdf.PG"
},
"foafUtils": {
"exports":"foafUtils"
},
"PGUtils": {
"deps":["rdflib-pg-extension"],
"exports":"PGUtils"
}
}
});
require(
[
"jquery",
"react",
"q",
"globalRdfStore",
"routing",
"jsx!App",
"less!css/base.less",
"notify",
"noty",
"notyLayout",
"notyTheme"
],
function ($, React, Q, globalRdfStore, routing, App, baseLess, notify) {
// Make these variable globals.
window.Q = Q; //TODO: find better way to deal with Q
// Set the bootstrap URL with the initial PG pointer.
// TODO bad !!!
var foafDocURL;
if (pointedGraph) {
foafDocURL = pointedGraph.pointer.uri;
}
else {
//foafDocURL = "http://bblfish.net/people/henry/card#me";
foafDocURL = "https://my-profile.eu/people/deiu/card#me";
//foafDocURL = "http://www-public.it-sudparis.eu/~berger_o/foaf.rdf";
// TODO need to add hash if needed: we do not look for primary topic anymore
//var foafDocURL = "https://my-profile.eu/people/mtita/card";// Not working
//var foafDocURL = "http://presbrey.mit.edu/foaf";
//var foafDocURL = 'https://ameliemelo3.localhost:8443/card';
//var foafDocURL = "https://my-profile.eu/people/tim/card";
//foafDocURL = "https://localhost:8443/2013/backboneFriend4#me";
//foafDocURL = 'https://localhost:8443/2013/testWoAddress';
}
// TODO maybe this should be injected as props???
routeHelper = new RouteHelper();
// Launch the App.
var mainComponent = App({
profileURL:foafDocURL
});
var mountNode = document.getElementById('container');
React.renderComponent(mainComponent,mountNode);
});
}
}