Commit e669a0d4 authored by Christopher Rogers's avatar Christopher Rogers

Adds rudimentary search support

Signed-off-by: 's avatarChristopher Rogers <chrissrogers@gmail.com>
parent d1b98be1
(function (global) {
window.topic = topic;
var index = lunr(function () {
this.ref('id');
this.field('title', { boost: 10 });
this.field('tags', { boost: 100 });
// this.field('tags', { boost: 100 });
this.field('body');
this.ref('id');
});
$(bindSearch);
$(populate);
$(bind);
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 bindSearch () {
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();
}
});
$('form').on('submit', function (event) {
event.preventDefault();
});
$('section, #toc .tocify-item').show();
}
function topic (title, tags, handle) {
index.add({
id: handle,
title: title,
tags: tags,
body: $('#' + handle + '-body').text()
});
}
......
......@@ -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;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment