Skip to content

Commit 11492b6

Browse files
authored
Merge pull request algorithm-visualizer#167 from duaraghav8/gh-pages
Search Bar
2 parents b815ef7 + a28acf8 commit 11492b6

12 files changed

+197
-83
lines changed

css/stylesheet.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ nav h3 {
180180
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.48), inset 0 -2px 2px rgba(0, 0, 0, 0.36);
181181
}
182182

183+
input.search_bar {
184+
box-sizing: border-box;
185+
background: rgba(0, 0, 0, .10);
186+
border: none;
187+
border-bottom: 2px solid rgb(38, 38, 38);
188+
width: 100%;
189+
height: 30px;
190+
color: white;
191+
padding-left: 10px;
192+
}
193+
194+
input.search_bar:focus {
195+
outline: none;
196+
}
197+
183198
.workspace {
184199
position: absolute;
185200
top: 30px;

gulpfile.babel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@ gulp.task('watch', ['build'], function() {
147147

148148
// Default
149149

150-
gulp.task('default', ['connect', 'watch']);
150+
gulp.task('default', ['connect', 'watch']);

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ <h3>
6161
</div>
6262
</nav>
6363
<section class="sidemenu active">
64+
<input type = "text" class="search_bar" id="search-bar" autofocus/>
6465
<div id="list">
6566
</div>
6667
<div id="footer">

js/dom/enable_search.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
module.exports = () => {
4+
let $buttons = $('[data-category]');
5+
6+
$('#search-bar').keyup (function () {
7+
let query = $(this).val ();
8+
let re = new RegExp (query, 'i');
9+
10+
if (query) $('#footer').hide ();
11+
else $('#footer').show ();
12+
13+
$.each ($('#list .category'), function (i, c) {
14+
let $c = $(c);
15+
!$c.hasClass ('open') && $c.click ();
16+
});
17+
18+
$buttons.show ().filter (function () {
19+
let cName = $(this).attr ('data-category');
20+
21+
if ($(this).hasClass ('category')) {
22+
return !re.test ($(`[data-category="${cName}"]`).text ());
23+
}
24+
else {
25+
return !(
26+
re.test ($(`.category[data-category="${cName}"]`).text()) || re.test ($(this).text ())
27+
);
28+
}
29+
}).hide ();
30+
31+
$('.algorithms').show ().filter (function () {
32+
return !$(this).children (':visible').length;
33+
}).hide ();
34+
});
35+
};

js/dom/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const addFiles = require('./add_files');
77
const showFirstAlgorithm = require('./show_first_algorithm');
88
const showRequestedAlgorithm = require('./show_requested_algorithm');
99
const showWiki = require('./show_wiki');
10+
const enableSearch = require('./enable_search');
1011

1112
module.exports = {
1213
showAlgorithm,
@@ -15,5 +16,6 @@ module.exports = {
1516
addFiles,
1617
showFirstAlgorithm,
1718
showRequestedAlgorithm,
18-
showWiki
19+
showWiki,
20+
enableSearch
1921
};

js/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ $(() => {
4545
app.setCategories(data);
4646
DOM.addCategories();
4747

48+
//enable search feature
49+
DOM.enableSearch ();
50+
4851
// determine if the app is loading a pre-existing scratch-pad
4952
// or the home page
5053
const {

public/algorithm_visualizer.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@ nav h3 {
300300
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.48), inset 0 -2px 2px rgba(0, 0, 0, 0.36);
301301
}
302302

303+
input.search_bar {
304+
box-sizing: border-box;
305+
background: rgba(0, 0, 0, .10);
306+
border: none;
307+
border-bottom: 2px solid rgb(38, 38, 38);
308+
width: 100%;
309+
height: 30px;
310+
color: white;
311+
padding-left: 10px;
312+
}
313+
314+
input.search_bar:focus {
315+
outline: none;
316+
}
317+
303318
.workspace {
304319
position: absolute;
305320
top: 30px;

0 commit comments

Comments
 (0)