forked from openshift/openshift-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhc-search.js
51 lines (45 loc) · 1.78 KB
/
hc-search.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
function hcSearchCategory(label, version) {
// optional version filters search results for a single specific product version
// currently can be used with OCP and Origin only
var modalSearch = document.getElementById("hc-search-modal");
var searchBtn = document.getElementById("hc-search-btn");
var closeModal = document.getElementById("hc-modal-close");
var searchResults = document.getElementById("hc-search-results");
var query = document.getElementById("hc-search-input");
// pressing enter in the input = search btn click
query.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode == 13) {
searchBtn.click();
}
});
//prepare iframe (without source)
var iframe = document.createElement("iframe");
iframe.frameBorder=0;
iframe.width="100%";
iframe.height=0.7*window.innerHeight;
iframe.id="search-result-iframe";
// open the modal and finalize the iframe on click
searchBtn.onclick = function() {
if (query.value) {
modalSearch.style.display = "block";
// limit search to a signle version, if specified
var urlFilter = (typeof version === "undefined" || version == "Branch Build") ? "" : (" url:*\\/" + version + "\\/*");
var iframeSrc = "https://help.openshift.com/customsearch.html?q=" +
encodeURIComponent(query.value) +
encodeURIComponent(urlFilter) +
"&l=" + encodeURIComponent(label);
iframe.setAttribute("src", iframeSrc);
searchResults.appendChild(iframe);
}
}
// hide search modal
closeModal.onclick = function() {
modalSearch.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modalSearch) {
modalSearch.style.display = "none";
}
}
} // hcSearchCategory(label)