-
Notifications
You must be signed in to change notification settings - Fork 0
/
gallery.min.js
7 lines (7 loc) · 4.27 KB
/
gallery.min.js
1
2
3
4
5
6
7
/**
* Standout gallery v0.0.2
*
* Copyright 2011, Standout AB, http://standout.se
* License: MIT
*/
(function(a){var b=function(b){var c;var d=function(){c=e();f()};var e=function(){var b=a("<canvas/>").appendTo("body");if(b[0].getContext){a(window).resize(f)}else{b.remove();b=a("<div/>").appendTo("body").css({width:"100%",height:"100%",backgroundColor:"#000"})}return b.css({display:"none",top:0,left:0,zIndex:1e4,position:"fixed",opacity:0})};var f=function(){if(c[0].getContext){var b=a(window).width();var d=a(window).height();var e=c[0].getContext("2d");c.attr({width:b,height:d});var f=e.createRadialGradient(b/2,d/2,0,b/2,d/2,d*1.3);f.addColorStop(0,"rgba(0,0,0,0.25)");f.addColorStop(1,"#000");e.fillStyle=f;e.fillRect(0,0,b,d)}};this.showDark=function(){c.css("display","block").animate({opacity:.75},b.animationSpeed)};this.hideDark=function(){c.animate({opacity:0},b.animationSpeed,function(){c.css("display","none")})};d()};var c=function(b){var c=a("<div/>").css({display:"none",top:0,left:0,zIndex:10010,position:"fixed"}).attr("id","gallery_wrapper").appendTo("body");var d=a('<div class="options"><div class="left"></div><div class="close"></div><div class="right"></div></div>').css({display:"none",opacity:0});var e=a("<div/>").addClass("title");var f=a();var g=[];var h=false;var i,j,k,l;var m=function(){c.delegate("div","click",function(a){if(a.target==i.copy[0]){q(r)}switch(this.className){case"right":q(r);break;case"left":q(s);break;case"close":p();break}});b.parent.delegate(b.selector,"click",function(b){b.preventDefault();n(a(b.currentTarget))});a(window).resize(u);a(document).keydown(x);a(document).mousemove(y)};var n=function(d){h=true;j=w(d);i=g[j];if(b.hideEmbeds){a("iframe, embed, select").css("visibility","hidden")}b.utils.showDark();c.css("display","block");v();t()};var o=function(){q(r)};var p=function(){h=false;if(b.hideEmbeds){a("iframe, embed, select").css("visibility","visible")}if(b.autoPlay){window.clearInterval(l)}b.utils.hideDark();c.css("display","none");q()};var q=function(c){if(k){window.clearTimeout(k);i.wrapper.children(".options, .title").each(function(){a(this).animate({opacity:0},b.animationSpeed,function(){a(this).remove()})})}if(b.autoPlay){window.clearInterval(l)}i.wrapper.animate({opacity:0},b.animationSpeed,function(){i.wrapper.css("display","none");if(c){c()}})};var r=function(){j=g[j+1]?j+1:0;i=g[j];v();t()};var s=function(){j=g[j-1]?j-1:g.length-1;i=g[j];v();t()};var t=function(){if(k){window.clearTimeout(k)}if(b.autoPlay){l=window.setInterval(o,5e3)}i.wrapper.animate({opacity:1},b.animationSpeed);i.wrapper.append(d.clone());y();if(b.title&&i.trigger.attr("title")){i.wrapper.prepend(e.clone().text(i.trigger.attr("title")))}};var u=function(){v()};var v=function(){i.wrapper.css("display","block");if(!i.copy.data("width")){i.copy.data("width",i.copy.width());i.copy.data("height",i.copy.height())}var c=a(window).width();var d=a(window).height();var e=i.copy.data("width");var f=i.copy.data("height");if(e>c*b.maxSize||f>d*b.maxSize){e=c*b.maxSize;f=i.copy.data("height")/i.copy.data("width")*e;if(f>i.copy.data("height")*b.maxSize){f=d*b.maxSize;e=i.copy.data("width")/i.copy.data("height")*f}}i.wrapper.css({width:e,height:f,top:(d-f)*.5,left:(c-e)*.5});i.copy.css({width:e,height:f})};var w=function(b){return f.index(a(b))};var x=function(a){if(h){switch(a.which){case 39:q(r);break;case 37:q(s);break;case 27:p();break}}};var y=function(){if(h){var c=i.wrapper.children(".options");if(c.is(":hidden")){c.css("display","block").animate({opacity:1},b.animationSpeed)}if(k){window.clearTimeout(k)}k=window.setTimeout(function(){c.animate({opacity:0},b.animationSpeed,function(){a(this).css("display","none")})},2e3)}};var z=function(b){var e=a("<div><img/></div>").css({display:"none",opacity:0,position:"absolute","-ms-interpolation-mode":"bicubic"}).appendTo(c);e.children("img").attr("src",b.attr("href"));c.append(d);return e};this.setImage=function(a){f=f.add(a);var b=z(a);g.push({trigger:a,wrapper:b,copy:b.children("img")})};if(!(b.noMobile&&/mobile/i.test(navigator.userAgent))){m()}};a.fn.gallery=function(d){var e=new b(a.extend({animationSpeed:200}),d);var f=new c(a.extend({utils:e,maxSize:.9,animationSpeed:200,parent:this.parent(),selector:"a",title:false,hideEmbeds:false,autoPlay:false,noMobile:false},d));return this.each(function(){f.setImage(a(this))})}})(jQuery)