Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

jquery Filter by username

  • Loading branch information...
commit 00e8674e078904b2472e89cbabdf250ba7dca14c 1 parent e185858
@joemsak joemsak authored
View
2  app/views/accounts/_account.html.erb
@@ -1,7 +1,7 @@
<% full ||= false -%>
<article class="account">
<%= render :partial => 'portrait', :locals => { :account => account, :full => full } %>
- <% unless full -%><h2><%= link_to account.username, account %></h2><% end -%>
+ <% unless full -%><h2 id="username_<%= account.id %>"><%= link_to account.username, account %></h2><% end -%>
<% unless account.names.empty? %>
<p><%= render :partial => 'name', :collection => account.names %></p>
View
1  app/views/accounts/index.html.erb
@@ -1,3 +1,4 @@
+<p><input id="filter_by_username" type="text" placeholder="Filter"></p>
<section id="accounts">
<%= render :partial => 'account', :collection => @accounts %>
</section>
View
10 public/javascripts/application.js
@@ -11,8 +11,14 @@ $(document).ready(function(){
})
//bind the filter input on the INDEX list
- $('#filter_by_username').change(function(){
-
+ $('#filter_by_username').keyup(function(){
+ $('#accounts .account').addClass('hide');
+ regexp = new RegExp($(this).val().toLowerCase());
+ for(var i=0; i<usernames.length; i++) {
+ if(usernames[i].toLowerCase().match(regexp)){
+ $('#accounts .account').find('h2:contains('+usernames[i]+')').parent().removeClass('hide');
+ }
+ }
})
});
View
12 public/stylesheets/site.css
@@ -128,6 +128,15 @@ body{
margin:0 0 25px;
}
+p{
+ margin:0 0 10px;
+}
+#filter_by_username{
+ padding:5px;
+ width:200px;
+ border:1px solid #333;
+}
+
#accounts{
overflow:hidden;
}
@@ -142,6 +151,9 @@ body{
font-size:16px;
margin:0 0 5px;
}
+.hide{
+ display:none;
+}
#footer-padding {
height: 70px;
Please sign in to comment.
Something went wrong with that request. Please try again.