// PatrimonioCulturalUdeC
var user_id = '188543137@N07',
api_key = 'f386106002c19958999905ffd17f4301';
var photosets = 'https://api.flickr.com/services/rest/?&method=flickr.photosets',
format = 'format=json&nojsoncallback=1',
url = photosets+'.getList&api_key='+api_key+'&user_id='+user_id+'&'+format,
divGaleria = document.getElementById('fotos'),
ctlGallery = document.getElementById('ctlGallery'),
dataAlbums = '',
listGallery = '',
tipoAlbum = '',
img_src = '',
listaFotos = '',
wordSearch = '',
xmlhttp = new XMLHttpRequest(),
regex = /[.*+?^${}()[\]\\]/gi;
if (user_id !='' && api_key!='') {
var str_dgpc = document.getElementsByClassName('pagina-seccion');
var acervoTag = document.getElementsByTagName('ARTISTAS')[0];
window.onload = function() {
albums(wordSearch);
};
function albums(wordSearch) {
Object.keys(str_dgpc).forEach( function(keys){
if(str_dgpc[keys].innerHTML.search('##ARTISTAS##') != -1)
wordSearch = 'Artistas';
var slct_div = str_dgpc[keys];
var result = slct_div.innerHTML.replace(/##ARTISTAS##|##EXPOSICIONES##/gi, '
');
slct_div.innerHTML = result;
listaFotos = $('[id*="fotos_"]')[0];
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (JSON.parse(this.response).stat=='ok'){
dataAlbums = JSON.parse(this.response).photosets.photoset;
listGallery = JSON.parse(this.responseText);
listaFotos.innerHTML = '';
dataAlbums.forEach(function(data,index){
if (listGallery.photosets.photoset.length>0) {
if(wordSearch == 'Artistas')
if (data.title._content.indexOf(wordSearch) != -1)
listaAlbums(data,listaFotos,index,wordSearch);
if(wordSearch != 'Artistas')
if (data.title._content.indexOf('Artistas') == -1)
listaAlbums(data,listaFotos,index,wordSearch);
getFotos(wordSearch);
} else listaFotos.innerHTML = 'No hay fotos
';
});
} else listaFotos.innerHTML = 'Hubo un problema al intentar cargar la galeria
';
};
};
xmlhttp.open('GET', url, true);
xmlhttp.send();
});
}
function listaAlbums(data,listaFotos,index) {
listaFotos = $('[id*="fotos_"]')[0];
img_src = 'https://farm'+data.farm+'.static.flickr.com/'+data.server+'/'+data.primary+'_'+data.secret+'_m.jpg';
listaFotos.innerHTML += ''+
'
'+
'
'+data.title._content+'
'+
'
'+
'
'+
'
';
}
function previewPhoto(album,tipoAlbum,index) {
if (listaFotos != null ) listaFotos.innerHTML = 'Cargando...
';
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var AlbumTitle ='',
AlbumDescription ='';
if(dataAlbums[index].title._content!='') AlbumTitle = ''+dataAlbums[index].title._content+'
';
if(dataAlbums[index].description._content!='') AlbumDescription = ''+dataAlbums[index].description._content+'
';
if(AlbumTitle!='' || AlbumDescription!='' ) listaFotos.innerHTML = ''+
''+
'
'+
AlbumTitle+
AlbumDescription+
'
'+
'
';
JSON.parse(this.response).photoset.photo.forEach(function(item,contx) {
var photoid = item.id,
secret = item.secret,
server = item.server,
farm = item.farm,
photo_url = 'https://farm' + farm + '.static.flickr.com/' + server + '/' + photoid + '_' + secret + '_m.jpg',
photo_url_big = 'https://farm' + farm + '.static.flickr.com/' + server + '/' + photoid + '_' + secret + '_b.jpg',
titlePhoto = '',
descriptionPhoto = '';
fetch('https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key='+api_key+'&photo_id='+photoid+'&'+format).then(res => res.json()).then((PhotoData) => {
var photoHtml = '';
titlePhoto = ''+PhotoData.photo.title._content+'
';
descriptionPhoto = ''+PhotoData.photo.description._content+'
';
photoHtml += '';
photoHtml += '
';
if(titlePhoto!='') photoHtml += titlePhoto;
if(descriptionPhoto!='') photoHtml += descriptionPhoto;
photoHtml += '
';
listaFotos.innerHTML += photoHtml;
visualizador();
}).catch(err => console.error(err));
if(item.isprimary==1) document.getElementsByClassName('album-description')[0].style.backgroundImage = 'url("'+photo_url_big+'")';
});
};
};
xmlhttp.open('GET', photosets+'.getPhotos&api_key='+api_key+'&photoset_id=' + album + '&'+format, true);
xmlhttp.send();
};
function getFotos(wordSearch) {
var albumGal = document.getElementsByClassName('album');
for(var i = 0; i < albumGal.length; i++) {
albumGal[i].addEventListener('click', function(){
tipoAlbum = wordSearch;
id_gal = this.getAttribute('id_gal');
x = this.getAttribute('x');
previewPhoto(id_gal,tipoAlbum,x);
}, false);
};
};
function visualizador() {
$("[id*='fotos'] a[rel^='prettyPhoto']").prettyPhoto({
animation_speed: 'normal',
theme: 'facebook',
slideshow: 3000,
autoplay_slideshow: false,
allow_resize: false,
deeplinking: false,
social_tools: false
});
};
};