mirror of
https://github.com/danbulant/api_docs
synced 2026-07-05 11:00:35 +00:00
Adds rudimentary search support
Signed-off-by: Christopher Rogers <chrissrogers@gmail.com>
This commit is contained in:
parent
d1b98be182
commit
e669a0d4ac
2 changed files with 178 additions and 174 deletions
|
|
@ -1,41 +1,45 @@
|
|||
(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');
|
||||
this.field('title', { boost: 10 });
|
||||
// this.field('tags', { boost: 100 });
|
||||
this.field('body');
|
||||
});
|
||||
|
||||
$(bindSearch);
|
||||
$(populate);
|
||||
$(bind);
|
||||
|
||||
function bindSearch () {
|
||||
function populate () {
|
||||
$('h1').each(function () {
|
||||
var title = $(this);
|
||||
var body = title.nextUntil('h1');
|
||||
var wrapper = $('<section id="section-' + title.prop('id') + '"></section>');
|
||||
|
||||
title.after(wrapper.append(body));
|
||||
wrapper.prepend(title);
|
||||
|
||||
index.add({
|
||||
id: title.prop('id'),
|
||||
title: title.text(),
|
||||
// tags: tags,
|
||||
body: body.text()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bind () {
|
||||
$('#search').on('keyup', function () {
|
||||
if (this.value) {
|
||||
var items = index.search(this.value);
|
||||
$('article, nav li').hide();
|
||||
$('section, #toc .tocify-item').hide();
|
||||
items.forEach(function (item) {
|
||||
$('#' + item.ref + ', #' + item.ref + '-nav').show();
|
||||
$('#section-' + item.ref + ', .tocify-item[data-unique=' + item.ref).show();
|
||||
});
|
||||
} else {
|
||||
$('article, nav li').show();
|
||||
$('section, #toc .tocify-item').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);
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ html, body {
|
|||
position: relative;
|
||||
z-index: 30;
|
||||
|
||||
|
||||
section {
|
||||
&>h1, &>h2, &>h3, &>p, &>table, &>ul, &>ol, &>aside, &>dl {
|
||||
margin-right: $examples-width;
|
||||
padding: 0 $main-padding;
|
||||
|
|
@ -384,7 +384,7 @@ html, body {
|
|||
aside.success:before {
|
||||
@extend %icon-ok-sign;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue