Skip to content

Commit 14ac8b6

Browse files
ahornaceVladimir Kotal
authored andcommitted
Add possibility to disable suggester by a cookie (#2237)
1 parent 74c428d commit 14ac8b6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Scripts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public String toHtml() {
126126
SCRIPTS.put("jquery-tablesorter", new FileScript("js/jquery-tablesorter-2.26.6.min.js", 12));
127127
SCRIPTS.put("tablesorter-parsers", new FileScript("js/tablesorter-parsers-0.0.1.js", 13));
128128
SCRIPTS.put("searchable-option-list", new FileScript("js/searchable-option-list-2.0.5.min.js", 14));
129-
SCRIPTS.put("utils", new FileScript("js/utils-0.0.23.js", 15));
129+
SCRIPTS.put("utils", new FileScript("js/utils-0.0.24.js", 15));
130130
SCRIPTS.put("repos", new FileScript("js/repos-0.0.1.js", 20));
131131
SCRIPTS.put("diff", new FileScript("js/diff-0.0.3.js", 20));
132132
SCRIPTS.put("jquery-caret", new FileScript("js/jquery.caret-1.5.2.min.js", 25));

opengrok-web/src/main/webapp/js/utils-0.0.23.js renamed to opengrok-web/src/main/webapp/js/utils-0.0.24.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,11 @@ function pageReadyMast() {
17161716
}
17171717

17181718
function domReadyMenu(minisearch) {
1719+
if (getCookie('OpenGrokSuggester.enabled') === 'false') {
1720+
console.log('Suggester disabled by a cookie');
1721+
return;
1722+
}
1723+
17191724
$.ajax({
17201725
// cannot use "/api/v1/configuration/suggester" because of security
17211726
url: window.contextPath + "/api/v1/suggest/config",
@@ -2326,3 +2331,24 @@ function escapeHtml(string) { // taken from https://stackoverflow.com/questions/
23262331
return htmlEscapeMap[s];
23272332
});
23282333
}
2334+
2335+
/**
2336+
* Taken from https://www.w3schools.com/js/js_cookies.asp .
2337+
* @param cname cookie name to retrieve
2338+
* @returns {string} cookie value
2339+
*/
2340+
function getCookie(cname) {
2341+
var name = cname + "=";
2342+
var decodedCookie = decodeURIComponent(document.cookie);
2343+
var ca = decodedCookie.split(';');
2344+
for (var i = 0; i < ca.length; i++) {
2345+
var c = ca[i];
2346+
while (c.charAt(0) == ' ') {
2347+
c = c.substring(1);
2348+
}
2349+
if (c.indexOf(name) == 0) {
2350+
return c.substring(name.length, c.length);
2351+
}
2352+
}
2353+
return "";
2354+
}

0 commit comments

Comments
 (0)