Last active
November 12, 2017 20:01
-
-
Save amdrade/c1c7e674e9c77c9dddb85b4635df6478 to your computer and use it in GitHub Desktop.
Funções JS
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
function generateUrl() { | |
var location = window.location, | |
url = window.location.href; | |
if (location.protocol == 'https:') { | |
url = 'https:' + location.href.substring(location.protocol.length); | |
} | |
return url; | |
} | |
function hasClass(el, className) { | |
if (el.classList) { | |
return el.classList.contains(className) | |
} else { | |
return !!el.className.match(new RegExp(('\\s|^') + className + '(\\s|$)')) | |
} | |
} | |
function addClass(el, className) { | |
if (el.classList) { | |
el.classList.add(className) | |
} else if (!hasClass(el, className)) { | |
el.className += " " + className; | |
} | |
} | |
function removeClass(el, className) { | |
if (el.classList) { | |
el.classList.remove(className) | |
} else if (hasClass(el, className)) { | |
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)'); | |
el.className = el.className.replace(reg, ' '); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment