mirror of
https://github.com/danbulant/api_docs
synced 2026-06-21 15:41:59 +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) {
|
(function (global) {
|
||||||
|
|
||||||
window.topic = topic;
|
|
||||||
|
|
||||||
var index = lunr(function () {
|
var index = lunr(function () {
|
||||||
this.field('title', { boost: 10 });
|
|
||||||
this.field('tags', { boost: 100 });
|
|
||||||
this.field('body');
|
|
||||||
this.ref('id');
|
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 () {
|
$('#search').on('keyup', function () {
|
||||||
if (this.value) {
|
if (this.value) {
|
||||||
var items = index.search(this.value);
|
var items = index.search(this.value);
|
||||||
$('article, nav li').hide();
|
$('section, #toc .tocify-item').hide();
|
||||||
items.forEach(function (item) {
|
items.forEach(function (item) {
|
||||||
$('#' + item.ref + ', #' + item.ref + '-nav').show();
|
$('#section-' + item.ref + ', .tocify-item[data-unique=' + item.ref).show();
|
||||||
});
|
});
|
||||||
} else {
|
} 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);
|
})(window);
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ html, body {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 30;
|
z-index: 30;
|
||||||
|
|
||||||
|
section {
|
||||||
&>h1, &>h2, &>h3, &>p, &>table, &>ul, &>ol, &>aside, &>dl {
|
&>h1, &>h2, &>h3, &>p, &>table, &>ul, &>ol, &>aside, &>dl {
|
||||||
margin-right: $examples-width;
|
margin-right: $examples-width;
|
||||||
padding: 0 $main-padding;
|
padding: 0 $main-padding;
|
||||||
|
|
@ -384,7 +384,7 @@ html, body {
|
||||||
aside.success:before {
|
aside.success:before {
|
||||||
@extend %icon-ok-sign;
|
@extend %icon-ok-sign;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue