diff options
author | Andinus <andinus@nand.sh> | 2022-06-11 15:16:13 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2022-06-11 15:16:13 +0530 |
commit | 3e8364c123f9e54e17540c9fbe5cdcc072355079 (patch) | |
tree | 74e17c8352ecc928669553687835869944de922f /resources | |
parent | 7b24df0be78fb9ba59e7ef4c6d7210530a19e98b (diff) | |
download | crater-3e8364c123f9e54e17540c9fbe5cdcc072355079.tar.gz |
Add styles for directory, improve gallery UX
Diffstat (limited to 'resources')
-rw-r--r-- | resources/css/style.css | 4 | ||||
-rw-r--r-- | resources/js/gallery.js | 35 |
2 files changed, 38 insertions, 1 deletions
diff --git a/resources/css/style.css b/resources/css/style.css index 240c98d..b2132df 100644 --- a/resources/css/style.css +++ b/resources/css/style.css @@ -111,6 +111,10 @@ img { width: 400px; } #gallery { margin: auto; } +#gallery a { + color: var(--fg-main); + text-decoration: none; +} #gallery img { transform-origin: center; transition: 0.5s; diff --git a/resources/js/gallery.js b/resources/js/gallery.js index 0289e58..b7b7e06 100644 --- a/resources/js/gallery.js +++ b/resources/js/gallery.js @@ -29,15 +29,26 @@ bricks )); document.addEventListener('DOMContentLoaded', event => { - bricks.resize(true); // bind resize handler + bricks.resize(true).pack(); // bind resize handler & initial pack }); +/** + * packing should be done multiple times. Sometimes the div of + * directories is not properly packed if packing is done only once. + */ // Packing after loading images //////////////////////////////////////////// const onImagesLoaded = (container, event) => { const images = container.getElementsByTagName("img"); const progressBar = document.getElementById("loading-progress"); + // Keeps track of how many times we've packed the images. + let packed = 0; + const incrementPackedAndPack = () => { + packed++; + bricks.pack(); + }; + // failed keeps track of images that failed to load. let failed = 0; let remaining = images.length; @@ -52,6 +63,28 @@ const onImagesLoaded = (container, event) => { progressBar.value = round( ((images.length - remaining) / images.length) * 100 ); + + // pack multiple times for better experience. This way + // the initial pictures are properly visible to the + // user while the other load. It's very cheap to pack + // lots of elements too using bricks.js so it's not an + // issue. + // + // There is no point in specifying such large ranges + // as this runs in a single thread to for sure we'll + // hit the range. + if (5 < progressBar.value && progressBar.value < 20) + if (packed < 2) + incrementPackedAndPack(); + + if (30 < progressBar.value && progressBar.value < 50) + if (packed < 4) + incrementPackedAndPack(); + + if (80 < progressBar.value && progressBar.value < 95) + if (packed < 5) + incrementPackedAndPack(); + if (remaining === failed) event(remaining, failed, progressBar); }); |