1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const resizeHandler = () => {
const photosElement = document.getElementById('photos');
const photos = document.querySelectorAll('.photo');
const containerWidth = parseFloat(photosElement.getBoundingClientRect().width, 10);
let ratio = [];
photos.forEach((element, index) => {
ratio[index] = element.dataset.height > 0 ? element.dataset.width / element.dataset.height : 1;
});
let layoutGeometry = require('justified-layout')(ratio, {
containerWidth: containerWidth,
containerPadding: 0,
targetRowHeight: 200
});
photosElement.style.height = layoutGeometry.containerHeight + 'px';
photos.forEach((element, index) => {
element.style.top = layoutGeometry.boxes[index].top + 'px';
element.style.width = layoutGeometry.boxes[index].width + 'px';
element.style.height = layoutGeometry.boxes[index].height + 'px';
element.style.left = layoutGeometry.boxes[index].left + 'px';
element.children[1].style.width = layoutGeometry.boxes[index].width + 'px';
});
};
resizeHandler();
document.addEventListener('keyup', () => {
if (event.ctrlKey === true || event.altKey === true) return;
if (event.key == "Escape") {
window.stop()
document.getElementById('back').click();
};
});
document.addEventListener('keydown', () => {
if (event.ctrlKey === true || event.altKey === true) return;
if (event.key == " ") {
event.preventDefault();
event.stopPropagation();
const element = document.getElementById("toggle");
element.checked = !element.checked;
};
});
document.addEventListener('DOMContentLoaded', () => {
const photosElement = document.getElementById("photos")
photosElement.classList.remove('flex');
photosElement.classList.add('justified');
window.onresize = resizeHandler;
resizeHandler();
});