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
|
var ARGUMENT1 = (function(window, undefined) {
var ARGUMENT1 = ARGUMENT1 || {};
function extractHostPortApp(src) {
ARGUMENT1.microserviceId = MICROSERVICE_ID;
ARGUMENT1.pathArray = src.split( '/' );
ARGUMENT1.widgetName = WIDGET_ID;
ARGUMENT1.serviceSeperator = ARGUMENT1.pathArray[ARGUMENT1.pathArray.length - 4];
ARGUMENT1.commonUrl = src.substring(0, src.lastIndexOf("/" + ARGUMENT1.pathArray[ARGUMENT1.pathArray.length - 2]));
ARGUMENT1.recipientDivDataAttrib = 'data-' + ARGUMENT1.widgetName;
ARGUMENT1.controllerName = 'ARGUMENT2';
ARGUMENT1.readyCssFlag = 'ARGUMENT3';
ARGUMENT1.readyCssFlagExpectedValue = '#bada55';
ARGUMENT1.serviceURL = src.substring(0, src.lastIndexOf("/" + ARGUMENT1.serviceSeperator)) + '/portalApi/microservice/proxy/parameter/' + WIDGET_ID;
}
extractHostPortApp(document.getElementsByTagName('script')[0].src);
function loadStylesheet(url) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = url;
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(link, entry);
}
function isCssReady(callback) {
var testElem = document.createElement('span');
testElem.id = ARGUMENT1.readyCssFlag;
testElem.style = 'CSS_ARG1';
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(testElem, entry);
(function poll() {
var node = document.getElementById('css-ready');
var value;
if (window.getComputedStyle) {
value = document.defaultView.getComputedStyle(testElem, null)
.getPropertyValue('color');
}
else if (node.currentStyle) {
value = node.currentStyle.color;
}
if (value && value === 'rgb(186, 218, 85)' || value.toLowerCase() === ARGUMENT1.readyCssFlagExpectedValue) {
callback();
} else {
setTimeout(poll, 500);
}
})();
}
function injectCss(css) {
var style = document.createElement('style');
style.type = 'text/css';
css = css.replace(/\}/g, "}\n");
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(style, entry);
}
function loadScript(url, callback) {
var script = document.createElement('script');
script.src = url;
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(script, entry);
script.onload = script.onreadystatechange = function() {
var rdyState = script.readyState;
if (!rdyState || /complete|loaded/.test(script.readyState)) {
callback();
script.onload = null;
script.onreadystatechange = null;
}
};
}
function loadSupportingFiles(callback) {
callback();
}
function getWidgetParams() {
}
function getWidgetData(widgetUrl, callback) {
var responseData;
try{
jQuery.ajax({
url: widgetUrl,
method: "GET",
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function (result) {
if (result.isOk == false){
}else{
callback(result);
}
}
});
}
catch(e){
}
}
function getMarkupContent(markupLocation, callback){
try{
jQuery.ajax({
url: markupLocation,
method: "GET",
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function (result) {
if (result.isOk == false){
}else{
callback(result);
}
}
});
}
catch(e){
}
}
function renderWidget(data, location, $controllerProvider) {
var div = document.createElement('div');
getMarkupContent(ARGUMENT1.commonUrl + "/markup/" + ARGUMENT1.widgetName, function(div){
location.append(div);
ARGUMENT1.widgetData = data;
app.controllerProvider.register(ARGUMENT1.controllerName, ARGUMENT1.controller);
var mController = angular.element(document.getElementById("widgets"));
mController.scope().activateThis(location);
});
}
function printAllArtifacts(moduleName, controllerName) {
var queue = angular.module(moduleName)._invokeQueue;
for(var i=0;i<queue.length;i++) {
var call = queue[i];
console.log(i + '. ' + call[0] + ' - ' + call[1] + ' - ' + call[2][0]);
}
}
function get(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
loadSupportingFiles(function() {
loadStylesheet(ARGUMENT1.commonUrl + '/' + ARGUMENT1.widgetName + '/style.css');
loadScript(ARGUMENT1.commonUrl + '/' + ARGUMENT1.widgetName + '/controller.js',
function() {
$('['+ ARGUMENT1.recipientDivDataAttrib + ']').each(function() {
var location = jQuery(this);
location.removeAttr(ARGUMENT1.recipientDivDataAttrib);
var id = location.attr(ARGUMENT1.recipientDivDataAttrib);
getWidgetData(ARGUMENT1.serviceURL, function(data) {
isCssReady(function(){
renderWidget(data, location);
});
});
});
}
);
});
return ARGUMENT1;
})(window);
|