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
Documentation - pagination improvements #9102
Comments
Note - this was flagged as part of the UX Unification (GSoC 2022) project - but de-scoped. Labelling as a good first issue though. |
Hi @lb- , can you assign this to me |
@akshay-gupta7 we do not really assign issues to contributors, only the core team in some cases. Feel free to get started with this and prepare a PR when you are ready. Reach out if you need a hand, and remember there is a |
@lb- sure, thank you. I'll get started with this. |
Hi @lb- , raised a PR against this issue. Please do have a look whenever you can |
Hi @lb- , thank you for taking out the time to review my code. As per your review, I have put in the suggestions. Please do have a look whenever you can. |
I have put some feedback on the PR but just adding some solution ideas here, but the general gist is that we probably should tackle this in two parts. A. clean up the existing code (use proper event listeners, move the code to an external file For item B, we need to rethink the JS solution which iterates through the 'pages' and adds buttons for each page, instead it can be much simpler and just have TWO buttons (prev/next) and one status label (Page X of Y) and avoid lots of the need for Here is a rough potential base HTML for the template, leveraging data attributes to attach our JS to and places to attach the X/Y labels to. Note: This may need a full review in a screen reader and accessibility checker also. {% extends "layout.html" %}
{% set title = _('Search') %}
{% block body %}
<noscript>
<div id="fallback" class="admonition warning">
<p class="last">
{% trans trimmed %}
Please activate JavaScript to enable the search functionality.
{% endtrans %}
</p>
</div>
</noscript>
<div id="search-results">
</div>
<nav class="pagination" aria-label="Pagination" hidden="true" data-pagination="7">
<button type="button" class="pagination-button pagination-previous" data-pagination-previous aria-describedby="pagination-status">
{% trans trimmed %}← Previous{% endtrans %}
</button>
<span id="pagination-status">
{% trans trimmed %}Page <span data-pagination-status-x></span> of <span data-pagination-status-y></span>{% endtrans %}
</span>
<button type="button" class="pagination-button pagination-next" data-pagination-next aria-describedby="pagination-status">
{% trans trimmed %}Next →{% endtrans %}
</button>
</nav>
{% endblock %} Then in the JS, we can make things much simpler, and just attach to these elements. Something like the below as a start. function displayPagination(page, totalPages) {
const pagination = document.querySelector('[data-pagination]');
const maxPagesToDisplay = Number(pagination.dataset.pagination) || 7;
// Hide previous/next button if showing first/last page
const previousButton = pagination.querySelector('[data-pagination-previous]');
previousButton.hidden = page === 0;
const nextButton = pagination.querySelector('[data-pagination-next]');
nextButton.hidden = page === totalPages - 1;
// update status labels
const xLabel = pagination.querySelector('[data-pagination-status-x]');
xLabel.innerText = `${page}`;
const yLabel = pagination.querySelector('[data-pagination-status-y]');
yLabel.innerText = `${Math.min(totalPages, maxPagesToDisplay)}`;
// add event listeners here to the prev/next button This approach avoids a lot of the JS writing of content (Page X of Y) and keeps that in the initial DOM, and hopefully we can avoid the complexity of iteration. This may not cover the full solution but just some ideas on approaches. Also, we need to consider the following when adopting this new code.
All of this means that the change of the button layout is probably a larger task on its own so any PRs are welcome that make partial progress towards this overall goal. Any feedback is welcome on this rough code also. |
@lb- can you assign me this issue? i would like to work on it |
@aym-n there is a PR already started #9224 and also some direction above. Please review it all and if you want to give this a go as a new PR - go for it. @akshay-gupta7 - it's been a few months so I'm assuming you are ok for someone else to give this a go. Let me know otherwise. |
|
working on cleaning up the code and the tasks mentioned in the #9224 |
commit 224b03e Author: Ayman Makroo <ajm8982@gmail.com> Date: Sun Jan 22 14:25:50 2023 +0530 Updated QuerySelector Updated Query Selectors to use Data attributes instead of Class or Id names Also Removed Id tags for buttons commit 2fb6ce0 Author: Akshay Gupta <gravity.akshay@gmail.com> Date: Sat Sep 24 18:13:37 2022 +0530 Remove extra dynamic elements for pagination buttons commit 9fb8a90 Author: Akshay Gupta <gravity.akshay@gmail.com> Date: Fri Sep 23 17:27:37 2022 +0530 Prettier formatting commit 26f0cf5 Author: Akshay Gupta <gravity.akshay@gmail.com> Date: Thu Sep 22 00:31:33 2022 +0530 Move comments above function and add window.docsearch to resolve lint error commit 9618750 Author: Akshay Gupta <gravity.akshay@gmail.com> Date: Wed Sep 21 23:55:48 2022 +0530 Merge layout and search.js into one JS file to resolve undefined lint errors commit c40fa6a Author: Akshay Gupta <gravity.akshay@gmail.com> Date: Tue Sep 20 18:20:40 2022 +0530 Add layout.html JS code to separate layout.js and refactored to remove lint errors commit 3892b0a Author: Akshay Gupta <gravity.akshay@gmail.com> Date: Sun Sep 18 21:07:33 2022 +0530 Implement pagination updates in response to wagtail#9102 commit 522d382 Author: Akshay Gupta <gravity.akshay@gmail.com> Date: Sat Sep 17 18:55:30 2022 +0530 Implement pagination improvements(# 9102)
This comment was marked as duplicate.
This comment was marked as duplicate.
Thank You! |
I want to work on this. If the issue is open, please assign it to me. |
@MashiatK Please read the discussion above - there is already a pull request for this. |
Is your proposal related to a problem?
Describe the solution you'd like
onclick
withaddEventListener
- this is preferredAdditional context
addEventListener
is preferredThe text was updated successfully, but these errors were encountered: