2023-05-25 09:31:14 -04:00
|
|
|
{"version":3,"file":"archive.min.js","sources":["../../../js/dom.js","../../../js/data_tables.js","../../../js/tag_input.js","../../../js/main.js","../../../js/archive.js","../../../js/utils.js"],"sourcesContent":["const $ = function(selector) {\n return document.querySelector(selector);\n};\n\nconst $$ = function(selector) {\n return document.querySelectorAll(selector) || [];\n};\n\nconst makeEl = function(html) {\n const template = document.createElement('template');\n\n template.innerHTML = html.trim();\n\n return template.content.firstChild;\n};\n\nconst clearEl = function(el) {\n while (el.firstChild) {\n el.removeChild(el.firstChild);\n }\n};\n\nconst toggleEl = function(el) {\n if (el.classList.contains('is-hidden')) {\n el.classList.remove('is-hidden');\n } else {\n el.classList.add('is-hidden');\n }\n};\n\nconst escape = function(unsafe) {\n return unsafe\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nconst whenReady = function(funcp) {\n if (document.readyState !== 'loading') {\n funcp();\n } else {\n document.addEventListener('DOMContentLoaded', funcp);\n }\n}\n\nexport { whenReady, $, $$, makeEl, clearEl, toggleEl, escape };","import { makeEl, clearEl } from \"./dom\";\n\nclass SimplePaginator {\n constructor(element) {\n this.element = element;\n }\n\n attach(pageCallback) {\n this.element.addEventListener('click', evt => {\n if (evt.target && evt.target.classList.contains('paginator__button')) {\n pageCallback(+evt.target.dataset.page);\n }\n });\n }\n\n update(totalRecords, perPage, currentPage) {\n clearEl(this.element);\n\n /* First and last page in existence */\n const firstPage = 0;\n const lastPage = Math.floor(totalRecords / perPage); // ish?\n const numPagesToShow = 2;\n\n if (lastPage === firstPage) {\n return;\n }\n\n /* First and last page the main paginator will show */\n const firstPageShow = (currentPage - numPagesToShow) < firstPage ? firstPage : (currentPage - numPagesToShow);\n const lastPageShow = (currentPage + numPagesToShow) > lastPage ? lastPage : (currentPage + numPagesToShow);\n\n /* Whether to show the first and last pages in existence at the ends of the paginator */\n const showFirstPage = (Math.abs(firstPage - currentPage)) > (numPagesToShow);\n const showLastPage = (Math.abs(lastPage - currentPage)) > (numPagesToShow);\n\n\n const prevButtonDisabled = currentPage === firstPage ? 'disabled' : ''\n\n /* Previous button */\n this.element.appendChild(makeEl(\n `<button class=\"paginator__button previous\" ${prevButtonDisabled} data-page=\"${currentPage - 1}\">Previous</button>`\n ));\n\n /* First page button */\n if (showFirstPage) {\n this.element.appendChild(makeEl(\n `<button class=\"paginator__button\" data-page=\"${firstPage}\">${firstPage}</button>`\n ));\n this.element.appendChild(makeEl(`<span class=\"ellipsis\">…</span>`));\n }\n\n /* \"window\" buttons */\n for (let i = firstPageShow; i <= lastPageShow; i++) {\n const selected = (i === currentPage ? 'paginator__button--selected' : '');\n this.element.appendChild(makeEl(\n `<button class=\"paginator__button ${selected}\" data-page=\"${i}\">${i}</button>`\n ));\n }\n\n /* Last page button */\n if (showLastPage) {\n this.element.appendChild(makeEl(`<span class=\"ellipsis\">…</span>`));\n this.element.appendChild(makeEl(\n `<button class=\"paginator__button\" data-page=\"${lastPage}\">${lastPage}</button>`\n ));\n }\n\n const nextButtonDisabled = currentPage === lastPage ? 'disabled' : ''\n
|