console.clear();
/**
* EC Lightbox
* @param {object} images Array of image URLs
* @param {mixed} image Index or URL of image to autoload
*/
function eclb(images, image){
// Set up variables
// Image list vars
this.CURRENT = 0;
this.IMAGES = images;
// Target vars
this.TARGET_ID = 'eclb-target';
this.TARGET_STATE = 0;
// Stage vars
this.STAGE_ID = 'eclb-stage';
this.STAGE_STATE = 0;
// Stage vars
this.NEXT_STATE = 0;
this.PREV_STATE = 0;
// If initial image index or string is provided, open upon initialization
if(typeof image !== 'undefined'){
this.openLightbox(image);
}
return this;
}
/**
* Closes lightbox target
*/
eclb.prototype.closeLightbox = function(){
var _t = this,
lb;
// Fail if target isn't open
if(_t.TARGET_STATE !== 1){
return false;
}
// Get target
lb = document.getElementById(_t.TARGET_ID);
// Fade out
return _fade('out', lb, 600, 'easeOut', function(){
// Remove target from DOM
lb.parentNode.removeChild(lb);
// Reset states
_t.TARGET_STATE = 0;
_t.STAGE_STATE = 0;
return true;
});
}
/**
* Opens lightbox with image index or string
* @param {mixed} image Image index or matching string
*/
eclb.prototype.openLightbox = function(image){
var _t = this,
lb;
// Only run if target state is closed (0)
if(_t.TARGET_STATE !== 0){
return false;
}
// Image index detection
if(typeof image === 'string'){
image = _t.IMAGES.indexOf(image); // Match first instance of image string
}else if(typeof current !== 'number'){
current = 0; // Default index to first
}
// Check index is in array range
if(!_t.IMAGES[image]){
return false;
}
// Update current image index
_t.CURRENT = image;
// Update state to opening (2)
_t.TARGET_STATE = 2;
// Create lightbox DOM object
lb = _render({
tag: 'div',
attr: {
'id': _t.TARGET_ID
},
css: {
'display': 'none' // display: none for...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.