Skip to content

Commit

Permalink
refactor: cleanstr-helper and classList.toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
janbritz committed Feb 8, 2024
1 parent 94394c4 commit 006ba9c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion amd/build/package_search/components/pagination.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/package_search/components/pagination.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions amd/src/package_search/components/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,12 @@ export default class extends Component {
const currentPage = this._getCurrentPage();
const lastPage = this._getLastPage();

// Update page status.
this.getElement(this.selectors.CURRENT).innerHTML = `${currentPage + 1} / ${lastPage + 1}`;

if (currentPage === 0) {
this.getElement(this.selectors.PREVIOUS_BUTTON).classList.add("disabled");
} else {
this.getElement(this.selectors.PREVIOUS_BUTTON).classList.remove("disabled");
}
if (currentPage === lastPage) {
this.getElement(this.selectors.NEXT_BUTTON).classList.add("disabled");
} else {
this.getElement(this.selectors.NEXT_BUTTON).classList.remove("disabled");
}
// Disable or enable buttons.
this.getElement(this.selectors.PREVIOUS_BUTTON).classList.toggle("disabled", currentPage === 0);
this.getElement(this.selectors.NEXT_BUTTON).classList.toggle("disabled", currentPage === lastPage);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions templates/package_search/pagination.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
Example context (json):
{}
}}
<nav data-for="pagination" aria-label="{{#str}}search_pagination_label_aria, qtype_questionpy{{/str}}">
<nav data-for="pagination" aria-label="{{#cleanstr}} search_pagination_label_aria, qtype_questionpy {{/cleanstr}}">
<ul class="pagination justify-content-center">
<li class="page-item disabled" data-for="pagination-previous">
<a role="button" class="page-link" aria-label="{{#str}}search_pagination_previous_aria, qtype_questionpy{{/str}}">
<a role="button" class="page-link" aria-label="{{#cleanstr}} search_pagination_previous_aria, qtype_questionpy {{/cleanstr}}">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li class="page-item active"><span class="page-link" data-for="pagination-current">1 / 1</span></li>
<li class="page-item disabled" data-for="pagination-next">
<a role="button" class="page-link" aria-label="{{#str}}search_pagination_next_aria, qtype_questionpy{{/str}}">
<a role="button" class="page-link" aria-label="{{#cleanstr}} search_pagination_next_aria, qtype_questionpy {{/cleanstr}}">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
Expand Down

0 comments on commit 006ba9c

Please sign in to comment.