-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
313 lines (227 loc) · 7.96 KB
/
index.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
/*
* add "active" className to primary nav elements on matching URLs
*/
(function () {
var elements, element, index, length, linkHref, windowHref;
elements = document.querySelectorAll(".q-navigation__item > a");
if (elements) {
length = elements.length;
for (index = 0; index < length; index += 1) {
element = elements[index];
linkHref = element.getAttribute("href");
windowHref = window.location.href;
if (windowHref.match(linkHref)) {
element.classList.add("active");
}
}
}
})();
/*
* handle taps in mobile hamburger menu
*/
(function () {
"use strict";
function handleMenuClick (event) {
var container, menu, menuIcon;
menuIcon = event.currentTarget;
menu = document.querySelector(".q-hamburger-menu__container");
container = document.querySelector(".q-header__background");
if (menuIcon.classList.toggle("active")) {
menu.classList.add("active");
container.classList.add("active");
} else {
menu.classList.remove("active");
container.classList.remove("active");
}
}
function handleMenuItemClick (event) {
event.preventDefault();
var container, menu, menuIcon;
menuIcon = event.currentTarget;
menu = document.querySelector(".q-header__nav-sub");
container = document.querySelector(".q-header__nav");
if (menuIcon.classList.toggle("active")) {
menu.classList.add("active");
container.classList.add("active");
} else {
menu.classList.remove("active");
container.classList.remove("active");
}
return false;
}
/*
* listen for clicks on the "Back to main menu" link
* and remove the active classes form the parent-level menu, icon, and container
*/
function handleBackMenuItemClick (event) {
event.preventDefault();
var container, menu, menuIcon;
menuIcon = document.querySelector(".q-header__nav > li:first-child > a");
menu = document.querySelector(".q-header__nav-sub");
container = document.querySelector(".q-header__nav");
menuIcon.classList.remove("active");
menu.classList.remove("active");
container.classList.remove("active");
return false;
}
function addEventListeners () {
if (hamburgerMenuIcon) {
hamburgerMenuIcon.addEventListener("click", handleMenuClick);
}
if (discussionMenuItem) {
discussionMenuItem.addEventListener("click", handleMenuItemClick);
}
if (backMenuItem) {
backMenuItem.addEventListener("click", handleBackMenuItemClick);
}
}
function removeEventListeners () {
if (hamburgerMenuIcon) {
hamburgerMenuIcon.removeEventListener("click", handleMenuClick);
}
if (discussionMenuItem) {
discussionMenuItem.removeEventListener("click", handleMenuItemClick);
}
if (backMenuItem) {
backMenuItem.removeEventListener("click", handleBackMenuItemClick);
}
}
function handleOrientationChange (mediaQueryList) {
if (mediaQueryList.matches) {
addEventListeners();
} else {
removeEventListeners();
}
}
var backMenuItem, discussionMenuItem, hamburgerMenuIcon, mediaQueryList;
hamburgerMenuIcon = document.querySelector(".q-hamburger-menu__icon");
discussionMenuItem = document.querySelector(".q-header__nav > li:nth-child(2) > a");
backMenuItem = document.querySelector("a.q-header__nav-back");
mediaQueryList = window.matchMedia("(max-width: 40em)");
mediaQueryList.addListener(handleOrientationChange);
handleOrientationChange(mediaQueryList);
})();
/* global Coveo */
document.addEventListener("DOMContentLoaded", function () {
fetch("https://hyppimpgupvx2ofcrsn2yxsg2i0dcmgs.lambda-url.us-east-1.on.aws/")
.then(response => {
if (!response.ok) {
throw new Error("Failed to fetch API key");
}
return response.json();
})
.then(responseData => {
const PUBLIC_API_KEY = responseData;
const searchbox = document.querySelector("#searchbox");
const search = document.querySelector("#search");
Coveo.SearchEndpoint.configureCloudV2Endpoint(
"",
PUBLIC_API_KEY,
"https://platform.cloud.coveo.com/rest/search",
{
queryStringArguments: {
searchHub: "CommunitySearch",
},
}
);
if (search) {
search.addEventListener("newResultDisplayed", hideShowMoreLink);
Coveo.init(search, {
externalComponents: [searchbox],
});
} else {
let searchPageURI = "https://success.qualys.com/support/s/global-search/%40uri";
let options = {
Omnibox: {
placeholder: "Search",
},
};
if (location.pathname.match(/^\/vulnerability-detection-pipeline/)) {
searchPageURI = "https://success.qualys.com/support/s/global-search/%40uri";
options.Omnibox.placeholder = "Search Discussions, Blog Posts, Training, Docs and Support";
}
if (location.pathname.match(/^\/documentation/)) {
searchPageURI = "https://success.qualys.com/support/s/global-search/%40uri#t=Docs";
options.Omnibox.placeholder = "Search documentation";
}
if (location.pathname.match(/^\/training/)) {
searchPageURI = "https://success.qualys.com/support/s/global-search/%40uri#t=Training";
options.Omnibox.placeholder = "Search training";
}
Coveo.initSearchbox(searchbox, searchPageURI, options);
}
}).catch(error => {
console.error(error);
// Handle error
});
// helper function to hide "Show more" links when there are no more results to show
function hideShowMoreLink (event) {
var result = event.detail.result;
var item = event.detail.item;
var totalNumberOfChildResults = result.raw.jivereplycount || result.raw.wpcommentcount || 0;
var numberOfChildResultsShown = result.childResults.length;
var numberOfChildResultsRemaining = totalNumberOfChildResults - numberOfChildResultsShown;
if (numberOfChildResultsRemaining < 1) {
// hide Show more link
var coveoFoldingFooter = item.querySelector(".coveo-folding-footer");
if (coveoFoldingFooter) {
coveoFoldingFooter.classList.add("hidden");
}
}
}
});
/*
* manage Choose a Topic navigation
*/
(function () {
/*
* move arrow to clicked element
* and reveal menu for clicked element
*/
function handleClick (event) {
var active, container, heading, index, menu;
heading = event.currentTarget;
menu = heading.parentNode;
container = menu.parentNode;
// check if the current menu is active so we can toggle
active = menu.classList.contains("active");
// do nothing if already active
if (active ) {
return;
}
// remove all selected-index-* class names
for (index = 0; index < 6; index += 1) {
container.classList.remove(`selected-index-${index}`);
}
// get index of clicked element
index = menu.getAttribute("data-index");
container.classList.add(`selected-index-${index}`);
// un mark all menus
for (index = 0; index < container.childNodes.length; index += 1) {
menu = container.childNodes[index];
if (menu && menu.classList) {
menu.classList.toggle("active", active);
}
}
// mark active menu
menu = heading.parentNode;
menu.classList.toggle("active", !active);
}
var headings, heading, index;
headings = document.querySelectorAll(".q-topic-tab_link");
if (headings) {
for (index = 0; index < headings.length; index += 1) {
heading = headings.item(index);
heading.addEventListener("click", handleClick);
}
}
// toggle apps menu in mobile
var appHeading = document.querySelectorAll(".q-nav-by-topic__heading");
Array.prototype.forEach.call(appHeading, function(el){
el.addEventListener("click", function(){
// toggle the minus class
el.classList.toggle("active");
el.nextElementSibling.classList.toggle("show");
});
});
}());