Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
expands comments on click
var comments = document.querySelector('#comments');
function findParentComment(elem) {
while (elem && elem.parentNode) {
if (elem.classList.contains('comment')) {
return elem;
}
elem = elem.parentNode;
}
return null;
}
function removeIndent(elem) {
while (elem && elem.parentNode) {
if (elem.classList.contains('indented')) {
elem.style.marginLeft = '0'
}
elem = elem.parentNode;
}
}
document.body.addEventListener('click', function (e) {
Array.prototype.slice.call(document.querySelectorAll('.indented')).forEach(function (elem) {
elem.style.marginLeft = '';
});
if (e.target.nodeName.toUpperCase() !== 'A') {
var c = findParentComment(e.target);
if (c) {
removeIndent(c);
}
}
});
Array.prototype.slice.call(document.querySelectorAll('.indented')).forEach(function (elem) {
elem.style.transition = 'margin 0.5s';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.