Skip to content

Commit accd8fe

Browse files
committed
Merge pull request #3198 from jpadilla/search
Fix weird search behavior
2 parents 6e3ba20 + ea1a8f4 commit accd8fe

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

docs_theme/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h3 id="myModalLabel">Documentation search</h3>
6969
</div>
7070

7171
<div class="modal-body">
72-
<form role="form">
72+
<form role="form" autocomplete="off">
7373
<div class="form-group">
7474
<input type="text" name="q" class="form-control" placeholder="Search..." id="mkdocs-search-query">
7575
</div>

docs_theme/js/theme.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
function getSearchTerm()
2-
{
3-
var sPageURL = window.location.search.substring(1);
4-
var sURLVariables = sPageURL.split('&');
5-
for (var i = 0; i < sURLVariables.length; i++)
6-
{
7-
var sParameterName = sURLVariables[i].split('=');
8-
if (sParameterName[0] == 'q')
9-
{
10-
return sParameterName[1];
11-
}
1+
var getSearchTerm = function() {
2+
var sPageURL = window.location.search.substring(1);
3+
var sURLVariables = sPageURL.split('&');
4+
for (var i = 0; i < sURLVariables.length; i++) {
5+
var sParameterName = sURLVariables[i].split('=');
6+
if (sParameterName[0] === 'q') {
7+
return sParameterName[1];
128
}
13-
}
9+
}
10+
};
1411

15-
$(function() {
16-
17-
var initialise_search = function(){
18-
require.config({"baseUrl":"/mkdocs/js"});
19-
require(["search",]);
20-
}
12+
var initilizeSearch = function() {
13+
require.config({ baseUrl: '/mkdocs/js' });
14+
require(['search']);
15+
};
2116

22-
var search_term = getSearchTerm();
23-
if(search_term){
24-
$('#mkdocs_search_modal').modal();
25-
}
17+
$(function() {
18+
var searchTerm = getSearchTerm(),
19+
$searchModal = $('#mkdocs_search_modal'),
20+
$searchQuery = $searchModal.find('#mkdocs-search-query'),
21+
$searchResults = $searchModal.find('#mkdocs-search-results');
2622

27-
$('pre code').parent().addClass('prettyprint well');
23+
$('pre code').parent().addClass('prettyprint well');
2824

29-
$(document).on("submit", "#mkdocs_search_modal form", function (e) {
30-
$("#mkdocs-search-results").html("Searching...");
31-
initialise_search();
32-
return false;
33-
});
25+
if (searchTerm) {
26+
$searchQuery.val(searchTerm);
27+
$searchResults.text('Searching...');
28+
$searchModal.modal();
29+
}
3430

31+
$searchModal.on('shown', function() {
32+
$searchQuery.focus();
33+
initilizeSearch();
34+
});
3535
});

0 commit comments

Comments
 (0)