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>');
function bindSearch () {
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,178 +213,178 @@ 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;
@include box-sizing(border-box);
display: block;
@include text-shadow($main-embossed-text-shadow);
}
&>h1, &>h2, &>h3, &>p, &>table, &>ul, &>ol, &>aside, &>dl {
margin-right: $examples-width;
padding: 0 $main-padding;
@include box-sizing(border-box);
display: block;
@include text-shadow($main-embossed-text-shadow);
}
&>ul, &>ol {
padding-left: $main-padding + 15px;
}
&>ul, &>ol {
padding-left: $main-padding + 15px;
}
// the div is the tocify hidden div for placeholding stuff
&>h1, &>h2, &>div {
clear:both;
}
// the div is the tocify hidden div for placeholding stuff
&>h1, &>h2, &>div {
clear:both;
}
h1 {
@extend %header-font;
font-size: 30px;
padding-top: 0.5em;
padding-bottom: 0.5em;
border-bottom: 1px solid #ccc;
margin-top: 2em;
margin-bottom: $h1-margin-bottom;
border-top: 1px solid #ddd;
@include background-image(
linear-gradient(top, #fff, #f9f9f9)
);
}
h1 {
@extend %header-font;
font-size: 30px;
padding-top: 0.5em;
padding-bottom: 0.5em;
border-bottom: 1px solid #ccc;
margin-top: 2em;
margin-bottom: $h1-margin-bottom;
border-top: 1px solid #ddd;
@include background-image(
linear-gradient(top, #fff, #f9f9f9)
);
}
// The header at the very top of the page
// shouldn't have top margin.
// (the div is because of tocify)
h1:first-child, div:first-child + h1 {
margin-top: 0;
}
// The header at the very top of the page
// shouldn't have top margin.
// (the div is because of tocify)
h1:first-child, div:first-child + h1 {
margin-top: 0;
}
h2 {
@extend %header-font;
font-size: 20px;
margin-top: 4em;
margin-bottom: 0;
border-top: 1px solid #ccc;
padding-top: 1.2em;
padding-bottom: 1.2em;
@include background-image(
linear-gradient(top, rgba(#fff,0.4), rgba(#fff, 0))
);
}
h2 {
@extend %header-font;
font-size: 20px;
margin-top: 4em;
margin-bottom: 0;
border-top: 1px solid #ccc;
padding-top: 1.2em;
padding-bottom: 1.2em;
@include background-image(
linear-gradient(top, rgba(#fff,0.4), rgba(#fff, 0))
);
}
// h2s right after h1s should bump right up
// against the h1s.
h1 + h2, h1 + div + h2 {
margin-top: $h1-margin-bottom * -1;
border-top: none;
}
// h2s right after h1s should bump right up
// against the h1s.
h1 + h2, h1 + div + h2 {
margin-top: $h1-margin-bottom * -1;
border-top: none;
}
h3 {
@extend %header-font;
font-size: 12px;
margin-top: 2.5em;
margin-bottom: 0.8em;
text-transform: uppercase;
}
h3 {
@extend %header-font;
font-size: 12px;
margin-top: 2.5em;
margin-bottom: 0.8em;
text-transform: uppercase;
}
hr {
margin: 2em 0;
border-top: 2px solid $examples-bg;
border-bottom: 2px solid $main-bg;
}
hr {
margin: 2em 0;
border-top: 2px solid $examples-bg;
border-bottom: 2px solid $main-bg;
}
table {
margin-bottom: 1em;
overflow: auto;
th,td {
text-align: left;
vertical-align: top;
line-height: 1.6;
}
table {
margin-bottom: 1em;
overflow: auto;
th,td {
text-align: left;
vertical-align: top;
line-height: 1.6;
}
th {
padding: 5px 10px;
border-bottom: 1px solid #ccc;
vertical-align: bottom;
}
th {
padding: 5px 10px;
border-bottom: 1px solid #ccc;
vertical-align: bottom;
td {
padding: 10px;
}
tr:last-child {
border-bottom: 1px solid #ccc;
}
tr:nth-child(odd)>td {
background-color: lighten($main-bg,4.2%);
}
tr:nth-child(even)>td {
background-color: lighten($main-bg,2.4%);
}
}
td {
padding: 10px;
dt {
font-weight: bold;
}
tr:last-child {
border-bottom: 1px solid #ccc;
dd {
margin-left: 15px;
}
tr:nth-child(odd)>td {
background-color: lighten($main-bg,4.2%);
p, li, dt, dd {
line-height: 1.6;
margin-top: 0;
}
tr:nth-child(even)>td {
background-color: lighten($main-bg,2.4%);
img {
max-width: 100%;
}
}
dt {
font-weight: bold;
}
code {
background-color: rgba(0,0,0,0.05);
padding: 3px;
border-radius: 3px;
@extend %break-words;
@extend %code-font;
}
dd {
margin-left: 15px;
}
aside {
padding-top: 1em;
padding-bottom: 1em;
text-shadow: 0 1px 0 lighten($aside-notice-bg, 15%);
margin-top: 1.5em;
margin-bottom: 1.5em;
background: $aside-notice-bg;
line-height: 1.6;
p, li, dt, dd {
line-height: 1.6;
margin-top: 0;
}
&.warning {
background-color: $aside-warning-bg;
text-shadow: 0 1px 0 lighten($aside-warning-bg, 15%);
}
img {
max-width: 100%;
}
&.success {
background-color: $aside-success-bg;
text-shadow: 0 1px 0 lighten($aside-success-bg, 15%);
}
}
code {
background-color: rgba(0,0,0,0.05);
padding: 3px;
border-radius: 3px;
@extend %break-words;
@extend %code-font;
}
aside {
padding-top: 1em;
padding-bottom: 1em;
text-shadow: 0 1px 0 lighten($aside-notice-bg, 15%);
margin-top: 1.5em;
margin-bottom: 1.5em;
background: $aside-notice-bg;
line-height: 1.6;
&.warning {
background-color: $aside-warning-bg;
text-shadow: 0 1px 0 lighten($aside-warning-bg, 15%);
aside.warning {
}
&.success {
background-color: $aside-success-bg;
text-shadow: 0 1px 0 lighten($aside-success-bg, 15%);
aside:before {
vertical-align: middle;
padding-right: 0.5em;
font-size: 14px;
}
}
aside.warning {
}
aside:before {
vertical-align: middle;
padding-right: 0.5em;
font-size: 14px;
}
aside.notice:before {
@extend %icon-info-sign;
}
aside.notice:before {
@extend %icon-info-sign;
}
aside.warning:before {
@extend %icon-exclamation-sign;
}
aside.warning:before {
@extend %icon-exclamation-sign;
}
aside.success:before {
@extend %icon-ok-sign;
aside.success:before {
@extend %icon-ok-sign;
}
}
}
......@@ -431,4 +431,4 @@ html, body {
border-bottom: 1px solid #404040;
}
}
}
\ No newline at end of file
}
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