-
Notifications
You must be signed in to change notification settings - Fork 0
/
kenburned.min.js
23 lines (17 loc) · 3.34 KB
/
kenburned.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
Based on
Ken Burns effect JQuery plugin
Copyright (C) 2011 Will McGugan http://www.willmcgugan.com
Modified by Oscar Chinellato - 2013 - SickDevelopers - http://www.sickdevelopers.com/blog
VERSION : 0.2
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/(function(e,t){e.fn.kenburned=function(t){function b(){i=null;l=t.display_time||7e3;c=Math.min(l/2,t.fade_time||1e3);h=l-c*2;p=c-l}function w(){var e=new Date;return e.getTime()-i}function E(e,t,n,r,i){return{x:e+(n-e)*i,y:t+(r-t)*i}}function S(e,t,n){var r=E(e[0],e[1],t[0],t[1],n),i=E(e[2],e[3],t[2],t[3],n);return[r.x,r.y,i.x,i.y]}function x(e,t){var n=e[2]-e[0],r=e[3]-e[1],i=(e[2]+e[0])/2,s=(e[3]+e[1])/2,o=n*t,u=r*t;return[i-o/2,s-u/2,i+o/2,s+u/2]}function T(e,t,n,r){var i=n/r,s=t*i,o=t;if(s>e){s=e;o=e/i}var u=(e-s)/2,a=(t-o)/2;return[u,a,u+s,a+o]}function N(e,t){var n=y[e];if(!n.initialized){var r=new Image;n.image=r;n.loaded=!1;r.onload=function(){n.loaded=!0;var i=r.width,u=r.height,f=T(i,u,s,o),l=x(f,a),c=Math.floor(Math.random()*3)-1,h=Math.floor(Math.random()*3)-1;c/=2;h/=2;var p=l[0];l[0]+=p*c;l[2]+=p*c;var d=l[1];l[1]+=d*h;l[3]+=d*h;if(e%2){n.r1=f;n.r2=l}else{n.r1=l;n.r2=f}t&&t()};n.initialized=!0;r.src=n.path}return n}function C(t,i,u){if(++g===1){e(".preloader").fadeOut(500);n.hide().fadeIn(2e3,function(){})}if(i>1)return;var a=N(t);if(a.loaded){var f=S(a.r1,a.r2,i),l=Math.min(1,u);if(l>0){r.save();r.globalAlpha=Math.min(1,l);r.drawImage(a.image,f[0],f[1],f[2]-f[0],f[3]-f[1],0,0,s,o);r.restore()}}}function k(){r.save();r.globalAlpha=1;r.fillStyle=f;r.fillRect(0,0,r.canvas.width,r.canvas.height);r.restore()}function L(){var e=w(),i=Math.floor(e/(l-c)),s=i*(l-c),o=e-s;if(o<c){var u=i-1,a=s-l+c,f=e-a;e<c?k():C(A(u),f/l,1)}C(A(i),o/l,o/c);t.post_render_callback&&t.post_render_callback(n,r);var h=A(i+1);N(h)}function A(e){return(e+y.length)%y.length}var n=e(this),r=this[0].getContext("2d"),i=null,s=n.width(),o=n.height(),u=t.images,a=1/(t.zoom||2),f=t.background_color||"#000000",l=t.display_time||7e3,c=Math.min(l/2,t.fade_time||1e3),h=l-c*2,p=c-l,d=t.frames_per_second||30,v=1/d*1e3,m,g=0,y=[];e(u).each(function(e,t){y.push({path:t,initialized:!1,loaded:!1})});N(0,function(){i=w();m=setInterval(L,v)});return{utils:{fadeOut:function(e){n.fadeOut(e)},fadeIn:function(){n.fadeIn(1e3)}},nextSlide:function(){var e=Math.floor(w()/(l-c)),t=this;this.utils.fadeOut(function(){clearInterval(m);N(A(e+1));var n=[];for(var r=y.length-1;r>e;r--)n.push(y.pop());n.reverse();y=n.concat(y);b();i=w();m=setInterval(L,v);t.utils.fadeIn()})},prevSlide:function(){var e=Math.floor(w()/(l-c)),t=this;this.utils.fadeOut(function(){clearInterval(m);N(A(e-1));var n=[];for(var r=0;r<A(e-1);r++)n.push(y.shift());y=y.concat(n);b();i=w();m=setInterval(L,v);t.utils.fadeIn()})}}}})(jQuery,undefined);