-
Notifications
You must be signed in to change notification settings - Fork 8
/
jquery.exposure.min.js
18 lines (18 loc) · 30.3 KB
/
jquery.exposure.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
* Exposure (http://http://exposure.blogocracy.org/)
* Copyright 2011, Kristoffer Jelbring
* Licensed under the MIT license.
*/
;(function($){$.exposure={v:'1.0.1',defaultTargetId:'exposure',wrapperClass:'exposureWrapper',targetClass:'exposureTarget',currentImageClass:'exposureCurrentImage',lastImageClass:'exposureLastImage',captionClass:'caption',imageDataClass:'extra',dataContainerClass:'exposureData',controlsClass:'exposureControls',slideshowControlsClass:'exposureSlideshowControls',firstPageClass:'exposureFirstPage',prevPageClass:'exposurePrevPage',nextPageClass:'exposureNextPage',lastPageClass:'exposureLastPage',pagingClass:'exposurePaging',playSlideshowClass:'exposurePlaySlideshow',pauseSlideshowClass:'exposurePauseSlideshow',maskClass:'exposureMask',thumbsClass:'exposureThumbs',imageClass:'exposureImage',imageHoverClass:'exposureHover',selectedImageClass:'selected',activeThumbClass:'active',currentThumbClass:'current',firstThumbClass:'first',lastThumbClass:'last',loadedClass:'loaded',activeLinkClass:'active',disabledLinkClass:'disabled',isDefined:function(v){return typeof v!=='undefined'},isObject:function(v){return typeof v==='object'},startsWith:function(s1,s2){if(s1&&s2){return s1.match("^"+s2)===s2}return false},widthDiff:function(el){return el?el.outerWidth(true)-el.width():0},heightDiff:function(el){return el?el.outerHeight(true)-el.height():0},createLink:function(text,onClick,linkClass){var a=$('<a href="javascript:void(0);"></a>').text(text).click(onClick);if(linkClass){a.addClass(linkClass)}return a},texts:{first:'First',previous:'Prev',next:'Next',last:'Last',play:'Play slideshow',pause:'Pause slideshow'}};var defaults={target:'#'+$.exposure.defaultTargetId,showThumbs:true,showControls:true,imageControls:false,controls:{prevNext:true,firstLast:true,pageNumbers:true},carouselControls:false,enableSlideshow:true,slideshowControlsTarget:null,autostartSlideshow:false,slideshowDelay:3000,onSlideshowPlayed:function(){},onSlideshowPaused:function(){},showCaptions:true,showExtraData:true,dataTarget:null,controlsTarget:null,onThumb:function(thumb){},onImage:function(image,imageData,thumb){image.siblings('.'+$.exposure.lastImageClass).remove()},onImageHoverOver:function(){},onImageHoverOut:function(){},onCarousel:function(firstImage,lastImage){},onNext:function(){},onPrev:function(){},onPageChanged:function(){},onPagingLink:function(link){return link},separatePageBrowsing:false,loop:true,onEndOfLoop:function(){},pageSize:5,viewFirstImage:true,visiblePages:5,preloadBuffer:3,keyboardNavigation:true,clickingNavigation:true,fixedContainerSize:false,maxWidth:null,maxHeight:null,stretchToMaxSize:false,fullScreen:false,onEnterFullScreen:function(mask){mask.show()},onExitFullScreen:function(target,mask){target.hide();mask.hide()},showThumbToolTip:true,onEmpty:function(gallery){gallery.hide();gallery.targetElement.remove();if(gallery.showControls){gallery.controlsElement.remove()}if(gallery.slideshowControlsTarget){gallery.slideshowControlsElement.remove()}},onInit:function(){},allowDuplicates:true,jsonSource:null};var Image=function(src,thumb,caption,data){this.src=src;this.thumb=thumb;this.caption=caption;this.data=data;this.loaded=false};$.fn.exposure=function(options){var gallery=this;var ex=$.exposure;var txt=ex.texts;$.extend(this,{images:[],sources:{},newImage:function(src,thumb,caption,data){var alreadyAdded=ex.isDefined(gallery.sources[src]);if(alreadyAdded&&!gallery.allowDuplicates){return-1}var image=new Image(src,thumb,caption,data);var imageIndex=gallery.images.push(image)-1;if(!alreadyAdded){gallery.sources[src]=imageIndex}return imageIndex},initialized:false,current:-1,deselectCurrentImage:function(){gallery.current=-1;gallery.find('li.'+ex.activeThumbClass).removeClass(ex.activeThumbClass)},loadQueue:[],addToLoadQueue:function(index){if(!gallery.loaded(index)&&!gallery.queued(index)){gallery.loadQueue.push(index)}},queued:function(index){return $.inArray(index,gallery.loadQueue)>-1},loaded:function(index){var image=gallery.getImage(index);if(image!==null){return image.loaded}return false},nextInLoadQueue:function(){var i;if(gallery.loadQueue.length>0){var next=gallery.loadQueue.shift();if(gallery.loaded(next)){i=$.inArray(next,this.loadQueue);gallery.loadQueue.splice(i,1);return gallery.nextInLoadQueue()}return next}return null},preloadNextInQueue:function(){if(gallery.loadQueue.length>0){var nextIndex=gallery.nextInLoadQueue();if(nextIndex!==null){gallery.loadImage(nextIndex,gallery.preloadNextInQueue)}}},loadImage:function(index,onload){var image=gallery.getImage(index);var img=$('<img />').addClass(ex.imageClass);var i;if(image!==null){image.loaded=true;if(gallery.queued(index)){i=$.inArray(index,gallery.loadQueue);gallery.loadQueue.splice(i,1)}if(typeof onload==='function'){img.load(onload)}img.attr('src',image.src)}return img},pageNumberForImage:function(index){return Math.ceil((index+1)/gallery.pageSize)},numberOfPages:function(){return this.pageNumberForImage(gallery.images.length-1)},atFirstPage:function(){return gallery.currentPage===1},atLastPage:function(){return gallery.currentPage===gallery.numberOfPages()},validPage:function(page){return page>0&&page<=gallery.numberOfPages()},createPaging:function(){var i;if(gallery.showControls&&gallery.controls.pageNumbers){var stop=gallery.imageControls?gallery.numberOfImages():gallery.numberOfPages();gallery.controlsElement.find('.'+ex.pagingClass).each(function(){for(i=1;i<=stop;i++){$(this).append(gallery.newPagingLink(i))}})}},updatePaging:function(newActivePage){if(gallery.showControls&&gallery.controls.pageNumbers){var current=gallery.imageControls?gallery.current+1:gallery.currentPage;var paging=gallery.controlsElement.find('.'+ex.pagingClass);paging.find(' span.'+ex.activeLinkClass).each(function(){$(this).replaceWith(gallery.newPagingLink(current))});paging.find('a[rel="'+newActivePage+'"]').each(function(){$(this).replaceWith($('<span>'+newActivePage+'</span>').addClass(ex.activeLinkClass))});var pageCount=gallery.imageControls?gallery.numberOfImages():gallery.numberOfPages();if(gallery.visiblePages>0&&pageCount>gallery.visiblePages){var firstVisiblePage=newActivePage;var lastVisiblePage=gallery.visiblePages;var flooredVisiblePages=Math.floor(gallery.visiblePages/2);if(newActivePage<=flooredVisiblePages){firstVisiblePage=1}else if(newActivePage>(pageCount-flooredVisiblePages)){lastVisiblePage=pageCount;firstVisiblePage=lastVisiblePage-gallery.visiblePages+1}else{firstVisiblePage-=flooredVisiblePages;lastVisiblePage=firstVisiblePage+gallery.visiblePages-1}paging.each(function(){$(this).children().each(function(i){var currentPage=i+1;if(currentPage>=firstVisiblePage&¤tPage<=lastVisiblePage){$(this).show()}else{$(this).hide()}})})}}},newPagingLink:function(index){var onclick=function(){var rel=Number($(this).attr('rel'));if(gallery.imageControls){gallery.viewImage(rel-1)}else{gallery.goToPage(rel)}};return ex.createLink(index,onclick).attr('rel',index)},getNextImage:function(){if(gallery.current===gallery.images.length-1){if(gallery.loop){return 0}else{gallery.onEndOfLoop()}}else{return gallery.current+1}return null},getPrevImage:function(){if(gallery.current===0){if(gallery.loop){return gallery.images.length-1}}else{return gallery.current-1}return null},currentPage:1,goToPage:function(page,imageToView){if(this.validPage(page)){gallery.find('li').removeClass(ex.currentThumbClass).hide();gallery.loadPage(page,imageToView);if(!gallery.imageControls){gallery.updatePaging(page)}gallery.currentPage=page;var disabled=ex.disabledLinkClass;if(gallery.showControls){if(gallery.atFirstPage()){if(gallery.controls.firstLast){gallery.find('.'+ex.firstPageClass).addClass(disabled)}if(!gallery.loop&&gallery.controls.prevNext){gallery.find('.'+ex.prevPageClass).hide()}}else{if(gallery.controls.firstLast){gallery.find('.'+ex.firstPageClass).removeClass(disabled)}if(!gallery.loop&&gallery.controls.prevNext){gallery.find('.'+ex.prevPageClass).show()}}if(gallery.atLastPage()){if(gallery.controls.firstLast){gallery.find('.'+ex.lastPageClass).addClass(disabled)}if(!gallery.loop&&gallery.controls.prevNext){gallery.find('.'+ex.nextPageClass).hide()}}else{if(gallery.controls.firstLast){gallery.find('.'+ex.lastPageClass).removeClass(disabled)}if(!gallery.loop&&gallery.controls.prevNext){gallery.find('.'+ex.nextPageClass).show()}}}if(!gallery.carouselControls){gallery.find('li.'+ex.currentThumbClass).show().each(function(i){var imageHeight=$(this).find('img').height();if(imageHeight>0){$(this).height(imageHeight)}});gallery.onPageChanged(gallery)}}},loadPage:function(page,imageToView){if(gallery.validPage(page)){var last=page*gallery.pageSize;var first=last-gallery.pageSize;if(last>gallery.images.length){last=gallery.images.length}gallery.pageTransition=true;gallery.viewThumbs(first,last-1);if(!gallery.separatePageBrowsing){if(imageToView){gallery.viewImage(imageToView)}else{if(page>1||((page===1&&gallery.viewFirstImage)||gallery.initialized)){gallery.viewImage(first)}}}gallery.pageTransition=false}},viewThumbs:function(first,last){var i;if(gallery.showThumbs){for(i=first;i<=last;i++){gallery.viewThumb(i,i===first,i===last,true)}if(!gallery.carouselControls&&gallery.currentPage<gallery.numberOfPages()){var firstNext=last+1;var lastNext=last+gallery.pageSize;if(lastNext>=gallery.images.length){lastNext=gallery.images.length-1}for(i=firstNext;i<=lastNext;i++){var container=gallery.viewThumb(i,i===firstNext,i===lastNext,false);if(container&&container.length){container.hide()}}}}},viewThumb:function(index,first,last,currentPage){if(index<0){index=gallery.images.length+index}else if(index>=gallery.images.length){index=index-gallery.images.length}var image=gallery.images[index];var container=gallery.getThumb(index).parent();if(!container.length){container=gallery.createThumbForImage(image,index);container.attr('rel',gallery.pageNumberForImage(index))}if(container.length){container.parent().append(container);if(first){container.addClass(ex.firstThumbClass)}else{container.removeClass(ex.firstThumbClass)}if(last){container.addClass(ex.lastThumbClass)}else{container.removeClass(ex.lastThumbClass)}if(currentPage){if(gallery.carouselControls){container.show()}else{container.addClass(ex.currentThumbClass)}}}return container},getThumb:function(index){return gallery.find('img[rel="'+index+'"]')},createThumbForImage:function(image,index){if(gallery.showThumbs){var thumb=gallery.getThumb(index);if(thumb===null||!thumb.length){var container=$('<li></li>');gallery.append(container);thumb=$('<img />');if(image.thumb){thumb.attr('src',image.thumb)}else{thumb.attr('src',image.src);var imageWidth=Math.ceil(thumb.width()/thumb.height()*container.height());var imageHeight=Math.ceil(thumb.height()/thumb.width()*container.width());if(imageWidth<imageHeight){thumb.css({height:'auto',maxWidth:container.width()})}else{thumb.css({width:'auto',maxHeight:container.height()})}}container.append(thumb.css('display','block'));thumb.attr('rel',index);if(image.caption&&gallery.showThumbToolTip){thumb.attr('title',image.caption)}thumb.data('data',image.data);thumb.click(function(){gallery.viewImage(Number($(this).attr('rel')))});thumb.load(function(){var imageHeight=$(this).height();if(imageHeight>0){$(this).parent().height(imageHeight)}});gallery.onThumb(thumb);return container}}return null},firstPage:function(){if(!gallery.atFirstPage()){gallery.goToPage(1)}},lastPage:function(){if(!gallery.atLastPage()){gallery.goToPage(gallery.numberOfPages())}},prevPage:function(){if(!gallery.atFirstPage()){gallery.goToPage(gallery.currentPage-1)}else if(gallery.loop){gallery.goToPage(gallery.numberOfPages())}},nextPage:function(){if(!gallery.atLastPage()){gallery.goToPage(gallery.currentPage+1)}else if(gallery.loop){gallery.goToPage(1)}},firstImageOnPage:function(index){if(!index){index=gallery.current}return gallery.pageSize===1||(index%gallery.pageSize===0)},lastImageOnPage:function(index){if(!index){index=gallery.current}var imageCount=gallery.images.length;if(gallery.pageSize===1||imageCount===1){return true}if(index>0){var currentPageSize=gallery.pageSize;var currentPage=gallery.pageNumberForImage(index);if(currentPage===gallery.numberOfPages()){var newPageSize=imageCount%gallery.pageSize;if(newPageSize>0){currentPageSize=newPageSize}}var imageIndex=index;if(currentPage>1){imageIndex-=(currentPage-1)*gallery.pageSize}return(imageIndex+1)%currentPageSize===0}return false},currentPageNumber:function(){return gallery.currentPage},numberOfImages:function(){return gallery.images.length},atFirstImage:function(){return gallery.current===0},atLastImage:function(){return gallery.current===gallery.numberOfImages()-1},getImage:function(index){if(index!==null&&index>-1&&index<gallery.images.length){return gallery.images[index]}return null},indexOfImage:function(src){if(src&&ex.isDefined(gallery.sources[src])){return gallery.sources[src]}return-1},currentImage:function(){return gallery.current},addImage:function(src,thumb,caption,data){var pageCount=gallery.numberOfPages();var index=gallery.newImage(src,thumb,caption,data);if(index>-1){var pageNumber=gallery.pageNumberForImage(index);var containers=$('.'+ex.thumbsClass+' li[rel="'+pageNumber+'"]');if(containers.length){containers.removeClass(ex.lastThumbClass)}var newPageAdded=pageNumber>pageCount;if(newPageAdded){$('.'+ex.pagingClass).empty();gallery.createPaging()}if(newPageAdded||pageNumber===gallery.currentPage){gallery.goToPage(gallery.currentPage)}}},removeImage:function(index){if(gallery.images.length===1){gallery.removeAllImages()}else{if(gallery.enableSlideshow){gallery.pauseSlideshow()}var oldPageCount=gallery.numberOfPages();gallery.images.splice(index,1);var queueIndex=$.inArray(index,gallery.loadQueue);if(queueIndex>-1){gallery.loadQueue.splice(queueIndex,1)}var container=gallery.getThumb(index).parent();container.remove();$('.'+ex.thumbsClass+' > li').each(function(i){if(i>=index){var newRel=gallery.pageNumberForImage(i);$(this).attr('rel',newRel);$(this).find('img').attr('rel',i);if(gallery.firstImageOnPage(i)){$(this).addClass(ex.firstThumbClass)}else{$(this).removeClass(ex.firstThumbClass)}if(gallery.lastImageOnPage(i)){$(this).addClass(ex.lastThumbClass)}else{$(this).removeClass(ex.lastThumbClass)}if(gallery.currentPage===newRel){$(this).show()}else{$(this).hide()}}});var pageRemoved=$.exposure.numberOfPages<oldPageCount;if(pageRemoved){$('.'+ex.pagingClass).empty();gallery.createPaging()}if(gallery.current===index){gallery.current=-1;var nextIndex=index;if(index===gallery.numberOfImages()){nextIndex=0}gallery.viewImage(nextIndex)}}},removeAllImages:function(){gallery.images=[];gallery.sources={};gallery.loadQueue=[];if(gallery.enableSlideshow){gallery.pauseSlideshow()}$('.'+ex.thumbsClass+', '+'.'+ex.pagingClass).empty();gallery.current=-1},viewImage:function(index){if(gallery.current!==index){if(gallery.enableSlideshow&&!gallery.slideshowTransition){gallery.pauseSlideshow()}var wrapper=gallery.wrapper;var validImage=false;var image=gallery.images[index];if(image){var src=image.src;var caption=image.caption;var extraImageData=image.data;if(src){validImage=true;var hasThumb=gallery.showThumbs;var thumb=null;if(gallery.showThumbs){thumb=gallery.find('img[rel="'+index+'"]');hasThumb=thumb&&thumb.length;var active=ex.activeThumbClass;if(hasThumb){thumb.parent().siblings().removeClass(active);thumb.parent().addClass(active)}else{gallery.find$('li.'+active).removeClass(active)}}wrapper.parent().removeClass(ex.loadedClass);if(gallery.loaded(index)){wrapper.parent().addClass(ex.loadedClass)}var img=gallery.loadImage(index,function(){var lastImage=wrapper.find('.'+ex.imageClass);if(lastImage.length){lastImage.removeClass(ex.currentImageClass);lastImage.addClass(ex.lastImageClass)}$(this).addClass(ex.currentImageClass);wrapper.append($(this));if(gallery.clickingNavigation){$(this).click(gallery.nextImage)}if(!$(this).width()||!$(this).height()){var i=$(this);var delay=setInterval(function(){gallery.resizeContainer(i);clearTimeout(delay)},2)}else{gallery.resizeContainer($(this))}if(gallery.fullScreen&&!gallery.infullScreen){gallery.onEnterFullScreen(gallery.mask);gallery.infullScreen=true}if(gallery.dataElement&&gallery.dataElement.length){if(gallery.showCaptions){var captionContainer=gallery.dataElement.find('.'+ex.captionClass);if(captionContainer.length){captionContainer.empty();if(!caption&&hasThumb){caption=thumb.attr('title')}}captionContainer.html(caption)}if(gallery.showExtraData){var extraImageDataContainer=gallery.dataElement.find('.'+ex.imageDataClass);if(extraImageDataContainer.length){extraImageDataContainer.empty();if(!extraImageData&&hasThumb){extraImageData=thumb.data('data')}extraImageDataContainer.html(extraImageData)}}}wrapper.hover(function(){wrapper.addClass(ex.imageHoverClass);gallery.onImageHoverOver()},function(){wrapper.removeClass(ex.imageHoverClass);gallery.onImageHoverOut()});gallery.onImage($(this),gallery.dataElement,thumb);gallery.preloadNextInQueue()})}}if(!validImage){wrapper.siblings().andSelf().empty();gallery.find('li.'+ex.activeThumbClass).removeClass(ex.activeThumbClass)}if(gallery.imageControls){var page=gallery.pageNumberForImage(index);if(gallery.currentPage!==page&&!gallery.pageTransition){gallery.goToPage(page,index)}gallery.updatePaging(index+1)}gallery.current=index;if(gallery.carouselControls&&gallery.images.length>gallery.pageSize){var firstVisibleImage=index;var lastVisibleImage=gallery.pageSize-1;var flooredVisibleImages=Math.floor(gallery.pageSize/2);if(!gallery.loop&&index<flooredVisibleImages){firstVisibleImage=0}else if(!gallery.loop&&index>=(gallery.length-flooredVisibleImages)){lastVisibleImage=gallery.length-1;firstVisibleImage=lastVisibleImage-gallery.pageSize+1}else{firstVisibleImage-=flooredVisibleImages;lastVisibleImage=firstVisibleImage+gallery.pageSize-1}gallery.onCarousel(firstVisibleImage,lastVisibleImage);gallery.find('li').removeClass(ex.currentThumbClass).hide();gallery.viewThumbs(firstVisibleImage,lastVisibleImage);gallery.currentPage=gallery.pageNumberForImage(index)}}},firstImage:function(){if(!gallery.atFirstImage()){if(gallery.separatePageBrowsing||gallery.atFirstPage()){gallery.viewImage(0)}else{gallery.goToPage(1)}}},nextImage:function(){if(!gallery.separatePageBrowsing&&gallery.lastImageOnPage()){if(gallery.atLastPage()&&gallery.loop){gallery.goToPage(1)}else{gallery.goToPage(gallery.currentPage+1)}gallery.onNext()}else{var next=gallery.getNextImage();if(next!==null){gallery.viewImage(next);gallery.onNext()}}var nextNext=gallery.getNextImage();if(nextNext!==null){gallery.addToLoadQueue(nextNext)}},prevImage:function(){if(!gallery.separatePageBrowsing&&gallery.firstImageOnPage()){if(gallery.atFirstPage()&&gallery.loop){gallery.goToPage(gallery.numberOfPages(),gallery.numberOfImages()-1)}else{var page=gallery.currentPage-1;gallery.goToPage(page,page*gallery.pageSize-1)}gallery.onPrev()}else{var prev=gallery.getPrevImage();if(prev!==null){gallery.viewImage(prev);gallery.onPrev()}}var prevPrev=gallery.getPrevImage();if(prevPrev!==null){gallery.addToLoadQueue(prevPrev)}},lastImage:function(){if(!gallery.atLastImage()){if(gallery.separatePageBrowsing||gallery.atLastPage()){gallery.viewImage(gallery.numberOfImages()-1)}else{gallery.goToPage(gallery.numberOfPages(),gallery.numberOfImages()-1)}}},imageHasData:function(){if(gallery.dataElement&&gallery.dataElement.length){var caption=gallery.dataElement.find('.'+$.exposure.captionClass).html();var extra=gallery.dataElement.find('.'+$.exposure.imageDataClass).html();return(caption&&caption.length>0)||(extra&&extra.length>0)}return false},pageTransition:false,playingSlideshow:false,slideshowTimer:null,slideshowTransition:false,slideshow:function(){gallery.slideshowTimer=setTimeout(function(){gallery.slideshowTransition=true;gallery.nextImage();gallery.slideshowTransition=false;gallery.slideshow()},gallery.slideshowDelay)},playSlideshow:function(){if(!gallery.playingSlideshow){if(gallery.slideshowControlsTarget){gallery.slideshowControlsElement.find('.'+ex.playSlideshowClass).hide();gallery.slideshowControlsElement.find('.'+ex.pauseSlideshowClass).show()}gallery.slideshow();gallery.playingSlideshow=true}gallery.onSlideshowPlayed()},pauseSlideshow:function(){if(gallery.playingSlideshow){if(gallery.slideshowControlsTarget){gallery.slideshowControlsElement.find('.'+ex.playSlideshowClass).show();gallery.slideshowControlsElement.find('.'+ex.pauseSlideshowClass).hide()}gallery.playingSlideshow=false;if(gallery.slideshowTimer){clearTimeout(gallery.slideshowTimer)}gallery.onSlideshowPaused()}},toggleSlideshow:function(){if(gallery.playingSlideshow){gallery.pauseSlideshow()}else{gallery.playSlideshow()}},first:function(){if(gallery.imageControls){gallery.firstImage()}else{gallery.firstPage()}},prev:function(){if(gallery.imageControls){gallery.prevImage()}else{gallery.prevPage()}},next:function(){if(gallery.imageControls){gallery.nextImage()}else{gallery.nextPage()}},last:function(){if(gallery.imageControls){gallery.lastImage()}else{gallery.lastPage()}},infullScreen:false,exitFullScreen:function(){if(gallery.infullScreen){gallery.pauseSlideshow();gallery.deselectCurrentImage();gallery.onExitFullScreen(gallery.targetElement,gallery.mask);gallery.infullScreen=false}},actualMaxWidth:function(image,target){return gallery.maxWidth?gallery.maxWidth-(ex.widthDiff(image)+ex.widthDiff(target)):0},actualMaxHeight:function(image,target){return gallery.maxHeight?gallery.maxHeight-(ex.heightDiff(image)+ex.heightDiff(target)):0},fitToMaxSize:function(image){var target=gallery.targetElement;if(gallery.stretchToMaxSize){if(gallery.maxWidth){image.width(gallery.actualMaxWidth(image,target))}if(gallery.maxHeight){image.height(gallery.actualMaxHeight(image,target))}}else{if(image.width()>image.height()){gallery.fitToMaxWidth(image,target);gallery.fitToMaxHeight(image,target)}else if(image.height()>image.width()){gallery.fitToMaxHeight(image,target);gallery.fitToMaxWidth(image,target)}else{var actualMaxHeight=gallery.actualMaxHeight(image,target);var smallest=gallery.actualMaxWidth(image,target);if(!smallest||(actualMaxHeight&&smallest&&actualMaxHeight<smallest)){smallest=actualMaxHeight}if(smallest&&image.width()>smallest){image.width(smallest);image.height(smallest)}}}},centerImageInWindow:function(image){var target=gallery.targetElement;target.width(image.width()).height(image.height());target.css({'top':($(window).height()-target.outerHeight(true))/2,'left':($(window).width()-target.outerWidth(true))/2});target.find('.'+ex.lastImageClass).each(function(){$(this).css({'top':(target.height()-$(this).height())/2,'left':(target.width()-$(this).width())/2})})},fitToWindow:function(){gallery.maxWidth=$(window).width();gallery.maxHeight=$(window).height();var image=gallery.targetElement.find('.'+$.exposure.currentImageClass).width('auto').height('auto');if(!image.width()||!image.height()){var delay=setInterval(function(){gallery.fitToMaxSize(image);gallery.centerImageInWindow(image);clearTimeout(delay)},2)}else{gallery.fitToMaxSize(image);gallery.centerImageInWindow(image)}},fitToMaxWidth:function(image,target){var actualMaxWidth=gallery.actualMaxWidth(image,target);if(actualMaxWidth&&image.width()>actualMaxWidth){var newHeight=Math.round(actualMaxWidth*image.height()/image.width());image.height(newHeight);image.width(actualMaxWidth)}},fitToMaxHeight:function(image,target){var actualMaxHeight=gallery.actualMaxHeight(image,target);if(actualMaxHeight&&image.height()>actualMaxHeight){var newWidth=Math.round(actualMaxHeight*image.width()/image.height());image.width(newWidth);image.height(actualMaxHeight)}},resizeContainer:function(img){gallery.fitToMaxSize(img);if(!gallery.fixedContainerSize){gallery.targetElement.show().width(img.width()).height(img.height())}}});$.extend(this,defaults,options);this.targetElement=$(this.target);if(!this.targetElement.length){this.target=defaults.target;this.targetElement=$('<div id="'+ex.defaultTargetId+'"></div>').insertBefore($(this))}var w=this.wrapper=$('<div class="'+ex.wrapperClass+'"></div>');var te=this.targetElement.addClass(ex.targetClass).append(w);if(this.showCaptions||this.showExtraData){var dataElementsHtml='';if(this.showCaptions){dataElementsHtml+='<div class="'+ex.captionClass+'"></div>'}if(this.showExtraData){dataElementsHtml+='<div class="'+ex.imageDataClass+'"></div>'}var dataElements=$(dataElementsHtml);if(dataElements.length){this.dataElement=$(this.dataTarget);if(this.dataTarget&&this.dataElement.length){this.dataElement.addClass(ex.dataContainerClass).append(dataElements)}else{this.dataElement=$('<div class="'+ex.dataContainerClass+'"></div>');te.append(this.dataElement.append(dataElements))}}}if(!this.showThumbs){this.carouselControls=false}if(this.carouselControls||!this.controlsTarget||(!this.controls.prevNext&&!this.controls.firstLast&&!this.controls.pageNumbers)){this.showControls=false}if(this.showControls){this.controlsElement=$(this.controlsTarget).addClass(ex.controlsClass).each(function(){if(gallery.controls.firstLast){$(this).append(ex.createLink(txt.first,gallery.first,ex.firstPageClass))}if(gallery.controls.prevNext){$(this).append(ex.createLink(txt.previous,gallery.prev,ex.prevPageClass))}if(gallery.controls.pageNumbers){$(this).append($('<div class="'+ex.pagingClass+'"></div>'))}if(gallery.controls.prevNext){$(this).append(ex.createLink(txt.next,gallery.next,ex.nextPageClass))}if(gallery.controls.firstLast){$(this).append(ex.createLink(txt.last,gallery.last,ex.lastPageClass))}})}if(this.enableSlideshow&&this.slideshowControlsTarget){this.slideshowControlsElement=$(this.slideshowControlsTarget).addClass(ex.slideshowControlsClass).each(function(){$(this).append(ex.createLink(txt.play,gallery.playSlideshow,ex.playSlideshowClass));$(this).append(ex.createLink(txt.pause,gallery.pauseSlideshow,ex.pauseSlideshowClass).hide())})}if(this.keyboardNavigation){if(this.carouselControls){$(document).bind('keyup','left',this.nextImage);$(document).bind('keyup','right',this.prevImage)}else{$(document).bind('keyup','left',this.prevImage);$(document).bind('keyup','right',this.nextImage);$(document).bind('keyup','ctrl+left',this.prevPage);$(document).bind('keyup','ctrl+right',this.nextPage);$(document).bind('keyup','up',this.lastImage);$(document).bind('keyup','down',this.firstImage);$(document).bind('keyup','ctrl+up',this.lastPage);$(document).bind('keyup','ctrl+down',this.firstPage)}if(this.enableSlideshow){$(document).bind('keyup','space',this.toggleSlideshow)}}if(this.fullScreen){$(window).resize(this.fitToWindow);this.mask=$('<div class="'+ex.maskClass+'"></div>').click(this.exitFullScreen).insertAfter(this.target);if(this.keyboardNavigation){$(document).bind('keyup','esc',this.exitFullScreen)}}var jsonImages=null;if(this.jsonSource){if(ex.isObject(this.jsonSource)){jsonImages=this.jsonSource}else if(this.jsonSource.length){if(ex.startsWith(this.jsonSource,"http://")||ex.startsWith(this.jsonSource,"https://")){jsonImages=$.ajax({url:this.jsonSource,type:'GET',async:false}).responseText}else{jsonImages=this.jsonSource}}}return this.addClass(ex.thumbsClass).each(function(){var i;if(jsonImages){var images=ex.isObject(jsonImages)?jsonImages:$.parseJSON(jsonImages);if(images&&images.data){for(i in images.data){var photo=images.data[i];if(photo.source&&photo.source.length){var item=$('<li></li>');var link=$('<a></a>').attr('href',photo.source);if(photo.thumb_source&&photo.thumb_source.length){var thumb=$('<img />').attr('src',photo.thumb_source);if(photo.caption&&photo.caption.length){thumb.attr('title',photo.caption)}link.append(thumb)}else if(photo.caption&&photo.caption.length){link.attr('title',photo.caption)}item.append(link);if(photo.extra_data&&photo.extra_data.length){item.append($(photo.extra_data))}$(this).append(item)}}}}var foundImage=false;var foundThumb=false;if($(this).children('li').length){var selectedIndex=null;$(this).show().children('li').each(function(){foundImage=true;var a=$(this).find('a');if(a.length){a=$(a[0]);var src=a.attr('href');var img=a.find('img');var thumbSrc=img.length?img.attr('src'):a.attr('rel');var caption=img.length?img.attr('title'):a.attr('title');var isSelected=a.hasClass(ex.selectedImageClass)&&!selectedIndex;a.remove();var thumbData=$(this).html();if(thumbSrc){foundThumb=true}$(this).remove();var imageIndex=gallery.newImage(src,thumbSrc,caption,thumbData);if(imageIndex>-1){if(isSelected){selectedIndex=imageIndex}if(gallery.loadQueue.length<gallery.preloadBuffer){gallery.addToLoadQueue(imageIndex)}}}else{$(this).remove()}});if(!gallery.showThumbs){gallery.pageSize=1;$(ex.thumbsClass).remove()}if(foundImage){gallery.preloadNextInQueue();gallery.createPaging();if(selectedIndex){gallery.goToPage(gallery.pageNumberForImage(selectedIndex));gallery.viewImage(selectedIndex)}else{gallery.goToPage(1)}if(gallery.enableSlideshow&&gallery.autostartSlideshow){gallery.playSlideshow()}}else{gallery.onEmpty(gallery)}}else{gallery.onEmpty(gallery)}gallery.onInit();gallery.initialized=true})}})(jQuery);
/*
* jQuery Hotkeys Plugin
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Based upon the plugin by Tzury Bar Yochay:
* http://github.com/tzuryby/hotkeys
*
* Original idea by:
* Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
*/
(function(jQuery){jQuery.hotkeys={version:"0.8",specialKeys:{8:"backspace",9:"tab",13:"return",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"del",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scroll",191:"/",224:"meta"},shiftNums:{"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+",";":": ","'":"\"",",":"<",".":">","/":"?","\\":"|"}};function keyHandler(handleObj){if(typeof handleObj.data!=="string"){return}var origHandler=handleObj.handler,keys=handleObj.data.toLowerCase().split(" ");handleObj.handler=function(event){if(this!==event.target&&(/textarea|select/i.test(event.target.nodeName)||event.target.type==="text")){return}var special=event.type!=="keypress"&&jQuery.hotkeys.specialKeys[event.which],character=String.fromCharCode(event.which).toLowerCase(),key,modif="",possible={};if(event.altKey&&special!=="alt"){modif+="alt+"}if(event.ctrlKey&&special!=="ctrl"){modif+="ctrl+"}if(event.metaKey&&!event.ctrlKey&&special!=="meta"){modif+="meta+"}if(event.shiftKey&&special!=="shift"){modif+="shift+"}if(special){possible[modif+special]=true}else{possible[modif+character]=true;possible[modif+jQuery.hotkeys.shiftNums[character]]=true;if(modif==="shift+"){possible[jQuery.hotkeys.shiftNums[character]]=true}}for(var i=0,l=keys.length;i<l;i++){if(possible[keys[i]]){return origHandler.apply(this,arguments)}}}}jQuery.each(["keydown","keyup","keypress"],function(){jQuery.event.special[this]={add:keyHandler}})})(jQuery);