mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-19 15:26:59 +00:00
Improve component filter experience
This commit is contained in:
parent
0e2d7473a7
commit
5a7de270dc
@ -19,8 +19,8 @@ Support for these components is provided by the Home Assistant community.
|
|||||||
{% assign categories = components | sort: 'ha_category' | map: 'ha_category' %}
|
{% assign categories = components | sort: 'ha_category' | map: 'ha_category' %}
|
||||||
|
|
||||||
<div class="filter-button-group">
|
<div class="filter-button-group">
|
||||||
<a href='#' class="btn" data-filter="*">All</a>
|
<a href='#all' class="btn">All</a>
|
||||||
<a href='#' class="btn current" data-filter=".featured">Featured</a>
|
<a href='#featured' class="btn">Featured</a>
|
||||||
|
|
||||||
{% comment %} Jekyll 2.5.2 does not support the uniq filter :/ {% endcomment %}
|
{% comment %} Jekyll 2.5.2 does not support the uniq filter :/ {% endcomment %}
|
||||||
{% assign category_printed = '' %}
|
{% assign category_printed = '' %}
|
||||||
@ -28,13 +28,13 @@ Support for these components is provided by the Home Assistant community.
|
|||||||
{% for category in categories %}
|
{% for category in categories %}
|
||||||
{% if category and category != 'Other' %}
|
{% if category and category != 'Other' %}
|
||||||
{% unless category_printed contains category %}
|
{% unless category_printed contains category %}
|
||||||
<a href='#' class="btn" data-filter=".{{ category | slugify }}">{{ category }}</a>
|
<a href='#{{ category | slugify }}' class="btn">{{ category }}</a>
|
||||||
{% assign category_printed = category_printed | append: ',' | append: category %}
|
{% assign category_printed = category_printed | append: ',' | append: category %}
|
||||||
{% endunless %}
|
{% endunless %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<a href='#' class="btn" data-filter=".{{ 'Other' | slugify }}">Other</a>
|
<a href='#other' class="btn">Other</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="componentContainer">
|
<div id="componentContainer">
|
||||||
@ -67,9 +67,31 @@ Support for these components is provided by the Home Assistant community.
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(window).load(function(){
|
$(window).load(function(){
|
||||||
var $container = $('#componentContainer');
|
var $container = $('#componentContainer');
|
||||||
|
|
||||||
|
function updateHash(newHash) {
|
||||||
|
if ('replaceState' in history) {
|
||||||
|
history.replaceState('', '', newHash);
|
||||||
|
} else {
|
||||||
|
location.hash = newHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyFilter() {
|
||||||
|
var filter = location.hash;
|
||||||
|
|
||||||
|
if (filter == '') {
|
||||||
|
filter = '.featured'
|
||||||
|
} else if (filter == 'all') {
|
||||||
|
filter = '*';
|
||||||
|
} else {
|
||||||
|
filter = '.' + filter.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.filter-button-group a.current').removeClass('current');
|
||||||
|
$('.filter-button-group a[href='+location.hash+']').addClass('current');
|
||||||
$container.isotope({
|
$container.isotope({
|
||||||
filter: '.featured',
|
filter: filter,
|
||||||
animationOptions: {
|
animationOptions: {
|
||||||
duration: 750,
|
duration: 750,
|
||||||
easing: 'linear',
|
easing: 'linear',
|
||||||
@ -78,23 +100,18 @@ $(window).load(function(){
|
|||||||
masonry: {
|
masonry: {
|
||||||
columnWidth: 210
|
columnWidth: 210
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$('.filter-button-group a').click(function() {
|
jQuery('.filter-button-group a').click(function() {
|
||||||
$('.filter-button-group .current').removeClass('current');
|
updateHash(this.getAttribute('href'));
|
||||||
$(this).addClass('current');
|
applyFilter();
|
||||||
|
|
||||||
var selector = $(this).attr('data-filter');
|
return false;
|
||||||
$container.isotope({
|
});
|
||||||
filter: selector,
|
|
||||||
animationOptions: {
|
|
||||||
duration: 750,
|
|
||||||
easing: 'linear',
|
|
||||||
queue: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
window.addEventListener('hashchange', applyFilter);
|
||||||
|
|
||||||
|
applyFilter();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user