batmanjs/batmanjs.github.io — pull request #16 by jahfer (2013-11-01 03:35:24+00:00)
Title: API Search Box

### Problem
For me, the worst part of the docs was figuring out where stuff was within the categories. So I decided to fix that.

### Solution
[Check out the demo video!](https://www.dropbox.com/s/wnqpa3z8itiri5w/api-search.mov)

A JSON search index is generated in `docs/api/search.json` by looping through all of the properties on `api_index`. This file then gets loaded via AJAX on the API page, and passed to the search lib.

Since I didn't want to make this a simple project, I decided to include a basic "intelligent" ranking to the results. The dropdown sorts all results by category, and every result in those categories are sorted by how well the match the search result. Then every category is sorted by the cumulative rank of the results within it.

Keyboard navigation is also supported. Up/down arrows navigate the result set, hitting enter will send you to that page, and escape will close the dropdown.

### Misc
I'm new to Jekyll so I wasn't too sure how to organize the JS involved. I've got a few scripts that I load using `docs_scripts.html`, which also tacks on a simple underscorejs template for rendering the results. If you've got suggestions for better code organization, I'm all ears.

The meat of the code can be found in ` js/api_search.js`. Fair warning, it's a *lot* of underscore methods.

@nickjs @pushrax