Skip to content

Instantly share code, notes, and snippets.

@scrubmx
Created March 11, 2014 00:19
Show Gist options
  • Select an option

  • Save scrubmx/9477175 to your computer and use it in GitHub Desktop.

Select an option

Save scrubmx/9477175 to your computer and use it in GitHub Desktop.
window.Lightbox = {};
/**
* Contenedor donde se pone la imagen
* @type jQuery Wrapped DOM Element
*/
Lightbox.$container =$('#evento-uploads-lightbox');
/**
* Contador que indica el indice de la imagen que estamos viendo
* @type integer
*/
Lightbox.current = 0;
/**
* Imagenes que se han subido al single del evento.
* @type JSON
*/
Lightbox.uploads = Museografo.eventoUploads;
/**
* Total de imagenes en el lightbox
* @type integer
*/
Lightbox.totalImages = Lightbox.uploads.length;
/**
* [init description]
*
* @return {[type]}
*/
Lightbox.init = function ()
{
this.getCurrentImage().load();
};
/**
* [getCurrentImage description]
*
* @return {[type]}
*/
Lightbox.getCurrentImage = function ()
{
this.currentImage = this.uploads[ this.current ];
return this;
};
/**
* [getNextImage description]
*
* @return {[type]}
*/
Lightbox.getNextImage = function ()
{
this.currentImage = this.uploads[ this.getIndex(+1) ];
return this;
};
/**
* [getPrevImage description]
*
* @return {[type]}
*/
Lightbox.getPrevImage = function ()
{
this.currentImage = this.uploads[ this.getIndex(-1) ];
return this;
};
/**
* [getIndex description]
*
* @param {[type]} direccion [description]
* @return {[type]}
*/
Lightbox.getIndex = function (direccion)
{
this.current += direccion;
if ( this.current > (this.totalImages - 1) )
this.current = 0;
if ( this.current < 0 )
this.current = this.totalImages - 1;
return this.current;
};
/**
* [load description]
*
* @return {[type]}
*/
Lightbox.load = function ()
{
// Vaciar el contendor
this.$container.empty();
// Mostrar la imagen
this.getThumbnail( this.currentImage.path )
.appendTo(this.$container);
};
/**
* [getThumbnail description]
*
* @return {[type]}
*/
Lightbox.getThumbnail = function ()
{
return $('<img />', {
'src': this.currentImage.path + '-large.jpg'
});
};
Lightbox.init();
$('body').on('click', function (e) {
Lightbox.getNextImage().load();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment