forked from stevenorell/jquery-backstretch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.backstretch.min.js
4 lines (4 loc) · 4.38 KB
/
jquery.backstretch.min.js
1
2
3
4
/*! Backstretch - v2.0.5 - 2015-03-13
* http://srobbin.com/jquery-plugins/backstretch/
* Copyright (c) 2015 Scott Robbin; Licensed MIT */
!function(t,i,e){"use strict";t.fn.backstretch=function(s,r){return(s===e||0===s.length)&&t.error("No images were supplied for Backstretch"),0===t(i).scrollTop()&&i.scrollTo(0,0),this.each(function(){var i=t(this),e=i.data("backstretch");if(e){if("string"==typeof s&&"function"==typeof e[s])return void e[s](r);r=t.extend(e.options,r),e.destroy(!0)}e=new n(this,s,r),i.data("backstretch",e)})},t.backstretch=function(i,e){return t("body").backstretch(i,e).data("backstretch")},t.expr[":"].backstretch=function(i){return t(i).data("backstretch")!==e},t.fn.backstretch.defaults={centeredX:!0,centeredY:!0,duration:5e3,fade:0,bleed:0};var s={wrap:{left:0,top:0,overflow:"hidden",margin:0,padding:0,height:"100%",width:"100%",zIndex:-999999},img:{position:"absolute",display:"none",margin:0,padding:0,border:"none",width:"auto",height:"auto",maxHeight:"none",maxWidth:"none",zIndex:-999999}},n=function(e,n,o){this.options=t.extend({},t.fn.backstretch.defaults,o||{}),this.images=t.isArray(n)?n:[n],t.each(this.images,function(){t("<img />")[0].src=this}),this.isBody=e===document.body,this.$container=t(e),this.$root=this.isBody?t(r?i:document):this.$container;var a=this.$container.children(".backstretch").first();if(this.$wrap=a.length?a:t('<div class="backstretch"></div>').css(s.wrap).appendTo(this.$container),!this.isBody){var h=this.$container.css("position"),c=this.$container.css("zIndex");this.$container.css({position:"static"===h?"relative":h,zIndex:"auto"===c?0:c,background:"none"}),this.$wrap.css({zIndex:-999998}),this.options.bleed>0&&(this.$container.css("overflow","hidden"),this.$wrap.css({top:-1*this.options.bleed,left:-1*this.options.bleed}))}this.$wrap.css({position:this.isBody&&r?"fixed":"absolute"}),this.index=0,this.show(this.index),t(i).on("resize.backstretch",t.proxy(this.resize,this)).on("orientationchange.backstretch",t.proxy(function(){this.isBody&&0===i.pageYOffset&&(i.scrollTo(0,1),this.resize())},this))};n.prototype={resize:function(){try{var t,e={left:0,top:0},s=this.isBody?this.$root.width():this.$root.innerWidth()+2*this.options.bleed,n=s,r=this.isBody?i.innerHeight?i.innerHeight:this.$root.height():this.$root.innerHeight()+2*this.options.bleed,o=n/this.$img.data("ratio");o>=r?(t=(o-r)/2,this.options.centeredY&&(e.top="-"+t+"px")):(o=r,n=o*this.$img.data("ratio"),t=(n-s)/2,this.options.centeredX&&(e.left="-"+t+"px")),this.$wrap.css({width:s,height:r}).find("img:not(.deleteable)").css({width:n,height:o}).css(e)}catch(a){}return this},show:function(i){if(!(Math.abs(i)>this.images.length-1)){var e=this,n=e.$wrap.find("img").addClass("deleteable"),r={relatedTarget:e.$container[0]};return e.$container.trigger(t.Event("backstretch.before",r),[e,i]),this.index=i,clearInterval(e.interval),e.$img=t("<img />").css(s.img).bind("load",function(s){var o=this.width||t(s.target).width(),a=this.height||t(s.target).height();t(this).data("ratio",o/a),t(this).fadeIn(e.options.speed||e.options.fade,function(){n.remove(),e.paused||e.cycle(),t(["after","show"]).each(function(){e.$container.trigger(t.Event("backstretch."+this,r),[e,i])})}),e.resize()}).appendTo(e.$wrap),e.$img.attr("src",e.images[i]),e}},next:function(){return this.show(this.index<this.images.length-1?this.index+1:0)},prev:function(){return this.show(0===this.index?this.images.length-1:this.index-1)},pause:function(){return this.paused=!0,this},resume:function(){return this.paused=!1,this.next(),this},cycle:function(){return this.images.length>1&&(clearInterval(this.interval),this.interval=setInterval(t.proxy(function(){this.paused||this.next()},this),this.options.duration)),this},destroy:function(e){t(i).off("resize.backstretch orientationchange.backstretch"),clearInterval(this.interval),e||this.$wrap.remove(),this.$container.removeData("backstretch")}};var r=function(){var t=navigator.userAgent,e=navigator.platform,s=t.match(/AppleWebKit\/([0-9]+)/),n=!!s&&s[1],r=t.match(/Fennec\/([0-9]+)/),o=!!r&&r[1],a=t.match(/Opera Mobi\/([0-9]+)/),h=!!a&&a[1],c=t.match(/MSIE ([0-9]+)/),d=!!c&&c[1];return!((e.indexOf("iPhone")>-1||e.indexOf("iPad")>-1||e.indexOf("iPod")>-1)&&n&&534>n||i.operamini&&"[object OperaMini]"==={}.toString.call(i.operamini)||a&&7458>h||t.indexOf("Android")>-1&&n&&533>n||o&&6>o||"palmGetResource"in i&&n&&534>n||t.indexOf("MeeGo")>-1&&t.indexOf("NokiaBrowser/8.5.0")>-1||d&&6>=d)}()}(jQuery,window);