Skip to content

Commit

Permalink
replaced DOMNodeInserted with MutationObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
degenone committed Aug 15, 2023
1 parent a14db9b commit fa90848
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/TagzApp.Web/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,29 @@
var connection;

const taggedContent = document.getElementById("taggedContent");
const observer = new MutationObserver(function (mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type !== 'childList') continue;
for (const node of mutation.addedNodes) {
const imgCardTop = node.querySelector(".card-img-top");
if (imgCardTop !== null) {
imgCardTop.addEventListener("load", function (ev) {
window.Masonry.resizeGridItem(node);
}, false);
imgCardTop.addEventListener("error", function (ev) {
window.Masonry.resizeGridItem(node);
}, false);
} else {
window.Masonry.resizeGridItem(node);
}
}
}
});
const observerConfig = {
childList: true
};

observer.observe(taggedContent, observerConfig);
async function start() {
try {
await connection.start();
Expand Down Expand Up @@ -50,15 +72,6 @@
`
}

if (content.previewCard) {
newMessage.querySelector(".card-img-top").addEventListener("load", function (ev) {
window.Masonry.resizeGridItem(newMessage);
}, false);
} else {
newMessage.addEventListener("DOMNodeInserted", function (ev) {
window.Masonry.resizeGridItem(newMessage);
}, false);
}
newMessage.addEventListener("click", function (ev) {

var el = ev.target.closest('article');
Expand Down

0 comments on commit fa90848

Please sign in to comment.