-
Notifications
You must be signed in to change notification settings - Fork 44
/
jquery.fullscreenslides.min.js
8 lines (8 loc) · 4.19 KB
/
jquery.fullscreenslides.min.js
1
2
3
4
5
6
7
8
/*
* Copyright Eike Send: http://eike.se/nd
* License: MIT / GPLv2
*
* This is a jQuery plugin to generate full screen galleries.
*
* https://github.com/eikes/jquery.fullscreen.js
*/(function(a){var b,c=function(){function g(a){b.data("isFullScreen")&&b.trigger("close"),b.data("isFullScreen",!0)}b.bind("updateSize orientationchange",function(d){b.height(a(window).height()),c()});var c=function(c){if(c===undefined)var c=b.data("currentSlide");if(c&&c.$img){var d=a(window).height(),e=a(window).width();e/d>c.$img.width()/c.$img.height()?c.$img.css({height:d+"px",width:"auto"}):c.$img.css({height:"auto",width:e+"px"}),c.$img.css({"margin-left":"-"+.5*c.$img.width()+"px","margin-top":"-"+.5*c.$img.height()+"px"})}};a(window).bind("resize",function(){b.trigger("updateSize")});var d=!1;b.bind("showSlide",function(f,g){if(!d){var h=b.data("currentSlide");"$img"in g?e(h,g):(d=!0,b.trigger("startLoading"),g.$img=a('<img class="slide">').css({position:"absolute",left:"50%",top:"50%"}).hide().load(function(){d=!1,b.trigger("stopLoading"),c(g),e(h,g)}).error(function(){d=!1,g.error=!0,b.trigger("stopLoading").trigger("error",g)}).attr("src",g.image),b.append(g.$img))}}),b.bind("prevSlide nextSlide",function(a){var c,d=b.data("slides"),e=b.data("currentSlide"),f=e&&e.id||0;a.type=="nextSlide"?c=(f+1)%d.length:c=(f-1+d.length)%d.length,b.trigger("showSlide",d[c])});var e=function(a,c){a!==undefined&&(b.trigger("endOfSlide",a),a.$img.fadeOut()),c.$img&&!c.error?c.$img.fadeIn(function(){b.trigger("startOfSlide",c)}):b.trigger("startOfSlide",c),b.data("currentSlide",c)},f=function(a){a.keyCode==27&&b.trigger("close"),a.keyCode==37&&b.trigger("prevSlide"),a.keyCode==39&&b.trigger("nextSlide")};b.bind("close",function(){var c=b.data("options"),d=b.data("currentSlide");d&&d.$img&&d.$img.hide(),b.trigger("endOfSlide",d),a(document).unbind("keydown",f),c.useFullScreen?(document.cancelFullScreen&&document.cancelFullScreen(),document.mozCancelFullScreen&&(a("html").css("overflow","auto"),a(document).scrollTop(b.data("mozScrollTop")),document.mozCancelFullScreen()),document.webkitCancelFullScreen&&document.webkitCancelFullScreen(),document.removeEventListener("fullscreenchange",g),document.removeEventListener("mozfullscreenchange",g),document.removeEventListener("webkitfullscreenchange",g)):(b.data("hiddenElements").show(),a(window).scrollTop(b.data("originalScrollTop"))),b.removeData("currentSlide slides width height originalScrollTop hiddenElements").hide()});var h=!0;b.bind("show",function(c,d,e){var i=b.data("options"),j=b.data("slideshows"),k=j[d];b.data("slides",k),b.trigger("updateSize"),a(document).bind("keydown",f),i.useFullScreen&&(con=b[0],con.requestFullScreen&&(con.requestFullScreen(),document.addEventListener("fullscreenchange",g)),con.mozRequestFullScreen&&(con.mozRequestFullScreen(),document.addEventListener("mozfullscreenchange",g),b.data("mozScrollTop",a(document).scrollTop()),a("html").css("overflow","hidden")),con.webkitRequestFullScreen&&(con.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT),document.addEventListener("webkitfullscreenchange",g)),b.data("isFullScreen",!1)),h&&(b.trigger("init"),h=!1),i.useFullScreen||b.data("hiddenElements",a("body > *").filter(function(){return a(this).css("display")!="none"}).hide()),b.data("originalScrollTop")||b.data("originalScrollTop",a(window).scrollTop()),b.show(),b.trigger("showSlide",e)})};a.fn.fullscreenslides=function(d){b=a("#fullscreenSlideshowContainer"),b.length==0&&(b=a('<div id="fullscreenSlideshowContainer">').hide(),a("body").append(b),c());var d=a.extend({bgColor:"#000",useFullScreen:!0,startSlide:0},d||{});d.useFullScreen=d.useFullScreen&&!!(b[0].requestFullScreen||b[0].mozRequestFullScreen||b[0].webkitRequestFullScreen),b.data("options",d),b.css({position:"absolute",top:"0px",left:"0px",width:"100%","text-align":"center","background-color":d.bgColor});var e={};this.each(function(){var c=a(this).parents("a")[0];c.rel||c.setAttribute("rel","__all__");var d={image:c.href,title:c.title,rel:c.rel};d.data=a.extend({},a(this).data(),a(c).data()),e[d.rel]=e[d.rel]||[],e[d.rel].push(d),d.id=e[d.rel].length-1,a(c).data("slide",d),a(c).click(function(c){b.trigger("show",[this.rel,a(this).data("slide")]),c.preventDefault()})}),b.data("slideshows",e)}})(jQuery)