$(document).ready(function () { var revista = '', filtro_anio = '', filtro_epoca = '', num_rev = 8, revista_num = 1; i = 0, x = 0; // Lista de revistas $.getJSON('/culturascontemporaneas/revistas/', function(data) { // Lee json y obtiene anios var anios_rev = data.map(function (anios) { return anios.anio; }); // Filtra los anios del json y regresa un arreglo sin repetidos var anios_revista = anios_rev.filter(function (value, index) { return value !== anios_rev[index+1]; }); // Arreglo de anios y los pinta en select filtro_anio+=''; anios_revista.forEach( anio_rev => { if(anio_rev!=='') filtro_anio+=''; }); $('#anio_rev').html(filtro_anio); // Carga lista de las revistas y genera paginado $.each(data, function (index, value) { for (; i < data.length;) { if(i===0) revista+='
'; revista+='
'; revista+='
'; revista+=''; revista+='
'; revista+='
'; revista+=''; revista+=''; revista+='
'; revista+='
'; revista+='
'; revista+='

'; if(data[i].epoca !== '' && data[i].epoca !== null) revista+='\u00C9poca '+data[i].epoca+' '; if(data[i].volumen !== '' && data[i].volumen !== null) revista+='\u2022 Volumen '+data[i].volumen+' '; if(data[i].numero !== '' && data[i].numero !== null) revista+='\u2022 N\u00FAmero '+data[i].numero+' '; if(data[i].mes !== '' && data[i].mes !== null) revista+='\u2022 '+data[i].mes+', '+data[i].anio+' '; if(data[i].fecha !== '' && data[i].fecha !== undefined && data[i].fecha !== null) revista+='\u2022 Fecha de publicaci\u00f3n en l\u00ednea '+data[i].fecha+' '; revista+='

'; revista+='

'; if(data[index].resumen !== '' && data[i].resumen !== null) { var string_cont = data[i].resumen.length; revista+=data[i].resumen.substr(0,180); if(string_cont>=180) revista +='...'; } else { revista +='Sin resumen...'; } revista+='

'; revista+='

Ver completo

'; revista+='
'; revista+='
'; revista+='
'; if(x!==(num_rev-1)){ x++; } else { x = 0; revista+='
'; revista_num++; revista+='
'; } i++ } }); $('#revistas').html(revista); $('#pagination-magazine').twbsPagination({ //Math.round(data.length / num_rev), totalPages: (data.length / num_rev)+1, // the current page that show on start startPage: 1, // maximum visible pages visiblePages: num_rev, // Text labels first: 'Primero', prev: 'Anterior', next: 'Siguiente', last: 'Ultimo', // callback function onPageClick: function (event, page) { $('.page-active').removeClass('page-active'); $('#page'+page).addClass('page-active'); } }); // Filtros anios $('#anio_rev').change(function() { var fltr_anio = ''; $('#mes_rev').prop('selectedIndex',0); $('#tempo_rev').prop('selectedIndex',0); $(this).find('option:selected').each(function() { if(this.value!=='anios'){ $('#revistas').addClass('fltr_anio'); $('#pagination_rev').addClass('hide'); $('[class*="anio_"]').addClass('hide'); fltr_anio = this.value; $( '#revistas' ).find('.anio_'+this.value).each(function( index ) { $(this).removeClass('hide'); }); } else { $('#revistas').removeClass('fltr_anio'); $('#pagination_rev').removeClass('hide'); $('[class*="anio_"]').removeClass('hide'); } }); }).trigger('change'); // Filtros meses $('#mes_rev').change(function() { var fltr_anio = ''; $('#anio_rev').prop('selectedIndex',0); $('#tempo_rev').prop('selectedIndex',0); $(this).find('option:selected').each(function() { if(this.value!=='meses'){ $('#revistas').addClass('fltr_anio'); $('#pagination_rev').addClass('hide'); $('[class*="mes_"]').addClass('hide'); fltr_anio = this.value; $( '#revistas' ).find('.mes_'+this.value).each(function( index ) { $(this).removeClass('hide'); }); } else { $('#revistas').removeClass('fltr_anio'); $('#pagination_rev').removeClass('hide'); $('[class*="mes_"]').removeClass('hide'); } }); }).trigger('change'); // Filtros temporadas $('#tempo_rev').change(function() { var fltr_anio = ''; $('#anio_rev').prop('selectedIndex',0); $('#mes_rev').prop('selectedIndex',0); $(this).find('option:selected').each(function() { if(this.value!=='temporadas'){ $('#revistas').addClass('fltr_anio'); $('#pagination_rev').addClass('hide'); $('[class*="mes_"]').addClass('hide'); fltr_anio = this.value; $( '#revistas' ).find('.mes_'+this.value).each(function( index ) { $(this).removeClass('hide'); }); } else { $('#revistas').removeClass('fltr_anio'); $('#pagination_rev').removeClass('hide'); $('[class*="mes_"]').removeClass('hide'); } }); }).trigger('change'); }); });