Skip to content

Commit

Permalink
Merge pull request #2652 from captbaritone/search-dot-under
Browse files Browse the repository at this point in the history
Allow users to prefix searches with `_.`
  • Loading branch information
akre54 committed Mar 7, 2017
2 parents 49e8d76 + 0d89d4d commit d4f52aa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
var sections = document.querySelectorAll('.searchable_section');
var searchInput = document.getElementById('function_filter');

function searchValue() {
return searchInput.value.trim().replace(/^_\.?/, '');
}

function strIn(a, b) {
a = a.toLowerCase();
b = b.toLowerCase();
Expand All @@ -12,7 +16,8 @@
function doesMatch(element) {
var name = element.getAttribute('data-name');
var aliases = element.getAttribute('data-aliases') || '';
return strIn(searchInput.value, name) || strIn(searchInput.value, aliases);
var value = searchValue();
return strIn(value, name) || strIn(value, aliases);
}

function filterElement(element) {
Expand All @@ -22,7 +27,7 @@
function filterToc() {
_.each(functions, filterElement);

var emptySearch = searchInput.value === '';
var emptySearch = searchValue() === '';

// Hide the titles of empty sections
_.each(sections, function(section) {
Expand All @@ -34,7 +39,7 @@

function gotoFirst() {
var firstFunction = _.find(functions, doesMatch);
if(firstFunction) {
if (firstFunction) {
window.location.hash = firstFunction.getAttribute('data-name');
searchInput.focus();
}
Expand Down

0 comments on commit d4f52aa

Please sign in to comment.