Created
November 13, 2013 13:52
-
-
Save skvggor/7449447 to your computer and use it in GitHub Desktop.
Apps TV Mauá
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
var Apps, TVMaua; | |
TVMaua = TVMaua || {}; | |
TVMaua.apps = { | |
identificarUserAgent: function() { | |
var doc; | |
doc = document.documentElement; | |
doc.setAttribute('data-useragent', navigator.userAgent); | |
}, | |
path: function() { | |
return 'http://tvmauaeregiao.com.br/wp-content/themes/tv-maua-e-regiao/'; | |
}, | |
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(TVMaua.apps.path() + 'js/libs/flowplayer-3.2.12.min.js'); | |
_carregar(TVMaua.apps.path() + 'js/libs/jquery.carouFredSel-6.2.1-packed.js'); | |
_carregar(TVMaua.apps.path() + 'js/libs/fancybox/source/jquery.fancybox.js'); | |
}, | |
flowPlayer: function(indexVideo) { | |
var Apps, a, botInformacoes, carousel, cats, clips, containerPlayer, dataPublicacao, dataPublicacaoVideo, descricao, descricaoVideo, flashPlayer, i, item, linkPublicidadeLateral, linksPublicidades, nomeAnuncte, nomes, perfis, publicidadeLateral, publicidades, urlPerfil, _alterarLocationParaPerfil, _alterarPublicidadeLateral, _desativarDragPlayer, _exibirDadosAnuncte, _i, _len, _listeners, _mudarVideo, _playerDefault; | |
containerPlayer = document.querySelector('#flv-player'); | |
if (containerPlayer) { | |
flashPlayer = TVMaua.apps.path() + 'flv-player/flowplayer-3.2.16.swf'; | |
a = document.querySelectorAll('.clips ul li a'); | |
botInformacoes = document.querySelector('.botao-mais-informacoes input[type="button"]'); | |
urlPerfil = ''; | |
publicidadeLateral = document.querySelector('.publicidade a img'); | |
publicidades = []; | |
linkPublicidadeLateral = document.querySelector('.publicidade a'); | |
linksPublicidades = []; | |
nomeAnuncte = document.querySelector('.informacoes-anunciante-nome .nome-anunciante'); | |
nomes = []; | |
dataPublicacaoVideo = document.querySelector('.informacoes-video-canal .data'); | |
dataPublicacao = []; | |
descricaoVideo = document.querySelector('.informacoes-video-canal .descricao-video'); | |
descricao = []; | |
clips = []; | |
cats = []; | |
perfis = []; | |
carousel = jQuery('.clips ul'); | |
Apps = TVMaua.apps; | |
_listeners = function() { | |
if (botInformacoes) { | |
botInformacoes.addEventListener('click', _alterarLocationParaPerfil); | |
containerPlayer.addEventListener('dragstart', _desativarDragPlayer); | |
} | |
}; | |
_desativarDragPlayer = function(evt) { | |
evt.preventDefault(); | |
}; | |
_alterarLocationParaPerfil = function() { | |
window.location = urlPerfil; | |
}; | |
_alterarPublicidadeLateral = function(imagem, link) { | |
linkPublicidadeLateral.setAttribute('href', link); | |
publicidadeLateral.setAttribute('src', imagem); | |
}; | |
_exibirDadosAnuncte = function(tipo, nome, container) { | |
var tag; | |
if (tipo === 'nome') { | |
tag = 'h1'; | |
} else if (tipo === 'categoria') { | |
tag = 'p'; | |
} else if (tipo === 'data') { | |
tag = 'span'; | |
} else if (tipo === 'descricao') { | |
tag = 'span'; | |
} | |
if (tipo === 'nome' && nome.length >= 90) { | |
nome = nome.slice(0, 90) + '...'; | |
} | |
container.innerHTML = '<' + tag + '>' + nome + '</' + tag + '>'; | |
}; | |
_playerDefault = function() { | |
$f(containerPlayer, { | |
src: flashPlayer, | |
wmode: 'transparent' | |
}, { | |
playlist: clips, | |
onStart: function(clip) { | |
carousel.trigger('slideTo', clip.index); | |
Apps.scrollTop(); | |
urlPerfil = perfis[clip.index]; | |
_exibirDadosAnuncte('nome', nomes[clip.index], nomeAnuncte); | |
if (dataPublicacaoVideo) { | |
_exibirDadosAnuncte('data', dataPublicacao[clip.index], dataPublicacaoVideo); | |
_exibirDadosAnuncte('descricao', descricao[clip.index], descricaoVideo); | |
} | |
if (publicidades[0]) { | |
_alterarPublicidadeLateral(publicidades[clip.index], linksPublicidades[clip.index]); | |
} | |
}, | |
onFinish: function() { | |
if (this.getClip().index + 1 === this.getPlaylist().length) { | |
$f().play(0); | |
} | |
}, | |
plugins: { | |
controls: { | |
buttonColor: 'rgba(150, 150, 150, 0.9)', | |
buttonOverColor: 'rgb(255, 255, 255)', | |
backgroundColor: 'rgb(97, 108, 112)', | |
backgroundGradient: 'none', | |
sliderColor: 'rgb(245, 134, 52)', | |
progressColor: 'rgb(245, 134, 52)', | |
sliderBorder: 'none', | |
volumeSliderColor: 'rgb(245, 134, 52)', | |
volumeBorder: 'none', | |
timeColor: 'rgb(255, 255, 255)', | |
durationColor: 'rgb(255, 255, 255)' | |
} | |
} | |
}); | |
if (indexVideo) { | |
return $f().play(indexVideo); | |
} | |
}; | |
_mudarVideo = function(evt) { | |
var index, len; | |
len = clips.length; | |
index = clips.indexOf(this.getAttribute('href')) + 1; | |
urlPerfil = perfis[index - 1]; | |
$f(containerPlayer, { | |
src: flashPlayer, | |
wmode: 'transparent' | |
}, { | |
onStart: function() { | |
carousel.trigger('slideTo', index - 1); | |
Apps.scrollTop(); | |
_exibirDadosAnuncte('nome', nomes[index - 1], nomeAnuncte); | |
if (dataPublicacaoVideo) { | |
_exibirDadosAnuncte('data', dataPublicacao[index - 1], dataPublicacaoVideo); | |
_exibirDadosAnuncte('descricao', descricao[index - 1], descricaoVideo); | |
} | |
if (publicidades[0]) { | |
_alterarPublicidadeLateral(publicidades[index - 1], linksPublicidades[index - 1]); | |
} | |
}, | |
onFinish: function() { | |
var posicao; | |
if (index !== len) { | |
posicao = index; | |
} else { | |
posicao = 0; | |
} | |
_playerDefault().play(posicao); | |
}, | |
plugins: { | |
controls: { | |
buttonColor: 'rgba(150, 150, 150, 0.9)', | |
buttonOverColor: 'rgb(245, 134, 52)', | |
backgroundColor: 'rgb(97, 108, 112)', | |
backgroundGradient: 'none', | |
sliderColor: 'rgb(245, 134, 52)', | |
progressColor: 'rgb(245, 134, 52)', | |
sliderBorder: 'none', | |
volumeSliderColor: 'rgb(245, 134, 52)', | |
volumeBorder: 'none', | |
timeColor: 'rgb(255, 255, 255)', | |
durationColor: 'rgb(255, 255, 255)' | |
} | |
} | |
}).play(this.getAttribute('href')); | |
evt.preventDefault(); | |
}; | |
for (i = _i = 0, _len = a.length; _i < _len; i = _i += 1) { | |
item = a[i]; | |
item.addEventListener('click', _mudarVideo); | |
clips[i] = item.getAttribute('href'); | |
nomes[i] = item.getAttribute('title'); | |
cats[i] = item.getAttribute('data-categoria'); | |
perfis[i] = item.getAttribute('data-perfil'); | |
linksPublicidades[i] = item.getAttribute('data-pub-link'); | |
publicidades[i] = item.getAttribute('data-pub-imagem'); | |
dataPublicacao[i] = item.getAttribute('data-data-publicacao'); | |
descricao[i] = item.getAttribute('data-descricao'); | |
} | |
(function() { | |
_listeners(); | |
_playerDefault(); | |
})(); | |
} | |
}, | |
menuCategorias: function() { | |
var categoria, listaCategorias, menuCategorias, textoCategoria, _esconder, _exibir, _listeners; | |
menuCategorias = document.querySelector('.menu-categorias'); | |
if (menuCategorias) { | |
categoria = document.querySelector('.cabecalho-categorias'); | |
textoCategoria = document.querySelector('.cabecalho-categorias .titulo p'); | |
listaCategorias = document.querySelector('.lista-categorias'); | |
_listeners = function() { | |
categoria.addEventListener('mouseover', _exibir); | |
listaCategorias.addEventListener('mouseover', _exibir); | |
menuCategorias.addEventListener('mouseout', _esconder); | |
}; | |
_exibir = function(evt) { | |
listaCategorias.style.display = 'block'; | |
textoCategoria.style.color = 'rgb(127, 137, 139)'; | |
evt.preventDefault(); | |
}; | |
_esconder = function(evt) { | |
listaCategorias.style.display = 'none'; | |
textoCategoria.style.color = 'rgb(255, 255, 255)'; | |
evt.preventDefault(); | |
}; | |
(function() { | |
_listeners(); | |
})(); | |
} | |
}, | |
menuCategoriasProgramas: function() { | |
var categoria, listaCategorias, menuCategoriasProgramas, textoCategoria, _esconder, _exibir, _listeners; | |
menuCategoriasProgramas = document.querySelector('.menu-categorias-programas'); | |
if (menuCategoriasProgramas) { | |
categoria = document.querySelector('.cabecalho-categorias-programas'); | |
textoCategoria = document.querySelector('.cabecalho-categorias-programas .titulo-categorias-programas p'); | |
listaCategorias = document.querySelector('.lista-categorias-programas'); | |
_listeners = function() { | |
categoria.addEventListener('mouseover', _exibir); | |
listaCategorias.addEventListener('mouseover', _exibir); | |
menuCategoriasProgramas.addEventListener('mouseout', _esconder); | |
}; | |
_exibir = function(evt) { | |
listaCategorias.style.display = 'block'; | |
textoCategoria.style.color = 'rgb(127, 137, 139)'; | |
evt.preventDefault(); | |
}; | |
_esconder = function(evt) { | |
listaCategorias.style.display = 'none'; | |
textoCategoria.style.color = 'rgb(255, 255, 255)'; | |
evt.preventDefault(); | |
}; | |
(function() { | |
_listeners(); | |
})(); | |
} | |
}, | |
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) + '...'; | |
} | |
} | |
} | |
} | |
}, | |
carousel: function() { | |
var carousel, _eventosTeclado, _executar; | |
carousel = document.querySelector('.clips ul'); | |
if (carousel) { | |
carousel = jQuery('.clips ul'); | |
_executar = function() { | |
carousel.carouFredSel({ | |
auto: false, | |
align: false, | |
width: '100%', | |
scroll: { | |
items: 1 | |
}, | |
prev: { | |
button: '.controles .anterior' | |
}, | |
next: { | |
button: '.controles .proximo' | |
} | |
}); | |
}; | |
_eventosTeclado = function() { | |
var controlarCarousel; | |
carousel = jQuery('.clips ul'); | |
controlarCarousel = function(evt) { | |
if (evt.keyCode === 37) { | |
carousel.trigger('prev'); | |
} else if (evt.keyCode === 39) { | |
carousel.trigger('next'); | |
} | |
evt.preventDefault(); | |
}; | |
window.addEventListener('keyup', controlarCarousel); | |
}; | |
(function() { | |
_executar(); | |
_eventosTeclado(); | |
})(); | |
} | |
}, | |
animacaoCabecalho: function() { | |
var cabecalho, _animar, _opacidadeOn; | |
cabecalho = document.querySelector('.cabecalho'); | |
if (cabecalho) { | |
_opacidadeOn = function() { | |
this.style.opacity = 1; | |
}; | |
_animar = function() { | |
if (this.pageYOffset > 100) { | |
cabecalho.style.opacity = 0.7; | |
} else if (this.pageYOffset <= 100) { | |
cabecalho.style.opacity = 1; | |
} | |
}; | |
window.addEventListener('scroll', _animar); | |
cabecalho.addEventListener('mouseover', _opacidadeOn); | |
} | |
}, | |
enviarEmail: function() { | |
var botao, cEmail, cMsg, cNome, formulario, msgSucesso; | |
formulario = document.querySelector('.formulario-fale-conosco form'); | |
if (formulario) { | |
cNome = document.querySelector('#nome'); | |
cEmail = document.querySelector('#email'); | |
cMsg = document.querySelector('#mensagem'); | |
msgSucesso = document.querySelector('.mensagem-sucesso'); | |
botao = document.querySelector('#enviar'); | |
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 (cMsg.value !== '') { | |
msg += 'nome=' + encodeURI(cNome.value); | |
msg += '&email=' + encodeURI(cEmail.value); | |
msg += '&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 exibir'); | |
} | |
}; | |
} else { | |
cMsg.focus(); | |
cMsg.setAttribute('class', 'erro'); | |
} | |
} else { | |
cEmail.focus(); | |
cEmail.setAttribute('class', 'erro'); | |
} | |
} else { | |
cNome.focus(); | |
cNome.setAttribute('class', 'erro'); | |
} | |
evt.preventDefault(); | |
}); | |
} | |
}, | |
scrollTop: function() { | |
$('html, body').animate({ | |
scrollTop: 0 | |
}, 1000); | |
}, | |
obterEnderecosDoTexto: function(texto) { | |
var endereco, enderecos, re; | |
enderecos = []; | |
re = /{([^}]+)}/g; | |
endereco = ''; | |
while ((endereco = re.exec(texto))) { | |
enderecos.push(endereco[1]); | |
} | |
return enderecos; | |
}, | |
removerChavesDoTexto: function(texto) { | |
texto = texto.replace(/[\{\}']+/g, ''); | |
return texto; | |
}, | |
criarMapa: function() { | |
var Apps, arrEnderecos, conteudoEnderecos, enderecos, i, linkMapa, linksMapa, _i, _len; | |
linksMapa = document.querySelectorAll('a[href="http://mapa"]'); | |
if (linksMapa[0]) { | |
Apps = TVMaua.apps; | |
enderecos = document.querySelectorAll('.lista-de-informacoes .box .elementos .texto'); | |
arrEnderecos = Apps.obterEnderecosDoTexto(enderecos[0].textContent); | |
for (i = _i = 0, _len = linksMapa.length; _i < _len; i = ++_i) { | |
linkMapa = linksMapa[i]; | |
linkMapa.setAttribute('class', 'fancybox.iframe'); | |
linkMapa.setAttribute('href', 'https://maps.google.com/?output=embed&q=' + arrEnderecos[i] + '¢er=' + arrEnderecos[i] + 'hl=pt&t=m&z=16'); | |
} | |
conteudoEnderecos = document.querySelector('.lista-de-informacoes .box .elementos .texto'); | |
conteudoEnderecos.innerHTML = Apps.removerChavesDoTexto(conteudoEnderecos.innerHTML); | |
} | |
}, | |
criarEfeitoNoMapa: function() { | |
$('[href^="https://maps.google.com"]').fancybox({ | |
maxWidth: 960, | |
maxHeight: 600, | |
fitToView: true, | |
width: '70%', | |
height: '70%', | |
closeClick: false, | |
iframe: { | |
preload: false | |
} | |
}); | |
}, | |
coresAleatorias: function() { | |
var cabecalhoCanal, coresBg, coresTexto, num, texto; | |
cabecalhoCanal = document.querySelector('.cabecalho-canal'); | |
if (cabecalhoCanal) { | |
texto = document.querySelector('.cabecalho-canal .nome-categoria-canal h2'); | |
coresBg = ["rgb(255, 102, 0)", "rgb(0, 148, 208)"]; | |
coresTexto = ["rgb(255, 252, 1)", "rgb(0, 70, 145)"]; | |
num = Math.floor(Math.random() * coresBg.length); | |
cabecalhoCanal.style.backgroundColor = coresBg[num]; | |
texto.style.color = coresTexto[num]; | |
} | |
} | |
}; | |
Apps = TVMaua.apps; | |
(function() { | |
Apps.carregarScripts(); | |
})(); | |
window.onload = function() { | |
Apps.identificarUserAgent(); | |
Apps.flowPlayer(); | |
Apps.menuCategorias(); | |
Apps.menuCategoriasProgramas(); | |
Apps.animacaoCabecalho(); | |
Apps.carousel(); | |
Apps.controlarTamanhoString('.titulo-video-home', 16); | |
Apps.controlarTamanhoString('.titulo-video-canal', 48); | |
Apps.controlarTamanhoString('.nome-programa a', 48); | |
Apps.controlarTamanhoString('.categoria-programa span', 16); | |
Apps.enviarEmail(); | |
Apps.criarMapa(); | |
Apps.criarEfeitoNoMapa(); | |
Apps.coresAleatorias(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment