forked from akademy/CanvasZoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvaszoom.min.js
2 lines (1 loc) · 4.14 KB
/
canvaszoom.min.js
1
function CanvasZoom(e,T,S,B){var R=256;var F=0;var i=0;var D=-1;var J=-1;var Q=0;var P=0;var k=0;var j=0;var N=0;var M=0;var f=false;var q=false;var d=0;var c=0;var s="w";var x="h";var A="t";var p="wt";var I=null;var h=null;var o=null;var u,O,K,t,n,E,C,b,l,m,H,g,z,G,v,a,r,y,w,L;u=function(V,U,W){return T+"/"+V+"/"+U+"_"+W+".jpg"};a=function(){var V=I[J];var X=V.length;var Y=V[0].length;var U=0,Z=0;var W=0;for(U=0;U<X;U++){for(Z=0;Z<Y;Z++){V[U][Z][A]=h.getImageById(W++)}}I[D][0][0][A]=h.getImageById(W);d=(e.width-V[s])/2;c=(e.height-V[x])/2;mouse="mouse";e.addEventListener(mouse+"move",function(aa){l(O(aa))},true);e.addEventListener(mouse+"down",function(aa){g(O(aa))},true);e.addEventListener(mouse+"up",function(aa){b(O(aa))},true);e.addEventListener(mouse+"out",function(aa){z(O(aa))},true);e.addEventListener(mouse+"over",function(aa){G(O(aa))},true);e.addEventListener("DOMMouseScroll",function(aa){v(O(aa))},true);e.addEventListener(mouse+"wheel",function(aa){v(O(aa))},true);window.addEventListener(mouse+"up",function(aa){m(O(aa))},false);window.addEventListener(mouse+"move",function(aa){H(O(aa))},false);o=e.getContext("2d");L()};O=function(U){if(!U){U=window.event}return U};g=function(U){f=true;q=false;k=E(U);j=C(U);N=k;M=j};b=function(U){f=false;q=false;Q=E(U);P=C(U);if(Q===k&&P===j){t()}};l=function(W){Q=E(W);P=C(W);if(f){var V=d+(Q-N);var U=c+(P-M);r(J,V,U);N=Q;M=P;d=V;c=U;L()}};E=function(V){var U=0;if(V.layerX||V.layerX===0){U=V.layerX-e.offsetLeft}else{if(V.offsetX||V.offsetX===0){U=V.offsetX}}return U};C=function(U){var V=0;if(U.layerY||U.layerY===0){V=U.layerY-e.offsetTop}else{if(U.offsetY||U.offsetY===0){V=U.offsetY}}return V};z=function(U){if(f){q=true}};G=function(U){q=false};v=function(U){var V=0;if(U.wheelDelta){V=-(U.wheelDelta/120)}else{if(U.detail){V=U.detail/3}}if(V){if(V<0){t()}else{n()}}if(U.preventDefault){U.preventDefault()}U.returnValue=false};m=function(U){if(f&&q){b(U)}};H=function(U){if(f&&q){l(U)}};t=function(){K(J+1);L()};n=function(){K(J-1);L()};this.zoomInCentre=function(){Q=e.width/2;P=e.height/2;t()};this.zoomOutCentre=function(){Q=e.width/2;P=e.height/2;n()};K=function(W){if(W>=F&&W<=i){var Z=W,ad=J;var ac=Q;var ab=P;var V=ac-d,U=ab-c;var X=I[Z][s]/I[ad][s];var af=V*X,ae=U*X;var aa=d-(af-V),Y=c-(ae-U);r(Z,aa,Y);J=Z;d=aa;c=Y}};r=function(U,al,aj){var Z=I[U];var af=-al,ai=-aj;var W=af+e.width,ak=ai+e.height;var X=0,ad=0,am=0,Y=0;var an=null;var ab=Z[s],aa=Z[x];var V=Z.length,ae=Z[0].length;var ah=0,ac=0;var ag=[];for(ah=0;ah<V;ah++){for(ac=0;ac<ae;ac++){an=Z[ah][ac];if(an[A]===null&&an[p]===false){X=ah*R;ad=X+Math.min(R,ab-X);am=ac*R;Y=am+Math.min(R,aa-am);if(!(X>W||ad<af||am>ak||Y<ai)){an[p]=true;ag.push({name:U+"_"+ah+"_"+ac,file:u(U,ah,ac)})}}}}y(ag)};y=function(U){if(U.length>0){h=new ImageLoader({images:U,onImageLoaded:function(V,W){w(V,W)}})}};w=function(V,W){var X=V.split("_");if(X.length===3){var U=I[X[0]][X[1]][X[2]];U[A]=W;U[p]=false;L()}};L=function(){var ak=e.width,U=e.height;o.fillStyle=o.strokeStyle="#fff";o.clearRect(0,0,ak,U);var Z=I[J];var V=Z.length,ae=Z[0].length;var ag=-d,ai=-c;var W=ag+ak,aj=ai+U;var X=0,ad=0,al=0,Y=0;var af=0;var an=null;var ab=Z[s];var aa=Z[x];var am=I[D][0][0][A];var ah=0,ac=0;for(ah=0;ah<V;ah++){for(ac=0;ac<ae;ac++){X=ah*R;ad=X+Math.min(R,ab-X);al=ac*R;Y=al+Math.min(R,aa-al);if(!(X>W||ad<ag||al>aj||Y<ai)){an=Z[ah][ac][A];X+=d;ad+=d;al+=c;Y+=c;if(an!==null){o.drawImage(an,X,al)}else{o.save();o.beginPath();o.moveTo(X,al);o.lineTo(ad,al);o.lineTo(ad,Y);o.lineTo(X,Y);o.closePath();o.clip();o.drawImage(am,d,c,ab,aa);o.restore()}}}}o.strokeStyle="#000";o.strokeRect(0,0,ak,U)};(function(){i=Math.ceil(Math.log(Math.max(S,B))/Math.LN2);I=[];var ab=S;var ad=B;var Y=-1;var U=0,Z=0,aa=0;var X=-1,ac=-1;for(U=i;U>=F;U--){X=Math.ceil(ab/R);ac=Math.ceil(ad/R);if(D===-1&&ab<=R&&ad<=R){D=U}if(Y===-1&&ab<=e.width&&ad<=e.height){Y=U}I[U]=[];for(Z=0;Z<X;Z++){I[U][Z]=[]}I[U][s]=ab;I[U][x]=ad;for(Z=0;Z<X;Z++){for(aa=0;aa<ac;aa++){I[U][Z][aa]=[];I[U][Z][aa][A]=null;I[U][Z][aa][p]=false}}ab/=2;ad/=2}J=Y;var W=[];var V=0;X=I[J].length;ac=I[J][0].length;for(Z=0;Z<X;Z++){for(aa=0;aa<ac;aa++){W.push({id:V++,file:u(J,Z,aa)})}}W.push({id:V,file:u(D,0,0)});h=new ImageLoader({images:W,onAllLoaded:function(){a()}})}())};