syriastreet.com/assets/js/components/zoomer.js

1 line
6.9 KiB
JavaScript
Raw Normal View History

2023-10-06 21:29:45 +00:00
define("zoomer",["queue","jquery","d3","picture-book","underscore"],function(a,o,s,e,u){c={};var i="/assets/images/syria",r={},l={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}]},d=new e;function g(){var n,a,i,e=d.activeBook;w!==e&&(w=e,n=[],a=[],i=[],u.each(e.pages,function(e){i.push(e.position),n.push(+e.node.getAttribute("data-pb-zoom"));var t=+e.node.getAttribute("data-pb-focus-x"),e=+e.node.getAttribute("data-pb-focus-y");a.push([t,e])}),t=s.scale.linear().domain(i).range(n).clamp(!0),focusScale=s.scale.linear().domain(i).range(a).clamp(!0),p=A?1.5*t(e.progress):t(e.progress),e.pages[0].node.getAttribute("data-pb-zoom"),e.pages[e.pages.length-1].node.getAttribute("data-pb-zoom")),y()||(e.minPage.node.getAttribute("data-pb-zoom"),e.maxPage.node.getAttribute("data-pb-zoom"),f=t(e.progress),v=focusScale(e.progress))}function h(e,t){var n,a=i+"/"+e.name;r.hasOwnProperty(e.name)?(e.imageObj=r[e.name],t(null,e)):((n=new Image).src=a,e.imageObj=n,r[e.name]=e.imageObj,n.onload=function(){t(null,e)})}var t,m={syria:.0057},p=.0057,f=.0057,b=[.5,.5],v=[.5,.5],x=.015,I=.6,w="",A=window.innerWidth<600;function P(e,t,n){var a=n.slug,i=n.width,o=n.height,s=n.ctx,r=(n.zoom=e,n.coverDim=window.innerWidth>window.innerHeight?i:o,n.coverDim),a=function(o,e){var s,r,c,d,g;o*=.9,u.each(l[e],function(e){var t=e.showAt=1/e.scale,n=Math.abs(t-o),a=void 0===s,i=void 0===c;t<=o&&(a||n<s.distance)&&((s=e).distance=n,0<=e-1)&&(r=e-1),o<=t&&(i||n<c.distance)&&((c=e).distance=n),(a||t<d.showAt)&&((d=e).distance=n),(i||t>g.showAt)&&((g=e).distance=n)}),void 0===s&&(s=d);void 0===r&&(r=d);void 0===c&&(c=g);return e=(o-s.showAt)/(c.showAt-s.showAt),e=isNaN(e)?0:isFinite(e)?e:1,{loImage:s,bgImage:r,hiImage:c,progress:e}}(e,a),c=a.hiImage,d=a.loImage,t=(a.bgImage,A&&(t[1]=I),[t[0]*i,t[1]*o]);A&&e<.02&&"syria"===n.slug&&(s.fillStyle="#152735",s.fillRect(0,0,i,o)),d.scale;s.save(),s.translate(t[0],t[1]),s.scale(e,e),s.save(),s.scale(d.scale,d.scale),s.globalAlpha=1,s.drawImage(d.imageObj,-r/2,-r/2,r,r),s.restore(),s.save(),s.scale(c.scale,c.scale),s.globalAlpha=+a.progress,s.drawImage(c.imageObj,-r/2,-r/2,r,r),s.restore(),s.restore(),e<.02&&n.slug}function y(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry/.test(navigator.userAgent)}return function(){var i,t,e,n;y()||(e="syria",n=c={},c.slug=e,c.container=s.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"),n=(i=n).slug,t=a(1),l[n].forEach(function(e){t.defer(h,e)}),t.awaitAll(function(e,t){n=i,o("#zoomer-syria").addClass("show");var n,a=n;P(m[a.slug],b,a),requestAnimationFrame(function e(){var t,n;d.activeBook&&a.slug===d.activeBook.slug&&(n=(t={z:f-p,f:[v[0]-b[0],v[1]-b[1]]}).z<0?Math.pow(x,.65):x,t.z=t.z*n,t.f=[t.f[0]*n,t.f[1]*n],p+=t.z,b=[b[0]+t.f[0],b[1]+t.f[1]],P(p,b,a)),requestAnimationFrame(e)})})),d.init(g)}}),define("picture-book",[],function(){/iPad|iPhone/.test(navigator.userAgent),/Android/.test(navigator.userAgent);var n=/Android|webOS|iPhone|iPad|iPod|BlackBerry/.test(navigator.userAgent)&&!(navigator.userAgent.match(/(iPad|iPhone);.*CPU.*OS [8|9]_\d/i)&&-1<navigator.userAgent.indexOf("Safari")&&-1==navigator.userAgent.indexOf("CriOS")||-1<navigator.userAgent.indexOf("Twitter"));return function(e){var c=0;function t(){return window.scrollY}this.init=function(e){var t=this;this.books.forEach(function(e){e.datum=[].slice.call(e.node.attributes).filter(function(e){return 0===e.name.indexOf("data-pb-")}).map(function(e){return{name:e.name.replace("data-pb-",""),value:+e.value}})}),document.addEventListener("scroll",function(){t.scroll