Skip to content

Commit

Permalink
Define various UI states for search [refs #5]
Browse files Browse the repository at this point in the history
  • Loading branch information
chadokruse committed Jul 15, 2016
1 parent f121b56 commit b21baff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
10 changes: 7 additions & 3 deletions assets/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ $wide-layout-margin: 20%;
}

/* Search */
.sort {
cursor: pointer;
}
.search-wrapper {
position: relative;
.search-box:not(:valid) ~ .search-clear {
Expand Down Expand Up @@ -381,9 +384,10 @@ $wide-layout-margin: 20%;
color: _palette(accent1, bg);
display: inline-block;
}
tr td.search-no-items-found {

}
}
#search-no-items-found {
display: none;
min-height: 500px;
}

a.grantee-thumb {
Expand Down
36 changes: 28 additions & 8 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,29 @@
listSearchAll.push(listObject);
});

//Define UI states
var listStateDefault = function() {
$('.search-box-label').css('visibility', 'hidden');
$('tfoot, thead').show();
$('.js-listjs').show();
$('tbody.list:parent').closest('.js-listjs').children('h3').show();
$('#search-no-items-found').hide();
};

var listStateSearching = function() {
$('.search-box-label').css('visibility', 'visible');
$('tfoot, thead').hide();
$('tbody.list:empty').closest('.js-listjs').children('h3').hide();
$('tbody.list:parent').closest('.js-listjs').children('h3').show();
$('.js-listjs').show();
$('#search-no-items-found').hide();
};

var listStateNoResults = function() {
$('#search-no-items-found').show();
$('.js-listjs').hide();
};

//Enable live search
$('#db-search').on('keyup', function() {
var searchString = $(this).val();
Expand All @@ -191,22 +214,19 @@
//Show count
var listSearchSize = $('.list tr').length;
$('.search-count').html(listSearchSize);
$('.search-box-label').css('visibility', 'visible');
//Simplify table styling
$('tfoot, thead').hide();
$('tbody.list:empty').closest('.js-listjs').children('h3').hide();
$('tbody.list:parent').closest('.js-listjs').children('h3').show();
listStateSearching();
});

//Add anchor reference to count element for scroll
var listFirstResult = $('tbody tr').eq(0).closest($('.js-listjs')).attr('id');
if ( typeof listFirstResult !== 'undefined' ) {
$('.search-count').attr('href', '#' + listFirstResult);
$('.scrolly').scrolly(); //Re-initialize Scrolly
listStateSearching();
}
else {
$('.search-count').removeAttr("href");
//TODO: Show no results found message

listStateNoResults();
}

});
Expand All @@ -216,7 +236,7 @@
$.each(listSearchAll, function(){
this.search();
});
$('.search-box-label').css('visibility', 'hidden');
listStateDefault();
});

// Format numbers
Expand Down
10 changes: 7 additions & 3 deletions pages/grantees.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ <h3 class="db-table-header">{{ year[0] }}</h3>
<table border="0px">
<thead>
<tr>
<th class="sort db-grantee-name" data-sort="db-grantee-name">Grantee Name</th>
<th class="sort db-grantee-location" data-sort="db-grantee-location">Location</th>
<th class="sort db-grant-amount" data-sort="db-grant-amount">Amount</th>
<th class="sort" data-sort="db-grantee-name">Grantee Name</th>
<th class="sort" data-sort="db-grantee-location">Location</th>
<th class="sort" data-sort="db-grant-amount">Amount</th>
<th class="db-grant-purpose">Purpose</th>
</tr>
</thead>
Expand Down Expand Up @@ -85,6 +85,10 @@ <h3 class="db-table-header">{{ year[0] }}</h3>
</table>
</div>
{% endfor %}
<section id="search-no-items-found">
<h3>No grants found</h3>
<!--p><a href="#db-search" class="scrolly">Try new search</a></p-->
</section>
</section>

<script src="{{ site.baseurl }}/assets/js/list.min.js"></script>

0 comments on commit b21baff

Please sign in to comment.