-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeviceStartUp.js
379 lines (320 loc) · 14.3 KB
/
deviceStartUp.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
var _deviceStartUp, _logo, application;
//var tela = null;
var currentLang = "pt";
var templatePatch = "./assets/template/"
var version = "0.0.005";
function bodyLoaded(){
if(_deviceStartUp)return;
_deviceStartUp = new deviceStartUp( onAppReady, onSplashReady ,version );
}
var addPopUpContent =null;
function onSplashReady(){
setRoutes();
var prst = document.getElementById('present')
if(prst)prst.innerHTML = getPresentContentByLang(currentLang);
if(webglAvailable){
_deviceStartUp.loadDependencies();
}else{
//usuário não tem webGl!!.
//mostrar tela informativa
}
}
function onAppReady(){
console.log('onAppReady <<< needs destroy' );
if( typeof lil === "undefined" || lil === null){
setTimeout(onAppReady, 1000 );
return;
}
lil.http.get( templatePatch + currentLang + "/add_popup.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
addPopUpContent = res.data;
createTutorial();
getCalcContent();
createObjectMenu_no();
createObjectMenu_circ();
createObjectMenu_line();
createShowObjectMenu_no();
createShowObjectMenu_circ();
createShowObjectMenu_line();
createShowPopSettings();
createShowPopAjuda();
createWorkMenu();
}
});
tela = new Tela();
};
function getPresentContentByLang(langs){
return langs === "en" ? '<h3>schanpsidee</h3><span>Schanpsidee is a simulator applied to electrostatic content.</span>' :
'<h3>schanpsidee</h3><span>Schanpsidee é um simulador aplicado ao conteúdo eletrostático.</span>'
}
function changeLang(langs){
console.log(langs);
currentLang = langs;
//window.location.href = window.location.host+"/#"+currentLang;
window.location.hash = "#"+currentLang;
window.location.reload();
}
var varPopUpContent = null;
function getCalcContent(){
lil.http.get( templatePatch + currentLang + "/var_popup.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopUpContent = res.data;
createMenu();
}
});
}
function setRoutes() {
if(!window.location.hash){
currentLang = "pt";
setQueryString("pt");
}else{
currentLang = window.location.hash.replace("#","");
currentLang = currentLang !== "pt" && currentLang !== "en" ? "pt" : currentLang;
}
// var searchs = parseQueryString();
// if (searchs.hasOwnProperty("en")) {
// currentLang ="en";
// }else if (searchs.hasOwnProperty("en")) {
// currentLang ="pt";
// }else{
// currentLang = "pt";
// }
// setQueryString(currentLang);
}
function setQueryString(value){
window.location.hash = value;
}
function parseQueryString() {
var str = window.location.search;
var objURL = {};
str.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function ($0, $1, $2, $3) {
objURL[$1] = $3;
}
);
return objURL;
};
// MY LOADER
var varPopTutorial = null;
function createTutorial(){
lil.http.get( templatePatch + currentLang + "/tutorial.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopTutorial = res.data;
}
});
}
var varPopWorkMenu = null;
function createWorkMenu(){
lil.http.get( templatePatch + currentLang + "/work_menu.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopWorkMenu = res.data;
}
});
}
var varPopObjectMenu = null;
function createObjectMenu_no(){
lil.http.get( templatePatch + currentLang + "/menu_type.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopObjectMenu = res.data;
}
});
}
var varPopObjectMenuCirc = null;
function createObjectMenu_circ(){
lil.http.get( templatePatch + currentLang + "/menu_type_circ.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopObjectMenuCirc = res.data;
}
});
}
var varPopObjectMenuLine = null;
function createObjectMenu_line(){
lil.http.get( templatePatch + currentLang + "/menu_type_line.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopObjectMenuLine = res.data;
}
});
}
// for show properties
var varPopShowObjectMenu = null;
function createShowObjectMenu_no(){
lil.http.get( templatePatch + currentLang + "/menu_show_type.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopShowObjectMenu = res.data;
}
});
}
var varPopShowObjectMenuCirc = null;
function createShowObjectMenu_circ(){
lil.http.get( templatePatch + currentLang + "/menu_show_type_circ.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopShowObjectMenuCirc = res.data;
}
});
}
var varPopShowObjectMenuLine = null;
function createShowObjectMenu_line(){
lil.http.get( templatePatch + currentLang + "/menu_show_type_line.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopShowObjectMenuLine = res.data;
}
});
}
var varPopSettings = null;
function createShowPopSettings(){
lil.http.get( templatePatch + currentLang + "/setts.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopSettings = res.data;
}
});
}
var varPopAjuda = null;
function createShowPopAjuda(){
lil.http.get( templatePatch + currentLang + "/ajuda.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
varPopAjuda = res.data;
}
});
}
//_-------------------
function createMenu(){
lil.http.get( templatePatch + currentLang + "/header_menu.html?" + version,{
headers: { "Content-Type": "text" }
}, function(err, res) {
if (err) throw new Error("Cannot perform the request: " + err.status);
if (res.status === 200 || res.status === 0) {
document.getElementsByTagName("header")[0].setAttribute("state", "hide");
setTimeout(showPageSite, 500 ,res.data);
}
});
}
function showPageSite( data ){
document.getElementsByTagName("header")[0].innerHTML = "";
document.getElementsByTagName("header")[0].innerHTML = data;
document.getElementsByTagName("header")[0].setAttribute("state", "menu");
startTutorial();
}
function webglAvailable() {
try {
var canvas = document.createElement("canvas");
return !!window.WebGLRenderingContext && window.CanvasRenderingContext2D &&
(canvas.getContext("webgl") || canvas.getContext("experimental-webgl"));
} catch(e) {
return false;
}
}
deviceStartUp = function ( _onAppReady, _onSplashReady , _version ) {
var onAppReady = _onAppReady;
var onSplashReady = _onSplashReady;
var version = _version;
var deviceDetector = (function ()
{
var ua = navigator.userAgent.toLowerCase();
var detect = (function(s){
if(s===undefined)s=ua;
else ua = s.toLowerCase();
if(/(tv|smartv)/.test(ua))
return 'tv';
else if(/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(ua))
return 'tablet';
else if(/(mobi|ipod|phone|blackberry|opera mini|fennec|minimo|symbian|psp|nintendo ds|archos|skyfire|puffin|blazer|bolt|gobrowser|iris|maemo|semc|teashark|uzard)/.test(ua))
return 'phone';
else if(/(crawl|googlebot|screenshot)/.test(ua))
return 'robo';
else return 'desktop';
});
return{ device:detect(), detect:detect, isMobile:((detect()!='desktop')?true:false), userAgent:ua };
}());
var prepare = function(){ // here can change the page for mobile
var requiresFirst = [ "./vendor/http.js" ,
deviceDetector.device == "phone" ? "./assets/css/phone.css" : "./assets/css/desktop.css" ];
requiresFirst.forEach(function(valu, inde, arr){
arr[inde] = valu + "?" + version;
});
ljs.load( requiresFirst ,function(p){
//onAppReady(getClientData());
onSplashReady();
});
}
var loadDependencies = function(){
var requiresFirst = [ "./vendor/three.js" ];
requiresFirst.forEach(function(valu, inde, arr){
arr[inde] = valu + "?" + version;
});
ljs.load( requiresFirst ,function(p){
loadDependencies2();
});
}
var loadDependencies2=function(){
var requiresFirst = [ "./vendor/Projector.js",
"./vendor/OrbitControls.js",
"./view/resize.js",
"./view/Tela.js",
"./view/Cena3D.js",
"./view/Objetos.js",
"./view/texto.js",
"./view/defines.js",
"./controller/controller.js",
"./model/fisica.js"
];
requiresFirst.forEach(function(valu, inde, arr){
arr[inde] = valu + "?" + version;
});
ljs.load( requiresFirst ,function(p){
onAppReady(getClientData());
});
}
var destroy = function(){
userSelector.destroy();
}
prepare();
var getClientData = function(){ return { device: deviceDetector.device, isMobile: deviceDetector.isMobile }}
return{
clientData: getClientData,
loadDependencies: loadDependencies,
destroy: destroy,
}
}
deviceStartUp.prototype = {
constructor: deviceStartUp,
}
//Other libs... see:
//https://github.com/malko/l.js
!function(t,e){var r=function(t,e){return t instanceof(e||Array)},i=document,n="getElementsByTagName",s="length",a="readyState",c="onreadystatechange",l=i[n]("script"),o=l[l[s]-1],u=o.innerHTML.replace(/^\s+|\s+$/g,"");if(!t.ljs){var f=o.src.match(/checkLoaded/)?1:0,h=i[n]("head")[0]||i.documentElement,d=function(t){var e={};return e.u=t.replace(/#(=)?([^#]*)?/g,function(t,r,i){return e[r?"f":"i"]=i,""}),e},p=function(t,e,r){var n,s=i.createElement(t);r&&(s[a]?s[c]=function(){("loaded"===s[a]||"complete"===s[a])&&(s[c]=null,r())}:s.onload=r);for(n in e)e[n]&&(s[n]=e[n]);h.appendChild(s)},v=function(t,e){if(this.aliases&&this.aliases[t]){var i=this.aliases[t].slice(0);return r(i)||(i=[i]),e&&i.push(e),this.load.apply(this,i)}if(r(t)){for(var n=t[s];n--;)this.load(t[n]);return e&&t.push(e),this.load.apply(this,t)}return t.match(/\.css\b/)?this.loadcss(t,e):this.loadjs(t,e)},y={},m={aliases:{},loadjs:function(t,r){var i=d(t);return t=i.u,y[t]===!0?(r&&r(),this):y[t]!==e?(r&&(y[t]=function(t,e){return function(){t&&t(),e&&e()}}(y[t],r)),this):(y[t]=function(e){return function(){y[t]=!0,e&&e()}}(r),r=function(){y[t]()},p("script",{type:"text/javascript",src:t,id:i.i,onerror:function(t){if(i.f){var e=t.currentTarget;e.parentNode.removeChild(e),p("script",{type:"text/javascript",src:i.f,id:i.i},r)}}},r),this)},loadcss:function(t,e){var r=d(t);return t=r.u,y[t]||p("link",{type:"text/css",rel:"stylesheet",href:t,id:r.i}),y[t]=!0,e&&e(),this},load:function(){var t=arguments,i=t[s];return 1===i&&r(t[0],Function)?(t[0](),this):(v.call(this,t[0],1>=i?e:function(){m.load.apply(m,[].slice.call(t,1))}),this)},addAliases:function(t){for(var e in t)this.aliases[e]=r(t[e])?t[e].slice(0):t[e];return this}};if(f){var g,j,x,A;for(g=0,j=l[s];j>g;g++)(A=l[g].getAttribute("src"))&&(y[A.replace(/#.*$/,"")]=!0);for(x=i[n]("link"),g=0,j=x[s];j>g;g++)("stylesheet"===x[g].rel||"text/css"===x[g].type)&&(y[x[g].getAttribute("href").replace(/#.*$/,"")]=!0)}t.ljs=m}o.src&&u&&p("script",{innerHTML:u})}(window);