Skip to content

Commit

Permalink
Only load the search results when the search form is submitted for the
Browse files Browse the repository at this point in the history
first time
  • Loading branch information
d0ugal committed May 31, 2015
1 parent 33666c4 commit 8ace80c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs_theme/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h3 id="myModalLabel">Documentation search</h3>
<div class="modal-body">
<form role="form">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search..." id="mkdocs-search-query">
<input type="text" name="q" class="form-control" placeholder="Search..." id="mkdocs-search-query">
</div>
</form>
<div id="mkdocs-search-results"></div>
Expand Down Expand Up @@ -167,9 +167,9 @@ <h3 id="myModalLabel">Documentation search</h3>
<script src="{{ base_url }}/js/jquery-1.8.1-min.js"></script>
<script src="{{ base_url }}/js/prettify-1.0.js"></script>
<script src="{{ base_url }}/js/bootstrap-2.1.1-min.js"></script>
<script src="{{ base_url }}/js/theme.js"></script>
<script>var base_url = '{{ base_url }}';</script>
<script data-main="{{ base_url }}/mkdocs/js/search.js" src="{{ base_url }}/mkdocs/js/require.js"></script>
<script src="{{ base_url }}/mkdocs/js/require.js"></script>
<script src="{{ base_url }}/js/theme.js"></script>

<script>
//$('.side-nav').scrollspy()
Expand Down
32 changes: 31 additions & 1 deletion docs_theme/js/theme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
$(function(){
function getSearchTerm()
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == 'q')
{
return sParameterName[1];
}
}
}

$(function() {

var initialise_search = function(){
require.config({"baseUrl":"/mkdocs/js"});
require(["search",]);
}

var search_term = getSearchTerm();
if(search_term){
$('#mkdocs_search_modal').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;
});

});
2 changes: 1 addition & 1 deletion docs_theme/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a class="repo-link btn btn-inverse btn-small {% if not previous_page %}disabled{% endif %}" rel="next" {% if previous_page %}href="{{ previous_page.url }}"{% endif %}>
<i class="icon-arrow-left icon-white"></i> Previous
</a>
<a class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
Expand Down

0 comments on commit 8ace80c

Please sign in to comment.