1 line
7.2 KiB
JavaScript
1 line
7.2 KiB
JavaScript
|
define("zoomer",["queue","jquery","d3","picture-book","underscore"],function(e,t,n,a,i){function o(){p()||r("syria"),w.init(s)}function s(){var e=w.activeBook;if(C!==e){C=e;var t=[],a=[],o=[];i.each(e.pages,function(e){o.push(e.position),t.push(+e.node.getAttribute("data-pb-zoom"));var n=+e.node.getAttribute("data-pb-focus-x"),i=+e.node.getAttribute("data-pb-focus-y");a.push([n,i])}),b=n.scale.linear().domain(o).range(t).clamp(!0),focusScale=n.scale.linear().domain(o).range(a).clamp(!0),P=E?1.5*b(e.progress):b(e.progress);+e.pages[0].node.getAttribute("data-pb-zoom"),+e.pages[e.pages.length-1].node.getAttribute("data-pb-zoom")}if(!p()){+e.minPage.node.getAttribute("data-pb-zoom"),+e.maxPage.node.getAttribute("data-pb-zoom");y=b(e.progress),O=focusScale(e.progress)}}function r(e){var t=c={};c.slug=e,c.container=n.select("#zoomer-"+e),c.zoomer=c.container.select(".g-zoomer"),c.width=parseInt(c.zoomer.style("width")),c.height=parseInt(c.zoomer.style("height")),c.canvas=c.zoomer.append("canvas").datum(function(){return{slug:e}}).attr("width",c.width).attr("height",c.height).style("width",c.width+"px").style("height",c.height+"px"),c.ctx=c.canvas.node().getContext("2d"),d(t)}function d(t){function n(e,n){u(e,n,t)}var a=t.slug,i=e(1);I[a].forEach(function(e){i.defer(g,e)}),i.awaitAll(n)}function u(e,n,a){t("#zoomer-syria").addClass("show"),l(a)}function g(e,t){var n=v+"/"+e.name;if(x.hasOwnProperty(e.name))e.imageObj=x[e.name],t(null,e);else{var a=new Image;a.src=n,e.imageObj=a,x[e.name]=e.imageObj,a.onload=function(){t(null,e)}}}function l(e){function t(){var n=!1;if(w.activeBook&&e.slug===w.activeBook.slug&&!n){var a={z:y-P,f:[O[0]-z[0],O[1]-z[1]]},i=a.z<0?Math.pow(j,.65):j;a.z=a.z*i,a.f=[a.f[0]*i,a.f[1]*i],P+=a.z,z=[z[0]+a.f[0],z[1]+a.f[1]],h(P,z,e)}requestAnimationFrame(t)}h(A[e.slug],z,e),requestAnimationFrame(t)}function h(e,t,n){var a=n.slug,i=n.width,o=n.height,s=n.ctx;n.zoom=e,n.coverDim=window.innerWidth>window.innerHeight?i:o;var r=n.coverDim,c=m(e,a),d=c.hiImage,u=c.loImage;c.bgImage;E&&(t[1]=k);var g=[t[0]*i,t[1]*o],l=0;E&&e<.02&&"syria"===n.slug&&(s.fillStyle="#152735",s.fillRect(0,0,i,o));e*u.scale<1.2;s.save(),s.translate(g[0],g[1]),s.scale(e,e),s.save(),s.scale(u.scale,u.scale),s.globalAlpha=1-l,s.drawImage(u.imageObj,-r/2,-r/2,r,r),s.restore(),s.save(),s.scale(d.scale,d.scale),s.globalAlpha=c.progress*(1-l),s.drawImage(d.imageObj,-r/2,-r/2,r,r),s.restore(),s.restore(),e<.02&&"syria"===n.slug}function m(e,t){var n,a,o,s,r,c;return e*=.9,i.each(I[t],function(t){var i=t.showAt=1/t.scale,c=Math.abs(i-e),d="undefined"==typeof n,u="undefined"==typeof o;i<=e&&(d||c<n.distance)&&(n=t,n.distance=c,t-1>=0&&(a=t-1)),i>=e&&(u||c<o.distance)&&(o=t,o.distance=c),(d||i<s.showAt)&&(s=t,s.distance=c),(u||i>r.showAt)&&(r=t,r.distance=c)}),"undefined"==typeof n&&(n=s),"undefined"==typeof a&&(a=s),"undefined"==typeof o&&(o=r),c=(e-n.showAt)/(o.showAt-n.showAt),c=isNaN(c)?0:isFinite(c)?c:1,{loImage:n,bgImage:a,hiImage:o,progress:c}}function f(){return{syria:[{name:"09.jpg",scale:1/.0057},{name:"08.jpg",scale:1/.0114},{name:"07.jpg",scale:1/.0228},{name:"06.jpg",scale:1/.0456},{name:"05.jpg",scale:1/.0912},{name:"04.jpg",scale:1/.184},{name:"03.jpg",scale:1/.368},{name:"02.jpg",scale:1/.736},{name:"01.jpg",scale:1/1.472},{name:"00.jpg",scale:1/2.944}]}}function p(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry/.test(navigator.userAgent)}var b,v=(c={},"/assets/images/syria"),x={},I=f(),w=new a,A={syria:.0057},P=.0057,y=.0057,z=[.5,.5],O=[.5,.5],j=.015,k=.6,C="",B=window.innerWidth,E=B<600;return o}),define("picture-book",[],function(){function e(){return n&&!t()}function t(){return navigator.userAgent.match(/(iPad|iPhone);.*CPU.*OS [8|9]_\d/i)&&navigator.userAgent.indexOf("Safari")>-1&&navigator.userAgent.indexOf("CriOS")==-1||navigator.userAgent.indexOf("Twitter")>-1}var n=(/iPad|iPhone/.test(navigator.userAgent),/Android/.test(navigator.userAgent),/Android|webOS|iPhone|iPad|iPod|BlackBerry/.test(navigator.userAgent)),a=e();return function(e){function t(){return window.scrollY}var n=0,i=.5;this.init=function(e){var t=this;this
|