api_docs/source/javascripts/app/search.js
Christopher Rogers b171d3c48a Organizes javascript into libraries and application code
Signed-off-by: Christopher Rogers <chrissrogers@gmail.com>
2014-04-09 14:54:23 -07:00

41 lines
863 B
JavaScript

(function (global) {
window.topic = topic;
var index = lunr(function () {
this.field('title', { boost: 10 });
this.field('tags', { boost: 100 });
this.field('body');
this.ref('id');
});
$(bindSearch);
function bindSearch () {
$('#search').on('keyup', function () {
if (this.value) {
var items = index.search(this.value);
$('article, nav li').hide();
items.forEach(function (item) {
$('#' + item.ref + ', #' + item.ref + '-nav').show();
});
} else {
$('article, nav li').show();
}
});
$('form').on('submit', function (event) {
event.preventDefault();
});
}
function topic (title, tags, handle) {
index.add({
id: handle,
title: title,
tags: tags,
body: $('#' + handle + '-body').text()
});
}
})(window);