Skip to content

Commit

Permalink
Add no results message and fix location hash (2factorauth#2608)
Browse files Browse the repository at this point in the history
  • Loading branch information
PSGS authored and jamcat22 committed Jul 4, 2017
1 parent e92878f commit 9ac5bc7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
6 changes: 6 additions & 0 deletions css/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ input[type=search] {
}
}

#no-results {
display: none;
padding-bottom: 40px;
text-align: center;
}

.active-icon {
background-color: $primary-color;
color: white;
Expand Down
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ <h5 class="ui icon header">
{% endif %}
{% endfor %}
</div>

<div id="no-results">
<h2>No results found</h2>
</div>
28 changes: 19 additions & 9 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ $(document).ready(function () {

// Unveil images 50px before they appear
$('img').unveil(50);

// Show exception warnings upon hover
$('span.popup.exception').popup({
hoverable: true
});
$('a.popup.exception').popup();
});

/**
Expand All @@ -22,47 +28,50 @@ $(window).resize(function () {
}, 500);
});

// Show exception warnings upon hover
(function (root, $) {
$('span.popup.exception').popup({
hoverable: true
});
$('a.popup.exception').popup();
}(window, jQuery));

var isSearching = false;
var jets = new Jets({
searchTag: '#jets-search',
contentTag: '.jets-content',
didSearch: function (searchPhrase) {
document.location.hash = '';
$('#no-results').css('display', 'none');
$('.category h5 i').removeClass('active-icon');
// Two separate table layouts are used for desktop/mobile
var platform = ($(window).width() > 768) ? 'desktop' : 'mobile';
var content = $('.' + platform + '-table .jets-content');
var table = $('.' + platform + '-table');

// Non-strict comparison operator is used to allow for null
if (searchPhrase == '') {
// Show all categories when no search term is entered
$('.website-table').css('display', 'none');
$('.website-table .label').css('display', 'none');
$('.category').show();
$('table').show();
isSearching = false;
} else {
// Hide irrelevant categories
$('.website-table').css('display', 'none');
$('.website-table .label').css('display', 'block');
$('.category').hide();
table.css('display', 'block');
content.parent().show();
content.each(function () {
// Hide table when all rows are hidden by Jets
// Hide table when all rows within are hidden by Jets
if ($(this).children(':hidden').length === $(this).children().length) {
if (platform == 'mobile') $(this).parent().hide();
else $(this).parent().parent().hide();
}
});

if (table.children().length == table.children(':hidden').length) {
$('#no-results').css('display', 'block');
}

isSearching = true;
}
},
// Process searchable elements manually
manualContentHandling: function(tag) {
return $(tag).find('.title > a.name').text();
}
Expand Down Expand Up @@ -127,4 +136,5 @@ function openCategory(category) {
function closeCategory(category) {
$('#' + category + ' h5 i').removeClass('active-icon');
$('.' + category + '-table').css('display', 'none');
document.location.hash = '';
}

0 comments on commit 9ac5bc7

Please sign in to comment.