JAVASCRIPT   23

android.js

Guest on 4th August 2021 02:35:03 PM

  1. var _slow=1;function initSimpleUtils(){var a=navigator.userAgent.toLowerCase();ANDROID40=window.system.platform.android&&-1!=a.indexOf("4.0.");ANDROID3=3==window.system.device.version&&window.system.platform.android;ANDROID2=2==window.system.device.version&&window.system.platform.android;FORCE_FLAT=ANDROID3;DEV_3D=Modernizr.csstransforms3d;DOUBLE_CLICK_TO_ZOOM=!0;UP_SCALE=1;fconsole.log("3D:",DEV_3D)}
  2. var DEBUG_SHOW_FOLD_SHADOW=!1,TUNE_FOLD_SCALE_ENABLE=!0,TUNE_MINIMUM_FOLD_SCALE=0.25,TUNE_FOLD_SHADOW_ALPHA=!0,TUNE_FOLD_SHADOW_KOEFF=0.35,TIMEOUT_TO_DO_PRETRANSFORM=60*_slow,TIMEOUT_TO_SET_TRANSITION=60*_slow,TIMEOUT_TO_DO_POSTTRANSFORM=60*_slow,TIMEOUT_AFTER_ALL=60*_slow,TUNE_ZINDEX_SINGLE_CANVAS=-100,Z_INDEX_ADD=350,LAST_Z=-300,Z_STEP=5,FIRST_Z=-100,_debugNC=!1,getBookLength=function(){return publicationData.pageCount};
  3. function SoftPlainFlipElements(a,d,b,c,g,s,q){function l(b,c){E+=1;var d=function(){this.style.webkitTransitionProperty="";this.style.webkitTransitionDuration="";this.removeEventListener("webkitTransitionEnd",d,!1);var b=this;setTimeout(function(){c&&c(b);_debugNC&&console.log(a+times()+"timeout",E,b.id);(E-=1)||setTimeout(function(){q&&q(w);Y=!1},TIMEOUT_AFTER_ALL)},TIMEOUT_TO_DO_POSTTRANSFORM)};b.addEventListener("webkitTransitionEnd",d,!1)}function L(){startTime=(new Date).getTime();_debugNC&&
  4. console.log(a+times()+"applyDestinationListen",E);l(m,function(){g&&g(w)});y(m,M.flipDiv);l(o);y(o,M.contentObject,t+2);F.backgroundDiv!=M.backgroundDiv&&(l(p),y(p,M.backgroundDiv,t+4));if(j)l(j,function(){}),y(j,M.nextShadow),j.style.opacity="0";z&&u&&(e(z,"end"),l(z,function(){e(z,"start")}))}function e(a,c){var d="start"==c,g=d?TUNE_MINIMUM_FOLD_SCALE:1,f=s?0:b-O,e=dev_translate((d?O*g:0)*(s?-1:1),0,8),g=TUNE_FOLD_SCALE_ENABLE?dev_scale(g<TUNE_MINIMUM_FOLD_SCALE?TUNE_MINIMUM_FOLD_SCALE:g):"";if(TUNE_FOLD_SHADOW_ALPHA)a.style.opacity=
  5. d?"0":"1";a.style.left=f+"px";a.style.webkitTransformOrigin=""+(s?0:O)+"px 0px";a.style.webkitTransform=g+" "+e}function y(b,a,c){var d=void 0==c?b.zOffset||0:c;if(void 0!=c)b.zOffset=c;b.xOffset=a;translate(b,a,d)}function f(b,a){b.zOffset=a;translate(b,b.xOffset||0,a)}function v(){var a={};s?u?(a.flipDiv=0,a.contentObject=0,a.backgroundDiv=-b,a.nextShadow=-Q):(a.flipDiv=0,a.contentObject=b,a.backgroundDiv=-b,a.nextShadow=-b):u&&G?(a.flipDiv=0,a.contentObject=0,a.backgroundDiv=b,a.nextShadow=b):
  6. G?(a.flipDiv=0,a.contentObject=-b,a.backgroundDiv=b,a.nextShadow=b):(a.flipDiv=-b,a.contentObject=0,a.backgroundDiv=-b,a.nextShadow=-2*b);return a}this.id=a;var w=this,u=!0,G=!0,Q=0.6*b,F=v(),M,R,Y,E=0,t=LAST_Z--,O=b*TUNE_FOLD_SHADOW_KOEFF,m=createDiv("flipd"+a,!0);m.style.webkitTransformStyle=ANDROID3||FORCE_FLAT?"flat":"preserve-3d";d.appendChild(m);sizeDiv(m,b,c);f(m,t);var o=createDiv("div"+a);sizeDiv(o,b,c);var J=createCanvas("cc"+a,b,c);o.appendChild(J);o.contentCanvas=J;J=createDiv("vd"+a,
  7. b,c);o.appendChild(J);o.vectorDiv=J;J=createCanvas("tc"+a,b,c);o.appendChild(J);o.topCanvas=J;m.appendChild(o);y(o,F.contentObject,t+2);var p=createBackgroundDiv("backd"+a);sizeDiv(p,b,c);m.appendChild(p);y(p,F.backgroundDiv,t+4);var j=createShadowOnNextDiv("nextsh"+a,s);j&&(d.appendChild(j),sizeDiv(j,Q,c),y(j,F.nextShadow,t));var z=createFoldShadow("foldsh"+a,O,c,s);z&&(m.appendChild(z),e(z,"start"));this.flipDiv=m;this.backgroundDiv=p;var S=function(b,c,d){_debugNC&&console.log(a+"prepare",b.id,
  8. E);b.style.webkitTransitionProperty="-webkit-transform "+(d||"");b.style.webkitTransitionTimingFunction="cubic-bezier(0.9,0.05,0.95,1)";b.style.webkitTransitionDuration=""+c*_slow+"s"};this.id=a;var T=function(){F=v();var a={};if(s)if(u&&G)a.flipDiv=b,a.contentObject=-b,a.backgroundDiv=0,a.nextShadow=b-Q;else{if(G)a.flipDiv=0,a.contentObject=0,a.backgroundDiv=-b,a.nextShadow=-b}else u&&G?(a.flipDiv=-b,a.contentObject=b,a.backgroundDiv=0,a.nextShadow=0):G?(a.flipDiv=0,a.contentObject=0,a.backgroundDiv=
  9. b+1,a.nextShadow=b):(a.flipDiv=0,a.contentObject=-b,a.backgroundDiv=0,a.nextShadow=-b);M=a;y(m,F.flipDiv,t);y(o,F.contentObject,t+2);y(p,F.backgroundDiv,t+4);z&&e(z,"start");if(j)y(j,F.nextShadow,t),j.style.opacity="1"},H=function(a){S(m,a);S(o,a);S(p,a);j&&S(j,a,"opacity");z&&u&&S(z,a,TUNE_FOLD_SHADOW_ALPHA?"opacity":"")};this.startAnimation=function(a,b,c,d){Y=!0;R=d;u=b;G=c;T();setTimeout(function(){H(a);setTimeout(function(){L()},TIMEOUT_TO_SET_TRANSITION)},TIMEOUT_TO_DO_PRETRANSFORM)};this.reset=
  10. function(){u=!0;T()};this.getContentObject=function(){return o};this.getFlipDiv=function(){return m};this.getNextFlipper=function(){return R};this.getFadeout=function(){return u};this.getDepth=function(){return t};this.getBGDiv=function(){return p};this.setNextFlipper=function(a){R=a};this.setDepth=function(a,b){t=a;m.style.zIndex=Z_INDEX_ADD+a;o.style.zIndex=Z_INDEX_ADD+a+1;p.style.zIndex=Z_INDEX_ADD+a+3;if(j)j.style.zIndex=Z_INDEX_ADD+a;if(z)z.style.zIndex=Z_INDEX_ADD+a+4;!0!=b&&(f(m,t),f(o,t+2),
  11. f(p,t+4),j&&y(j,F.nextShadow,t))};this.isFree=function(){return!Y};this.clearContent=function(){o.contentCanvas.width=b;o.topCanvas.width=0;deleteAllChildren(o.vectorDiv)};var K;this.setBackgroundContent=function(a){K=a;deleteAllChildren(p);p.appendChild(K)};this.getBGCanvas=function(){K||(K=createFECanvas(a+"bgCont",b,c),p.appendChild(K));return K}}function createFECanvas(a,d,b){a=createCanvas(a);if(a.width!=d||a.height!=b)a.width=d,a.height=b;return a}
  12. var createBackgroundDiv=function(a){a=createDiv(a);a.style.backgroundColor="#dddddf";return a},createShadowOnNextDiv=function(a,d){var b=createDiv(a);b.style.backgroundImage="-webkit-gradient(linear,"+(d?"right bottom,left bottom":"left bottom,right bottom")+", color-stop(1.00, rgba(0,0,0,0)),color-stop(0.00, rgba(0,0,0,0.6)) )";return b},createFoldShadow=function(a,d,b,c){a=createCanvas(a);a.width=d;a.height=b;var g=a.getContext("2d"),c=c?g.createLinearGradient(d,0,0,0):g.createLinearGradient(0,
  13. 0,d,0);c.addColorStop(0,"rgba(0, 0, 0, 0)");c.addColorStop(0.72,"rgba(0, 0, 0, 0.2)");c.addColorStop(0.89,"rgba(0, 0, 0, 0.4)");c.addColorStop(1,"rgba(0, 0, 0, 0)");DEBUG_SHOW_FOLD_SHADOW?(g.lineWidth=16,g.strokeStyle="red",g.strokeRect(16,16,d-32,b-32)):(g.fillStyle=c,g.fillRect(0,0,d,b));return a},times=function(){return" "+((new Date).getTime()-startTime)+" "},sizeDim="px";
  14. function sizeDiv(a,d,b,c){if(void 0==d&&void 0==b)d=window.innerWidth,b=window.innerHeight;a.style.width=c?d+"%":Math.ceil(d)+sizeDim;a.style.height=c?b+"%":Math.ceil(b)+sizeDim}function createDiv(a,d){var b=document.createElement("div");b.setAttribute("id",a);b.style.position="absolute";if(d)b.style.overflow="hidden";return b}function createCanvas(a,d,b){var c=document.createElement("canvas");c.setAttribute("id",a);c.style.position="absolute";void 0!=d&&void 0!=b&&sizeCanvas(c,d,b);return c}
  15. function sizeCanvas(a,d,b){a.width=d;a.height=b}function setElementPosition(a,d){a.style.left=(""+d.left).concat("px");a.style.top=(""+d.top).concat("px")}function translate(a,d,b){a.style.webkitTransform="translate3d("+d+sizeDim+",0px,"+(""+b)+sizeDim+")"}function dev_scale(a,d,b){return prepare_xyz("scale",a,d,b)}function dev_translate(a,d,b){return prepare_xyz("translate",a,d,b)}function dev_translate_percents(a,d,b){return prepare_xyz("translate",a,d,b,"%")}
  16. function dev_rotateXY(a){return"rotate"+(DEV_3D?"":"")+"("+a.toString()+"rad)"}function prepare_xyz(a,d,b,c,g){var s="scale"==a,q=s?1:0,g=s?"":g||sizeDim;void 0==d&&(d=q);void 0==b&&(b=q);void 0==c&&(c=q);return a+(DEV_3D?"3d("+d+g+","+b+g+","+c+g+")":"("+d+g+","+b+g+")")}var startTime;function centerRect(a,d,b,c){return{x:(a-b)/2,y:(d-c)/2}}function traceChildren(a){for(var d="",b=0;b<a.length;b++)d+=a[b].id+" ";console.log(d)}
  17. function deleteAllChildren(a){for(;a.firstChild;)a.removeChild(a.firstChild)}
  18. function parseVectorizedContentToDiv(a,d,b,c){for(var c="undefined"!=typeof c?c:!0,g=0;4>g;g++);for(var d=d||createDiv(),g=[],s=0;s<a.length;s++){var q=a[s],l=0,L=q[l++].toString(),e=q[l++].toString(),y=parseFloat(q[l++]);parseFloat(q[l++]);var f=parseFloat(q[l++]),v=parseFloat(q[l++]),w=parseFloat(q[l++]),u=q[l++].toString(),q=parseFloat(q[l++]),G=Math.round(v*b),l=v=document.createElement("p");l.style.position="absolute";l.style.whiteSpace="nowrap";v.innerText=L;v.style.fontFamily=e;l.style.top=
  19. px(Math.round(f*b));l.style.left=px(G);e=w;f=g[e];w="undefined"==typeof f?Math.floor(w*b):f.size;v.style.fontSize=px(w);v.style.color=u;d.appendChild(l);y*=b;if(c)for(;v.offsetWidth>y&&1<w;)w-=1,v.style.fontSize=px(w);if("undefined"==typeof f)g[e]={size:w,elements:[v]};else if(f.size>=w){if(f.size>w){g[e].size=w;for(var Q in f.elements)u=f.elements[Q],w=u.offsetWidth,u.style.fontSize=px(g[e].size),u.style.wordSpacing="0px",u.style.wordSpacing=px((w-u.offsetWidth)/(u.innerText.split(" ").length-1))}g[e].elements.push(v)}v.style.webkitTransform=
  20. q?dev_rotateXY(q):"";v.style.webkitTransformOrigin=q?"0 0":"";L=L.split(" ");v.style.wordSpacing="0px";v.style.wordSpacing=px((y-v.offsetWidth)/(L.length-1))}return d}function px(a){return a.toString()+"px"}
  21. function scaleAndPositionPageContent(a,d,b){var c=UP_SCALE*parseFloat(publicationData.getPageProperty(a,"width")),g=UP_SCALE*parseFloat(publicationData.getPageProperty(a,"height"));sizeDiv(d,c,g);if(void 0!=b)d.style.left=px(b.x),d.style.top=px(b.y),b=b.width/c,d.style.webkitTransform=dev_scale(b,b),d.style.webkitTransformOrigin="0 0",fconsole.log("page ",a," scale is ",b," srcWidth ",c)}
  22. function getPageContentRect(a,d,b){var c=parseFloat(publicationData.getPageProperty(a,"proportions")),a={};a.width=Math.min(c*b,d);a.height=a.width/c;d=centerRect(d,b,a.width,a.height);a.x=d.x;a.y=d.y;return a}function applyRectToCanvas(a,d){a.width=d.width;a.height=d.height;a.style.left=px(d.x);a.style.top=px(d.y)}function fillCanvas(a,d,b){var c=a.getContext("2d");c.fillStyle=void 0!=d?d:"red";b?c.fillRect(b.x,b.y,b.width,b.height):c.fillRect(0,0,a.width,a.height)}
  23. function getIsPreloader(){return!0==window.preloaderIsShown}function showPreloader(){if(!window.preloaderIsShown)window.preloaderIsShown=!0,workspace.preloader.add()}var hidePreloaderTimeout=null;function hidePreloader(){if(window.preloaderIsShown)workspace.preloader.del(),window.preloaderIsShown=!1}function flipPage(a){a?pageMediator.right():pageMediator.left()}function getIsPortrait(){return innerHeight>innerWidth}function getIsAlbum(){return publicationData.type==ALBUM}
  24. function SimpleViewer(a){function d(){var b;deleteAllChildren(A);if(V)(b=document.getElementById("stubPage"))&&a.contains(b)&&a.removeChild(b),b=R().div(ga).x,ca&&parseVectorizedContentToDiv(ca,A,b),s("link",publicationData.page[i].links,A),s("video",publicationData.page[i].videos,A),q();else if(f())b=document.getElementById("stubPage")||createDiv("stubPage"),sizeDiv(b,innerWidth,innerHeight),b.style.backgroundColor=publicationData.getPageProperty(i,"BGColor"),a.contains(b)||a.appendChild(b)}function b(){window.requestAnimFrame=
  25. window.requestAnimFrame||function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();ha=!0;var a=H?u:F;(function oa(){ha&&(a(),requestAnimFrame(oa))})()}function c(a,b){D.style.left=px(a-D.offsetWidth/2);D.style.top=px(b-D.offsetHeight/2)}function g(){var a=e()[0]>innerWidth,b=e()[1]>innerHeight;a?(h[0]=0<h[0]?0:h[0],h[0]=e()[0]+h[0]<innerWidth?
  26. innerWidth-e()[0]:h[0]):h[0]=innerWidth/2-e()[0]/2;b?(h[1]=0<h[1]?0:h[1],h[1]=h[1]+e()[1]<innerHeight?innerHeight-e()[1]:h[1]):h[1]=innerHeight/2-e()[1]/2}function s(a,b,c,d){var g=R().div(ga).x,h;for(h in b){var x=b[h],f=new Vector2(x.x,x.y),i=new Vector2(x.width,x.height),e=createDiv(a+h);(function(a,b,C,c){a.style.webkitTransformOrigin="0 0";var d=c?Math.sin(c):0,c=c?Math.cos(c):1;a.style.webkitTransform="matrix("+[c,d,-d,c,b.x,b.y].join()+")";sizeDiv(a,C.x,C.y,!1)})(e,f.mul(g),i.mul(g),x.angle);
  27. if("undefined"!=typeof x.zindex)e.style.zIndex=x.zindex;if("highlight"==a)e.style.backgroundColor=d||highlight.getFillStyle(),c.appendChild(e);else if("link"==a)e.style.backgroundColor=publicationData.linkcolor,e.style.opacity="0.23",(f=x.urls)&&0!=f.length?(x=document.createElement("a"),x.href=f[0],x.target="_blank",x.appendChild(e),c.appendChild(x)):void 0!=x.page&&(function(a){setClickEvents(e,"md",!1);e.addEventListener(SINGLE_CLICK,function(){pageMediator.goToPage(parseInt(a))})}(x.page),c.appendChild(e));
  28. else if("video"==a){e.id="video."+x.id;if(x.showImage){var k=video.getVideoImageUrl(x.imageUri);(function(a){changeUrlWhenPubl(k,function(b){a.style.backgroundImage="url('"+b+"')";a.style.backgroundSize="100% 100%"})})(e)}f=new Image;i=x.height*g;i=50<i?50:0.8*i;f.src=video.getPlayImage();e.appendChild(f);f.style.position="absolute";f.style.margin="auto";f.style.left="0";f.style.right="0";f.style.top="0";f.style.bottom="0";f.style.height=px(i);(function(a){setClickEvents(e,"md",!1);e.addEventListener(SINGLE_CLICK,
  29. function(){video.play(a.type,a.id)})})(x);c.appendChild(e)}}}function q(){l();search.active&&search.pages[i]&&(A.appendChild(W),highlight.getHighlights(i,function(a){A.contains(W)&&s("highlight",a,W)}))}function l(){deleteAllChildren(W);A.contains(W)&&A.removeChild(W)}function L(a,b,c){var e=k,a=b&&t(r.map,k)>=r.map.length-1?r.defaultPos:t(r.map,k*(b?2:1))+(b?0:a?1:-1),a=Math.min(Math.max(a,0),r.map.length-1);m(r.map[a]);c=c?c:p?[innerWidth/2,innerHeight/2]:[publicationData.rtlMode?innerWidth:0,0];
  30. for(a=0;2>a;a++)h[a]-=(c[a]-h[a])*(k/e-1);g();d();O();P=!0}function e(){return B.map(function(a){return a*k})}function y(){H&&X.createPattern(n,"no-repeat");var a=B[0]!=n.naturalWidth||B[1]!=n.naturalHeight;B=[n.naturalWidth,n.naturalHeight];v("change",a);var b=da?i+1:i-1;1<=b&&b<=publicationData.pageCount&&!f(b)&&setTimeout(function(){loadManager.addPageToQueue({position:b,quality:!0,image:na})},500)}function f(a){a=void 0!=a?a:i;return publicationData.getPageProperty(a,"stub")}function v(a,b){var c=
  31. "change"==a,d=c&&!b&&j,f=c&&b||"resize"==a;f&&(r=Y());if(f||p||t(r.map,k)>r.textVisibleMaxPos)m(r.map[r.defaultPos]),O();d||(h[0]=p?(innerWidth-e()[0])/2:publicationData.rtlMode?innerWidth-e()[0]:0);c&&(h[1]=p?(innerHeight-e()[1])/2:0);g();P=!0}function w(a,b,c){da=i<a;if(i!=a){var e=!i||publicationData.getPageProperty(i,"width")!=publicationData.getPageProperty(a,"width")||publicationData.getPageProperty(i,"height")!=publicationData.getPageProperty(a,"height"),g=!1!==c&&!S&&!H&&!T&&(!N||!ANDROID3)&&
  32. i&&!e&&1==Math.abs(i-a)&&!f(a)&&!f()&&!(t(r.map,k)>r.textVisibleMaxPos);if(i&&f(i)&&!f(a))n.style.visibility="visible";i=a;showPreloader();if(Z.length)throw"waitingForAnimationEnd.length";Z=[];var h=function(a){g&&ea?Z.push(a):a()};if(f()){H||g&&G();V=!1;if(!H)n.style.visibility="hidden";B=[publicationData.getPageProperty(i,"width"),publicationData.getPageProperty(i,"height")];v("change",!0);d();hidePreloader();b&&h(b)}else(function(){ca=null;ga=new Vector2(publicationData.getPageProperty(i,"width"),
  33. publicationData.getPageProperty(i,"height"));deleteAllChildren(A);H||g&&G();loadManager.addPageToQueue({skipCurrentLoading:!0,image:n,quality:!0,position:i,onImageLoadComplete:function(){V=$=!0;h(y)},onPageLoadError:function(){V=!1},onAllIsComplete:function(a,c){ca=c;h(d);h(hidePreloader);b&&h(b)},onJSLoadComplete:function(){}})})()}}function u(){if(V||f()){var a=I.width,b=I.height;if($){X.clearRect(0,0,a,b);if(f())X.fillStyle=publicationData.getPageProperty(i,"BGColor"),X.fillRect(0,0,a,b);else{var c=
  34. n,d=h,e=k,g=Math.round(d[0]),d=Math.round(d[1]),x=0<g?0:Math.abs(g/e),l=0<d?0:Math.abs(d/e),a=Math.min(c.width*e,a)/e-x,b=Math.min(c.height*e,b)/e-l;(a||b)&&X.drawImage(c,g,d,c.width*e,c.height*e);c=Math.round(h[0]);e=Math.round(h[1]);M(A,c,e)}$=!1}}}function G(){A.style.visibility="hidden";var a=n;n=freeImage;freeImage=a;ia=(da?1:-1)*B[0]*k;ka=(new Date).getTime();ja=h[0];la=ia;n.style.left=px(ia);ea=!0;N&&sizeDiv(U,2*B[0]*k,B[1])}function Q(){var a=(new Date).getTime()-ka;h[0]=ja-la*a/ma;if(a>=
  35. ma){ea=!1;n.style.left="0px";h[0]=ja;freeImage.style.visibility="hidden";for(A.style.visibility="visible";Z.length;)Z.shift().call(null,null);a=da?i+1:i-1;1<=a&&a<=publicationData.pageCount&&!f(a)&&loadManager.addPageToQueue({position:a,quality:!0,image:freeImage})}}function F(){ea&&!H&&(Q(),P=!0);var a=R();if(aa||$||fa)T?(I.width=a.x,I.height=a.y,X.drawImage(n,0,0,B[0],B[1],0,0,a.x,a.y)):(n.style.width=1!=k?px(a.x):null,n.style.height=1!=k?px(a.y):null),a=B.map(function(a){return Math.floor((a-1)*
  36. k-1)}),sizeDiv(U,a[0],a[1]),sizeDiv(A,a[0],a[1]),$=aa=!1;if(P||fa){var a=Math.round(h[0]),b=Math.round(h[1]);N||M(U,a,b);fa=P=!1}}function M(a,b,c,d){d=d?"%":"px";a.style.left=b.toString()+d;a.style.top=c.toString()+d}function R(){return new Vector2(Math.round(B[0]*k),Math.round(B[1]*k))}function Y(){var a=getPageContentRect(i,innerWidth,innerHeight).width/B[0],b=innerWidth/B[0],c=b/0.8,d;p?(a=[a],d=1.5):(a=[b],d=Math.sqrt(c/b),a=a.concat([b*d,c]));for(;2.15>a[a.length-1]*d;)a[a.length]=a[a.length-
  37. 1]*d;E(a,0.25,d);E(a,0.5,d);E(a,0.75,d);E(a,1,d);fconsole.log("map: "+a.map(function(a){return a.toFixed(2)}).join(", "));return{defaultPos:0,map:a,textVisibleMaxPos:4}}function E(a,b,c){for(var d=Math.abs(a[0]-b),e=1,g=0;e<a.length;){var f=Math.abs(a[e]-b);f<d&&(d=f,g=e);e++}(b+d)/(b-d)<c&&0!=g&&(a[g]=b)}function t(a,b){for(var c=0;c<a.length;c++){var d=a[c];if(0==c){if(b<=d||1==a.length)return 0}else{if(c==a.length-1)return a.length-1;if(b<a[c])return b<=(a[c-1]+a[c])/2?c-1:c;if(b<=(a[c]+a[c+1])/
  38. 2)return c}}}function O(){customEvents.fireEvent(ZOOM_LEVEL_CHANGED_FOR_WORKSPACE,{isSmallest:0==t(r.map,k),isLargest:t(r.map,k)==r.map.length-1})}function m(a,b){k!=a&&(k=a,fconsole.update("scale",a),b||(aa=!0))}function o(a,b,c,d){var g,f,h,i,k,l,q,t,v,r,o;function n(a){a.ctrlKey&&(b.sendPinch&&(b.startPinch&&b.startPinch(a.pageX,a.pageY),b.sendPinch(z,0,0,a.pageX,a.pageY),b.endPinch&&b.endPinch()),a.stopImmediatePropagation());a.altKey&&b.sendPinch&&(b.startPinch&&b.startPinch(a.pageX,a.pageY),
  39. b.sendPinch(A,0,0,a.pageX,a.pageY),b.endPinch&&b.endPinch());a.shiftKey&&b.handleDoubleClick(a);var c=a.currentTarget;if(Modernizr.touch){if(1<a.touches.length)return p(a);c.addEventListener(DOWN_EVENT,p,!1)}c.removeEventListener(DOWN_EVENT,n,!1);c.addEventListener(MOVE_EVENT,w,!1);c.addEventListener(UP_EVENT,j,!1);c.addEventListener("touchcancel",j,!1);c.addEventListener("mouseout",j,!1);a=a.touches?a.touches[0]:a;c.pos={pageX:a.pageX,pageY:a.pageY};s()}function w(a){a.preventDefault();var d=a.touches?
  40. a.touches[0]:a,g=a.currentTarget.pos,C=d.pageX-g.pageX,g=d.pageY-g.pageY;f=f||C;a.currentTarget.pos={pageX:d.pageX,pageY:d.pageY};if(h){a=(new Date).getTime();d=a-h;i+=C;k+=g;l+=d;h=a;q+=Math.abs(C);t.push({dx:C,dy:g,time:d});c&&(a=k?Math.abs(i)/Math.abs(k):1E10,Math.abs(i)>B/1.5*(1.5-a)?v=!0:k&&!(1.5<Math.abs(i)/Math.abs(k))&&(v||(C=0)));if(1E3<l||f&&C&&f/Math.abs(f)!=C/Math.abs(C))r=!0;!r&&i&&0.5>Math.abs(k)/Math.abs(i)&&(g=0);if(!r&&4<q&&75<l){for(var j=t,a=e()[1]>innerHeight,n,m,o,p,u=p=o=m=n=
  41. d=0;u<j.length;u++){var s=j[u],d=d+s.dx;n+=s.dy;m+=Math.abs(s.dx);o+=s.dy*s.dy;p+=s.time}Math.sqrt(o);j=Math.abs(d);m=Math.abs(j-m);fromRight=0>d;14>m&&7<j&&(!a&&1>=Math.abs(n)/j||a&&j>7+200*Math.abs(n)/j&&j>0.2*p)?(fconsole.log(j/p),b.sendDrag&&b.sendDrag(fromRight),a=!0):a=!1;a&&(r=!0)}}(C||g)&&b.sendMove&&b.sendMove(C,g)}function p(a){if(1<a.touches.length){var c=a.currentTarget,d=a.touches[0],a=a.touches[1];c.pos={pageX:(d.pageX+a.pageX)/2,pageY:(d.pageY+a.pageY)/2};c.startDist=J(d,a);c.removeEventListener(UP_EVENT,
  42. j,!1);c.removeEventListener("touchcancel",j,!1);c.removeEventListener(MOVE_EVENT,w,!1);c.removeEventListener(DOWN_EVENT,p,!1);c.addEventListener(MOVE_EVENT,u,!1);c.addEventListener(UP_EVENT,m,!1);c.addEventListener("touchcancel",m,!1);b.startPinch&&b.startPinch(c.pos.pageX,c.pos.pageY);g=1}}function u(a){a.preventDefault();if(1<a.touches.length){var c=a.currentTarget,e=a.touches[0],f=a.touches[1],a=J(e,f),e={pageX:(e.pageX+f.pageX)/2,pageY:(e.pageY+f.pageY)/2},f=a/c.startDist,f=b.isLargest&&1<f?1:
  43. f,f=b.isSmallest&&1>f?1:f,h=e.pageX-c.pos.pageX,C=e.pageY-c.pos.pageY;d?g*=f:b.sendPinch&&b.sendPinch(f,h,C,e.pageX,e.pageY);c.startDist=a;c.pos=e}}function m(a){var c=a.currentTarget,e=a.touches.length;if(0<e){c.removeEventListener(MOVE_EVENT,u,!1);c.removeEventListener(UP_EVENT,m,!1);c.removeEventListener("touchcancel",m,!1);c.addEventListener(MOVE_EVENT,w,!1);c.addEventListener(UP_EVENT,j,!1);c.addEventListener("touchcancel",j,!1);var f=a.touches?a.touches[0]:a;c.pos={pageX:f.pageX,pageY:f.pageY};
  44. s()}d&&(b.sendPinch&&b.sendPinch(g),fconsole.log(g));b.endPinch&&b.endPinch();0==e&&j(a)}function y(a){o||(o=setTimeout(function(){v=!1;o=null},a))}function j(a){var b=a.currentTarget;if(!Modernizr.touch||!a.touches||0==a.touches.length)b.removeEventListener(MOVE_EVENT,w,!1),b.removeEventListener(UP_EVENT,j,!1),b.removeEventListener("touchcancel",j,!1),b.removeEventListener("mouseout",j,!1),b.addEventListener(DOWN_EVENT,n,!1);k=i=0;y(D)}function s(){h=(new Date).getTime();l=0;t=[];q=0;r=!1;f=0}var z=
  45. 1.15,A=0.8,B=innerWidth/4,D=0;a.addEventListener(DOWN_EVENT,n,!1);a.draggerResetState=function(){a.removeEventListener(DOWN_EVENT,n,!1);a.removeEventListener(DOWN_EVENT,p,!1);a.removeEventListener(MOVE_EVENT,u,!1);a.removeEventListener(MOVE_EVENT,w,!1);a.removeEventListener(UP_EVENT,m,!1);a.removeEventListener("touchcancel",m,!1);a.removeEventListener(UP_EVENT,j,!1);a.removeEventListener("touchcancel",j,!1);a.removeEventListener("mouseout",j,!1);a.addEventListener(DOWN_EVENT,n,!1)};f=void 0;h=void 0;
  46. i=void 0;k=void 0;l=void 0;q=void 0;t=void 0;v=void 0;r=void 0;o=void 0;k=i=0;g=void 0}function J(a,b){return Math.sqrt(Math.pow(a.pageX-b.pageX,2)+Math.pow(a.pageY-b.pageY,2))}var p=publicationData.type==PT_PHOTOALBUM,j=publicationData.type==PT_BOOK,z=function(a){a=a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");return null==RegExp("[\\?&]"+a).exec(window.location.href)?!1:!0}("c")?"canvas":"webkit",S=!0,T=!1,H="canvas"==z,K="webkit"==z,N="scroll"==z,i,n=new Image,na=new Image,V=!1,I=document.createElement("canvas"),
  47. X=I.getContext("2d"),ha,$,P,aa,fa,da,ea,ia,la,ka,ma=700,ja,Z=[],h=[0,0],B=[],k=0.1,ga=new Vector2(100,100),r,ca,A=createDiv("contentDiv");if(K||N)var U=createDiv("srcollDiv");this.resize=function(){V&&v("resize");d();H?(I.width=innerWidth,I.height=innerHeight):sizeDiv(a,innerWidth,innerHeight)};this.goToPage=function(a){w(a,function(){customEvents.fireEvent(ANDROID_PAGE_PREPARED,{page:f()?[]:[i]})})};var ba,D=document.createElement("p");D.style.opacity="0.7";D.style.backgroundColor="#e0efee";D.style.color=
  48. "#11111f";D.style.fontSize="18px";D.style.zIndex=1E3;D.style.position="absolute";this.sendDrag=function(a){(e()[0]<=innerWidth||f())&&flipPage(a)};this.sendMove=function(a,b){N||(h[0]+=a,h[1]+=b,g(),P=!0)};this.startPinch=function(b,d){a.appendChild(D);c(b,d);ba?(clearTimeout(ba),ba=null):A.style.visibility="hidden"};this.endPinch=function(){a.removeChild(D);ba=setTimeout(function(){d();A.style.visibility="visible";ba=null;O();K&&(aa=P=!0)},f()?0:500)};this.sendPinch=function(a,b,d,e,f){k*a<r.map[0]?
  49. a=r.map[0]/k:k*a>r.map[r.map.length-1]&&(a=r.map[r.map.length-1]/k);b+=(e-h[0])*(1-a);d+=(f-h[1])*(1-a);m(k*a,K);N||(h[0]+=b,h[1]+=d);g();K?(D.innerText=window.LOCALS.ZOOM+" "+(100*k).toFixed(0)+"%",c(e,f)):P=aa=!0};this.incZoom=function(){L(!0)};this.decZoom=function(){L(!1)};var W=createDiv("highlightContainer");this.setHighlight=function(a){a?q():(search.active=!1,l())};this.set=function(c,d){fconsole.update("zmode",z);setElementPosition(a,{left:0,top:0});if(H)a.style.overflow="visible",a.appendChild(I),
  50. a.appendChild(A);else{if(!N)a.style.position="absolute",A.style.webkitTransform=null,U.style.webkitTransform=null,a.style.webkitTransform=null,n.style.webkitTransform=null;n.style.position="absolute";a.style.overflow=N?"scroll":"hidden";a.appendChild(U);U.appendChild(T?I:n);U.appendChild(A);if(T)I.style.position="absolute";n.style.border="1px solid #333333"}w(c,d,!1);this.resize();b();setInterval(function(){fa=!0},1E3);o(a,this,publicationData.type!=PT_PHOTOALBUM,!1)};this.clear=function(){ha=!1;
  51. H?a.removeChild(I):a.removeChild(null)};this.handleDoubleClick=function(a){a=a.touches?a.touches[0]:a;L(!0,!0,[a.pageX,a.pageY])}}
  52. (function(){var a=function(){if(2===arguments.length&&"number"===typeof arguments[0]&&"number"===typeof arguments[1])this.x=arguments[0],this.y=arguments[1];else if(0===arguments.length)this.y=this.x=0;else throw"Arguments must be 2 numbers or nothing at all";},d=a.prototype;a.type="Vector2";d.type=a.type;d.set=function(b,c){if(2===arguments.length&&"number"===typeof arguments[0]&&"number"===typeof arguments[1])this.x=arguments[0],this.y=arguments[1];else if(1===arguments.length&&arguments[0].type===
  53. a.type)this.x=arguments[0].x,this.y=arguments[0].y;else throw'Argument must be 2 numbers or 1 "Vector2"';};d.neg=function(){return new a(-this.x,-this.y)};d.add=function(b){var c=new a(this.x,this.y);if("number"===typeof b)c.x+=b,c.y+=b;else if(b instanceof Box2d.Math.Vector2)c.x+=b.x,c.y+=b.y;else throw'Argument must be of type "Vector2" or "number"';return c};d.sub=function(b){var c=new a(this.x,this.y);if("number"===typeof b)c.x-=b,c.y-=b;else if(b.type&&b.type===a.type)c.x-=b.x,c.y-=b.y;else throw'Argument must be of type "Vector2" or "number"';
  54. return c};d.mul=function(b){var c=new a(this.x,this.y);if("number"===typeof b)c.x*=b,c.y*=b;else if(b.type&&b.type===a.type)c.x*=b.x,c.y*=b.y;else throw'Argument must be of type "Vector2" or "number"';return c};d.div=function(b){var c=new a(this.x,this.y);if("number"===typeof b)c.x/=b,c.y/=b;else if(b.type&&b.type===a.type)c.x/=b.x,c.y/=b.y;else throw'Argument must be of type "Vector2" or "number"';return c};d.dot=function(b){if(!b||!b.type||b.type!==a.type)throw'Arguments must be of type "Vector2"';
  55. return this.x*b.x+this.y*b.y};d.square=function(){return new a(this.x*this.x,this.y*this.y)};d.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)};d.abs=function(){return new a(Math.abs(this.x),Math.abs(this.y))};a.dot=function(b,c){if(b.type!==a.type||c.type!==a.type)throw'Arguments must be of type "Vector2"';return b.x*c.x+b.y*c.y};a.crossVV=function(b,c){if(b.type!==a.type||c.type!==a.type)throw'Arguments must be of type "Vector2"';return b.x*c.y-b.y*c.x};a.crossVN=function(b,c){if(b.type!==
  56. a.type||"number"!==typeof c)throw'Arguments must be of type "Vector2" and "number"';return new a(c*b.y,-c*b.x)};a.crossNV=function(b,c){if("number"!==typeof b||c.type!==a.type)throw'Arguments must be of type "number" and "Vector2"';return new a(-b*c.y,b*c.x)};a.abs=function(b){if(b.type!==a.type)throw'Argument must be of type "Vector2"';return new a(Math.abs(b.x),Math.abs(b.y))};window.Vector2=a})();

Raw Paste


Login or Register to edit or fork this paste. It's free.