View file upload/js/themehouse/class/vendor/backstretch/jquery.backstretch.min.min.js

File size: 16.97Kb
/*
 Backstretch - v2.1.15 - 2017-06-22\n* Copyright (c) 2017 Scott Robbin;* Fork of improvements - by Daniel Cohen Gindi (danielgindi@gmail.com) Licensed MIT */
!function(d,f,q){function y(a){return F.hasOwnProperty(a)?a:"cover"}var u=/^.*(youtu\.be\/|youtube\.com\/v\/|youtube\.com\/embed\/|youtube\.com\/watch\?v=|youtube\.com\/watch\?.*&v=)([^#&\?]*).*/i;d.fn.backstretch=function(a,c){var b=arguments;0===d(f).scrollTop()&&f.scrollTo(0,0);var e;return this.each(function(g){var k=d(this),h=k.data("backstretch");if(h){if("string"==typeof b[0]&&"function"==typeof h[b[0]])return k=h[b[0]].apply(h,Array.prototype.slice.call(b,1)),k===h&&(k=q),void(k!==q&&(e=e||
[],e[g]=k));c=d.extend(h.options,c);h.hasOwnProperty("destroy")&&h.destroy(!0)}if(!a||a&&0===a.length)(g=k.css("background-image"))&&"none"!==g?a=[{url:k.css("backgroundImage").replace(/url\(|\)|"|'/g,"")}]:d.error("No images were supplied for Backstretch, or element must have a CSS-defined background image.");h=new z(this,a,c||{});k.data("backstretch",h)}),e?1===e.length?e[0]:e:this};d.backstretch=function(a,c){return d("body").backstretch(a,c).data("backstretch")};d.expr[":"].backstretch=function(a){return d(a).data("backstretch")!==
q};d.fn.backstretch.defaults={duration:5E3,transition:"fade",transitionDuration:0,animateFirst:!0,alignX:.5,alignY:.5,paused:!1,start:0,preload:2,preloadSize:1,resolutionRefreshRate:2500,resolutionChangeRatioThreshold:.1};var G={left:0,top:0,overflow:"hidden",margin:0,padding:0,height:"100%",width:"100%",zIndex:-999999},H={position:"absolute",display:"none",margin:0,padding:0,border:"none",width:"100%",height:"100%",zIndex:-999999},I={position:"absolute",margin:0,padding:0,border:"none",width:"100%",
height:"100%",maxWidth:"none"},A=function(){var a=function(a){for(var b=1;b<a.length;b++){for(var c=a[b],e=b;a[e-1]&&parseInt(a[e-1].width,10)>parseInt(c.width,10);)a[e]=a[e-1],--e;a[e]=c}return a},c=function(a,b,c){var e,d,g=f.devicePixelRatio||1,k=J();b=b>a?"portrait":a>b?"landscape":"square";for(var m=0,l=0;l<c.length&&(d=c[l],"string"==typeof d&&(d=c[l]={url:d}),d.pixelRatio&&"auto"!==d.pixelRatio&&parseFloat(d.pixelRatio)!==g||d.deviceOrientation&&d.deviceOrientation!==k||d.windowOrientation&&
d.windowOrientation!==k||d.orientation&&d.orientation!==b||(m=l,e=a,"auto"===d.pixelRatio&&(a*=g),!(d.width>=e)));l++);return c[Math.min(l,m)]},b=function(a,c){if("string"==typeof a)a=a.replace(/{{(width|height)}}/g,c);else if(a instanceof Array)for(var d=0;d<a.length;d++)a[d].src?a[d].src=b(a[d].src,c):a[d]=b(a[d],c);return a};return function(e,g){for(var k=e.width(),h=e.height(),f=[],t=function(a,b){return"width"===b?k:"height"===b?h:a},n=0;n<g.length;n++)if(d.isArray(g[n])){g[n]=a(g[n]);var m=
c(k,h,g[n]);f.push(m)}else"string"==typeof g[n]&&(g[n]={url:g[n]}),m=d.extend({},g[n]),m.url=b(m.url,t),f.push(m);return f}}(),v=function(a){return u.test(a.url)||a.isVideo},B=function(a,c,b,e,g){var f=[],h=function(a){for(var b=0;b<f.length;b++)if(f[b].src===a.src)return f[b];return f.push(a),a};return function w(a,b,c,e,g){if("undefined"!=typeof a){d.isArray(a)||(a=[a]);5>arguments.length&&"function"==typeof arguments[arguments.length-1]&&(g=arguments[arguments.length-1]);b="function"!=typeof b&&
b?b:0;c="function"==typeof c||!c||0>c?a.length:Math.min(c,a.length);e="function"!=typeof e&&e?e:1;b>=a.length&&(b=0,c=0);0>e&&(e=c);e=Math.min(e,c);var f=a.slice(b+e,c-e);if(a=a.slice(b,e),c=a.length,c)for(var k,l=0,m=function(){l++;l===c&&("function"==typeof g&&g.call(a,!f),w(f,0,0,e,g))},n=0;n<a.length;n++)v(a[n])||(k=new Image,k.src=a[n].url,k=h(k),k.complete?m():d(k).on("load error",m));else"function"==typeof g&&g.call(a,!0)}}}(),C=function(a){for(var c=[],b=0;b<a.length;b++)"string"==typeof a[b]?
c.push({url:a[b]}):d.isArray(a[b])?c.push(C(a[b])):c.push(D(a[b]));return c},D=function(a,c){(a.centeredX||a.centeredY)&&(f.console&&f.console.log&&f.console.log("jquery.backstretch: `centeredX`/`centeredY` is deprecated, please use `alignX`/`alignY`"),a.centeredX&&(a.alignX=.5),a.centeredY&&(a.alignY=.5));a.speed!==q&&(f.console&&f.console.log&&f.console.log("jquery.backstretch: `speed` is deprecated, please use `transitionDuration`"),a.transitionDuration=a.speed,a.transition="fade");a.resolutionChangeRatioTreshold!==
q&&(f.console.log("jquery.backstretch: `treshold` is a typo!"),a.resolutionChangeRatioThreshold=a.resolutionChangeRatioTreshold);a.fadeFirst!==q&&(a.animateFirst=a.fadeFirst);a.fade!==q&&(a.transitionDuration=a.fade,a.transition="fade");a.scale&&(a.scale=y(a.scale));return"left"===a.alignX?a.alignX=0:"center"===a.alignX?a.alignX=.5:"right"===a.alignX?a.alignX=1:(a.alignX!==q||void 0)&&(a.alignX=parseFloat(a.alignX),isNaN(a.alignX)&&(a.alignX=.5)),"top"===a.alignY?a.alignY=0:"center"===a.alignY?a.alignY=
.5:"bottom"===a.alignY?a.alignY=1:(a.alignX!==q||void 0)&&(a.alignY=parseFloat(a.alignY),isNaN(a.alignY)&&(a.alignY=.5)),a},F={cover:"cover",fit:"fit","fit-smaller":"fit-smaller",fill:"fill"},z=function(a,c,b){this.options=d.extend({},d.fn.backstretch.defaults,b||{});this.firstShow=!0;D(this.options,!0);this.images=C(d.isArray(c)?c:[c]);this.options.paused&&(this.paused=!0);this.options.start>=this.images.length&&(this.options.start=this.images.length-1);0>this.options.start&&(this.options.start=
0);this.isBody=a===document.body;c=d(f);this.$container=d(a);this.$root=this.isBody?E?c:d(document):this.$container;this.originalImages=this.images;this.images=A(this.options.alwaysTestWindowResolution?c:this.$root,this.originalImages);B(this.images,this.options.start||0,this.options.preload||1);a=this.$container.children(".backstretch").first();(this.$wrap=a.length?a:d('<div class="backstretch"></div>').css(this.options.bypassCss?{}:G).appendTo(this.$container),this.options.bypassCss)||(this.isBody||
(a=this.$container.css("position"),b=this.$container.css("zIndex"),this.$container.css({position:"static"===a?"relative":a,zIndex:"auto"===b?0:b}),this.$wrap.css({zIndex:-999998})),this.$wrap.css({position:this.isBody&&E?"fixed":"absolute"}));this.index=this.options.start;this.show(this.index);c.on("resize.backstretch",d.proxy(this.resize,this)).on("orientationchange.backstretch",d.proxy(function(){this.isBody&&0===f.pageYOffset&&(f.scrollTo(0,1),this.resize())},this))},L=function(a){var c=a.transition||
"fade";"string"==typeof c&&-1<c.indexOf("|")&&(c=c.split("|"));c instanceof Array&&(c=c[Math.round(Math.random()*(c.length-1))]);var b=a["new"],e=a.old?a.old:d([]);switch(c.toString().toLowerCase()){default:case "fade":b.fadeIn({duration:a.duration,complete:a.complete,easing:a.easing||q});break;case "fadeinout":case "fade_in_out":c=function(){b.fadeIn({duration:a.duration/2,complete:a.complete,easing:a.easing||q})};e.length?e.fadeOut({duration:a.duration/2,complete:c,easing:a.easing||q}):c();break;
case "pushleft":case "push_left":case "pushright":case "push_right":case "pushup":case "push_up":case "pushdown":case "push_down":case "coverleft":case "cover_left":case "coverright":case "cover_right":case "coverup":case "cover_up":case "coverdown":case "cover_down":c=c.match(/^(cover|push)_?(.*)$/);var g="left"===c[2]?"right":"right"===c[2]?"left":"down"===c[2]?"top":"up"===c[2]?"bottom":"right",f={display:""},h={};if(f[g]="-100%",h[g]=0,b.css(f).animate(h,{duration:a.duration,complete:function(){b.css(g,
"");a.complete.apply(this,arguments)},easing:a.easing||q}),"push"===c[1]&&e.length)c={},c[g]="100%",e.animate(c,{duration:a.duration,complete:function(){e.css("display","none")},easing:a.easing||q})}};z.prototype={resize:function(){try{var a=this.options.alwaysTestWindowResolution?d(f):this.$root,c=a.width(),b=a.height(),e=c/(this._lastResizeContainerWidth||0),g=b/(this._lastResizeContainerHeight||0),k=this.options.resolutionChangeRatioThreshold||0;if((c!==this._lastResizeContainerWidth||b!==this._lastResizeContainerHeight)&&
(Math.abs(e-1)>=k||isNaN(e)||Math.abs(g-1)>=k||isNaN(g))&&(this._lastResizeContainerWidth=c,this._lastResizeContainerHeight=b,this.images=A(a,this.originalImages),this.options.preload&&B(this.images,(this.index+1)%this.images.length,this.options.preload),1===this.images.length&&this._currentImage.url!==this.images[0].url)){var h=this;clearTimeout(h._selectAnotherResolutionTimeout);h._selectAnotherResolutionTimeout=setTimeout(function(){h.show(0)},this.options.resolutionRefreshRate)}var r,t,n={left:0,
top:0,right:"auto",bottom:"auto"},m=this.isBody?this.$root.width():this.$root.innerWidth(),l=this.isBody?f.innerHeight?f.innerHeight:this.$root.height():this.$root.innerHeight(),p=this.$itemWrapper.data("width"),w=this.$itemWrapper.data("height");a=p/w||1;var K=this._currentImage.alignX===q?this.options.alignX:this._currentImage.alignX,u=this._currentImage.alignY===q?this.options.alignY:this._currentImage.alignY,x=y(this._currentImage.scale||this.options.scale);if("fit"===x||"fit-smaller"===x){if(r=
p,t=w,r>m||t>l||"fit-smaller"===x)p=m/l,p>a?(r=Math.floor(l*a),t=l):p<a?(r=m,t=Math.floor(m/a)):(r=m,t=l)}else"fill"===x?(r=m,t=l):(r=Math.max(l*a,m),t=Math.max(r/a,l));n.top=-(t-l)*u;n.left=-(r-m)*K;n.width=r;n.height=t;this.options.bypassCss||this.$wrap.css({width:m,height:l}).find(">.backstretch-item").not(".deleteable").each(function(){d(this).find("img,video,iframe").css(n)});var v=d.Event("backstretch.resize",{relatedTarget:this.$container[0]});this.$container.trigger(v,this)}catch(M){}return this},
show:function(a,c){if(!(Math.abs(a)>this.images.length-1)){var b=this,e=b.$wrap.find(">.backstretch-item").addClass("deleteable"),g=b.videoWrapper,f={relatedTarget:b.$container[0]};b.$container.trigger(d.Event("backstretch.before",f),[b,a]);this.index=a;var h=b.images[a];clearTimeout(b._cycleTimeout);delete b.videoWrapper;var r=v(h);return r?(b.videoWrapper=new p(h),b.$item=b.videoWrapper.$video.css("pointer-events","none")):b.$item=d("<img />"),b.$itemWrapper=d('<div class="backstretch-item">').append(b.$item),
this.options.bypassCss?b.$itemWrapper.css({display:"none"}):(b.$itemWrapper.css(H),b.$item.css(I)),b.$item.bind(r?"canplay":"load",function(h){h=d(this).parent();var k=h.data("options");c&&(k=d.extend({},k,c));var m=this.naturalHeight||this.videoHeight||this.height;h.data("width",this.naturalWidth||this.videoWidth||this.width).data("height",m);var l=function(a){return k[a]!==q?k[a]:b.options[a]};m=l("transition");var p=l("transitionEasing");l=l("transitionDuration");var t=function(){g&&(g.stop(),
g.destroy());e.remove();!b.paused&&1<b.images.length&&b.cycle();b.options.bypassCss||b.isBody||b.$container.css("background-image","none");d(["after","show"]).each(function(){b.$container.trigger(d.Event("backstretch."+this,f),[b,a])});r&&b.videoWrapper.play()};b.firstShow&&!b.options.animateFirst||!l||!m?(h.show(),t()):L({"new":h,old:e,transition:m,duration:l,easing:p,complete:t});b.firstShow=!1;b.resize()}),b.$itemWrapper.appendTo(b.$wrap),b.$item.attr("alt",h.alt||""),b.$itemWrapper.data("options",
h),r||b.$item.attr("src",h.url),b._currentImage=h,b}},current:function(){return this.index},next:function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(this.index<this.images.length-1?this.index+1:0),this.show.apply(this,a)},prev:function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(0===this.index?this.images.length-1:this.index-1),this.show.apply(this,a)},pause:function(){return this.paused=!0,this.videoWrapper&&this.videoWrapper.pause(),this},resume:function(){return this.paused=
!1,this.videoWrapper&&this.videoWrapper.play(),this.cycle(),this},cycle:function(){if(1<this.images.length){clearTimeout(this._cycleTimeout);var a=this._currentImage&&this._currentImage.duration||this.options.duration,c=v(this._currentImage),b=function(){this.$item.off(".cycle");this.paused||this.next()};if(c){if(!this._currentImage.loop){var e=0;this.$item.on("playing.cycle",function(){var a=d(this).data("player");clearTimeout(e);e=setTimeout(function(){a.pause();a.$video.trigger("ended")},1E3*(a.getDuration()-
a.getCurrentTime()))}).on("ended.cycle",function(){clearTimeout(e)})}this.$item.on("error.cycle initerror.cycle",d.proxy(b,this))}c&&!this._currentImage.duration?this.$item.on("ended.cycle",d.proxy(b,this)):this._cycleTimeout=setTimeout(d.proxy(b,this),a)}return this},destroy:function(a){d(f).off("resize.backstretch orientationchange.backstretch");this.videoWrapper&&this.videoWrapper.destroy();clearTimeout(this._cycleTimeout);a||this.$wrap.remove();this.$container.removeData("backstretch")}};var p=
function(){this.init.apply(this,arguments)};p.prototype.init=function(a){var c=this,b="video";if(a.url instanceof Array||!u.test(a.url)||(b="youtube"),c.type=b,"youtube"===b){p.loadYoutubeAPI();c.ytId=a.url.match(u)[2];b="https://www.youtube.com/embed/"+c.ytId+"?rel=0&autoplay=0&showinfo=0&controls=0&modestbranding=1&cc_load_policy=0&disablekb=1&iv_load_policy=3&loop=0&enablejsapi=1&origin="+encodeURIComponent(f.location.origin);c.__ytStartMuted=!!a.mute||a.mute===q;var e=d("<iframe />").attr({src_to_load:b}).css({border:0,
margin:0,padding:0}).data("player",c);a.loop&&e.on("ended.loop",function(){c.__manuallyStopped||c.play()});c.ytReady=!1;c.$video=e;c.video=e[0];f.YT?(c._initYoutube(),e.trigger("initsuccess")):d(f).one("youtube_api_load",function(){c._initYoutube();e.trigger("initsuccess")})}else{e=d("<video>").prop("autoplay",!1).prop("controls",!1).prop("loop",!!a.loop).prop("muted",!!a.mute||a.mute===q).prop("preload","auto").prop("poster",a.poster||"");a=a.url instanceof Array?a.url:[a.url];for(b=0;b<a.length;b++){var g=
a[b];"string"==typeof g&&(g={src:g});d("<source>").attr("src",g.src).attr("type",g.type||null).appendTo(e)}e[0].canPlayType&&a.length?e.trigger("initsuccess"):e.trigger("initerror");c.$video=e;c.video=e[0]}};p.prototype._initYoutube=function(){var a=this,c=f.YT;a.$video.attr("src",a.$video.attr("src_to_load")).removeAttr("src_to_load");var b=!!a.$video[0].parentNode;if(!b){var e=d("<div>").css("display","none !important").appendTo(document.body);a.$video.appendTo(e)}var g=new c.Player(a.video,{events:{onReady:function(){a.__ytStartMuted&&
g.mute();b||(a.$video[0].parentNode===e[0]&&a.$video.detach(),e.remove());a.ytReady=!0;a._updateYoutubeSize();a.$video.trigger("canplay")},onStateChange:function(b){switch(b.data){case c.PlayerState.PLAYING:a.$video.trigger("playing");break;case c.PlayerState.ENDED:a.$video.trigger("ended");break;case c.PlayerState.PAUSED:a.$video.trigger("pause");break;case c.PlayerState.BUFFERING:a.$video.trigger("waiting");break;case c.PlayerState.CUED:a.$video.trigger("canplay")}},onPlaybackQualityChange:function(){a._updateYoutubeSize();
a.$video.trigger("resize")},onError:function(b){a.hasError=!0;a.$video.trigger({type:"error",error:b})}}});return a.ytPlayer=g,a};p.prototype._updateYoutubeSize=function(){switch(this.ytPlayer.getPlaybackQuality()||"medium"){case "small":this.video.videoWidth=426;this.video.videoHeight=240;break;case "medium":this.video.videoWidth=640;this.video.videoHeight=360;break;default:case "large":this.video.videoWidth=854;this.video.videoHeight=480;break;case "hd720":this.video.videoWidth=1280;this.video.videoHeight=
720;break;case "hd1080":this.video.videoWidth=1920;this.video.videoHeight=1080;break;case "highres":this.video.videoWidth=2560,this.video.videoHeight=1440}return this};p.prototype.play=function(){return this.__manuallyStopped=!1,"youtube"===this.type?this.ytReady&&(this.$video.trigger("play"),this.ytPlayer.playVideo()):this.video.play(),this};p.prototype.pause=function(){return this.__manuallyStopped=!1,"youtube"===this.type?this.ytReady&&this.ytPlayer.pauseVideo():this.video.pause(),this};p.prototype.stop=
function(){return this.__manuallyStopped=!0,"youtube"===this.type?this.ytReady&&(this.ytPlayer.pauseVideo(),this.ytPlayer.seekTo(0)):(this.video.pause(),this.video.currentTime=0),this};p.prototype.destroy=function(){return this.ytPlayer&&this.ytPlayer.destroy(),this.$video.remove(),this};p.prototype.getCurrentTime=function(a){return"youtube"!==this.type?this.video.currentTime:this.ytReady?this.ytPlayer.getCurrentTime():0};p.prototype.setCurrentTime=function(a){return"youtube"===this.type?this.ytReady&&
this.ytPlayer.seekTo(a,!0):this.video.currentTime=a,this};p.prototype.getDuration=function(){return"youtube"!==this.type?this.video.duration:this.ytReady?this.ytPlayer.getDuration():0};p.loadYoutubeAPI=function(){if(!f.YT){d("script[src*=www\\.youtube\\.com\\/iframe_api]").length||d('<script type="text/javascript" src="https://www.youtube.com/iframe_api">').appendTo("body");var a=setInterval(function(){f.YT&&f.YT.loaded&&(d(f).trigger("youtube_api_load"),clearTimeout(a))},50)}};var J=function(){if("matchMedia"in
f){if(f.matchMedia("(orientation: portrait)").matches)return"portrait";if(f.matchMedia("(orientation: landscape)").matches)return"landscape"}return screen.height>screen.width?"portrait":"landscape"},E=function(){var a=navigator.userAgent,c=navigator.platform,b=a.match(/AppleWebKit\/([0-9]+)/);b=!!b&&b[1];var e=a.match(/Fennec\/([0-9]+)/);e=!!e&&e[1];var d=a.match(/Opera Mobi\/([0-9]+)/),k=!!d&&d[1],h=a.match(/MSIE ([0-9]+)/);h=!!h&&h[1];return!((-1<c.indexOf("iPhone")||-1<c.indexOf("iPad")||-1<c.indexOf("iPod"))&&
b&&534>b||f.operamini&&"[object OperaMini]"==={}.toString.call(f.operamini)||d&&7458>k||-1<a.indexOf("Android")&&b&&533>b||e&&6>e||"palmGetResource"in f&&b&&534>b||-1<a.indexOf("MeeGo")&&-1<a.indexOf("NokiaBrowser/8.5.0")||h&&6>=h)}()}(jQuery,window);