Created
November 9, 2012 05:06
-
-
Save island205/4043817 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| calculateDOMDepth = (doc = document)-> | |
| max = 0 | |
| _calculateDOMDepth = (dom)-> | |
| domdepth = dom.dataset.domdepth = parseInt(dom.parentNode.dataset.domdepth) + 1 | |
| max = domdepth if domdepth > max | |
| Array.prototype.forEach.call dom.children, (child)-> | |
| _calculateDOMDepth(child) | |
| body = doc.body | |
| body.parentNode.dataset.domdepth = 0 | |
| _calculateDOMDepth(body) | |
| max | |
| console.log calculateDOMDepth(document) | |
| console.log calculateDOMDepth() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment