feat(pagination): Add handler to pagination buttons

This commit is contained in:
Joxit
2019-06-04 22:06:14 +02:00
parent 02210e0943
commit 92fc37adb4
5 changed files with 47 additions and 3 deletions

View File

@@ -85,7 +85,7 @@ registryUI.removeServer = function(url) {
}
registryUI.updateHistory = function(url) {
history.pushState(null, '', (url ? '?url=' + registryUI.encodeURI(url) : '?') + window.location.hash);
registryUI.updateQueryString({ url: registryUI.encodeURI(url) })
registryUI._url = url;
}
@@ -100,10 +100,12 @@ registryUI.getUrlQueryParam = function () {
};
registryUI.encodeURI = function(url) {
if (!url) { return; }
return url.indexOf('&') < 0 ? window.encodeURIComponent(url) : btoa(url);
};
registryUI.decodeURI = function(url) {
if (!url) { return; }
return url.startsWith('http') ? window.decodeURIComponent(url) : atob(url);
};

View File

@@ -76,7 +76,7 @@ registryUI.getPage = function(elts, page, limit) {
registryUI.getNumPages = function(elts, limit) {
if (!limit) { limit = 100; }
if (!elts) { return 0; }
return Math.trunc((elts.length / limit) % 10);
return Math.trunc((elts.length / limit) % 10) + 1;
}
registryUI.getPageLabels = function(page, nPages) {
@@ -95,4 +95,14 @@ registryUI.getPageLabels = function(page, nPages) {
pageLabels.push({'icon': 'last_page', page: nPages});
}
return pageLabels;
}
registryUI.updateQueryString = function(qs) {
var search = '';
for (var key in qs) {
if (qs[key] !== undefined) {
search += (search.length > 0 ? '&' : '?') +key + '=' + qs[key];
}
}
history.pushState(null, '', search + window.location.hash);
}