Prevent pressing Enter in search box from reloading the page

This commit is contained in:
Yeray Diaz Diaz
2018-08-12 16:39:42 +01:00
committed by Waylan Limberg
parent 24d61cec13
commit 7aaf5a685c
4 changed files with 29 additions and 16 deletions

View File

@@ -70,7 +70,9 @@ if (!window.Worker) {
$.getScript(base_url + "/search/worker.js").done(function () {
console.log('Loaded worker');
init();
window.postMessage = initSearch;
window.postMessage = function (msg) {
onWorkerMessage({data: msg});
};
}).fail(function (jqxhr, settings, exception) {
console.error('Could not load worker.js');
});

View File

@@ -84,7 +84,7 @@ function onScriptsLoaded () {
console.log('Lunr index built, search ready');
}
allowSearch = true;
postMessage({allowSearch: true});
postMessage({allowSearch: allowSearch});
}
function init () {

View File

@@ -128,8 +128,11 @@ pre .cs, pre .c {
* Additions specific to the search functionality provided by MkDocs
*/
.search-results article {
.search-results {
margin-top: 23px;
}
.search-results article {
border-top: 1px solid #E1E4E5;
padding-top: 24px;
}

View File

@@ -13,19 +13,27 @@ $( document ).ready(function() {
// Keyboard navigation
document.addEventListener("keydown", function(e) {
if ($(e.target).is(':input')) return true;
var key = e.which || e.keyCode || window.event && window.event.keyCode;
var page;
switch (key) {
case 78: // n
page = $('[role="navigation"] a:contains(Next):first').prop('href');
break;
case 80: // p
page = $('[role="navigation"] a:contains(Previous):first').prop('href');
break;
default: break;
}
if (page) window.location.href = page;
var key = e.which || e.keyCode || window.event && window.event.keyCode;
var page;
switch (key) {
case 78: // n
page = $('[role="navigation"] a:contains(Next):first').prop('href');
break;
case 80: // p
page = $('[role="navigation"] a:contains(Previous):first').prop('href');
break;
case 13: // enter
if (e.target === document.getElementById('mkdocs-search-query')) {
e.preventDefault();
}
break;
default: break;
}
if ($(e.target).is(':input')) {
return true;
} else if (page) {
window.location.href = page;
}
});
$(document).on('click', "[data-toggle='rst-current-version']", function() {