function CyberWow(){
this.templateProducto = Handlebars.compile($('#template-producto').html());
this.templateCategorias = Handlebars.compile($('#template-categorias').html());
this.urlProductoTotal = CONTEXT_PATH+ '/producto/totalProductos';
this.cantProductos = 0;
this.attributeFechaFinal = '2018-07-11 23:59:59';
}
CyberWow.prototype.init = function(){
//this.validarFechaCyberwow();
this.cargarBanner();
this.fnBanner();
this.cargarProductos();
this.cargarCategorias();
this.cargarNumeroProductos();
this.bannerVuelos();
}
CyberWow.prototype.validarFechaCyberwow = function(){
//alert()
var dateActual = new Date(this.attributeFechaActual);
var dateInicial = new Date(this.attributeFechaInicial);
var dateFinal = new Date(this.attributeFechaFinal);
if(dateActual < dateInicial || dateActual > dateFinal){
window.location.href = '/';
}
}
CyberWow.prototype.cargarBanner = function(){
var cyber = this;
var agotado = false;
var bannerImages = [];
if(!agotado){
bannerImages = [
{image: 'cyber_wow', imageResponsive: 'cyber_wow_responsive', path: ''},
{image: 'banner_vuelos', imageResponsive: 'banner_vuelos_responsive', path: CONTEXT_PATH + '/viajes'}
];
}
else {
bannerImages = [
{image: 'cyber_wow', imageResponsive: 'cyber_wow_responsive', path: ''},
{image: 'banner_vuelos_agotado', imageResponsive: 'banner_vuelos_responsive_agotado', path: CONTEXT_PATH + '/viajes'}
];
}
$.each(bannerImages, function(index, values){
var image = (window.innerWidth > 700) ? bannerImages[index].image : bannerImages[index].imageResponsive;
$('#banner-cyber .cont-slides').append('
');
if(index == 0){
$('#banner-cyber .cont-slides article').first().addClass('active');
}
});
$('#banner-cyber .cont-slides a').click(function(ev){
var path = $(this).attr('href');
if(path == ''){
ev.preventDefault();
}
});
var images = $('#banner-cyber .cont-slides img');
var count = 0;
$.each(images, function(index, value){
$(images[index]).load(function(){
count++;
if(count == 1){
$('#banner-cyber .cont-slides').height($(this).height());
}
});
});
}
CyberWow.prototype.fnBanner = function(){
var images = $('#banner-cyber').find('img');
$(window).on('ready resize', function(){
var alto = $(images[0]).height();
$('#banner-cyber .cont-slides').height(alto);
});
$.each(images, function(index, value){
$('#banner-cyber .handlers').append('');
if(index==0){ $('#banner-cyber .handlers span').first().addClass('active'); }
});
var position = 1;
var slides = $('#banner-cyber .cont-slides');
var handlers = $('#banner-cyber .handlers');
var fnInterval = function(){
if(position < images.length){
slides.find('.active').removeClass('active').addClass('pass').next('article').addClass('active');
handlers.find('.active').removeClass('active').addClass('pass').next('span').addClass('active');
position++;
}
else {
slides.find('article').removeClass('active pass');
slides.find('article').first().addClass('active');
handlers.find('span').removeClass('active pass');
handlers.find('span').first().addClass('active');
position = 1;
}
};
var intervalo = setInterval(fnInterval, 5000);
$('#banner-cyber .handlers span').click(function(){
var index = $(this).index();
var slideActive = slides.find('article').eq(index);
slideActive.removeClass('pass').addClass('active').siblings().removeClass('active');
slideActive.prevAll().addClass('pass');
slideActive.nextAll().removeClass('pass active');
$(this).addClass('active').siblings().removeClass('active');
position = index+1;
clearInterval(intervalo);
intervalo = setInterval(fnInterval, 5000);
});
}
CyberWow.prototype.cargarNumeroProductos = function(){
var miObjeto = this;
$.ajax({
url: this.urlProductoTotal,
dataType: "json",
type: "GET",
data: {
keyBusqueda: "",
idCategorias: "",
idSubcategorias: ""
},
success : function(data){
miObjeto.cantProductos = data.result;
$(".ver-todos-normal").text('Ver todos ('+data.result+')');
$(".ver-todos").text('Ver todos ('+data.result+')');
if(window.innerWidth > 950){
$('.todos-producto-categoria').text('Ver todos los productos(' + data.result + ')');
}
},
error : function(){}
})
};
CyberWow.prototype.cargarProductos = function(){
var miObjeto = this;
/**/
var uri = CONTEXT_PATH + '/producto/destacados/filtro';
var idCategoria = "";
var idSubcategoria = "";
var miObjeto = this;
$.ajax({
url : uri,
dataType : "json",
type : "GET",
success : function(data) {
$.each(data.result.listaProductos, function(index, value) {
if (index < 16) {
$('#carousel-productos .cont-carousel').append(miObjeto.templateProducto(value));
if(window.innerWidth <= 600) {
$('#carousel-productos .cont-carousel article').eq(3).nextAll().hide();
$('#productos .ver-todos').css('display', 'block');
}
}
});
miObjeto.carouselProductos();
},
error : function() {
}
});
}
CyberWow.prototype.carouselProductos = function(){
var miObjecto = this;
var productos = $('#carousel-productos article');
var position = 1;
var row;
if(window.innerWidth <= 1050){
row = 3;
}
if(window.innerWidth <= 840){
row = 2;
}
if(window.innerWidth <= 450 || window.innerWidth > 1050) {
row = 4;
}
showHandlers();
function showHandlers(){
if(productos.length > 4){
$('#next').show();
if(position > 1){
$('#prev').show();
}
if(position == Math.ceil(productos.length/row)){
$('#next').hide();
}
if(position == 1){
$('#prev').hide();
}
}
else {
$('.handler').hide();
}
}
var containerWidth = $('#carousel-productos').width();
var translate = 0;
var fnInterval = function(){
translate = containerWidth + 30;
if(position < Math.ceil(productos.length/row)){
translate *= position;
$('#carousel-productos .cont-carousel').css('transform', 'translateX(-' + translate + 'px)');
position++;
}
else {
$('#carousel-productos .cont-carousel').removeAttr('style');
position = 1;
}
showHandlers();
};
var intervalo;
if(window.innerWidth > 600){
intervalo = setInterval(fnInterval, 10000);
}
$('#productos .handler').click(function(ev){
clearInterval(intervalo);
if($(ev.target).is('#next')) {
translate = (containerWidth + 30) * position;
$('#carousel-productos .cont-carousel').css('transform', 'translateX(-' + translate + 'px)');
position++;
}
else if($(ev.target).is('#prev')) {
translate -= (containerWidth + 30);
$('#carousel-productos .cont-carousel').css('transform', 'translateX(-' + translate + 'px)');
position--;
}
showHandlers();
intervalo = setInterval(fnInterval, 10000);
});
if(window.innerWidth > 600){
var images = $('#carousel-productos .cont-carousel article img');
var count = 0;
$.each(images, function(index, value){
$(images[index]).load(function(){
count++;
if(count == 1){
$('#carousel-productos .cont-carousel article > a').height($(this).height());
}
});
});
}
function fnTodosProductos(){
var articles = $('#carousel-productos .cont-carousel article');
if(window.innerWidth <= 600){
articles.eq(3).nextAll().hide();
$('#productos .ver-todos').css('display', 'block');
}
else {
articles.show();
$('#productos .ver-todos').hide();
}
}
$('.detalle-producto .canjear').click(function(ev){
if($(this).is('.agotado')){
ev.preventDefault();
}
});
}
CyberWow.prototype.cargarCategorias = function(){
var miObjeto = this;
var dataUat = [
{ name: "Electrodomésticos", image: "electrodomesticos", filtroCategoria: "/electrodomesticos" },
{ name: "Moda", image: "moda", filtroCategoria: "/moda" },
{ name: "Licores", image: "licores", filtroCategoria: "/licores" },
{ name: "Hogar", image: "hogar", filtroCategoria: "/hogar" },
{ name: "Deporte y outdoor", image: "deporte", filtroCategoria: "/deporte-y-outdoor" },
{ name: "Belleza y cuidado personal", image: "belleza", filtroCategoria: "/belleza-y-cuidado-personal" },
{ name: "Cómputo", image: "computo", filtroCategoria: "/computo" },
{ name: "Mascotas", image: "mascotas", filtroCategoria: "/mascotas" },
{ name: "Entretenimiento", image: "entretenimiento", filtroCategoria: "/entretenimiento" },
{ name: "TV, audio y fotografía", image: "tv_audio_foto", filtroCategoria: "/tv-audio-y-fotografia" },
{ name: "Celulares y tables", image: "celulares", filtroCategoria: "/celulares-y-tablets" },
{ name: "Videojuegos", image: "videojuegos", filtroCategoria: "/videojuego" },
{ name: "Niños y bebés", image: "ninos_bebes", filtroCategoria: "/ninos-y-bebes" },
{ name: "Vales", image: "vales", filtroCategoria: "/vales" },
{ name: "Giftcards", image: "giftcards", filtroCategoria: "/gift-cards" }
];
var dataProd = [
{ name: "Electrodomésticos", image: "electrodomesticos", filtroCategoria: "/electrodomesticos" },
{ name: "Moda", image: "moda", filtroCategoria: "/moda" },
{ name: "Licores", image: "licores", filtroCategoria: "/licores" },
{ name: "Hogar", image: "hogar", filtroCategoria: "/hogar" },
{ name: "Deporte y outdoor", image: "deporte", filtroCategoria: "/deporte-y-outdoor" },
{ name: "Belleza y cuidado personal", image: "belleza", filtroCategoria: "/belleza-y-cuidado-personal" },
{ name: "Cómputo", image: "computo", filtroCategoria: "/computo" },
{ name: "Mascotas", image: "mascotas", filtroCategoria: "/mascotas" },
{ name: "Entretenimiento", image: "entretenimiento", filtroCategoria: "/entretenimiento" },
{ name: "TV, audio y fotografía", image: "tv_audio_foto", filtroCategoria: "/tv-audio-y-fotografia" },
{ name: "Celulares y tables", image: "celulares", filtroCategoria: "/celulares-y-tablets" },
{ name: "Videojuegos", image: "videojuegos", filtroCategoria: "/videojuegos" },
{ name: "Niños y bebés", image: "ninos_bebes", filtroCategoria: "/ninos-y-bebes" },
{ name: "Vales", image: "vales", filtroCategoria: "/vales" },
{ name: "Giftcards", image: "giftcards", filtroCategoria: "/gift-cards" }
];
switch (AMBIENTE_DEPLOY){
case 1: data = dataUat; break;
case 2: data = dataProd; break;
}
$.each(data, function(index, value){
$('#categorias .lista-categorias .todas').before(miObjeto.templateCategorias(value));
});
$(window).on('ready', function(){
if(window.innerWidth <= 950){
$('#categorias .lista-categorias article').eq(3).nextAll(':not(.todas)').hide();
$('#categorias .lista-categorias .todas').addClass('responsive').find('a').text('Ver todas las categorías(15)');
}
else {
$('#categorias .lista-categorias article').eq(3).nextAll(':not(.todas)').show();
$('#categorias .lista-categorias .todas').removeClass('responsive').find('a').text('Ver todos los productos(' + miObjeto.cantProductos + ')');
}
});
var visible = false;
$('.todos-producto-categoria').click(function(ev){
ev.preventDefault();
if(window.innerWidth <= 950) {
if(!visible){
$('#categorias .lista-categorias article').show();
$('#categorias .lista-categorias .responsive a').text('Ocultar');
visible = true;
}
else {
$('#categorias .lista-categorias article').eq(3).nextAll(':not(.todas)').hide();
$('#categorias .lista-categorias .responsive a').text('Ver todas las categorías(15)');
$('html, body').scrollTop($('#categorias').offset().top - 20);
visible = false;
}
}
else {
console.log('asd')
window.location = CONTEXT_PATH + '/compras';
}
});
}
CyberWow.prototype.bannerVuelos = function(){
var agotado = false;
var data = {};
if(agotado){
data = {
title: '¡Viaja a los mejores destinos con cualquier aerolínea!',
image: 'vuelos-agotado-b',
imageResponsive: 'vuelos-agotado-responsive',
select: 'no-select'
};
}
else {
data = {
title: '¡Aprovecha nuestros descuentos para cualquier destino!',
image: 'vuelos',
imageResponsive: 'vuelos-responsive',
select: ''
};
}
$(window).on('ready resize', function(){
var image = (window.innerWidth > 600) ? data.image : data.imageResponsive;
$('#vuelos').find('h3').text(data.title);
$('#vuelos').find('img').attr('src', URL_RESOURCES + 'static/images/cyber-wow/' + image + '.jpg');
$('#vuelos').find('.select').addClass(data.select);
});
}