-
Notifications
You must be signed in to change notification settings - Fork 7
/
tracemon-widget-main.js
executable file
·125 lines (106 loc) · 4.76 KB
/
tracemon-widget-main.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
/**
* The location of the widget
*/
TRACEMON_EXTERNAL_WIDGET_URL = (typeof TRACEMON_EXTERNAL_WIDGET_URL == 'undefined') ? "https://massimo.ripe.net/tracemon/widget/" : TRACEMON_EXTERNAL_WIDGET_URL; // Remove this
TRACEMON_WIDGET_URL = ((typeof TRACEMON_EXTERNAL_WIDGET_URL == 'undefined') ? "https://www-static.ripe.net/static/rnd-ui/atlas/static/measurements/widgets/tracemon/" : TRACEMON_EXTERNAL_WIDGET_URL) ;
/**
* Name space configuration
*/
window.atlas = window.atlas || {};
window.atlas._widgets = window.atlas._widgets || {};
window.atlas._widgets.tracemon = window.atlas._widgets.tracemon || {};
window.atlas._widgets.tracemon.urls = window.atlas._widgets.tracemon.urls || {
libs: TRACEMON_WIDGET_URL + "dev/libs/",
env: TRACEMON_WIDGET_URL + "dev/environment/",
connector: TRACEMON_WIDGET_URL + "dev/connector/",
model: TRACEMON_WIDGET_URL + "dev/model/",
view: TRACEMON_WIDGET_URL + "dev/view/",
controller: TRACEMON_WIDGET_URL + "dev/controller/",
session: TRACEMON_WIDGET_URL + "dev/session/"
};
window.atlas._widgets.tracemon.instances = window.atlas._widgets.tracemon.instances || {
requested: [],
running: {},
callback: {}
};
if (!window.atlas._widgets.widgetInjectorRequested) { // Only one injector
window.atlas._widgets.widgetInjectorLoaded = false;
window.atlas._widgets.widgetInjectorRequested = true;
window.atlas._widgets.tracemon.tmp_scripts = document.getElementsByTagName('script');
window.atlas._widgets.tracemon.tmp_scrip = window.atlas._widgets.tracemon.tmp_scripts[window.atlas._widgets.tracemon.tmp_scripts.length - 1];
window.atlas._widgets.injectorScript = document.createElement('script');
window.atlas._widgets.injectorScript.async = false;
window.atlas._widgets.injectorScript.src = window.atlas._widgets.tracemon.urls.libs + 'require.min.js';
window.atlas._widgets.tracemon.tmp_scrip.parentNode.appendChild(window.atlas._widgets.injectorScript);
}
/**
* Widget injector
*/
function initTracemon(domElement, instanceParams, queryParams){
var run;
run = function(){
var instances, instance;
instances = window.atlas._widgets.tracemon.instances;
instance = instances.requested.shift();
while (instance){
(function(instances, instance){
requirejs.config({
waitSeconds: 60
});
if (instance.instanceParams.dev) { // Load dev version
require([TRACEMON_WIDGET_URL + 'tracemon-loader.js'], function(Tracemon){
instances.running[instance.domElement] = Tracemon(instance);
});
} else { // Load released version
var distFile = (instance.instanceParams.onlyCore)
? TRACEMON_WIDGET_URL + 'tracemon-core-dist.js'
: TRACEMON_WIDGET_URL + 'tracemon-dist.js';
require([distFile], function () {
require(['tracemon-loader'], function(Tracemon){
instances.running[instance.domElement] = Tracemon(instance);
});
});
}
})(instances, instance);
instance = instances.requested.shift();
}
};
window.atlas._widgets.tracemon.instances.callback[domElement] = null;
window.atlas._widgets.tracemon.instances.requested
.push({domElement: domElement, instanceParams: instanceParams, queryParams: queryParams, callbacks: {}});
if (document.readyState == 'complete'){
window.atlas._widgets.widgetInjectorLoaded = true;
} else {
function ieLoadBugFix(){
if (!window.atlas._widgets.widgetInjectorLoaded){
if (document.readyState=='loaded' || document.readyState=='complete') {
window.atlas._widgets.injectorScript.onload();
}else {
setTimeout(ieLoadBugFix, 200);
}
}
}
ieLoadBugFix();
}
if (window.atlas._widgets.widgetInjectorLoaded === false){
window.atlas._widgets.injectorScript.onload = function(){
window.atlas._widgets.widgetInjectorLoaded = true;
run();
};
} else {
run();
}
return {
ready: function(callback){
window.atlas._widgets.tracemon.instances.callback[domElement] = callback;
},
shell: function(){
var instance = window.atlas._widgets.tracemon.instances.running[domElement];
if (instance) {
return instance;
} else {
throw "Widget not loaded yet. Try again in a few seconds."
}
}
};
}