forked from eddiesigner/liebling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotos.hbs
66 lines (55 loc) · 2.2 KB
/
photos.hbs
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
57
58
59
60
61
62
63
64
65
66
{{!--
This template is used for this page.
It can be used also as the home page or the default page.
--}}
{{!-- This block preloads specific assets for this page --}}
{{#contentFor "preload"}}
<link rel="preload" href="{{asset "css/home.css"}}" as="style" />
<link rel="preload" href="{{asset "css/listing.css"}}" as="style" />
<link rel="preload" href="{{asset "js/home.js"}}" as="script" />
{{/contentFor}}
{{!-- This block loads specific styles for this page --}}
{{#contentFor "styles"}}
<link rel="stylesheet" type="text/css" href="{{asset "css/home.css"}}" media="screen" />
<link rel="stylesheet" type="text/css" href="{{asset "css/listing.css"}}" media="screen" />
<link rel="stylesheet" href="https://use.typekit.net/eyj8xkd.css">
{{/contentFor}}
{{!< default}}
<main class="main-wrap">
{{> "photo-loop"}}
</main>
{{!-- The #contentFor helper here will send everything inside it up to the matching #block helper found in default.hbs --}}
{{#contentFor "scripts"}}
<script defer src="{{asset "js/home.js"}}"></script>
<script src="{{asset "js/vendor.js"}}"></script>
<script src="{{asset "js/helpers.js"}}"></script>
<script>
// The following block will reorder the default list of photos such that the (2) columns
// each are as close in height as possible. This fixes situations where the default order
// produces relatively off-balance columns.
// calculate reorder
function calculateReorder() {
var photos = document.getElementById("photo-list"); // element wrapper containing all the photos
var col1 = document.createDocumentFragment();
var col2 = document.createDocumentFragment();
var col1Sum = 0;
var col2Sum = 0;
for (const child of photos.children) { // iterate to calculate order based on offsetHeight
var h = child;
if(col1Sum < col2Sum) {
col1Sum += h.offsetHeight;
col1.appendChild(h.cloneNode(true));
} else {
col2Sum += h.offsetHeight;
col2.appendChild(h.cloneNode(true));
}
}
// apply reorder to DOM
photos.innerHTML = ""; // reset element with new order
photos.appendChild(col1);
photos.appendChild(col2);
console.log("Done reordering!");
}
window.onresize = calculateReorder();
</script>
{{/contentFor}}