Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty filters -button disabled styles #83

Open
wants to merge 3 commits into
base: PO-350-base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Perustuu projektiin [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

### Korjattu
- PO-293: Vinkkien järjestäminen
- PO-350: Tehdään tyhjentämisen jälkeen haku vain jos jotain muuttui

## [1.2.0] - 2018-09-05

Expand Down
2 changes: 1 addition & 1 deletion content/themes/custom/assets/dist/admin.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion content/themes/custom/assets/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion content/themes/custom/assets/dist/main.js.map

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions content/themes/custom/assets/scripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class Search {
$( e.currentTarget ).toggleClass( 'active' );
}

setEmptyBtnStatus() {
const url = new Url();
if ( !! _.get( url, 'query.post_guids', []).length ) {
this.$emptyFiltersButton.removeClass( 'disabled' );
} else {
this.$emptyFiltersButton.addClass( 'disabled' );
}
}

/**
* Handle search metadata
*
Expand Down Expand Up @@ -101,6 +110,7 @@ class Search {
this.$emptyFiltersButton.on( 'click', ( e ) => this.emptyFilters( e ) );

this.populateFilters();
this.setEmptyBtnStatus();
}
};

Expand Down Expand Up @@ -265,6 +275,7 @@ class Search {
// Collect args from the form that was submitted either via click or submit event
const args = this.getArgs( $form );
this.handleUrlOnSearch( args );
this.setEmptyBtnStatus();

// Abort any existing calls
if ( this.xhr ) {
Expand Down Expand Up @@ -445,10 +456,11 @@ class Search {
* Empty filters.
*/
emptyFilters( e ) {
const checkboxes = this.$searchFilter.find( 'input[type=checkbox]:not(.and-or-input)' );
checkboxes.filter( '[type="checkbox"]:checked' ).removeAttr( 'checked' ).prop( 'checked', false );

this.doSearch( e );
const $btn = $( e.currentTarget );
if ( ! $btn.hasClass( 'disabled' ) ) {
this.$searchFilter.find( 'input[type=checkbox]:not(.and-or-input):checked' ).removeAttr( 'checked' ).prop( 'checked', false );
this.doSearch( e );
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion content/themes/custom/partials/shared/search-filter.dust
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

{^embed}
<div class="search-buttons">
<button class="search-buttons__btn" type="button" id="search-empty-filters-button">Tyhjennä</button>
<button class="search-buttons__btn disabled" type="button" id="search-empty-filters-button">Tyhjennä</button>
</div>

<input type="hidden" name="s" value="{Term}" placeholder="{Header.S.search_placeholder}" title="{Header.S.search_title}">
Expand Down