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

WCAG Pagination: Added Button Support #9755

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion site/pages/docs/ref/paginate/paginate-en.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"categoryfile": "plugins",
"description": "Adds pagination at the bottom of a list of items.",
"altLangPrefix": "paginate",
"dateModified": "2023-05-15"
"dateModified": "2024-04-25"
}
---

Expand Down Expand Up @@ -118,6 +118,12 @@
</dl>
</td>
</tr>
<tr>
<td><code>buttonsUI</code></td>
<td>Sets the list of items to be created as buttons instead of anchor tags.</td>
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
<td>Boolean</td>
<td><code>true</code></td>
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
</tr>
</tbody>
</table>
</section>
Expand Down
8 changes: 7 additions & 1 deletion site/pages/docs/ref/paginate/paginate-fr.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"categoryfile": "plugins",
"description": "Ajoute une pagination à la fin d'une liste d'items.",
"altLangPrefix": "paginate",
"dateModified": "2023-05-15"
"dateModified": "2024-04-25"
}
---

Expand Down Expand Up @@ -127,6 +127,12 @@
</dl>
</td>
</tr>
<tr>
<td><code>buttonsUI</code></td>
<td>Définit la liste des éléments à créer sous forme de boutons au lieu de balises d'ancrage.</td>
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
<td>Booléen</td>
<td><code>true</code></td>
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
</tr>
</tbody>
</table>
</section>
Expand Down
61 changes: 61 additions & 0 deletions src/plugins/paginate/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,67 @@
border-bottom-right-radius: 4px;
border-top-right-radius: 4px;
}

BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
li.active:nth-last-child(2) button {
border-bottom-right-radius: 4px;
border-top-right-radius: 4px;
}

.pagination > li > button, .pagination > li > span {
background-color: #eaebed;
border: 1px solid #dcdee1;
color: #335075;
float: left;
line-height: 1.4375;
margin-left: -1px;
position: relative;
text-decoration: none;
}

.pagination > .active > button, .pagination > .active > button:focus, .pagination > .active > button:hover, .pagination > .active > span, .pagination > .active > span:focus, .pagination > .active > span:hover {
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
background-color: #2572b4;
border-color: #2572b4;
color: #fff;
cursor: default;
z-index: 3;
}


.pagination > li:first-child > button, .pagination > li:first-child > span {
border-bottom-left-radius: 4px;
border-top-left-radius: 4px;
margin-left: 0;
}

.pagination > li:last-child > button, .pagination > li:last-child > span {
border-bottom-right-radius: 4px;
border-top-right-radius: 4px;
}

.pagination > li > button:hover, .pagination > li > button:focus,
.pagination > li > span:hover,
.pagination > li > span:focus {
background-color: #d4d6da;
border-color: #bbbfc5;
color: #335075;
z-index: 2;
}

.pager > li > button, .pagination > li > button {
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
cursor: pointer;
display: inline-block;
margin-bottom: .5em;
padding: 10px 16px;
}

.pager > li.disabled + li > button, .pagination > li.disabled + li > button {
border-bottom-left-radius: 4px;
border-top-left-radius: 4px;
}

.pager > li.active > button, .pagination > li.active > button {
cursor: default;
}
}

html:not(.wb-disable) .wb-pgfltr-out {
Expand Down
15 changes: 9 additions & 6 deletions src/plugins/paginate/paginate-en.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"tag": "paginate",
"parentdir": "paginate",
"altLangPrefix": "paginate",
"dateModified": "2023-05-15"
"dateModified": "2024-04-25"
}
---

Expand All @@ -25,15 +25,16 @@

<h2>On this page:</h2>
<ul>
<li><a href="#paginatedList">Example 1 - List</a></li>
<li><a href="#paginatedList">Example 1 - List with buttons</a></li>
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
<li><a href="#paginatedTable">Example 2 - Table</a></li>
<li><a href="#paginatedArticles">Example 3 - Articles</a></li>
<li><a href="#filteredEventsList">Example 4 - Events list</a></li>
</ul>

<section id="paginatedList">
<h2>Example 1 - List</h2>
<ul class="wb-paginate provisional">
<h2>Example 1 - List with buttons</h2>
<ul class="wb-paginate provisional" data-wb-paginate='{
"buttonsUI": true }'>
<li>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Illum, at!</li>
<li>Soluta maiores deserunt fugit dolorum ratione cum necessitatibus dolore ipsum?</li>
<li>Libero debitis dicta porro modi nobis odit labore dolor eveniet.</li>
Expand Down Expand Up @@ -119,7 +120,8 @@
</ul>
<details>
<summary>Source code</summary>
<pre><code>&lt;ul class="wb-paginate provisional">
<pre><code>&lt;ul class="wb-paginate provisional" data-wb-paginate='{
"buttonsUI": true }'>
&lt;li>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Illum, at!&lt;/li>
&lt;li>Soluta maiores deserunt fugit dolorum ratione cum necessitatibus dolore ipsum?&lt;/li>
&lt;li>Libero debitis dicta porro modi nobis odit labore dolor eveniet.&lt;/li>
Expand Down Expand Up @@ -428,7 +430,8 @@
<h2>Example 3 - Articles</h2>
<p>This example leverages the following option: <code>itemsPerPage</code></p>
<div class="wb-paginate provisional row wb-eqht-grd" data-wb-paginate='{
"itemsPerPage": 12
"itemsPerPage": 12,
"buttonsUI": true
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
}'>
<article class="col-sm-6 col-md-4 col-lg-3">
<div class="well">
Expand Down
12 changes: 7 additions & 5 deletions src/plugins/paginate/paginate-fr.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"tag": "paginate",
"parentdir": "paginate",
"altLangPrefix": "paginate",
"dateModified": "2023-05-15"
"dateModified": "2024-04-25"
}
---

Expand All @@ -22,15 +22,16 @@

<h2>Sur cette page:</h2>
<ul>
<li><a href="#paginatedList">Exemple 1 - Liste</a></li>
<li><a href="#paginatedList">Exemple 1 - Liste avec des boutons</a></li>
<li><a href="#paginatedTable">Exemple 2 - Tableau</a></li>
<li><a href="#paginatedArticles">Exemple 3 - Articles</a></li>
<li><a href="#filteredEventsList">Exemple 4 - Liste d'événements</a></li>
</ul>

<section id="paginatedList">
<h2>Exemple 1 - Liste</h2>
<ul class="wb-paginate provisional">
<h2>Exemple 1 - Liste avec des boutons</h2>
<ul class="wb-paginate provisional" data-wb-paginate='{
"buttonsUI": true }'>
<li>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Illum, at!</li>
<li>Soluta maiores deserunt fugit dolorum ratione cum necessitatibus dolore ipsum?</li>
<li>Libero debitis dicta porro modi nobis odit labore dolor eveniet.</li>
Expand Down Expand Up @@ -116,7 +117,8 @@
</ul>
<details>
<summary>Code source</summary>
<pre><code>&lt;ul class="wb-paginate provisional">
<pre><code>&lt;ul class="wb-paginate provisional" data-wb-paginate='{
"buttonsUI": true }'>
&lt;li>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Illum, at!&lt;/li>
&lt;li>Soluta maiores deserunt fugit dolorum ratione cum necessitatibus dolore ipsum?&lt;/li>
&lt;li>Libero debitis dicta porro modi nobis odit labore dolor eveniet.&lt;/li>
Expand Down
52 changes: 46 additions & 6 deletions src/plugins/paginate/paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const componentName = "wb-paginate",
elm.pgSettings.itemsPerPage = elm.pgSettings.itemsPerPage || defaults.itemsPerPage;
elm.pgSettings.items = elm.querySelectorAll( ( elm.pgSettings.section || ":scope" ) + " " + elm.pgSettings.selector + notFilterClassSel );

// elm.pgSettings.buttonsUI = true;

// Setup pagination container
paginationElm = document.createElement( "div" );
paginationElm.id = componentName + "-" + elm.id;
Expand Down Expand Up @@ -103,6 +105,7 @@ const componentName = "wb-paginate",
currPage = elm.pgSettings.currPage,
pagesCount = elm.pgSettings.pagesCount,
paginationElm = document.querySelector( "#" + componentName + "-" + elm.id ),
buttonsUI = elm.pgSettings.buttonsUI,
i = 1;

// Make sure the defined current page is not bigger than the total pages
Expand All @@ -115,16 +118,47 @@ const componentName = "wb-paginate",
paginationUI = "<ol class=\"pagination\">";

// Add Previous page button
paginationUI += "<li" + ( i === currPage ? " class=\"disabled\"" : "" ) + "><a class=\"paginate-prev\" aria-controls=\"" + elm.id + "\" href=\"#" + elm.id + "\">" + i18nText.prv + "</a></li>";
var prevLI = "";
prevLI += "<li" + ( i === currPage ? " class=\"disabled\"" : "" ) + ">";

if ( buttonsUI ) {
prevLI += "<button class=\"paginate-prev\" aria-controls=\"" + elm.id + "\"><span class=\"wb-inv\">Page </span>" + i18nText.prv + "</button>";
Garneauma marked this conversation as resolved.
Show resolved Hide resolved

} else {
prevLI += "<a class=\"paginate-prev\" aria-controls=\"" + elm.id + "\" href=\"#" + elm.id + "\">" + i18nText.prv + "</a>";
}

prevLI += "</li>";

paginationUI += prevLI;

// Add pages buttons
for ( i; i <= pagesCount; i++ ) {
paginationUI += "<li class=\"" + returnItemClass( currPage, pagesCount, i ) + "\"" + ( i === currPage ? " aria-current=\"page\"" : "" ) + "><a href=\"#" + elm.id + "\" " + pageData + "=\"" + i + "\" aria-controls=\"" + elm.id + "\"><span class=\"wb-inv\">Page </span>" + i + "</a></li>";
var pageButtonLI = "";
pageButtonLI += "<li class=\"" + returnItemClass( currPage, pagesCount, i ) + "\"" + ( i === currPage ? " aria-current=\"page\"" : "" ) + ">";

if ( buttonsUI ) {
pageButtonLI += "<button " + pageData + "=\"" + i + "\" aria-controls=\"" + elm.id + "\"><span class=\"wb-inv\">Page </span>" + i + "</button>";
} else {
pageButtonLI += "<a href=\"#" + elm.id + "\" " + pageData + "=\"" + i + "\" aria-controls=\"" + elm.id + "\"><span class=\"wb-inv\">Page </span>" + i + "</a>";
}

pageButtonLI += "</li>";
paginationUI += pageButtonLI;
}

// Add Next page button
paginationUI += "<li" + ( i === currPage ? " class=\"disabled\"" : "" ) + "><a class=\"paginate-next\" aria-controls=\"" + elm.id + "\" href=\"#" + elm.id + "\">" + i18nText.nxt + "</a></li>";
var nextLI = "";
nextLI += "<li" + ( i === currPage ? " class=\"disabled\"" : "" ) + ">";

if ( buttonsUI ) {
nextLI += "<button class=\"paginate-next\" aria-controls=\"" + elm.id + "\"><span class=\"wb-inv\">Page </span>" + i18nText.nxt + "</button>";
Garneauma marked this conversation as resolved.
Show resolved Hide resolved
} else {
nextLI += "<a class=\"paginate-next\" aria-controls=\"" + elm.id + "\" href=\"#" + elm.id + "\">" + i18nText.nxt + "</a>";
}

nextLI += "</li>";
paginationUI += nextLI;
paginationUI += "</ol>";
}

Expand Down Expand Up @@ -156,10 +190,16 @@ const componentName = "wb-paginate",
itemClass,
pageLink,
currPage = elm.pgSettings.currPage,
pagesCount = elm.pgSettings.pagesCount;
pagesCount = elm.pgSettings.pagesCount,
buttonsUI = elm.pgSettings.buttonsUI;

pageItems.forEach( function( pageItem, i ) {
pageLink = pageItem.querySelector( "a" );
if ( buttonsUI ) {
pageLink = pageItem.querySelector( "button" );
} else {
pageLink = pageItem.querySelector( "a" );
}


BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
if ( pageLink.classList.contains( "paginate-prev" ) ) {
if ( currPage > 1 ) {
Expand Down Expand Up @@ -234,7 +274,7 @@ const componentName = "wb-paginate",
};

// When a filter is updated
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
$document.on( "click", "." + pagerClass + " a", function() {
$document.on( "click", "." + pagerClass + " a, ." + pagerClass + " button", function() {
BrahimMahadi marked this conversation as resolved.
Show resolved Hide resolved
let elm = document.querySelector( "#" + this.getAttribute( "aria-controls" ) ),
pageDest = ( ( this.getAttribute( pageData ) ) * 1 ) || elm.pgSettings.currPage;

Expand Down