Skip to content

Commit 272cc44

Browse files
committed
more work on find as you type
1 parent 5dce5ef commit 272cc44

File tree

6 files changed

+114
-2
lines changed

6 files changed

+114
-2
lines changed

lib/resources/script.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,33 @@ function shiftWindow() {
5858
scrollBy(0, -68);
5959
}
6060

61+
function initSearch() {
62+
var elements = new Bloodhound({
63+
datumTokenizer: function(d) {
64+
return Bloodhound.tokenizers.whitespace(d.name);
65+
},
66+
queryTokenizer: Bloodhound.tokenizers.whitespace,
67+
prefetch: 'index.json'
68+
});
69+
70+
$('#search-box.typeahead').typeahead({
71+
hint: true,
72+
highlight: true,
73+
minLength: 3
74+
},
75+
{
76+
name: 'elements',
77+
source: elements,
78+
displayKey: 'name',
79+
limit: 10
80+
});
81+
}
82+
6183
document.addEventListener("DOMContentLoaded", function() {
6284
prettyPrint();
6385
initScroller();
6486
initSideNav();
87+
initSearch();
6588

6689
// Make sure the anchors scroll past the fixed page header (#648).
6790
if (location.hash) shiftWindow();

lib/resources/styles.css

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ footer .container-fluid {
354354
line-height: 1;
355355
}
356356

357+
@media screen and (min-width: 768px) {
358+
nav ol.breadcrumbs {
359+
float: left;
360+
}
361+
}
362+
357363
@media screen and (max-width: 768px) {
358364
.breadcrumbs {
359365
margin: 0 0 24px 0;
@@ -594,8 +600,75 @@ button {
594600
}
595601
}
596602

597-
/* source code method bodies */
598-
599603
#overlay-under-drawer {
600604
display: none;
601605
}
606+
607+
/* find-as-you-type search box */
608+
609+
.typeahead,
610+
.tt-query,
611+
.tt-hint {
612+
width: 396px;
613+
height: 30px;
614+
padding: 8px 12px;
615+
font-size: 24px;
616+
line-height: 30px;
617+
outline: none;
618+
}
619+
620+
.typeahead {
621+
background-color: #fff;
622+
}
623+
624+
.typeahead:focus {
625+
border: 2px solid #0097cf;
626+
}
627+
628+
.tt-query {
629+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
630+
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
631+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
632+
}
633+
634+
.tt-hint {
635+
color: #999
636+
}
637+
638+
.tt-menu {
639+
width: 422px;
640+
margin: 12px 0;
641+
padding: 8px 0;
642+
background-color: #fff;
643+
border: 1px solid #ccc;
644+
border: 1px solid rgba(0, 0, 0, 0.2);
645+
-webkit-border-radius: 8px;
646+
-moz-border-radius: 8px;
647+
border-radius: 8px;
648+
-webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
649+
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
650+
box-shadow: 0 5px 10px rgba(0,0,0,.2);
651+
}
652+
653+
.tt-suggestion {
654+
padding: 3px 20px;
655+
font-size: 18px;
656+
line-height: 24px;
657+
color: #212121;
658+
}
659+
660+
.tt-suggestion:hover {
661+
cursor: pointer;
662+
color: #fff;
663+
background-color: #0097cf;
664+
}
665+
666+
.tt-suggestion.tt-cursor {
667+
color: #fff;
668+
background-color: #0097cf;
669+
670+
}
671+
672+
.tt-suggestion p {
673+
margin: 0;
674+
}

lib/resources/typeahead.bundle.min.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/resources.g.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const List<String> resource_names = const [
88
'package:dartdoc/resources/prettify.js',
99
'package:dartdoc/resources/script.js',
1010
'package:dartdoc/resources/styles.css',
11+
'package:dartdoc/resources/typeahead.bundle.min.js',
1112
'package:dartdoc/resources/css/bootstrap.css',
1213
'package:dartdoc/resources/css/bootstrap.css.map',
1314
'package:dartdoc/resources/css/bootstrap.min.css'

lib/templates/_footer.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
</div>
2323
</footer>
2424

25+
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
26+
<script src="static-assets/typeahead.bundle.min.js"></script>
2527
<script src="static-assets/prettify.js"></script>
2628
<script src="static-assets/script.js"></script>
2729
<!-- Do not remove placeholder -->

lib/templates/_head.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
<li class="self-crumb">{{self.name}}</li>
3838
</ol>
3939
<div class="self-name">{{self.name}}</div>
40+
<form class="navbar-form navbar-right" role="search">
41+
<div class="form-group">
42+
<input type="text" id="search-box" class="form-control typeahead" placeholder="Search">
43+
</div>
44+
</form>
4045
</div>
4146
</nav>
4247
<div class="container masthead">

0 commit comments

Comments
 (0)