mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Prevent pressing Enter in search box from reloading the page
This commit is contained in:
committed by
Waylan Limberg
parent
24d61cec13
commit
7aaf5a685c
@@ -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');
|
||||
});
|
||||
|
||||
@@ -84,7 +84,7 @@ function onScriptsLoaded () {
|
||||
console.log('Lunr index built, search ready');
|
||||
}
|
||||
allowSearch = true;
|
||||
postMessage({allowSearch: true});
|
||||
postMessage({allowSearch: allowSearch});
|
||||
}
|
||||
|
||||
function init () {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user