mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-27 19:26:50 +00:00
Feature component search (#2275)
* * added search box to the component overview page. * minor fixes in the javascript * minor fix: spaces
This commit is contained in:
parent
1a08bf7a48
commit
0e92aacf6e
@ -330,6 +330,21 @@ p.note {
|
|||||||
-moz-transition-property: -moz-transform, opacity;
|
-moz-transition-property: -moz-transform, opacity;
|
||||||
transition-property: transform, opacity;
|
transition-property: transform, opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.component-search{
|
||||||
|
margin-bottom: 24px;
|
||||||
|
|
||||||
|
input{
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
|
||||||
|
background-color: #fefefe;
|
||||||
|
border-radius: 2px;
|
||||||
|
border: 1px solid;
|
||||||
|
border-color: #7c7c7c #c3c3c3 #ddd;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: $lap-end) {
|
@media only screen and (max-width: $lap-end) {
|
||||||
|
@ -52,24 +52,33 @@ Support for these components is provided by the Home Assistant community.
|
|||||||
<a href='#other' class="btn">Other</a>
|
<a href='#other' class="btn">Other</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid__item five-sixths lap-one-whole palm-one-whole hass-option-cards" id="componentContainer">
|
<div class="grid__item five-sixths lap-one-whole palm-one-whole">
|
||||||
{% for component in components %}
|
<div class="component-search">
|
||||||
{% if component.ha_category %}
|
<form onsubmit="event.preventDefault(); return false">
|
||||||
{% assign sliced_version = component.ha_release | split: '.' %}
|
<input type="text" name="search" id="search" class="search" placeholder="Search components...">
|
||||||
{% assign minor_version = sliced_version[1]|plus: 0 %}
|
</form>
|
||||||
<a href='{{ component.url }}'
|
</div>
|
||||||
class='option-card {{ component.ha_category | slugify }}{% if minor_version == site.current_minor_version %} added_in_current_version{% elsif minor_version == added_one_ago_minor_version %} added_one_version_ago{% elsif minor_version == added_two_ago_minor_version %} added_two_versions_ago{% endif %}{% if component.featured %} featured{% endif %}'
|
<div class="hass-option-cards" id="componentContainer">
|
||||||
{% unless component.featured %}style='display: none'{% endunless %}>
|
{% for component in components %}
|
||||||
<div class='img-container'>
|
{% if component.ha_category %}
|
||||||
{% if component.logo %}
|
{% assign sliced_version = component.ha_release | split: '.' %}
|
||||||
<img src='/images/supported_brands/{{ component.logo }}'>
|
{% assign minor_version = sliced_version[1]|plus: 0 %}
|
||||||
{% endif %}
|
<a href='{{ component.url }}'
|
||||||
</div>
|
class='option-card {{ component.ha_category | slugify }}{% if minor_version == site.current_minor_version %} added_in_current_version{% elsif minor_version == added_one_ago_minor_version %} added_one_version_ago{% elsif minor_version == added_two_ago_minor_version %} added_two_versions_ago{% endif %}{% if component.featured %} featured{% endif %}'
|
||||||
<div class='title'>{{ component.title }}</div>
|
data-title="{{component.title| downcase}}"
|
||||||
<div class='category'>{{ component.ha_category }}</div>
|
data-ha_category="{{component.ha_category | downcase}}"
|
||||||
</a>
|
{% unless component.featured %}style='display: none'{% endunless %}>
|
||||||
{% endif %}
|
<div class='img-container'>
|
||||||
{% endfor %}
|
{% if component.logo %}
|
||||||
|
<img src='/images/supported_brands/{{ component.logo }}'>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class='title'>{{ component.title }}</div>
|
||||||
|
<div class='category'>{{ component.ha_category }}</div>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -85,20 +94,32 @@ Support for these components is provided by the Home Assistant community.
|
|||||||
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
|
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// undo initial hiding of non-featured cards
|
// undo initial hiding of non-featured cards
|
||||||
if (location.hash !== '') {
|
(function(){
|
||||||
if (location.hash === '#all') {
|
var hash = location.hash;
|
||||||
jQuery('#componentContainer a').show();
|
if (hash !== '') {
|
||||||
} else {
|
if (hash === '#all' || hash.indexOf('#search/') === 0) {
|
||||||
jQuery('#componentContainer .featured').hide();
|
jQuery('#componentContainer a').show();
|
||||||
jQuery('#componentContainer .' + location.hash.substr(1)).show();
|
} else {
|
||||||
|
jQuery('#componentContainer .featured').hide();
|
||||||
|
jQuery('#componentContainer .' + hash.substr(1)).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hash.indexOf('#search/') === 0) {
|
||||||
|
// set default value in search from URL
|
||||||
|
jQuery('.component-search input').val(decodeURIComponent(hash).substring(8));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})();
|
||||||
</script>
|
</script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(window).load(function(){
|
$(window).load(function(){
|
||||||
|
|
||||||
var $container = $('#componentContainer');
|
var $container = $('#componentContainer');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the browser location hash. This enables users to use the browser-history
|
||||||
|
*/
|
||||||
function updateHash(newHash) {
|
function updateHash(newHash) {
|
||||||
if ('replaceState' in history) {
|
if ('replaceState' in history) {
|
||||||
history.replaceState('', '', newHash);
|
history.replaceState('', '', newHash);
|
||||||
@ -107,21 +128,47 @@ $(window).load(function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* filter all components, based on the location's hash
|
||||||
|
*/
|
||||||
function applyFilter() {
|
function applyFilter() {
|
||||||
var hash = location.hash;
|
var hash = location.hash;
|
||||||
|
|
||||||
var filter;
|
var filter;
|
||||||
|
|
||||||
if (hash == '') {
|
if (hash == '') {
|
||||||
filter = '.featured'
|
filter = '.featured';
|
||||||
hash = '#featured'
|
hash = '#featured';
|
||||||
} else if (hash == '#all') {
|
|
||||||
|
} else if (hash === '#all') {
|
||||||
|
// show all elements
|
||||||
filter = '*';
|
filter = '*';
|
||||||
|
|
||||||
|
} else if (hash.indexOf('#search/') === 0) {
|
||||||
|
// search for the given string
|
||||||
|
var text = decodeURIComponent(hash).substring(8).toLowerCase();
|
||||||
|
text = text.replace(/[(\?|\&\{\}\(\))]/gi, '').toLowerCase();
|
||||||
|
|
||||||
|
if(text && text.length === 0){
|
||||||
|
filter = '*';
|
||||||
|
} else {
|
||||||
|
filter = function() {
|
||||||
|
var title = $(this).data('title');
|
||||||
|
var cat = $(this).data('ha_category');
|
||||||
|
return title.indexOf(text) != -1 || cat.indexOf(text) != -1;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
filter = '.' + hash.substr(1);
|
filter = '.' + hash.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hash.indexOf('#search/') === 0) {
|
||||||
|
// reset the search field when no longer searching
|
||||||
|
$('.component-search input').val(null);
|
||||||
|
}
|
||||||
|
|
||||||
$('.filter-button-group a.current').removeClass('current');
|
$('.filter-button-group a.current').removeClass('current');
|
||||||
$('.filter-button-group a[href='+hash+']').addClass('current');
|
$('.filter-button-group a[href="'+hash+'"]').addClass('current');
|
||||||
|
|
||||||
$container.isotope({
|
$container.isotope({
|
||||||
filter: filter,
|
filter: filter,
|
||||||
@ -136,6 +183,7 @@ $(window).load(function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update view by filter selection
|
||||||
jQuery('.filter-button-group a').click(function() {
|
jQuery('.filter-button-group a').click(function() {
|
||||||
updateHash(this.getAttribute('href'));
|
updateHash(this.getAttribute('href'));
|
||||||
applyFilter();
|
applyFilter();
|
||||||
@ -143,8 +191,40 @@ $(window).load(function(){
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple debounce implementation, based on http://davidwalsh.name/javascript-debounce-function
|
||||||
|
*/
|
||||||
|
function debounce(func, wait, immediate) {
|
||||||
|
var timeout;
|
||||||
|
return function() {
|
||||||
|
var context = this, args = arguments;
|
||||||
|
var later = function() {
|
||||||
|
timeout = null;
|
||||||
|
if (!immediate) {
|
||||||
|
func.apply(context, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var callNow = immediate && !timeout;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(later, wait);
|
||||||
|
if (callNow) {
|
||||||
|
func.apply(context, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// update view by search text
|
||||||
|
$('.component-search input').keyup(debounce(function() {
|
||||||
|
var text = $(this).val();
|
||||||
|
// sanitize input
|
||||||
|
text = text.replace(/[(\?|\&\{\}\(\))]/gi, '');
|
||||||
|
updateHash('#search/' + text);
|
||||||
|
applyFilter();
|
||||||
|
}, 500));
|
||||||
|
|
||||||
window.addEventListener('hashchange', applyFilter);
|
window.addEventListener('hashchange', applyFilter);
|
||||||
|
|
||||||
|
// initialize from URL
|
||||||
applyFilter();
|
applyFilter();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user