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

Fix(#10210): Hide pager when there is only one page (#10210) #10221

Merged
Merged
Changes from 3 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
76 changes: 39 additions & 37 deletions openlibrary/plugins/openlibrary/js/editions-table/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ export function initEditionsTable() {
var rowCount;
let currentLength;

$('#editions th.title').on('mouseover', function(){
$('#editions th.title').on('mouseover', function () {
if ($(this).hasClass('sorting_asc')) {
$(this).attr('title','Sort latest to earliest');
$(this).attr('title', 'Sort latest to earliest');
} else if ($(this).hasClass('sorting_desc')) {
$(this).attr('title','Sort earliest to latest');
$(this).attr('title', 'Sort earliest to latest');
} else {
$(this).attr('title','Sort by publish date');
$(this).attr('title', 'Sort by publish date');
}
});
$('#editions th.read').on('mouseover', function(){
$('#editions th.read').on('mouseover', function () {
if ($(this).hasClass('sorting_asc')) {
$(this).attr('title','Push readable versions to the bottom');
$(this).attr('title', 'Push readable versions to the bottom');
} else if ($(this).hasClass('sorting_desc')) {
$(this).attr('title','Sort by editions to read');
$(this).attr('title', 'Sort by editions to read');
} else {
$(this).attr('title','Available to read');
$(this).attr('title', 'Available to read');
}
});

Expand All @@ -38,44 +38,46 @@ export function initEditionsTable() {
}

$('#editions th.read span').html(' ↑');
$('#editions th').on('mouseup', function() {
toggleSorting(this)
$('#editions th').on('mouseup', function () {
toggleSorting(this);
});

$('#editions').on('length.dt', function(e, settings, length) {
$('#editions').on('length.dt', function (e, settings, length) {
localStorage.setItem(LS_RESULTS_LENGTH_KEY, length);
togglePaginationVisibility(length);
});

$('#editions th').on('keydown', function(e) {
$('#editions th').on('keydown', function (e) {
if (e.key === 'Enter') {
toggleSorting(this);
}
})
});

rowCount = $('#editions tbody tr').length;
if (rowCount < 4) {
$('#editions').DataTable({
aoColumns: [{sType: 'html'},null],
order: [ [1,'asc'] ],
bPaginate: false,
bInfo: false,
bFilter: false,
bStateSave: false,
bAutoWidth: false
});
} else {
currentLength = Number(localStorage.getItem(LS_RESULTS_LENGTH_KEY));
$('#editions').DataTable({
aoColumns: [{sType: 'html'},null],
order: [ [1,'asc'] ],
lengthMenu: [ [3, 10, 25, 50, 100, -1], [3, 10, 25, 50, 100, 'All'] ],
bPaginate: true,
bInfo: true,
sPaginationType: 'full_numbers',
bFilter: true,
bStateSave: false,
bAutoWidth: false,
pageLength: currentLength ? currentLength : DEFAULT_LENGTH
});
currentLength = Number(localStorage.getItem(LS_RESULTS_LENGTH_KEY)) || DEFAULT_LENGTH;

const dataTable = $('#editions').DataTable({
aoColumns: [{ sType: 'html' }, null],
order: [[1, 'asc']],
lengthMenu: [[3, 10, 25, 50, 100, -1], [3, 10, 25, 50, 100, 'All']],
bPaginate: rowCount > currentLength ,
bInfo: true,
sPaginationType: 'full_numbers',
bFilter: true,
bStateSave: false,
bAutoWidth: false,
pageLength: currentLength
});

// Toggle pagination visibility based on row count and selected length
function togglePaginationVisibility(selectedLength) {
if (rowCount <= selectedLength || selectedLength === -1) {
$('.dataTables_paginate').hide();
} else {
$('.dataTables_paginate').show();
}
}

// Initial pagination visibility toggle
togglePaginationVisibility(currentLength);
}
Loading