Merge pull request #3198 from jpadilla/search

Fix weird search behavior
This commit is contained in:
Tom Christie 2015-07-30 09:09:49 +01:00
commit accd8fe16b
2 changed files with 29 additions and 29 deletions

View File

@ -69,7 +69,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form role="form"> <form role="form" autocomplete="off">
<div class="form-group"> <div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search..." id="mkdocs-search-query"> <input type="text" name="q" class="form-control" placeholder="Search..." id="mkdocs-search-query">
</div> </div>

View File

@ -1,35 +1,35 @@
function getSearchTerm() var getSearchTerm = function() {
{ var sPageURL = window.location.search.substring(1);
var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&');
var sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) {
for (var i = 0; i < sURLVariables.length; i++) var sParameterName = sURLVariables[i].split('=');
{ if (sParameterName[0] === 'q') {
var sParameterName = sURLVariables[i].split('='); return sParameterName[1];
if (sParameterName[0] == 'q')
{
return sParameterName[1];
}
} }
} }
};
var initilizeSearch = function() {
require.config({ baseUrl: '/mkdocs/js' });
require(['search']);
};
$(function() { $(function() {
var searchTerm = getSearchTerm(),
$searchModal = $('#mkdocs_search_modal'),
$searchQuery = $searchModal.find('#mkdocs-search-query'),
$searchResults = $searchModal.find('#mkdocs-search-results');
var initialise_search = function(){ $('pre code').parent().addClass('prettyprint well');
require.config({"baseUrl":"/mkdocs/js"});
require(["search",]);
}
var search_term = getSearchTerm(); if (searchTerm) {
if(search_term){ $searchQuery.val(searchTerm);
$('#mkdocs_search_modal').modal(); $searchResults.text('Searching...');
} $searchModal.modal();
}
$('pre code').parent().addClass('prettyprint well');
$(document).on("submit", "#mkdocs_search_modal form", function (e) {
$("#mkdocs-search-results").html("Searching...");
initialise_search();
return false;
});
$searchModal.on('shown', function() {
$searchQuery.focus();
initilizeSearch();
});
}); });