Skip to content

Commit

Permalink
Don't show random page option for single page results
Browse files Browse the repository at this point in the history
Change-Id: I2ec9177a9aa78cb0f0bc0f1cd8791191bdc29ce4
  • Loading branch information
Akron committed Sep 26, 2024
1 parent 17b4146 commit 0ac1b5f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- Support VCs via URL without queries (diewald)
- Added translations for regexp and FCSQL (r-wilm)
- Introduce 'ui-ready' global event. (diewald)
- Don't show random page option for single page
results (diewald)

0.56 2024-09-23
- Improve slim test for plugin support
Expand Down
24 changes: 23 additions & 1 deletion dev/js/spec/panelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ define(['panel','view','panel/result','panel/pagination','util'], function (pane
expect(list.classList.contains('button-group-list')).toBeTruthy();
expect(list.classList.contains('visible')).toBeFalsy();

pagination.addRandomPage();
expect(pagination.addRandomPage()).toBeTruthy();

let clicked = false;
pagination.actions().add(
Expand All @@ -225,5 +225,27 @@ define(['panel','view','panel/result','panel/pagination','util'], function (pane
document.body.removeChild(p);
document.body.removeChild(pagination.actions().element());
});

it('shouldn\'t show random page on single pages', function () {

// Create pagination element for pagination information
let p = document.createElement('div');
p.setAttribute('id', 'pagination')
p.setAttribute('data-page',1);
p.setAttribute('data-total',1);
p.setAttribute('data-count',25);

document.body.appendChild(p);

// Create pagination class object
var pagination = paginationClass.create();
let list = pagination.actions().element();
expect(pagination.type).toEqual('pagination');
expect(list.classList.contains('button-group-list')).toBeTruthy();
expect(list.classList.contains('visible')).toBeFalsy();

expect(pagination.addRandomPage()).toBeFalsy();
});

});
});
12 changes: 8 additions & 4 deletions dev/js/src/panel/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ define([
// Localization values
const loc = KorAP.Locale;
loc.RANDOM_PAGE = loc.RANDOM_PAGE || 'Random page';


return {
type : 'pagination',
Expand Down Expand Up @@ -77,18 +76,23 @@ define([
*/
addRandomPage : function () {
const pi = pageInfoClass.create();


if (pi.total() < 2)
return false;

const button = this.actions().add(
loc.RANDOM_PAGE,
{},
function () {
if (pi.total() > 0) {
if (pi.total() > 1) {
const sp = new URLSearchParams(window.location.search);
sp.set("p", Math.floor(Math.random() * pi.total()) + 1);
window.location.search = sp.toString();
};
}
)
);

return true;
}
}
});

0 comments on commit 0ac1b5f

Please sign in to comment.