/*
Custom "lightbox" similar alternative - css style.
*/
if(typeof sircon === 'undefined' || typeof sircon.funcs === 'undefined'){
var sircon = window.sircon || {};
sircon.funcs = sircon.funcs || {};
}
//CALL this function to make stuff lateboxable
sircon.funcs.lateboxify = function(){
var $ = window.jQuery;
//Find these suckers and make them work as a lateboxable item
var targets = 'a>img',
validImageEndings = ['jpg', 'jpeg', 'png', 'gif'],
counter = 0;
$(targets).each(function(){
$(this).attr('data-lateboxcount', counter++);
});
$(targets).each(function(){
var $this = $(this),
$anchor = $this.parent(),
href = $anchor.attr('href'),
isImageLink = false;
//Verify as image link
for(var i in validImageEndings){
var ending = validImageEndings[i],
hrefEnd = href.substr(ending.length * -1);
if(hrefEnd === ending){
isImageLink = true;
break;
}
}
//Did we verify as image link?
if(!isImageLink){return;}
//IS image link!
$anchor.click(function(event){
event.preventDefault();//No clicky, because latebox
//Remove other latebox
$('body > .latebox-outer').remove();
//Add new latebox
var $latebox = $('
'),
$figure;
//Add navigation
$latebox
.prepend('')
.prepend('');
//Insert latebox
$('body').append($latebox);
$figure = $latebox.find('.latebox-figure');
//Load image
sircon.funcs.lateboxInsertImage($anchor);
});
});
}
//Common way to insert image
sircon.funcs.lateboxInsertImage = function($anchor){
//Load image
var img = new Image(),
$figure = $('.latebox-figure');
img.onload = function(){
//Put image in figure
$figure.css('backgroundImage', 'url('+this.src+')');
$figure.html(this);
$figure.attr('data-lateboxcount', $anchor.find('img').attr('data-lateboxcount'));
};
img.src = $anchor.attr('href');
img.alt = $anchor.find('img').attr('alt') || 'fullsize display';
}
//Nav clicky
$(document).on('click', '.latebox-nav > div', function(){
var $this = $(this),
hasClassNext = $this.hasClass('nav-next'),
$latebox = $this.closest('.latebox-outer'),
currentLateboxCount = parseInt($latebox.find('figure').attr('data-lateboxcount')),
$targetImg,
$targetAnchor;
if(hasClassNext){
currentLateboxCount++;
}else{
currentLateboxCount--;
}
$targetImg = $('[data-lateboxcount='+currentLateboxCount+']');
if($targetImg.length == 0){return;}
$targetAnchor = $targetImg.closest('a');
if($targetAnchor.length > 0){
sircon.funcs.lateboxInsertImage($targetAnchor);
}
});
$(document).ready(sircon.funcs.lateboxify);
$(document).on('click', '.latebox-outer .close-this', function(){
$(this).closest('.latebox-outer').remove();
});