Skip to content

Commit 7822041

Browse files
committed
Add search history for Scaladoc
1 parent ecc8944 commit 7822041

File tree

1 file changed

+24
-0
lines changed
  • src/scaladoc/scala/tools/nsc/doc/html/resource/lib

1 file changed

+24
-0
lines changed

src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ var Index = {};
2121
}
2222
})(Index);
2323

24+
/** Find query string from URL */
25+
var QueryString = function(key) {
26+
if (QueryString.map === undefined) { // only calc once
27+
QueryString.map = {};
28+
var keyVals = window.location.search.split("?").pop().split("&");
29+
keyVals.forEach(function(elem) {
30+
var pair = elem.split("=");
31+
if (pair.length == 2) QueryString.map[pair[0]] = pair[1];
32+
});
33+
}
34+
35+
return QueryString.map[key];
36+
};
37+
2438
$(document).ready(function() {
2539
// Clicking #doc-title returns the user to the root package
2640
$("#doc-title").click(function() { document.location = toRoot + "index.html" });
@@ -39,6 +53,11 @@ $(document).ready(function() {
3953
else
4054
$("#textfilter > .input > .clear").hide();
4155
});
56+
57+
if (QueryString("search") !== undefined) {
58+
$("#index-input").val(QueryString("search"));
59+
searchAll();
60+
}
4261
});
4362

4463
/* Handles all key presses while scrolling around with keyboard shortcuts in search results */
@@ -510,6 +529,11 @@ function searchAll() {
510529
return;
511530
}
512531

532+
// Replace ?search=X with current search string if not hosted locally on Chrome
533+
try {
534+
window.history.replaceState({}, "", "?search=" + searchStr);
535+
} catch(e) {}
536+
513537
$("div#results-content > span.search-text").remove();
514538

515539
var memberResults = document.getElementById("member-results");

0 commit comments

Comments
 (0)