-
Notifications
You must be signed in to change notification settings - Fork 11
/
jquery.prezento.min.js
1 lines (1 loc) · 3.35 KB
/
jquery.prezento.min.js
1
(function(e){"use strict";e.fn.prezento=function(t){function u(){a();f(n.devices.length)}function a(){n.devices.sort(function(e,t){return t.breakpoint-e.breakpoint})}function f(t){if(n.responsive==="parent"){var o=r.parent().width()}else{var o=e(window).width()}for(var u=0;u<t;u++){i[n.devices[u].name]=u}for(var u=0;u<t;u++){if(o-n.devices[u].breakpoint>0){s=u;d(s);break}}}function l(t,r){var i="moveBG "+n.devices[t].bgTransitionDuration+" linear forwards",s=c(),u=(100-s)/100*n.devices[t].bgTransitionDuration.replace("s",""),a="all "+u+"s linear";if(r==="play"){e("."+n.deviceScreen).css({animation:i,transition:"none"})}if(r==="pause"){e("."+n.deviceScreen).css({"background-position":"0% "+s+"%",animation:"none",transition:"none"});o="paused"}if(r==="resume"){if(o==="paused"){e("."+n.deviceScreen).css({"background-position":"0% 100%",transition:a});o="resumed"}}if(r==="reset"){e("."+n.deviceScreen).css({"background-position":"0% 0%",animation:"none",transition:"none"})}}function c(){var t=e("."+n.deviceScreen).css("background-position").split(" ");t=t[1].replace("%","");return t}function h(){if(typeof s==="undefined"){u()}var t=r.offset().top,i=r.height(),o=e(window).height(),a=e(document).scrollTop();if((t-a)/o<n.distanceTop&&(t-a+i)/o>0){l(s,"play")}else{if(n.resetWhenBelow){l(s,"reset")}}}function p(){if(!window.console){window.console={log:function(){}}}if(typeof console!="undefined"&&typeof console.debug!="undefined"){console.log(n)}}function d(t){var r=new Image;r.src=n.devices[t].deviceImageSRC;r.onload=function(){v(t,r)};e("."+n.deviceScreen).css({"background-position":"0% 0%",animation:"none",transition:"none"})}function v(t,r){var i=n.devices[t],s="."+n.deviceHolder,o="."+n.deviceScreen,u=r.naturalWidth,a=r.naturalHeight;e(s).html(e(r).clone());e(s).find("img").load(function(){var t=e(this).width(),n=e(this).height(),r=i.xRightBottom-i.xLeftTop,f=i.yRightBottom-i.yLeftTop,l=r/u,c=f/a,h=i.xLeftTop/u,p=i.yLeftTop/a;e(s).css({position:"relative","z-index":3});e(o).css({position:"absolute","z-index":2,width:Math.ceil(t*l),height:Math.ceil(n*c),left:Math.round(t*h),top:Math.round(n*p),"background-size":"100%","background-image":"url("+i.bgImgSrc+")","background-position":"0% 0%"})});if(!n.startAfterScroll&&n.autoPlay){l(t,"play")}}var n=e.extend({devices:[],debug:false,deviceHolder:"prezento-device",deviceScreen:"prezento-screen",startAfterScroll:false,distanceTop:.25,resetWhenBelow:false,responsive:"window",autoPlay:true},t),r=this,i=[],s,o;n.distanceTop=typeof n.distanceTop==="string"?parseFloat(n.distanceTop)/100:n.distanceTop;r.css({position:"relative",display:"inline-block",margin:"0 auto",width:"100%","text-align":"center"}).append('<div class="'+n.deviceHolder+'"></div>').append('<div class="'+n.deviceScreen+'"></div>');if(n.devices.length!=0){if(n.debug){e(document).on("ready",p)}if(n.startAfterScroll){e(window).on("scroll",h)}if(n.responsive==="window"||n.responsive==="parent"){e(window).on("resize",u)}e(window).on("load",u)}else{r.append('<p class="pserror">You haven\'t defined any devices. Please read <a href="https://github.com/ivaldi/prezento/blob/master/README.md">the instructions</a> on how to do this. At least one device is needed for this plugin to work.</p>')}e.extend(e.fn.prezento,{play:function(){l(s,"play")},pause:function(){l(s,"pause")},resume:function(){l(s,"resume")},reset:function(){l(s,"reset")},changeDevice:function(e){d(i[e])}})}})(jQuery)