Skip to content

Commit c3384bc

Browse files
committedDec 27, 2022
docs: fix search re: #12830
1 parent fd1fa9d commit c3384bc

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed
 

‎docs/js/navbar-search.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
document.getElementById('search-button-nav').onclick = function() {
2-
var q = document.getElementById('search-input-nav').value;
3-
window.location.href = 'search.html?q=' + encodeURIComponent(q);
4-
};
1+
(function() {
2+
var versionFromUrl = window.location.pathname.match(/^\/docs\/(\d+\.x)/);
3+
var version = versionFromUrl ? versionFromUrl[1] : defaultVersion;
54

6-
var q = document.getElementById('search-input-nav').onkeyup = function(ev) {
7-
if (ev.keyCode === 13) {
5+
var searchPrefix = versionFromUrl ? '/docs/' + version + '/docs/' : '/docs/';
6+
7+
document.getElementById('search-button-nav').onclick = function() {
88
var q = document.getElementById('search-input-nav').value;
9-
window.location.href = '/docs/search.html?q=' + encodeURIComponent(q);
10-
}
11-
};
9+
window.location.href = searchPrefix + 'search.html?q=' + encodeURIComponent(q);
10+
};
11+
12+
document.getElementById('search-input-nav').onkeyup = function(ev) {
13+
if (ev.keyCode === 13) {
14+
var q = document.getElementById('search-input-nav').value;
15+
window.location.href = searchPrefix + '/search.html?q=' + encodeURIComponent(q);
16+
}
17+
};
18+
})();

‎docs/js/search.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ for (var i = 0; i < pairs.length; ++i) {
99
}
1010
}
1111

12+
var defaultVersion = '6.x';
1213
var versionFromUrl = window.location.pathname.match(/^\/docs\/(\d+\.x)/);
13-
var version = versionFromUrl ? versionFromUrl[1] : '6.x';
14+
var version = versionFromUrl ? versionFromUrl[1] : defaultVersion;
1415

1516
if (q != null) {
1617
document.getElementById('search-input').value = decodeURIComponent(q);

0 commit comments

Comments
 (0)
Please sign in to comment.