Skip to content

Commit

Permalink
Rollup merge of rust-lang#45281 - GuillaumeGomez:tab-selection, r=Qui…
Browse files Browse the repository at this point in the history
…etMisdreavus

Save selected search tab

Fixes rust-lang#45278.

r? @rust-lang/docs
  • Loading branch information
kennytm authored Oct 18, 2017
2 parents 0350c2f + 45bb03f commit 4913b92
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
"associatedconstant",
"union"];

// On the search screen, so you remain on the last tab you opened.
//
// 0 for "Types/modules"
// 1 for "As parameters"
// 2 for "As return value"
var currentTab = 0;

function hasClass(elem, className) {
if (elem && className && elem.className) {
var elemClass = elem.className;
Expand Down Expand Up @@ -758,7 +765,7 @@

var output = '';
if (array.length > 0) {
output = `<table class="search-results"${extraStyle}>`;
output = '<table class="search-results"' + extraStyle + '>';
var shown = [];

array.forEach(function(item) {
Expand Down Expand Up @@ -812,24 +819,32 @@
});
output += '</table>';
} else {
output = `<div class="search-failed"${extraStyle}>No results :(<br/>` +
output = '<div class="search-failed"' + extraStyle + '>No results :(<br/>' +
'Try on <a href="https://duckduckgo.com/?q=' +
encodeURIComponent('rust ' + query.query) +
'">DuckDuckGo</a>?</div>';
}
return output;
}

function makeTabHeader(tabNb, text) {
if (currentTab === tabNb) {
return '<div class="selected">' + text + '</div>';
}
return '<div>' + text + '</div>';
}

function showResults(results) {
var output, query = getQuery();

currentResults = query.id;
output = '<h1>Results for ' + escape(query.query) +
(query.type ? ' (type: ' + escape(query.type) + ')' : '') + '</h1>' +
'<div id="titles">' +
'<div class="selected">Types/modules</div>' +
'<div>As parameters</div>' +
'<div>As return value</div></div><div id="results">';
makeTabHeader(0, "Types/modules") +
makeTabHeader(1, "As parameters") +
makeTabHeader(2, "As return value") +
'</div><div id="results">';

output += addTab(results['others'], query);
output += addTab(results['in_args'], query, false);
Expand Down Expand Up @@ -1405,6 +1420,9 @@

// In the search display, allows to switch between tabs.
function printTab(nb) {
if (nb === 0 || nb === 1 || nb === 2) {
currentTab = nb;
}
var nb_copy = nb;
onEach(document.getElementById('titles').childNodes, function(elem) {
if (nb_copy === 0) {
Expand Down

0 comments on commit 4913b92

Please sign in to comment.