-
Notifications
You must be signed in to change notification settings - Fork 2
/
simple-gallery.js
1 lines (1 loc) · 5.43 KB
/
simple-gallery.js
1
function debug(e){window.console}jQuery.browser={},jQuery.browser.msie=!1,jQuery.browser.version=0,navigator.userAgent.match(/MSIE ([0-9]+)\./)&&(jQuery.browser.msie=!0,jQuery.browser.version=RegExp.$1),jQuery.noConflict(),jQuery(document).ready((function(e){var l=e("div.simplegallery"),t=l.size();for(i=0;i<t;i++)r(e(l[i]).attr("id"));function r(l){var t="#"+l,r=0,s=e(t+" .thumbnails dt a"),n=e(t+" .thumbnails"),d=e(t+" .largeimage"),o=e(d).children("a").children("img"),c=e(d).children("h3"),h=s.size();s[r];function u(i){if(debug(t+": img showImg() called for thumbnail <a> with href "+e(i).attr("href")),e(i).attr("href")!=e(o).attr("src")){"out-in"!=gallerySettings[l].fade&&"over"!=gallerySettings[l].fade||(e(o).hide(),e(d).addClass("loading")),e(o).attr("src",e(i).attr("href")).attr("title",e(i).attr("title")).attr("alt",e(i).attr("title"));var a=e.trim(e(i).parent().parent().children("dd").html());e(c).html(a),e(o).parent().attr("href",e(i).attr("href")),"object"==typeof shutterReloaded&&e(o).parent().click((function(){return shutterLinks.simpleviewer=null,shutterLinks.simpleviewer={link:e(i).attr("href"),num:-1,set:0,title:a},shutterReloaded.make("simpleviewer"),e(window).attr("onresize",""),!1})),e(s).removeClass("current"),e(i).addClass("current"),function(){f()?(e(t+" .simplegalleryprev").addClass("enabled"),e(t+" .simplegalleryprev").removeClass("disabled")):(e(t+" .simplegalleryprev").addClass("disabled"),e(t+" .simplegalleryprev").removeClass("enabled"));p()?(e(t+" .simplegallerynext").addClass("enabled"),e(t+" .simplegallerynext").removeClass("disabled")):(e(t+" .simplegallerynext").addClass("disabled"),e(t+" .simplegallerynext").removeClass("enabled"));e(t+" .simplegalleryimagenumber").html(r+1)}()}}function m(e){switch(e.keyCode){case 40:case 39:g();break;case 38:case 37:b();break}}function g(){p()&&(r++,u(s[r]))}function b(){f()&&(r--,u(s[r]))}function p(){return r<h-1}function f(){return r>0}if(e(s).attr("class",""),debug(t+": thumbnail classes removed"),e(d).children("a").attr("class",""),debug(t+": large image classes removed: "+e(d).children("a").attr("class")),e(s).click((function(){for(i=0;i<h;i++)if(s[i]==this){r=i;break}return u(e(this)),!1})),e(o).load((function(){debug(t+": img load() called for img "+e(this).attr("src"));var i=!1;if(e.browser.msie&&0==e.browser.version.indexOf("6.0")&&(i=!0),i){e(o).width(""),e(o).height("");var r=e(o).attr("src"),a="width",s=parseInt(e(o).width()),n=e(o).css("max-"+a),c=parseInt(n)/parseInt(e(o).css("max-height")),h=s/parseInt(e(o).height());debug(t+": "+r+": css ratio "+c+" img ratio "+h),parseInt(e(o).height())>s&&(a="height",s=parseInt(e(o).height()),n=e(o).css("max-height")),debug(t+": "+r+": constraint is "+a),""!=n&&n.indexOf("px")>-1&&(s>(n=parseInt(n))?("height"==a?e(o).height(n):"width"==a&&e(o).width(n),debug(t+": "+r+": "+a+" of changed from "+s+" down to "+n)):debug(t+": "+r+": no need to shrink. "+a+" already "+s))}debug(t+": image W x H: "+e(o).width()+" x "+e(o).height()),"out-in"!=gallerySettings[l].fade&&"over"!=gallerySettings[l].fade||e(o).fadeIn(gallerySettings[l].fadespeed,(function(){e(d).removeClass("loading"),function(){if("over"!=gallerySettings[l].fade)return;debug(t+": set background image to "+e(o).attr("src")),e(d).css("background-image","url("+e(o).attr("src")+")")}()}))})),u(s[0]),e(t+" .simplegallerynavbar").append("<ul>"),e(t+" .simplegallerynavbar ul").append('<li class="simplegalleryprev disabled"><a href="javascript:void();" title="Previous"><span>←</span></a></li>').append('<li class="simplegalleryimagenumbers"><span class="simplegalleryimagenumber">1</span> / <span class="simplegallerytotalimages">'+h+"</span></li>").append('<li class="simplegallerynext enabled"><a href="javascript:void();" title="Next"><span>→</span></a></li>').append("</ul>"),e(t+" .simplegalleryprev").click((function(){return e(this).hasClass("disabled")||b(),!1})),e(t+" .simplegallerynext").click((function(){return e(this).hasClass("disabled")||g(),!1})),e.browser.mozilla?e(document).keypress(m):e(document).keydown(m),1==gallerySettings[l].thumbnailscroll){var v=e(n).find(".gallery dl.gallery-item"),y=0,x=e(n).find("div.gallerywrapper").width();totalWidth=0,scrollingIndexEnd=0,v.each((function(){totalWidth+=parseInt(e(this).outerWidth(!0))})),scrollingIndexEnd=totalWidth/x-1,scrollingIndexEnd<0&&(scrollingIndexEnd=0),e(n).find("div.gallerywrapper div.gallery").css("min-width",totalWidth+"px"),e(n).find(".thumbnailscroll").height(e(n).height()),scrollingIndexEnd>0&&(e(n).find(".thumbnailscroll.thumbnailscroll-prev").click((function(){y>0&&(y--,a(n,y,scrollingIndexEnd),v.animate({left:"+="+x+"px"},"slow"))})),e(n).find(".thumbnailscroll.thumbnailscroll-next").click((function(){y<scrollingIndexEnd&&(y++,a(n,y,scrollingIndexEnd),v.animate({left:"-="+x+"px"},"slow"))}))),a(n,y,scrollingIndexEnd)}}function a(l,i,t){0==i&&t>0?(e(l).find(".thumbnailscroll.thumbnailscroll-prev").css("visibility","hidden"),e(l).find(".thumbnailscroll.thumbnailscroll-next").css("visibility","visible")):0==i&&0==t?(e(l).find(".thumbnailscroll.thumbnailscroll-prev").css("visibility","hidden"),e(l).find(".thumbnailscroll.thumbnailscroll-next").css("visibility","hidden")):i>0&&i<t?(e(l).find(".thumbnailscroll.thumbnailscroll-prev").css("visibility","visible"),e(l).find(".thumbnailscroll.thumbnailscroll-next").css("visibility","visible")):i>0&&i>=t&&(e(l).find(".thumbnailscroll.thumbnailscroll-prev").css("visibility","visible"),e(l).find(".thumbnailscroll.thumbnailscroll-next").css("visibility","hidden"))}}));