UNPKG

4.74 kBJavaScriptView Raw
1/**!
2 * @preserve nanogallery2 - GOOGLE PHOTOS data provider
3 * Homepage: http://nanogallery2.nanostudio.org
4 * Sources: https://github.com/nanostudio-org/nanogallery2
5 *
6 * License: GPLv3 and commercial licence
7 *
8*/
9!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery","nanogallery2"],e):"object"==typeof exports&&"function"==typeof require?e(require(["jquery","nanogallery2"])):e(jQuery)}((function(e){jQuery.nanogallery2.data_google2=function(e,t){var a=e,o=function(e,t,o,n){var d="",s="image",u=NGY2Item.GetIdx(a,e),m="";a.galleryMaxItems.Get()>0&&(m="&max-results="+a.galleryMaxItems.Get());var h="";"undefined"!=typeof ngy2_pwa_at&&(h=ngy2_pwa_at),0==e?(d=""!=h?"https://photoslibrary.googleapis.com/v1/albums":a.O.google2URL+"?nguserid="+a.O.userID+"&alt=json&v=3&kind=album"+m+"&rnd="+(new Date).getTime(),s="album"):d=""!=h?"https://photoslibrary.googleapis.com/v1/mediaItems:search":a.O.google2URL+"?nguserid="+a.O.userID+"&ngalbumid="+e+"&alt=json&v=3&kind=photo&"+m,a.O.debugMode&&console.log("Google Photos URL: "+d),r(!0),jQuery.ajaxSetup({cache:!1}),jQuery.support.cors=!0;try{var c=setTimeout((function(){r(!1),l("Could not retrieve AJAX data...")}),6e4);jQuery.getJSON(d+"&callback=?",(function(d){if("error"==d.nano_status)return clearTimeout(c),r(!1),void l(a,"Could not retrieve Google data. Error: "+d.nano_message);clearTimeout(c),r(!1),i(u,s,d),g(e),null!=t&&t(o,n,null)})).fail((function(e,t,o){clearTimeout(c),r(!1);var i="";for(var n in e)i+=n+"="+e[n]+"<br>";l(a,"Could not retrieve Google data. Error: "+(t+", "+o+" "+i+"<br><br>URL:"+d))}))}catch(e){l(a,"Could not retrieve Google data. Error: "+e)}};function i(e,t,o){a.O.debugMode&&(console.log("Google Photos data:"),console.dir(o));var i=a.I[e].GetID();jQuery.each(o,(function(e,o){if("object"==typeof o&&null!==o){var r="",l="";"image"==t?(void 0!==o.description&&(r=o.description),""!=a.O.thumbnailLabel.get("title")&&(l=d(o.filename))):l=o.title,null==l&&(l="");var g=o.id;if("album"==t&&(!u(l,g)||null==o.coverPhotoBaseUrl))return!0;var m=NGY2Item.New(a,l,r,g,i,t,""),h=0,c=0,f="";"image"==t?(f=o.baseUrl,a.O.viewerZoom||null==a.O.viewerZoom?f+="=h"+o.mediaMetadata.height+"-w"+o.mediaMetadata.width:window.screen.width>window.screen.height?f+="=w"+window.screen.width:f=s+"=h"+window.screen.height,m.setMediaURL(f,"img"),void 0!==o.mediaMetadata.width&&(m.imageWidth=parseInt(o.mediaMetadata.width),h=m.imageWidth),void 0!==o.mediaMetadata.height&&(m.imageHeight=parseInt(o.mediaMetadata.height),c=m.imageHeight),void 0!==o.mediaMetadata.photo&&(null!=o.mediaMetadata.photo.exposureTime&&(m.exif.exposure=o.mediaMetadata.photo.exposureTime),null!=o.mediaMetadata.photo.focalLength&&(m.exif.focallength=o.mediaMetadata.photo.focalLength),null!=o.mediaMetadata.photo.apertureFNumber&&(m.exif.fstop=o.mediaMetadata.photo.apertureFNumber),null!=o.mediaMetadata.photo.isoEquivalent&&(m.exif.iso=o.mediaMetadata.photo.isoEquivalent),null!=o.mediaMetadata.photo.cameraModel&&(m.exif.model=o.mediaMetadata.photo.cameraModel)),void 0!==o.mediaMetadata.video&&(null!=o.mediaMetadata.video.cameraModel&&(m.exif.model=o.mediaMetadata.video.cameraModel),m.downloadURL=o.baseUrl+"=dv")):m.numberItems=o.mediaItemsCount,m.thumbs=n("l1",m.thumbs,o,t,c,h),m.thumbs=n("lN",m.thumbs,o,t,c,h);var p=a.O.fnProcessData;null!==p&&("function"==typeof p?p(m,"google2",o):window[p](m,"google2",o))}})),a.I[e].contentIsLoaded=!0}function n(e,t,o,i,n,r){for(var l=["xs","sm","me","la","xl"],d=0;d<l.length;d++){if("image"==i){if("auto"==a.tn.settings.width[e][l[d]]){let i=r/n;t.height[e][l[d]]=a.tn.settings.getH(e,l[d]),t.width[e][l[d]]=a.tn.settings.getH(e,l[d])*i,t.url[e][l[d]]=o.baseUrl+"=h"+a.tn.settings.getH(e,l[d]);continue}if("auto"==a.tn.settings.height[e][l[d]]){let i=n/r;t.width[e][l[d]]=a.tn.settings.getW(e,l[d]),t.height[e][l[d]]=a.tn.settings.getW(e,l[d])*i,t.url[e][l[d]]=o.baseUrl+"=w"+a.tn.settings.getW(e,l[d]);continue}t.height[e][l[d]]=a.tn.settings.getH(e,l[d]),t.width[e][l[d]]=a.tn.settings.getW(e,l[d]),t.url[e][l[d]]=o.baseUrl+"=w"+a.tn.settings.getW(e,l[d])}if("album"==i){if("auto"==a.tn.settings.width[e][l[d]]){t.url[e][l[d]]=o.coverPhotoBaseUrl+"=h"+a.tn.settings.getH(e,l[d]);continue}if("auto"==a.tn.settings.height[e][l[d]]){t.url[e][l[d]]=o.coverPhotoBaseUrl+"=w"+a.tn.settings.getW(e,l[d]);continue}t.url[e][l[d]]=o.coverPhotoBaseUrl+"=h"+a.tn.settings.getH(e,l[d])+"-w"+a.tn.settings.getW(e,l[d])}}return t}var r=NGY2Tools.PreloaderDisplay.bind(a),l=NGY2Tools.NanoAlert,d=NGY2Tools.GetImageTitleFromURL.bind(a),u=NGY2Tools.FilterAlbumName.bind(a),g=NGY2Tools.AlbumPostProcess.bind(a);switch(t){case"AlbumGetContent":var m=arguments[2],h=arguments[3],c=arguments[4],f=arguments[5];o(m,h,c,f)}}}));
\No newline at end of file