-
Notifications
You must be signed in to change notification settings - Fork 2
/
integrierteNavi.js
299 lines (254 loc) · 10.5 KB
/
integrierteNavi.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
"use strict";
(function () {
var customizationDir = '/xcc/rest/public/custom/';
var request = new XMLHttpRequest();
request.open('GET', "".concat(customizationDir, "intNaviConfig.json"));
request.onload = function () {
function callback(config) {
var parentID = config.parentID,
wikiID = config.wikiID,
wikiURL = config.wikiURL,
customIcons = config.customIcons;
var stylesheet = "".concat(customizationDir, "integratedNavi.css");
var replacedIcons = [{
parent: '.help-image',
content: "<style type=\"text/css\">\n\t\t .st0{fill:#FFFFFF;}\n\t\t</style>\n\t\t<path class=\"st0\" d=\"M495.9,336.7c-2.1-7.6-6.9-13.9-13.7-17.8l-50.7-29.2c2-10.8,3.1-21.9,3.1-33.2c0-11.2-1-22.3-3.1-33.2\n\t\t l50.7-29.2c14.1-8.1,18.9-26.2,10.8-40.3l-29.6-51.1c-5.2-9.1-15-14.7-25.5-14.7c-5.1,0-10.2,1.4-14.7,3.9l-50.7,29.2\n\t\t C355.7,106.7,336,95.3,315,87.9V29.5C315,13.2,301.8,0,285.5,0h-59.1C210.2,0,197,13.2,197,29.5v58.5c-20.9,7.3-40.6,18.7-57.5,33.2\n\t\t L88.8,91.9c-4.4-2.6-9.5-3.9-14.7-3.9c-10.5,0-20.3,5.6-25.6,14.7L19,153.8c-8.1,14-3.3,32.1,10.8,40.3l50.7,29.2\n\t\t c-2.1,10.9-3.1,22.1-3.1,33.2c0,11.1,1,22.3,3.1,33.2l-50.7,29.3c-14,8.1-18.9,26.2-10.8,40.2l29.6,51.2c5.2,9,15,14.6,25.6,14.6\n\t\t c5.1,0,10.2-1.4,14.7-3.9l50.7-29.3c16.9,14.5,36.6,25.9,57.5,33.2v58.5c0,16.2,13.2,29.5,29.5,29.5h59.1\n\t\t c16.2,0,29.5-13.2,29.5-29.5V425c20.9-7.3,40.6-18.7,57.5-33.2l50.8,29.3c4.5,2.6,9.5,3.9,14.6,3.9c10.5,0,20.3-5.6,25.5-14.7\n\t\t l29.5-51.2C496.9,352.3,497.9,344.3,495.9,336.7z M256,344.7c-48.7,0-88.3-39.6-88.3-88.2c0-48.6,39.6-88.2,88.3-88.2\n\t\t c48.7,0,88.2,39.6,88.2,88.2C344.3,305.1,304.7,344.7,256,344.7z\"/>",
viewBox: '0 0 512 512'
}];
var target;
var parent = document.getElementById(parentID);
var observer;
var sheet;
function getWikiFeed(url, isJSON, callback) {
var request = new XMLHttpRequest();
request.open('GET', url);
request.onload = function () {
try {
isJSON ? callback(JSON.parse(this.response)) : callback(this.responseXML);
} catch (err) {
callback({});
}
};
request.send();
} // Get
function retrieveUrl(wikiPageId) {
function getCurrentServletUrl(currentServlet) {
// If we are in Communities, we will use /xcc/main
// if we are in on premise, we will cut the url for # (if you got CNX Widgets/RC/AS)
// because the url can something like that: https://dev.cnx.local/xcc/main#myStream/imFollowing/all
// if we are in cloud/global we will cut for ?
if (!currentServlet) {
currentServlet = window.location.href.indexOf('/xcc/') > -1 ? "".concat(window.location.href, "?").split('?')[0].split('#')[0] : '/xcc/main';
}
return currentServlet;
}
getWikiFeed("".concat(wikiURL + wikiID, "/page/").concat(wikiPageId, "/entry"), false, function (xml) {
var content = xml.getElementsByTagName('summary')[0].textContent,
contentLength = content.indexOf("fullpageWidgetId") + 53;
String.prototype.insert = function (index, string) {
if (index > 0) {
return this.substring(0, index) + string + this.substring(index, this.length);
}
return string + this;
};
if (content.indexOf('xcc://') >= 0) {
content = content.replace('xcc://', getCurrentServletUrl());
}
if (content.length > contentLength) {
content = content.insert(contentLength, "&");
}
if (content.length > 0) {
// event.target.href = content;
window.location.href = content;
}
}, false);
return true;
} // Create Navigation from Wikifeed
function createNav(element, wikiData, level) {
var htmlParent = document.createElement('li');
var a = document.createElement('a');
var htmlChildren;
var i;
var el;
var child;
var filterArr;
a.innerHTML = element.label;
a.id = element.id;
a.name = element.label;
a.onmousedown = function (event) {
return retrieveUrl((event.target || event.srcElement).id, event);
};
htmlParent.classList.add('customNavigation');
htmlParent.appendChild(a);
if (element.childSize > 0) {
filterArr = function filterArr(obj) {
return obj.id === el;
};
htmlParent.classList.add('hasChildren');
htmlChildren = document.createElement('ul');
htmlChildren.setAttribute('class', "navLevel-".concat(level));
for (i = 0; i < element.children.length; i += 1) {
el = element.children[i]._reference;
child = wikiData.items.filter(filterArr);
htmlChildren.appendChild(createNav(child[0], wikiData, level + 1));
}
htmlParent.appendChild(htmlChildren);
}
return htmlParent;
} // Add Custom Header Icons
function addCustomIcons() {
var container = document.getElementById(parentID);
customIcons.forEach(function (icon) {
{
var node = document.createElement('A');
var nodeIMG = document.createElement('IMG');
var childMenu;
node.classList.add('headerIcons');
nodeIMG.src = customizationDir + icon.filename;
node.style.order = icon.order;
node.setAttribute('title', icon.title || '');
if (icon.children) {
node.classList.add('navmenu');
childMenu = document.createElement('UL');
childMenu.classList.add('navsimplelist');
icon.children.forEach(function (child) {
var listElement = document.createElement('LI');
listElement.innerHTML = "<a title=\"".concat(child.title || '', "\" href = ").concat(child.href, ">").concat(child.label, "</a>");
childMenu.appendChild(listElement);
});
node.appendChild(childMenu);
} else {
node.href = icon.href;
}
node.appendChild(nodeIMG);
container.appendChild(node);
}
});
} // Replace Existing Header Icons
function replaceIcons() {
var target = document.querySelector('.ics-scbanner');
var observer = new MutationObserver(function () {
replacedIcons.reduce(function (accumulator, currentValue, index) {
var parent = document.querySelector(currentValue.parent);
if (parent) {
changeSVG(parent, currentValue);
return accumulator.splice(index, 1);
}
return accumulator;
}, replacedIcons);
if (!replacedIcons.length) {
observer.disconnect();
}
});
function changeSVG(parent, element) {
parent.setAttribute('viewBox', element.viewBox);
parent.innerHTML = element.content;
}
observer.observe(target, {
attributes: false,
childList: true,
characterData: false,
subtree: false
});
}
function initNavi(container) {
container.classList.add('integrated-navi');
getWikiFeed("".concat(wikiURL + wikiID, "/nav/feed"), true, function (wikiData) {
var tree = wikiData.items.filter(function (obj) {
return obj.id === 'tree';
}); // JSON mit allen (Unter)seiten
var target = document.createElement('UL');
var nav = createNav(tree[0], wikiData, 0);
var nodeList = nav.querySelector('ul').childNodes;
target.classList.add('navLevel-0');
while (nodeList.length) {
target.insertBefore(nodeList[nodeList.length - 1], target.firstChild);
}
container.appendChild(target);
});
addCustomIcons();
replaceIcons();
} // START
sheet = document.createElement('link');
sheet.rel = 'stylesheet';
sheet.type = 'text/css';
sheet.href = stylesheet;
sheet.media = 'all';
document.getElementsByTagName('head')[0].appendChild(sheet);
if (parent) {
initNavi(parent);
} else {
target = document.querySelector('body');
observer = new MutationObserver(function () {
parent = document.getElementById(parentID);
if (parent) {
initNavi(parent);
observer.disconnect();
}
});
observer.observe(target, {
attributes: false,
childList: true,
characterData: false,
subtree: false
});
}
}
try {
var config = JSON.parse(this.response);
callback(config);
} catch (err) {
callback({
parentID: 'nav_bar_include',
wikiID: 'W55e7185d8d53_4911_a6a2_b4e945e264a2',
wikiURL: '/wikis/basic/api/wiki/',
customIcons: [{
name: 'activityStream',
filename: 'stream_white.svg',
title: 'Activity Stream',
href: '/homepage/web/updates/#myStream/imFollowing/all',
order: 360001 // 350000 < order < 400000
}, {
name: 'communities',
title: 'Community',
filename: 'communities_white.svg',
href: '/communities/service/html/mycommunities',
order: 360002
}, {
name: 'files',
filename: 'files_white.svg',
title: 'Files',
href: '/files/app#/',
order: 360003
}, {
name: 'apps',
filename: 'applications_white.svg',
title: 'Applications',
children: [{
name: '',
title: 'Activity Stream',
label: 'Activity Stream',
href: '/activities/service/html/mainpage'
}, {
name: '',
label: 'Besprechungen',
title: 'Besprechungen',
href: '/meetings/sthome'
}, {
name: '',
label: 'Besprechungen organisieren',
title: 'Besprechungen organisieren',
href: '/stmeetings/room/join/access?id=E9531-1290'
}],
order: 360004
}, {
name: 'help',
filename: 'bulb_white.svg',
href: '/communities/service/html/communitystart?communityUuid=bbe69c20-16a4-42fd-b7a1-bccf29f37522',
order: 550001 // > 500000
}]
});
}
};
request.send();
})();