forked from jarun/buku
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jarun#603] implemented a custom/default list size action
- Loading branch information
1 parent
ba9d62b
commit 2e5fb19
Showing
2 changed files
with
31 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
$(document).ready(function() { | ||
const SIZES = [20, 50, 100]; // hardcoded list; see page_size_form in admin/model/layout.html | ||
let pageSize = url => new URL(url || location.host).searchParams.get('page_size'); | ||
$(`.actions-nav .dropdown-menu`).each(function () { | ||
let _sizes = $(`li a`, this).map(function () {return pageSize(this.href)}).get(); | ||
if (SIZES.every((x, i) => x == _sizes[i])) | ||
$(`li`, this).last().clone().each(function () { | ||
$('a', this).text("custom").attr('href', `#`).on('click', () => { | ||
let page = prompt(`Set custom page size (empty for default)`, pageSize(location) || ''); | ||
if (Number(page) || (page == "")) { | ||
let search = new URL(location).searchParams; | ||
(page ? search.set('page_size', page) : search.delete('page_size')); | ||
location.search = search; | ||
} else if (page != null) | ||
alert(`Invalid page size: "${page}"`); | ||
return false; | ||
}); | ||
}).appendTo(this); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters