rustdoc: Fix search for something on the same page
This commit is contained in:
parent
a925762c3b
commit
b93678eca5
|
@ -66,7 +66,8 @@ pub fn render<T: fmt::Default, S: fmt::Default>(
|
||||||
</form>
|
</form>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<section class=\"content {ty}\">{content}</section>
|
<section id='main' class=\"content {ty}\">{content}</section>
|
||||||
|
<section id='search' class=\"content hidden\">{content}</section>
|
||||||
|
|
||||||
<section class=\"footer\"></section>
|
<section class=\"footer\"></section>
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,15 @@
|
||||||
if (e.keyCode === 188 && $('#help').hasClass('hidden')) { // question mark
|
if (e.keyCode === 188 && $('#help').hasClass('hidden')) { // question mark
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$('#help').removeClass('hidden');
|
$('#help').removeClass('hidden');
|
||||||
} else if (e.keyCode === 27 && !$('#help').hasClass('hidden')) { // esc
|
} else if (e.keyCode === 27) { // esc
|
||||||
e.preventDefault();
|
if (!$('#help').hasClass('hidden')) {
|
||||||
$('#help').addClass('hidden');
|
e.preventDefault();
|
||||||
|
$('#help').addClass('hidden');
|
||||||
|
} else if (!$('#search').hasClass('hidden')) {
|
||||||
|
e.preventDefault();
|
||||||
|
$('#search').addClass('hidden');
|
||||||
|
$('#main').removeClass('hidden');
|
||||||
|
}
|
||||||
} else if (e.keyCode === 83) { // S
|
} else if (e.keyCode === 83) { // S
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$('.search-input').focus();
|
$('.search-input').focus();
|
||||||
|
@ -202,7 +208,13 @@
|
||||||
var hoverTimeout, $results = $('.search-results .result');
|
var hoverTimeout, $results = $('.search-results .result');
|
||||||
|
|
||||||
$results.on('click', function () {
|
$results.on('click', function () {
|
||||||
document.location.href = $(this).find('a').prop('href');
|
var dst = $(this).find('a')[0];
|
||||||
|
console.log(window.location.pathname, dst.pathname);
|
||||||
|
if (window.location.pathname == dst.pathname) {
|
||||||
|
$('#search').addClass('hidden');
|
||||||
|
$('#main').removeClass('hidden');
|
||||||
|
}
|
||||||
|
document.location.href = dst.href;
|
||||||
}).on('mouseover', function () {
|
}).on('mouseover', function () {
|
||||||
var $el = $(this);
|
var $el = $(this);
|
||||||
clearTimeout(hoverTimeout);
|
clearTimeout(hoverTimeout);
|
||||||
|
@ -277,7 +289,6 @@
|
||||||
'/index.html" class="' + type +
|
'/index.html" class="' + type +
|
||||||
'">' + name + '</a>';
|
'">' + name + '</a>';
|
||||||
} else if (item.parent !== undefined) {
|
} else if (item.parent !== undefined) {
|
||||||
console.log(item);
|
|
||||||
var myparent = allPaths[item.parent];
|
var myparent = allPaths[item.parent];
|
||||||
var anchor = '#' + type + '.' + name;
|
var anchor = '#' + type + '.' + name;
|
||||||
output += item.path + '::' + myparent.name +
|
output += item.path + '::' + myparent.name +
|
||||||
|
@ -308,7 +319,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
output += "</p>";
|
output += "</p>";
|
||||||
$('.content').html(output);
|
$('#main.content').addClass('hidden');
|
||||||
|
$('#search.content').removeClass('hidden').html(output);
|
||||||
$('.search-results .desc').width($('.content').width() - 40 -
|
$('.search-results .desc').width($('.content').width() - 40 -
|
||||||
$('.content td:first-child').first().width());
|
$('.content td:first-child').first().width());
|
||||||
initSearchNav();
|
initSearchNav();
|
||||||
|
|
Loading…
Reference in New Issue