Skip to content

Instantly share code, notes, and snippets.

@amdrade
Last active November 12, 2017 20:01
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 amdrade/c1c7e674e9c77c9dddb85b4635df6478 to your computer and use it in GitHub Desktop.
Save amdrade/c1c7e674e9c77c9dddb85b4635df6478 to your computer and use it in GitHub Desktop.
Funções JS
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