Skip to content

Commit 234a19a

Browse files
committed
Fix documentation search feature.
Via readthedocs/readthedocs.org#1088 (comment)
1 parent a66e989 commit 234a19a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/assets/fix_search.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$(document).ready(fixSearch);
2+
3+
function fixSearch() {
4+
var target = document.getElementById('rtd-search-form');
5+
var config = {attributes: true, childList: true};
6+
7+
var observer = new MutationObserver(function(mutations) {
8+
// if it isn't disconnected it'll loop infinitely because the observed element is modified
9+
observer.disconnect();
10+
var form = $('#rtd-search-form');
11+
form.empty();
12+
form.attr('action', 'https://' + window.location.hostname + '/en/' + determineSelectedBranch() + '/search.html');
13+
$('<input>').attr({
14+
type: "text",
15+
name: "q",
16+
placeholder: "Search docs"
17+
}).appendTo(form);
18+
});
19+
// don't run this outside RTD hosting
20+
if (window.location.origin.indexOf('readthedocs') > -1) {
21+
observer.observe(target, config);
22+
}
23+
}

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ google_analytics: ['UA-29492860-5', 'auto']
66
theme: 'readthedocs'
77
site_dir: 'deploy'
88
extra_css: [assets/fathom.css]
9+
extra_js: [assets/fix_search.js]
910

1011
pages:
1112
- 'Overview': index.md

0 commit comments

Comments
 (0)