#Javascript Project Utils
Created
May 19, 2015 07:47
-
-
Save dewwwald/9108829b004a8867c0a0 to your computer and use it in GitHub Desktop.
Javascript project utils
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
getParentWithClassName = (node, className) -> | |
parent = node.parentNode | |
if parent.className.indexOf(className) >= 0 | |
return parent | |
return getParentWithClassName(parent, className) | |
getSiblingByClassName = (node, className) -> | |
parent = node.parentNode | |
return getChildByClassName(parent, className) | |
getChildByClassName = (node, className) -> | |
for child in node.childNodes | |
if child.nodeName != '#text' && child.className.indexOf(className) >= 0 | |
return child | |
return false | |
getFilename = (string) -> | |
_arr = string.split('\\') | |
_arr[_arr.length - 1] | |
addClass = (node, clss) -> | |
node.className = "#{node.className} #{clss}" | |
removeClass = (node, clss) -> | |
for item in node.classList | |
node.classList.remove(clss) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment