Skip to content

Commit 9def48f

Browse files
committed
Add search UI to navbar
1 parent 578b365 commit 9def48f

File tree

6 files changed

+98
-10
lines changed

6 files changed

+98
-10
lines changed

app/assets/javascripts/search.coffee

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/assets/javascripts/search.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$(function () {
2+
$('a[href="#search"]').on('click', function(event) {
3+
event.preventDefault();
4+
$('#search').addClass('open');
5+
$('#search > form > input[type="search"]').focus();
6+
});
7+
8+
$('#search, #search button.close').on('click keyup', function(event) {
9+
if (event.target == this || event.target.className == 'close red' || event.keyCode == 27) {
10+
$(this).removeClass('open');
11+
}
12+
});
13+
});

app/assets/stylesheets/search.scss

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,68 @@
1-
// Place all the styles related to the Search controller here.
2-
// They will automatically be included in application.css.
3-
// You can use Sass (SCSS) here: http://sass-lang.com/
1+
#search {
2+
position: fixed;
3+
top: 0px;
4+
left: 0px;
5+
width: 100%;
6+
height: 100%;
7+
background-color: rgba(0, 0, 0, 0.7);
8+
z-index: 9001;
9+
10+
-webkit-transition: all 0.5s ease-in-out;
11+
-moz-transition: all 0.5s ease-in-out;
12+
-o-transition: all 0.5s ease-in-out;
13+
-ms-transition: all 0.5s ease-in-out;
14+
transition: all 0.5s ease-in-out;
15+
16+
-webkit-transform: translate(0px, -100%) scale(0, 0);
17+
-moz-transform: translate(0px, -100%) scale(0, 0);
18+
-o-transform: translate(0px, -100%) scale(0, 0);
19+
-ms-transform: translate(0px, -100%) scale(0, 0);
20+
transform: translate(0px, -100%) scale(0, 0);
21+
22+
opacity: 0;
23+
}
24+
25+
#search.open {
26+
-webkit-transform: translate(0px, 0px) scale(1, 1);
27+
-moz-transform: translate(0px, 0px) scale(1, 1);
28+
-o-transform: translate(0px, 0px) scale(1, 1);
29+
-ms-transform: translate(0px, 0px) scale(1, 1);
30+
transform: translate(0px, 0px) scale(1, 1);
31+
opacity: 1;
32+
}
33+
34+
#search input[type="search"] {
35+
position: absolute;
36+
top: 50%;
37+
width: 100%;
38+
color: rgb(255, 255, 255);
39+
background: rgba(0, 0, 0, 0);
40+
font-size: 60px;
41+
font-weight: 300;
42+
text-align: center;
43+
border-bottom: 1px solid blue;
44+
margin: 0px auto;
45+
margin-top: -51px;
46+
padding-left: 30px;
47+
padding-right: 30px;
48+
outline: none;
49+
}
50+
#search .btn {
51+
position: absolute;
52+
top: 50%;
53+
left: 50%;
54+
margin-top: 61px;
55+
margin-left: -45px;
56+
border: black;
57+
58+
}
59+
#search .close {
60+
position: fixed;
61+
top: 15px;
62+
right: 15px;
63+
color: #fff;
64+
opacity: 1;
65+
padding: 10px 17px;
66+
font-size: 27px;
67+
border: 0px;
68+
}

app/views/layouts/_navbar.html.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@
154154
<i class="material-icons">recent_actors</i>
155155
</a>
156156
</li>
157+
<li>
158+
<a href="#search" class="dropdown-button tooltipped" href="#!" data-tooltip="Search your notebook">
159+
<i class="material-icons">search</i>
160+
</a>
161+
</li>
157162
<% else %>
158163
<li>
159164
<a href="#" data-activates="login-slide" class="button-collapse">
@@ -165,3 +170,11 @@
165170
</div>
166171
</nav>
167172
</div>
173+
174+
<div id="search">
175+
<button type="button" class="close red">×</button>
176+
<%= form_tag search_path, method: :get do %>
177+
<input type="search" name="q" value="" placeholder="search your notebook" />
178+
<button type="submit" class="btn btn-primary blue">Search everything</button>
179+
<% end %>
180+
</div>

app/views/search/results.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<h3>
2-
<%= @query %>
1+
<h4 class="center">
2+
<div><%= @query %></div>
33
<small class="grey-text">
44
<%= pluralize @results.values.flatten.count, 'match' %>
55
</small>
6-
</h3>
6+
</h4>
77

88
<ul class="collapsible popout" data-collapsible="accordion">
99
<% @results.each do |content_type, content_list| %>
1010
<% next if content_list.empty? %>
1111
<% content_class = content_type.to_s.singularize.capitalize.constantize %>
1212

1313
<li>
14-
<div class="collapsible-header">
14+
<div class="collapsible-header active">
1515
<i class="material-icons <%= content_class.color %>-text"><%= content_class.icon %></i>
1616
<%= content_type.to_s.humanize %>
1717
<span class="grey-text"><%= pluralize content_list.count, 'result' %></span>

0 commit comments

Comments
 (0)