prime-photo-gallery
Version:
A javascript utility to allow you to embed a shared prime photo gallery on your own site.
2 lines • 2.43 kB
JavaScript
!function(){const scpt=document.currentScript,share=scpt.getAttribute("data-share"),useBlueimp=scpt.hasAttribute("data-blueimp"),clip=scpt.hasAttribute("data-clip-thumb")?"&fit=clip":"",container=scpt.getAttribute("data-target")||"links",containerId=`#${container}`,corsProxy=scpt.getAttribute("data-cors-proxy")||"https://crossorigin.me/",amazonNodeApi="https://www.amazon.com/drive/v1/nodes",shareUrl=`${corsProxy}https://www.amazon.com/drive/v1/shares/${share}?id=${share}&resourceVersion=V2&ContentType=JSON`,thumb=`/alt/thumb?viewBox=250${clip}`,fullSize=`/alt/thumb?viewBox=${Math.max(window.screen.width,window.screen.height)*(devicePixelRatio||1)}`,sortDirection=scpt.getAttribute("data-sort-direction")||"ASC",sortProperty=scpt.getAttribute("data-sort-property")||"contentProperties.contentDate",sort=`%5B%27${sortProperty}+${sortDirection}%27%5D`,maxRetries=scpt.getAttribute("data-max-retries")||3;$(function(){function walkDescendants(node){const object=node.id,childrenUrl=`${corsProxy}${amazonNodeApi}/${object}/children?asset=ALL&tempLink=true&sort=${sort}&shareId=${share}&searchOnFamily=true&offset=0&resourceVersion=V2&ContentType=JSON`;$.get(childrenUrl,function(data){data.data.forEach(node=>{if(node.tempLink){const ap=`<a href="${node.tempLink+fullSize}" data-gallery="#blueimp-gallery"><img src="${node.tempLink+thumb}"></a> `;$cont.append($(ap))}else node.collectionProperties&&walkDescendants(node)})})}$(containerId).length||$("body").append(`<div id="${container}"></div>`);const $cont=$(containerId);useBlueimp&&$cont.on("click",event=>{event=event||window.event;const target=event.target||event.srcElement,link=target.src?target.parentNode:target,options={index:link,event:event,hidePageScrollbars:!1},links=$cont.find("a");blueimp.Gallery(links,options)}),function retry(count){$.ajax({type:"GET",url:shareUrl,success:function(shareInfo){const album=shareInfo.nodeInfo.id,childrenUrl=`${corsProxy}${amazonNodeApi}/${album}/children?asset=ALL&shareId=${share}&tempLink=true&limit=1&searchOnFamily=true&offset=0&resourceVersion=V2&ContentType=JSON`;$.get(childrenUrl,function(data){if(!data.count)return void $cont.append("Error, no albums found");data.data.forEach(node=>{walkDescendants(node)})})},fail:function(){if(count<=maxRetries)return setTimeout(retry.bind(null,count+1),1e3<<count);console.error("Could not fetch gallery")}})}(0)})}();
//# sourceMappingURL=prime-photo-gallery.min.js.map