Skip to content

Commit

Permalink
Perfomance and ADA updates
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroslavRaksha committed Jul 23, 2024
1 parent 935f4b6 commit 4f83e47
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 100 deletions.
16 changes: 10 additions & 6 deletions assets/findify-filter.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ button {
cursor: pointer;
}

#findify-filters *[aria-hidden="true"] {
display: none !important;
#findify-filters *[data-opened="true"] {
display: block;
}

/* SECTION - HEADER & BODY EXPAND */
Expand All @@ -139,11 +139,12 @@ button {
background: #fff;
width: 100%;
}
.findify-filters-body[aria-expanded="false"] {

.findify-filters-body[data-opened="false"] {
display: none;
}

.findify-filter-group:has(.findify-filters-body[aria-expanded="false"])
.findify-filter-group:has(.findify-filters-body[aria-expanded="true"])
.findify-filters-header
svg {
transform: rotate(180deg);
Expand Down Expand Up @@ -469,13 +470,16 @@ button {
}

.findify-price-range-input-container {
display: flex;
align-items: center;
padding: 0 8px;
border: 1px solid #000;
background: #fff;
}

.findify-price-range-input-container label {
display: flex;
align-items: center;
}

.price-range-input {
box-shadow: none;
max-width: 50px;
Expand Down
32 changes: 32 additions & 0 deletions assets/findify-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const filterSearch = (filter_group_id, input_id) => {
const filterSelector = '.findify-filters-checkbox-item';
const filterTextSelector = 'label';

const filterGroupElement = document.getElementById(filter_group_id);
const filters = filterGroupElement.querySelectorAll(filterSelector);
const input = document.getElementById(input_id);

const inputHandler = (e) => {
const value = e.target.value.trim().toLowerCase();
filters.forEach(item => {
const text = item.querySelector(filterTextSelector).innerText.trim().toLowerCase();
const shouldHide = value && !text.includes(value);
item.setAttribute("aria-hidden", shouldHide.toString());
});
};

input.addEventListener("input", inputHandler);
};

const collapseFilter = (element_id) => {
const filterGroupElement = document.getElementById(element_id);
const [header, body] = filterGroupElement.querySelectorAll('div');

const headerClickHandler = (e) => {
e.preventDefault();
const isOpen = body.getAttribute("data-opened") === "true";
body.setAttribute("data-opened", (!isOpen).toString());
};

header.addEventListener("click", headerClickHandler);
};
5 changes: 4 additions & 1 deletion assets/findify-sorting.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@

.findify-sorting-mobile-list li {
list-style: none;
justify-content: left;
}

.findify-sorting-mobile-list li label {
display: flex;
justify-content: start;
}

.findify-sorting-mobile-list li input {
Expand Down
65 changes: 2 additions & 63 deletions sections/findify-filter-group.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</label>
{% render 'findify-icon-arrow' %}
</div>
<div class="findify-filters-body" aria-expanded="true">
<div class="findify-filters-body" data-opened="true">
{% case component %}
{% when 'text' %}
{% render 'findify-filter-text'
Expand Down Expand Up @@ -82,67 +82,6 @@
</div>

<script>
const collapseFilter = () => {
const element_id = "{{ element_id }}";
const filterGroupElement = document.getElementById(element_id);
const [header, body] = filterGroupElement.querySelectorAll('div');
const isOneFilterOpen = document.querySelector('.findify-one-filter-open');
const headerClickHandler = (e) => {
e.preventDefault();
if(isOneFilterOpen){
const isExpanded = e.target
.parentNode
.parentNode
.querySelector('.findify-filters-body')?.getAttribute('aria-expanded');
if(isExpanded == 'false')
document.querySelector('#findify-filters [aria-expanded="true"]')?.setAttribute('aria-expanded', 'false');
}
const isOpen = body.getAttribute("aria-expanded") === "true";
body.setAttribute("aria-expanded", (!isOpen).toString());
};
header.addEventListener("click", headerClickHandler);
};
const filtersPosition = document.querySelector('#findify-filters').getBoundingClientRect().top;
const filterClass = document.querySelector('#findify-filters').className;
const searchWrapperTop = document.querySelector('.findify-search-container').getBoundingClientRect().x;
const isHorizontal = document.querySelector('.findify-search-section.filters-horizontal');
const fixedFilters = () => {
const scrollPosition = window.scrollY;
const classNames = document.querySelector('#findify-filters').className;
const searchWrapperHeight = document.querySelector('.findify-search-main').offsetHeight;
const filtersWrapperHeight = document.querySelector('#findify-filters').offsetHeight;
if(scrollPosition >= filtersPosition && !classNames.includes('fixed')){
document.querySelector('#findify-filters').className = classNames?.replace('absolute', '');
document.querySelector('#findify-filters').style.top = `0px`;
document.querySelector('#findify-filters').className += ' fixed';
}
if(scrollPosition > (searchWrapperHeight - 50) && !isHorizontal){
document.querySelector('#findify-filters').className = filterClass;
document.querySelector('#findify-filters').className += ' absolute';
document.querySelector('#findify-filters').style.top = `${searchWrapperHeight - filtersWrapperHeight}px`;
}
if( (scrollPosition - 80) < searchWrapperTop)
document.querySelector('#findify-filters').className = classNames.replace('fixed', '');
}
const isSticky = document.querySelector('.findify-filters-sticky');
if(isSticky) {
window.addEventListener('scroll', fixedFilters);
document.querySelectorAll('#shopify-section-findify-filter-group').forEach( item => {
item.addEventListener('click', fixedFilters);
})
}
collapseFilter();
collapseFilter("{{ element_id }}");
</script>
{% endif %}
17 changes: 10 additions & 7 deletions snippets/findify-filter-price-range.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
</div>
<span>-</span>
<div class="findify-price-range-input-container">
<input
min="{{ min_value }}"
max="{{ max_value }}"
type="number"
class="price-range-input"
id="{{ input_to_selector_id }}">
<span>{{ currency }}</span>
<label>
<input
min="{{ min_value }}"
max="{{ max_value }}"
type="number"
class="price-range-input"
id="{{ input_from_selector_id }}"
>
{{ currency }}
</label>
</div>
</div>
<button id='{{ submit_btn_selector_id }}'>{{ 'findify.filters.go' | t }}</button>
Expand Down
24 changes: 1 addition & 23 deletions snippets/findify-filter-search-input.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,5 @@
</div>

<script>
const filterSearch = () => {
const filter_group_id = "{{ filter_group_element_id }}";
const input_id = "{{ input_id }}";
const filterSelector = '.findify-filters-checkbox-item';
const filterTextSelector = 'label';
const filterGroupElement = document.getElementById(filter_group_id);
const filters = filterGroupElement.querySelectorAll(filterSelector);
const input = document.getElementById(input_id);
const inputHandler = (e) => {
const value = e.target.value.trim().toLowerCase();
filters.forEach(item => {
const text = item.querySelector(filterTextSelector).innerText.trim().toLowerCase();
const shouldHide = value && !text.includes(value);
item.setAttribute("aria-hidden", shouldHide.toString());
});
};
input.addEventListener("input", inputHandler);
};
filterSearch();
filterSearch("{{ filter_group_element_id }}", "{{ input_id }}");
</script>
1 change: 1 addition & 0 deletions snippets/findify-head-injector.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</script>

<script src="{{ 'findify-analytics.js' | asset_url }}" defer></script>
<script src="{{ 'findify-filter.js' | asset_url }}" defer></script>

<link
rel="stylesheet"
Expand Down

0 comments on commit 4f83e47

Please sign in to comment.