Skip to content

Commit

Permalink
JS tidy-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Starcross committed Oct 25, 2024
1 parent 6c66ffb commit 111afe3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion static/gallery/js/image_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const left = 37; const right = 39;

document.addEventListener("keydown", function(event) {
document.addEventListener('keydown', function(event) {
switch(event.which) {
case left:
if (previous_image_url) {
Expand Down
4 changes: 1 addition & 3 deletions static/gallery/js/infinite_scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function init_infinite_scroll() {
}

function check_infinite_scroll(event) {

// Based on https://benjaminhorn.io/code/how-to-implement-infinite-scroll/
// Handle a scrollable element nested within fixed elements by referring to event.target
let target = (event.target instanceof HTMLDocument) ?
Expand All @@ -26,8 +25,7 @@ function check_infinite_scroll(event) {

}

function load_images_from_cursor(cursor) {

function load_images_from_cursor() {
// Find the images in the thumbnail container
const images = document.querySelectorAll('.image');
const thumbnails = document.querySelectorAll('.thumbnail');
Expand Down
18 changes: 9 additions & 9 deletions static/gallery/js/justify_images.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/



function justify_images() {
/** Fix the width each image in a container to fully justify each row */

Expand All @@ -18,7 +17,7 @@ function justify_images() {

// Find the images in the thumbnail container
const images = document.querySelectorAll('.image');
if (images == []) {
if (!images.length) {
return;
}

Expand Down Expand Up @@ -60,24 +59,25 @@ function justify_images() {

function resize_row(images, factor) {
/** Set each item in the image array according to the given factor */
const spacer = 'image_spacer'; // Spacer CSS class name

for (let i=0; i < images.length; i++) {

const overlay = images[i].nextElementSibling;
const width = ((images[i].naturalWidth / hdpi_factor) * factor);
images[i].style.width = width + "px";
images[i].style.width = width + 'px';
const height = ((images[i].naturalHeight / hdpi_factor) * factor);
images[i].style.height = height + "px";
images[i].style.height = height + 'px';
// Add a margin to image and overlay if this is not the last image
if (i < (images.length - 1)) {
images[i].classList.add('image_spacer');
overlay.classList.add('image_spacer');
images[i].classList.add(spacer);
overlay.classList.add(spacer);

} else {
images[i].classList.remove('image_spacer');
overlay.classList.remove('image_spacer');
images[i].classList.remove(spacer);
overlay.classList.remove(spacer);
}
}
}

window.addEventListener('resize',justify_images);
window.addEventListener('resize', justify_images);

0 comments on commit 111afe3

Please sign in to comment.