Last active
August 29, 2015 14:12
-
-
Save Ajnasz/bcade75b5e9fd949f2fb to your computer and use it in GitHub Desktop.
expands comments on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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