Skip to content

Instantly share code, notes, and snippets.

@skvggor
Created January 26, 2014 15:46
Show Gist options
  • Save skvggor/8634657 to your computer and use it in GitHub Desktop.
Save skvggor/8634657 to your computer and use it in GitHub Desktop.
example
var Apps, Nevada;
Nevada = Nevada || {};
Nevada.apps = {
indexOf: function() {
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(searchElement) {
'use strict';
var k, len, n, t;
if (typeof this === "undefined" || this === null) {
throw new TypeError();
}
n = void 0;
k = void 0;
t = Object(this);
len = t.length >>> 0;
if (len === 0) {
return -1;
}
n = 0;
if (arguments.length > 1) {
n = Number(arguments[1]);
if (n !== n) {
n = 0;
} else {
if (n !== 0 && n !== Infinity && n !== -Infinity) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
}
if (n >= len) {
return -1;
}
k = (n >= 0 ? n : Math.max(len - Math.abs(n), 0));
while (k < len) {
if (k in t && t[k] === searchElement) {
return k;
}
k++;
}
return -1;
};
}
},
converterSegParaMili: function(tempoSegundos) {
return tempoSegundos * 1000;
},
carregarScripts: function() {
var scripts, _carregar;
scripts = document.getElementsByTagName('script')[0];
_carregar = function(url) {
var script;
script = document.createElement('script');
script.async = true;
script.src = url;
scripts.parentNode.insertBefore(script, scripts);
};
_carregar('http://e.issuu.com/embed.js');
},
removerBackgroundMenu: function() {
var i, lis, menuChildren, _i, _ref;
menuChildren = document.querySelectorAll('.menu')[0];
lis = menuChildren.querySelectorAll('li');
for (i = _i = 0, _ref = lis.length - 1; _i <= _ref; i = _i += 1) {
if (lis[i].innerHTML.match('<ul class="submenu">') === null) {
lis[i].setAttribute('class', 'sem-background');
}
}
},
ajustarWidthSubmenu: function() {
var i, item, offsetWidths, submenus, _i, _len;
submenus = document.querySelectorAll('.submenu');
offsetWidths = [];
for (i = _i = 0, _len = submenus.length; _i < _len; i = _i += 1) {
item = submenus[i];
offsetWidths[i] = submenus[i].previousSibling.previousSibling.offsetWidth;
submenus[i].style.width = offsetWidths[i] + 'px';
}
},
slider: function() {
var inicializar, interval, n, slides, _anterior, _destacarSlide, _listeners, _pause, _play, _proximo, _timer;
slides = document.querySelectorAll('.slide');
if (slides[0]) {
interval = window.interval;
n = 0;
_listeners = function() {
var btnAnterior, btnProximo, controles;
controles = document.querySelector('.controles');
btnAnterior = document.querySelector('.anterior');
btnProximo = document.querySelector('.proximo');
if (btnAnterior.addEventListener) {
btnAnterior.addEventListener('click', _anterior);
btnProximo.addEventListener('click', _proximo);
controles.addEventListener('mouseover', _pause);
controles.addEventListener('mouseout', _play);
} else {
btnAnterior.attachEvent('onclick', _anterior);
btnProximo.attachEvent('onclick', _proximo);
controles.attachEvent('onmouseover', _pause);
controles.attachEvent('onmouseout', _play);
}
};
_destacarSlide = function(n) {
var arranjos, i, item, posicoes, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
posicoes = ['esquerda', 'centro', 'direita'];
arranjos = [1, 0, 2, 2, 1, 0, 0, 2, 1];
if (n === 0) {
_ref = arranjos.slice(0, 3);
for (i = _i = 0, _len = _ref.length; _i < _len; i = _i += 1) {
item = _ref[i];
slides[item].setAttribute('class', 'slide ' + posicoes[i]);
}
} else if (n === 1) {
_ref1 = arranjos.slice(3, 6);
for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = _j += 1) {
item = _ref1[i];
slides[item].setAttribute('class', 'slide ' + posicoes[i]);
}
} else if (n === 2) {
_ref2 = arranjos.slice(6, 9);
for (i = _k = 0, _len2 = _ref2.length; _k < _len2; i = _k += 1) {
item = _ref2[i];
slides[item].setAttribute('class', 'slide ' + posicoes[i]);
}
}
};
_timer = function() {
var paraSegundos, tempo;
tempo = 4;
paraSegundos = Nevada.apps.converterSegParaMili;
interval = setInterval(function() {
_proximo();
}, paraSegundos(tempo));
};
_anterior = function() {
if (n > 0) {
n -= 1;
} else {
n = 2;
}
_destacarSlide(n);
};
_proximo = function() {
if (n < slides.length - 1) {
n += 1;
} else {
n = 0;
}
_destacarSlide(n);
};
_pause = function() {
clearInterval(interval);
};
_play = function() {
_timer();
};
inicializar = (function() {
_listeners();
_timer();
})();
}
},
controlarTamanhoString: function(seletor, maxCaract) {
var item, tag, texto, _i, _j, _len, _len1;
tag = document.querySelectorAll(seletor);
if (tag[0]) {
if (tag[0].textContent) {
for (_i = 0, _len = tag.length; _i < _len; _i += 1) {
item = tag[_i];
texto = item.textContent;
if (texto.length > maxCaract) {
item.textContent = texto.slice(0, maxCaract) + '...';
}
}
} else {
for (_j = 0, _len1 = tag.length; _j < _len1; _j += 1) {
item = tag[_j];
texto = item.innerText;
if (texto.length > maxCaract) {
item.innerText = texto.slice(0, maxCaract) + '...';
}
}
}
}
},
configIdIssuu: function() {
var embed, id, link;
embed = document.querySelector('.issuuembed');
if (embed) {
link = embed.getAttribute('data-configid');
id = link.match(/0\/[0-9]*/g);
embed.setAttribute('data-configid', id[0]);
}
},
configIdYouTube: function() {
var id, iframe, link;
iframe = document.querySelector('.youtube');
if (iframe) {
link = iframe.getAttribute('src');
id = link.match(/[\w-]{11}/);
iframe.setAttribute('src', 'http://www.youtube.com/embed/' + id);
}
},
sliderPagInternas: function(container) {
var HEIGHT, WIDTH, arrImgs, botaoAvancar, botaoVoltar, imgDestacada, imgs, inicializar, nSlide, paginasVisiveis, _ativarClick, _ativarSlideMiniatura, _avancar, _desativarSlides, _esconderSlides, _exibir, _listeners, _nodeListParaArray, _voltar;
imgs = document.querySelectorAll(container + ' .lista-imagem img');
if (imgs[0]) {
imgDestacada = document.querySelector(container + ' .imagem-destacada img');
botaoVoltar = document.querySelector(container + ' .voltar');
botaoAvancar = document.querySelector(container + ' .avancar');
WIDTH = 735;
HEIGHT = 491;
nSlide = 0;
paginasVisiveis = 5;
_nodeListParaArray = function() {
var arr, i, _i, _len;
arr = [];
for (_i = 0, _len = imgs.length; _i < _len; _i += 1) {
i = imgs[_i];
arr.push(i);
}
return arr;
};
arrImgs = _nodeListParaArray();
_listeners = function() {
var i, item, _i, _ie8, _len;
_ie8 = function(evt) {
var caller;
caller = evt.srcElement;
nSlide = arrImgs.indexOf(caller);
_exibir(caller);
};
for (i = _i = 0, _len = imgs.length; _i < _len; i = _i += 1) {
item = imgs[i];
if (imgs[i].addEventListener) {
imgs[i].addEventListener('click', _ativarClick);
} else {
imgs[i].attachEvent('onclick', _ie8);
}
}
if (botaoVoltar) {
if (botaoVoltar.addEventListener) {
botaoVoltar.addEventListener('click', _voltar);
} else {
botaoVoltar.attachEvent('onclick', _voltar);
}
}
if (botaoAvancar) {
if (botaoAvancar.addEventListener) {
botaoAvancar.addEventListener('click', _avancar);
} else {
botaoAvancar.attachEvent('onclick', _avancar);
}
}
};
_ativarClick = function() {
nSlide = arrImgs.indexOf(this);
_exibir(this);
};
_ativarSlideMiniatura = function(elemento) {
elemento.setAttribute('class', 'slide-ativo');
};
_desativarSlides = function() {
var i, item, _i, _len;
for (i = _i = 0, _len = imgs.length; _i < _len; i = _i += 1) {
item = imgs[i];
imgs[i].setAttribute('class', '');
}
};
_voltar = function(evt) {
var i, _i, _j, _len, _len1, _ref, _ref1;
if (nSlide > 0) {
nSlide -= 1;
if (nSlide % paginasVisiveis === 4) {
_ref = arrImgs.slice(nSlide + 1, arrImgs.length);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
i.style.display = 'none';
}
_ref1 = arrImgs.slice(nSlide - 4, nSlide + 1);
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
i = _ref1[_j];
i.style.display = '';
}
}
_desativarSlides();
_exibir(imgs[nSlide]);
_ativarSlideMiniatura(imgs[nSlide]);
}
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
};
_avancar = function(evt) {
var i, _i, _j, _len, _len1, _ref, _ref1;
if (nSlide < imgs.length - 1) {
nSlide += 1;
if (nSlide % paginasVisiveis === 0) {
_ref = arrImgs.slice(0, nSlide);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
i.style.display = 'none';
}
_ref1 = arrImgs.slice(nSlide, nSlide + paginasVisiveis);
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
i = _ref1[_j];
i.style.display = '';
}
}
_desativarSlides();
_exibir(imgs[nSlide]);
_ativarSlideMiniatura(imgs[nSlide]);
}
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
};
_esconderSlides = function() {
var i, item, _i, _len;
for (i = _i = 0, _len = imgs.length; _i < _len; i = _i += 1) {
item = imgs[i];
if (i >= 5) {
imgs[i].style.display = 'none';
}
}
};
_exibir = function(img) {
var src, srcAtivo;
srcAtivo = img.getAttribute('src');
src = srcAtivo.substr(0, srcAtivo.length - 11) + 'w=' + WIDTH + '&' + 'h=' + HEIGHT;
imgDestacada.setAttribute('src', src);
_desativarSlides();
_ativarSlideMiniatura(img);
};
inicializar = (function() {
_listeners();
_esconderSlides();
_ativarSlideMiniatura(imgs[0]);
})();
}
},
animBarraSup: function() {
var barra, inicializar, _animacao, _listeners;
barra = document.querySelector('.barra-superior');
if (barra) {
_listeners = function() {
if (window.addEventListener) {
window.addEventListener('scroll', _animacao);
} else {
window.attachEvent('onscroll', _animacao);
}
};
_animacao = function() {
if (!this.pageYOffset) {
barra.style.height = '0';
}
if (this.pageYOffset > 0) {
barra.style.height = '0';
} else if (this.pageYOffset === 0) {
barra.style.height = '15px';
}
};
inicializar = (function() {
_listeners();
})();
}
},
animFilterProprietarios: function() {
var foto, inicializar, _animacao, _listeners;
foto = document.querySelector('.proprietarios img');
if (foto) {
_listeners = function() {
if (window.addEventListener) {
window.addEventListener('scroll', _animacao);
} else {
window.attachEvent('onscroll', _animacao);
}
};
_animacao = function() {
if (this.pageYOffset > 800) {
foto.style.webkitFilter = 'grayscale(0%)';
} else if (this.pageYOffset < 800) {
foto.style.webkitFilter = 'grayscale(100%)';
}
};
inicializar = (function() {
_listeners();
})();
}
},
uploadCurriculo: function() {
var alerta, cabecalho, campo, containerForm, formatos, formulario, p, _ativarAnimacao, _desativarAnimacao, _exibirAlerta, _exibirMensagem, _mudarCursor;
campo = document.querySelector('.campo-upload input');
if (campo) {
cabecalho = document.querySelector('.cabecalho-formulario-upload h1');
containerForm = document.querySelector('.formulario');
formulario = containerForm.children[0];
formatos = ['image/jpeg', 'application/pdf', 'application/stream', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
alerta = document.querySelector('.alertas');
p = document.createElement('p');
p.innerHTML = '';
_ativarAnimacao = function() {
alerta.setAttribute('class', 'alertas on');
};
_desativarAnimacao = function() {
alerta.setAttribute('class', 'alertas');
};
_mudarCursor = function(cursor) {
document.body.style.cursor = cursor;
};
_exibirMensagem = function(mensagem) {
cabecalho.innerHTML = mensagem;
containerForm.style.display = 'none';
};
_exibirAlerta = function(mensagem) {
p.innerHTML = mensagem;
alerta.appendChild(p);
alerta.style.opacity = 1;
};
if (campo.addEventListener) {
campo.addEventListener('change', function(evt) {
var FILESIZE, arquivo, xhr;
xhr = new XMLHttpRequest();
arquivo = campo.files[0];
FILESIZE = (2 * 1024) * 1024;
if (xhr.upload) {
if (arquivo.size <= FILESIZE) {
if (arquivo.type === formatos[0] || arquivo.type === formatos[1] || arquivo.type === formatos[2] || arquivo.type === formatos[3] || arquivo.type === formatos[4]) {
xhr.upload.onprogress = function(evt) {
if (evt.lengthComputable) {
_mudarCursor('wait');
_exibirMensagem('Enviando...');
_ativarAnimacao();
_exibirAlerta('Carregando o arquivo "' + arquivo.name + '"...');
}
};
xhr.open(formulario.method, formulario.action, true);
xhr.setRequestHeader("AJAXUPLOAD", arquivo.name);
xhr.send(arquivo);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
_mudarCursor('auto');
_exibirMensagem('Currículo enviado!');
_desativarAnimacao();
_exibirAlerta('Arquivo "' + arquivo.name + '" carregado com sucesso!');
}
};
} else {
_exibirAlerta('Formato de arquivo inválido. ' + 'Envie apenas .docx, .doc, .pdf ou .jpg.');
}
} else {
_exibirAlerta('Seu arquivo possui ' + ((arquivo.size / 1024) / 1024).toFixed(1) + ' MB e ultrapassa o limite de ' + ((FILESIZE / 1024) / 1024).toFixed(1) + ' MB permitidos.');
}
}
});
} else {
campo.attachEvent('onchange', function(evt) {
_exibirMensagem('Seu navegador não oferece suporte a este ' + 'recurso. <br /><small>Mas você pode enviar o ' + 'seu currículo para o e-mail: ' + '[email protected]</small>');
});
}
}
},
ajustarBackground: function() {
var cabecalho, item, w, _i, _len;
cabecalho = document.querySelectorAll('.cabecalho-textual');
if (cabecalho) {
for (_i = 0, _len = cabecalho.length; _i < _len; _i += 1) {
item = cabecalho[_i];
w = item.textContent ? item.textContent.length * 20 : item.innerText.length * 20;
item.style.width = w + 'px';
}
}
},
transicaoPaginas: function() {
var item, links, pagina, _animacao, _animacao_ie8, _i, _len;
pagina = document.body;
links = document.querySelectorAll('.menu a');
_animacao_ie8 = function(evt) {
var interval, _this;
_this = evt.srcElement;
interval = setInterval(function() {
window.location = _this.href;
}, 1500);
};
_animacao = function(evt) {
var interval, _this;
_this = this;
pagina.style.opacity = 0;
interval = setInterval(function() {
window.location = _this.getAttribute('href');
}, 1500);
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
};
for (_i = 0, _len = links.length; _i < _len; _i += 1) {
item = links[_i];
if (item.addEventListener) {
item.addEventListener('click', _animacao);
} else {
item.attachEvent('onclick', _animacao_ie8);
}
}
},
exibirPagina: function() {
var pagina;
pagina = document.body;
pagina.style.opacity = 1;
},
removerLoading: function() {
var pagina;
pagina = document.body;
pagina.setAttribute('class', '');
},
enviarEmail: function() {
var botao, cEmail, cLoja, cMsg, cNome, formulario, msgSucesso;
formulario = document.querySelector('.formulario-contato form');
if (formulario) {
cNome = document.querySelector('#campo-nome');
cEmail = document.querySelector('#campo-email');
cLoja = document.querySelector('#campo-loja');
cMsg = document.querySelector('#campo-mensagem');
msgSucesso = document.querySelector('.mensagem-sucesso p');
botao = document.querySelector('#botao-enviar');
if (botao.addEventListener) {
botao.addEventListener('click', function(evt) {
var msg, regexEmail, xhr;
xhr = new XMLHttpRequest();
regexEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
msg = '';
if (cNome.value !== '') {
if (cEmail.value !== '' && cEmail.value.match(regexEmail) !== null) {
if (cLoja.options.selectedIndex !== 0) {
if (cMsg.value !== '') {
msg += 'campo-nome=' + encodeURI(cNome.value);
msg += '&campo-email=' + encodeURI(cEmail.value);
msg += '&campo-loja=' + encodeURI(cLoja.options[cLoja.options.selectedIndex].innerHTML);
msg += '&campo-mensagem=' + encodeURI(cMsg.value);
xhr.open(formulario.method, formulario.action + '?' + msg, true);
xhr.send(msg);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
formulario.style.display = 'none';
msgSucesso.setAttribute('class', 'mensagem-sucesso exibe');
}
};
} else {
cMsg.focus();
cMsg.setAttribute('class', 'erro');
}
} else {
cLoja.focus();
cLoja.setAttribute('class', 'erro');
}
} else {
cEmail.focus();
cEmail.setAttribute('class', 'erro');
}
} else {
cNome.focus();
cNome.setAttribute('class', 'erro');
}
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
});
} else {
botao.attachEvent('onclick', function(evt) {
var msg, regexEmail, xhr;
xhr = new XMLHttpRequest();
regexEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
msg = '';
if (cNome.value !== '') {
if (cEmail.value !== '' && cEmail.value.match(regexEmail) !== null) {
if (cLoja.options.selectedIndex !== 0) {
if (cMsg.value !== '') {
msg += 'campo-nome=' + encodeURI(cNome.value);
msg += '&campo-email=' + encodeURI(cEmail.value);
msg += '&campo-loja=' + encodeURI(cLoja.options[cLoja.options.selectedIndex].innerHTML);
msg += '&campo-mensagem=' + encodeURI(cMsg.value);
xhr.open(formulario.method, formulario.action + '?' + msg, true);
xhr.send(msg);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
formulario.style.display = 'none';
msgSucesso.setAttribute('class', 'mensagem-sucesso exibe');
}
};
} else {
cMsg.focus();
cMsg.setAttribute('class', 'erro');
}
} else {
cLoja.focus();
cLoja.setAttribute('class', 'erro');
}
} else {
cEmail.focus();
cEmail.setAttribute('class', 'erro');
}
} else {
cNome.focus();
cNome.setAttribute('class', 'erro');
}
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
});
}
}
}
};
Apps = Nevada.apps;
(function() {
Apps.indexOf();
Apps.transicaoPaginas();
Apps.carregarScripts();
Apps.removerBackgroundMenu();
Apps.ajustarBackground();
Apps.controlarTamanhoString('.nome-produto p', 25);
Apps.slider();
Apps.configIdIssuu();
Apps.configIdYouTube();
Apps.animBarraSup();
Apps.animFilterProprietarios();
Apps.sliderPagInternas('.evento-agita');
Apps.sliderPagInternas('.evento-doacao-sangue');
Apps.sliderPagInternas('.evento-vacinacao');
Apps.sliderPagInternas('.evento-gincana-solidaria');
Apps.sliderPagInternas('.evento-exame-vista');
Apps.sliderPagInternas('.apresentacao-cursos-palestras');
Apps.sliderPagInternas('.apresentacao-lojas');
Apps.uploadCurriculo();
Apps.enviarEmail();
})();
window.onload = function() {
Apps.ajustarWidthSubmenu();
Apps.removerLoading();
Apps.exibirPagina();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment