From d60de02faa836bdc05619f1b45dbaccd9c80d7cc Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 1 Oct 2022 23:55:12 +0700 Subject: [PATCH] fix: album page header's total size text also simplify various logics --- src/js/album.js | 26 +++++++++++--------------- views/album.njk | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/js/album.js b/src/js/album.js index 617d74d..51822d0 100644 --- a/src/js/album.js +++ b/src/js/album.js @@ -13,21 +13,18 @@ const page = { } window.addEventListener('DOMContentLoaded', () => { - const files = document.querySelectorAll('.image-container') + // Prettify all .file-size elements + const sizeElements = document.querySelectorAll('.file-size') + for (let i = 0; i < sizeElements.length; i++) { + const string = sizeElements[i].dataset.value || sizeElements[i].innerHTML + sizeElements[i].innerHTML = page.getPrettyBytes(parseInt(string, 10)) + } - // Prettify individual file's data rows - for (let i = 0; i < files.length; i++) { - const sizeElem = files[i].querySelector('.details .file-size') - if (sizeElem) { - const str = sizeElem.dataset.value || sizeElem.innerHTML.replace(/\s*B$/i, '') - sizeElem.innerHTML = page.getPrettyBytes(parseInt(str)) - } - - const dateElem = files[i].querySelector('.details .file-date') - if (dateElem) { - const str = dateElem.dataset.value - dateElem.innerHTML = page.getPrettyDate(new Date(parseInt(str) * 1000)) - } + // Prettify all .file-date elements + const dateElements = document.querySelectorAll('.file-date') + for (let i = 0; i < dateElements.length; i++) { + const string = dateElements[i].dataset.value + dateElements[i].innerHTML = page.getPrettyDate(new Date(parseInt(string, 10) * 1000)) } page.lazyLoad = new LazyLoad() @@ -38,7 +35,6 @@ window.addEventListener('DOMContentLoaded', () => { return ext.substring(1) // removes starting dot }).join('|')}`, 'i') - console.log(imageExtsRegex) page.lightbox = new SimpleLightbox('#table a.image', { captions: true, captionSelector: 'img', diff --git a/views/album.njk b/views/album.njk index cd2bb6f..5a25264 100644 --- a/views/album.njk +++ b/views/album.njk @@ -131,7 +131,7 @@

{{ file.name }}

-

{{ file.size }} B

+

{{ file.size }} B