Merge pull request #93 from JoahG/add-search

Add search
This commit is contained in:
Hosein Emrani 2013-12-15 09:49:22 -08:00
commit a159ebe690
3 changed files with 52 additions and 1 deletions

View File

@ -43,8 +43,14 @@
</div>
</section>
<!-- That's it ! compartion table :) -->
<section>
<div class="search">
<input type="text" placeholder="Search Frontend Frameworks" id="search">
</div>
</section>
<!-- That's it ! compartion table :) -->
<section id="comparisonTable">
<nav>
<blockquote class="guide">Browser version " + " means latest version .</blockquote>
<div class="parent">
@ -1788,6 +1794,9 @@
</div>
</div>
<div class="parent" id="noSearch">
There were no search results matching <span></span>
</div>
</nav>
</section>
@ -1824,6 +1833,7 @@
<!-- Scripts -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/search.js"></script>
<script>
$('nav .parent ul').on('click', function (e) {
$(this).next('.info').toggleClass('active')

View File

@ -141,6 +141,22 @@ section p:last-child {
top: 50%;
margin-top: -7px;
}
/* Search */
#noSearch {
display: none;
text-align: center;
}
#search {
width: 100%;
margin-top: 20px;
font-size: 16px;
line-height: 25px;
font-family: 'Droid Sans';
}
#search:focus {
outline: auto 5px #900;
outline-offset: -2px;
}
/* Table */ /* We should use nav and ul li for collapsing details */
nav {
width: 980px;

25
js/search.js Normal file
View File

@ -0,0 +1,25 @@
$(document).ready(function(){
$("input#search").keyup(function(){
var query = $(this).val();
if (!query) {
$("#comparisonTable div.parent").show();
$("#noSearch").hide();
return;
}
var regex = new RegExp(query, "ig"), count = 0;
$("#comparisonTable div.parent:not(#noSearch)").each(function(){
if ($(this).text().search(regex) < 0) {
$(this).hide();
} else {
$(this).show();
count += 1
}
});
if (count == 0) {
$("#noSearch span").text(query)
$("#noSearch").show();
} else {
$("#noSearch").hide();
}
});
});