Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ajnasz/bcade75b5e9fd949f2fb to your computer and use it in GitHub Desktop.
Save Ajnasz/bcade75b5e9fd949f2fb to your computer and use it in GitHub Desktop.
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