-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnote.js
30 lines (25 loc) · 1.07 KB
/
note.js
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
import imagesLoaded from 'imagesloaded'
document.addEventListener('DOMContentLoaded', function () {
function resizeGridItem (item) {
const grid = document.getElementsByClassName('note-card-holder')[0]
const rowHeight = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-auto-rows'))
const rowGap = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-row-gap'))
const rowSpan = Math.ceil((item.querySelector('.item').getBoundingClientRect().height + rowGap) / (rowHeight + rowGap))
item.style.gridRowEnd = 'span ' + rowSpan
}
function resizeAllGridItems () {
const allItems = document.getElementsByClassName('note-card')
for (let x = 0; x < allItems.length; x++) {
resizeGridItem(allItems[x])
}
}
function resizeInstance (instance) {
const item = instance.elements[0]
resizeGridItem(item)
}
window.addEventListener('resize', resizeAllGridItems)
const allItems = document.getElementsByClassName('note-card')
for (let x = 0; x < allItems.length; x++) {
imagesLoaded(allItems[x], resizeInstance)
}
})