-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathviewer.min.js
1 lines (1 loc) · 19.5 KB
/
viewer.min.js
1
!function(){function a(){$(".viewers-ugc-carousel").width()<860?$(".upload-option").addClass("upload-option-small"):$(".upload-option").removeClass("upload-option-small")}var b=0,c=function(a,c,d,e,f,g,h){var i=this;if(this.name="ugc-carousel",this.namespace=this.name+"-"+b,b++,!a){return void console.warn("viewers-ugc-carousel needs account settings")}if(!c){return void console.warn("viewers-ugc-carousel needs carousel settings")}this.viewerSettings=c,this.accountSettings=a,this.modalSettings=d,this.uploadModalSettings=e,this.uploadSettings=f,this.instagramSettings=g,this.ctaText=i.viewerSettings.callToActionText||"Shop the look",this.spacing=i.viewerSettings.spacing,this.ampAnalyticsGlobName=this.accountSettings.ampAnalyticsGlobName||"aa",this.ampAnalyticsScriptUrl=this.accountSettings.ampAnalyticsScriptUrl||"//s1.adis.ws/analytics.js",this.numberOfAssets=0,void 0===this.spacing&&(this.spacing=3),window.self!==window.top&&(i.viewerSettings.disableDeepLinking=!0);var j={client_id:i.accountSettings.client,di_basepath:i.accountSettings.imageBasePath||"https://i1.adis.ws/",content_basepath:i.accountSettings.contentBasePath||"https://c1.adis.ws/"};if(void 0!==i.accountSettings.cache_window&&(j.cache_window=i.accountSettings.cache_window),!this.accountSettings.ampAnalyticsDisabled&&this.accountSettings.ampAnalyticsCollectorId){!function(a,b,c,d,e,f,g){a.AmplienceAnalyticsObject=e,a[e]=a[e]||function(){(a[e].q=a[e].q||[]).push(arguments)},a[e].l=1*new Date,f=b.createElement(c),g=b.getElementsByTagName(c)[0],f.async=1,f.src=d,g.parentNode.insertBefore(f,g)}(window,document,"script",this.ampAnalyticsScriptUrl,this.ampAnalyticsGlobName);var k;this.accountSettings.ampAnalyticsBeacon&&(k={baseUrl:this.accountSettings.ampAnalyticsBeacon}),window[this.ampAnalyticsGlobName]("create",this.accountSettings.ampAnalyticsCollectorId,k)}amp.init(j),amp.stats.bind(function(a,b,c,d){var e={index:d&&d.index,streamName:i.viewerSettings.stream,totalAssets:i.numberOfAssets};if(window[i.ampAnalyticsGlobName]){if("productQuickView"===c||"productDisplayPage"===c||"selectProduct"===c){d.sku&&(e.sku=d.sku),d.url&&(e.url=d.url),e.imageName=d.ugcdata.name,e.channel=d.ugcdata.social.source,window[i.ampAnalyticsGlobName]("trackEvent","ugc:selectProduct",e)}else{if("selectPost"===c){var f=d.ugcdata.enrich&&d.ugcdata.enrich.urls&&d.ugcdata.enrich.urls.toString(),g=d.ugcdata.enrich&&d.ugcdata.enrich.skus&&d.ugcdata.enrich.skus.toString();f&&(e.productUrls=f),g&&(e.productSkus=g),e.imageName=d.ugcdata.name,e.channel=d.ugcdata.social.source,window[i.ampAnalyticsGlobName]("trackEvent","ugc:"+c,e)}}}if((b===i.namespace||$.contains(i.viewerSettings.appendTo[0],a[0]))&&h&&"function"==typeof h){var j={viewer:i.name,eventName:c,element:a,value:d,parent:i.container},k=-1===b.indexOf(i.name);k&&(j.sdkComponent=b),h(j)}});var l=function(a,b,c,d){i.modal&&i.modal.show(c,d),i.reporter&&i.reporter.setImage(b.src,a.social.postID)},m=function(a,b,c,d){var e;a.enrich&&a.enrich.urls&&a.enrich.urls.length>0&&(e=a.enrich.urls[0],amp.stats.event(d,i.namespace,"selectProduct",{index:c,ugcdata:a,url:e}),setTimeout(function(){window.location.href=e},50))};i.viewerSettings.onSelect=i.modalSettings.showModal?l:m,amp.content([i.viewerSettings.stream+"_ugcdata"],function(a){if(i.data=JSON.parse(a[0].value),i.images=i.buildImageData(i.data),i.numberOfAssets=i.data.length,i.data.length>0&&(i.buildContent(),i.setupReporting(),i.modalSettings.showModal)){var b=amp.DeepLink.prototype.hasDeepLink(i.viewerSettings.stream),c=function(){return b||""===window.location.hash};if((!i.viewerSettings.disableDeepLinking&&c()||i.viewerSettings.forceDeepLinking)&&(i.deepLinker=new amp.DeepLink({stream:i.viewerSettings.stream,disableDeepLinking:i.viewerSettings.disableDeepLinking}),$(window).on("hashchange",$.proxy(i.checkIfDeepLinkChanged,i))),i.buildModal(),b){var d=i.getUGCDataByAssetID(b);i.viewerSettings.onSelect(d.data,d.image,d.index)}}amp.stats.event(i.container,i.namespace,"moduleView",{stream:i.viewerSettings.stream,ugcdata:i.data,count:i.images.length})},function(a){})};c.prototype.checkIfDeepLinkChanged=function(){if(this.deepLinker.checkIfDeepLinkChanged()){var a=amp.DeepLink.prototype.hasDeepLink(self.viewerSettings.stream);if(a){var b=this.getUGCDataByAssetID(a);this.viewerSettings.onSelect(b.data,b.image,b.index)}else{this.modal.hide()}}},c.prototype.getUGCDataByAssetID=function(a){for(var b=0;b<this.data.length;b++){if(this.data[b].id===a){return{data:this.data[b],image:this.images[b],index:b}}}},c.prototype.buildImageData=function(a){var b,c,d,e=[];for(b=0;b<a.length;b++){c=a[b],d=this.generateImagePathFromName(c.name),e.push({src:d})}return e},c.prototype.generateImagePathFromName=function(a){return this.accountSettings.imageBasePath+"i/"+this.accountSettings.client+"/"+a},c.prototype.next=function(){this.carousel.ampCarousel("next")},c.prototype.prev=function(){this.carousel.ampCarousel("prev")},c.prototype.setupReporting=function(){var a=this,b={basepath:this.viewerSettings.reportpath,xd:this.viewerSettings.xd,stream:this.viewerSettings.stream,referer:window.location.href,tags:"ugc-report-img",onsubmit:$.proxy(function(){amp.stats.event(e.container,a.namespace,"postReported",{index:a.selected.index,ugcdata:a.data[a.selected.index]}),e.hide()},this)},c=a.reporter=new amp.Report(b),d={content:c.form,width:400,height:380},e=a.reportModal=new amp.Modal(d);$(d.content).parent().find(".amp-close").on("touchstart mousedown",function(){c.reset()}),$(d.content).closest(".amp-modal-grey-out").on("touchstart mousedown",function(){c.reset()})},c.prototype.buildModal=function(){var a=this,b={cdnAccount:"",displayText:void 0!==typeof a.modalSettings.displayText?a.modalSettings.displayText:!0,displayUsername:void 0!==typeof a.modalSettings.displayUsername?a.modalSettings.displayUsername:!0,mainDiOptions:a.viewerSettings.mainDiOptions||"",diOptions:a.modalSettings.diOptions||"",data:a.data,images:a.images,deepLinker:a.deepLinker,reporter:a.reporter,namespace:a.namespace,reportModal:a.reportModal};a.modal=new amp.ImageModal(b)},c.prototype.buildContent=function(){var b=this,c=this.viewerSettings.clientName||"Retailer",d=this.uploadSettings.tcsLink||"",e=this.uploadSettings.gnipTcsLink||"",f=!1;if(0===this.images.length){return void console.warn("No image data found")}if(0===this.data.length){return void console.warn("No data content found")}this.viewerSettings.numShow=Math.min(this.viewerSettings.numShow,this.data.length);var g=this.container=$('<div class="viewers-ugc-carousel"><div class="amp-row"><div class="amp-cell navigation prev"><div class="noselect caret-left"></div></div><div class="amp-cell carousel"></div><div class="amp-cell navigation next"><div class="noselect caret-right"></div></div></div><div class="upload-option"><a href="#" id="amp-upload-modal">Upload your photo</a></div><div class="amp-tcs-links"><a class="twitter-tcs" href="'+e+'" target="_blank">Twitter T&C's - </a><a class="retailer-tcs" href="'+d+'" target="_blank">'+c+" T&C's</a></div></div>");g.css("max-width",640*this.viewerSettings.numShow+"px");var h=this.carousel=g.find(".carousel");g.find(".next").on("mousedown touchstart",$.proxy(this.next,this)),g.find(".prev").on("mousedown touchstart",$.proxy(this.prev,this));for(var i=0;i<this.images.length;i++){var j=this.images[i],k=this.data[i],l=$('<div class="viewers-ugc-carousel-image" style="border:'+this.spacing+"px solid transparent;width:"+100/b.viewerSettings.numShow+'%"><div class="hover"><div class="amp-row full-size"><div class="amp-cell amp-full-size call-to-action">'+this.ctaText+'</div></div></div><div class="amp-social-icon-overlay amp-'+k.social.source+'-icon"></div><img class="amp-main-img" src="'+j.src+"?"+b.viewerSettings.diOptions+'"/></div>');h.append(l),l.on("click",function(a,c,d,e){return function(){b.selected={data:a,image:c,index:e,item:d},b.viewerSettings.onSelect(a,c,e,d)}}(k,j,l,i)),"twitter"===k.social.source&&(f=!0)}if(this.uploadModalSettings&&this.uploadSettings&&this.instagramSettings){var m=$('<div class="amp-upload-content"></div>');this.uploadModalSettings.content=m;var n=new amp.UploadModal(this.uploadModalSettings),o=$.proxy(function(a,b,c,d){amp.stats.event($(this.uploadSettings.area).find(".amp-submit-button, .amp-inst-submit-button"),this.namespace,"uploadCompleted",{status:c,type:d})},this,window);this.uploadSettings.completed=o,this.instagramSettings.completed=o,this.uploadSettings.area=m;new amp.Upload(this.uploadSettings);this.instagramSettings.area=m;new amp.Instagram(this.instagramSettings);$(b.container).on("click","#amp-upload-modal",function(a){return a.preventDefault(),n.show(),!1})}$(this.viewerSettings.appendTo).append(g);var p={autoplay:b.viewerSettings.autoplay,width:1*b.viewerSettings.numShow,height:1,onActivate:{select:!1,goTo:!1}};p.autoplay&&(p.delay=1000*b.viewerSettings.autoRotationSpeed),$(window).on("resize",function(){a()}),a(),f||$(".twitter-tcs").hide(),h.ampCarousel(p)},amp.Carousel=c}(),function(a){var b=function(a){this.settings=a,this.images=a.images,this.data=a.data,this.params=this.getFragmentParams()};b.prototype.hasDeepLink=function(a){var c=b.prototype.getFragmentParams();return c&&c.stream===a&&c.asset?c.asset:void 0},b.prototype.getFragmentParams=function(){var b=a.location.hash,c={};if(b){b=b.substring(1);for(var d=b.split("&"),e=0,f=d.length;f>e;e++){if(void 0!==typeof d[e]){var g=d[e].split("=");c[g[0]]=g[1]}}c.stream&&(c.stream=a.decodeURIComponent(c.stream))}return c},b.prototype.checkIfDeepLinkChanged=function(){return this.params.stream!==this.oldParams.stream||this.params.asset!==this.oldParams.asset},b.prototype.addFragment=function(a){this.params=this.params||{},this.params.stream=this.settings.stream,this.params.asset=a,this.updateFragment()},b.prototype.updateFragment=function(){this.oldParams=$.extend({},this.params);var b=this.params,c=[];for(var d in b){if(b.hasOwnProperty(d)){var e=b[d];d&&void 0!==e&&("stream"===d&&(e=a.encodeURIComponent(e)),c.push(d+"="+e))}}var f=c.join("&");if(f){a.location.hash=c.join("&")}else{var g=$(a).scrollTop();a.location.hash="",$(a).scrollTop(g)}},b.prototype.removeFragment=function(){this.params&&(this.params.asset&&delete this.params.asset,this.params.stream&&delete this.params.stream,this.updateFragment())},a.amp.DeepLink=b}(window),function(){function a(a,b){var c="",d="";return"twitter"===a.toLowerCase()?(c=b.split("/").pop(),d='<a href="https://twitter.com/intent/tweet?in_reply_to='+c+'" target="_blank"><span class="twitter-tweet-intent"></span></a><a href="https://twitter.com/intent/retweet?tweet_id='+c+'" target="_blank"><span class="twitter-retweet-intent"></span></a><a href="https://twitter.com/intent/favorite?tweet_id='+c+'" target="_blank"><span class="twitter-fav-intent"></span></a>'):d}function b(a){var b,c=(new Date).getTime(),d=(c-a)/1000,e=Math.floor(d/3600),f=Math.floor(d/3600/24),g=Math.floor(d/3600/24/7),h=Math.floor(d/3600/24/7/4),i=d%3600,j=Math.floor(i/60),k=i%60,l=Math.ceil(k),m={M:h,w:g,d:f,h:e,m:j,s:l};switch(!0){case 0!==m.M:b="1"==m.M?m.M+" Month ago":m.M+" Months ago";break;case 0!==m.w:b="1"==m.w?m.w+" Week ago":m.w+" Weeks ago";break;case 0!==m.d:b="1"==m.d?m.d+" Day ago":m.d+" Days ago";break;case 0!==m.h:b="1"==m.h?m.h+" Hour ago":m.h+" Hours ago";break;case 0!==m.m:b="1"==m.m?m.m+" Minute ago":m.m+" Minutes ago";break;case 0!==m.s:b="1"==m.s?m.s+" Second ago":m.s+" Seconds ago"}return b}function c(a){var b=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c=new Date(a),d=(new Date).getTime(),e=Math.floor((d-a)/1000),f=Math.floor(e/60),g=Math.floor(e/3600),h=(Math.floor(e/3600/24),"");switch(!0){case 59>=e&&e>=1:h=e+"s";break;case 59>=f&&f>=1:h=f+"m";break;case 23>=g&&g>=1:h=g+"h";break;default:h=c.getDate()+" "+b[c.getMonth()]+" "+c.getFullYear()}return h}var d=function(a){var b=this;this.settings=a,this.namespace=a.namespace,this.buildHTML(),this.container.hide(),this.settings.displayText||this.container.find(".social-text").remove(),this.settings.displayUsername||this.container.find(".social-profile").hide(),this.resizeModal(),$(window).resize(function(){b.resizeModal()})};d.prototype.show=function(a){this.getSelected(a),this.settings.deepLinker&&this.settings.deepLinker.addFragment(this.data.id),this.container.find(".amp-main-image").remove(),this.updateValues(),this.container.show(),this.getProducts()},d.prototype.hide=function(){this.settings.deepLinker&&this.settings.deepLinker.removeFragment(this.data.id),amp.stats.event(this.container,this.namespace,"postClosed",{index:this.selected,ugcdata:this.data}),this.container.hide()},d.prototype.getSelected=function(a){var b=0,c=this.settings.data.length-1;b>a&&(a=c),a>c&&(a=b),this.selected=a,this.data=this.settings.data[a],this.image=this.settings.images[a],this.settings.reporter&&this.settings.reporter.setImage(this.image.src,this.data.social.postID),amp.stats.event(this.container,this.namespace,"selectPost",{index:this.selected,ugcdata:this.data})},d.prototype.next=function(){this.selected+=1,this.show(this.selected),this.settings.onnext&&"function"==typeof this.settings.onnext&&this.settings.onnext(this.selected)},d.prototype.prev=function(){this.selected-=1,this.show(this.selected),this.settings.onprev&&"function"==typeof this.settings.onprev&&this.settings.onprev(this.selected)},d.prototype.getProducts=function(a){if(window.ecommBridge&&window.ecommBridge.capability&&window.ecommBridge.capability.getProduct){var a=this.container.find(".amp-products");if(a.html(""),this.data.enrich&&this.data.enrich.skus&&this.data.enrich.skus.length>0){for(var a=[],b=this,c=0;c<this.data.enrich.skus.length;c++){a.push({id:this.data.enrich.skus[c]})}if(a.length<=0){return}var d=this.data.id;window.ecommBridge.site.getProduct(a,function(a,c){d===b.data.id&&(b.products=c,b.updateProductValues())})}else{this.data.enrich&&this.data.enrich.urls&&(this.products=[],this.products.push(this.data.enrich.urls[0]),this.updateProductValues())}}},d.prototype.updateValues=function(){var d=("@"+this.data.social.profileName,this.data.social.source?"social-icon-"+this.data.social.source.toLowerCase():"");socialProfileClass=this.data.social.source?"profile-image-"+this.data.social.source.toLowerCase():"",socialHandle="twitter"===this.data.social.source.toLowerCase()?"@":"",socialDisplayName=this.data.social.profileDisplayName?this.data.social.profileDisplayName:"",postCreatedTime="twitter"===this.data.social.source.toLowerCase()?c(this.data.social.created):b(this.data.social.created),profileLink="",this.container.find(".amp-main-image-container").append('<img class="amp-main-image" src="'+(this.image.src+"?"+(this.settings.diOptions||this.settings.mainDiOptions))+'">'),this.container.find(".social-details").find(".social-profile-image").attr("class","social-profile-image").addClass(socialProfileClass).find(".social-profile-image-primary").attr("style","background-image: url("+this.data.social.profilePicture+")").end().end().find(".social-display-name").html(socialDisplayName).end().find(".social-handle").html(socialHandle+this.data.social.profileName).end().end().find(".social-intents").html(a(this.data.social.source,this.data.social.url)).end().find(".social-icon").attr("class","social-icon").removeClass("social-icon-twitter").attr("href","").end().find(".social-text").html(this.data.social.text).end(),this.data.social.profileLink?(profileLink="//"+this.data.social.profileLink.split("//")[1],this.container.find(".social-details").find(".social-profile-created a").attr("href",this.data.social.url).html(postCreatedTime).end().find(".social-profile-name").attr("href",profileLink).end()):this.container.find(".social-details").find(".social-profile-name").removeAttr("href").end().find(".social-profile-created a").removeAttr("href").html(postCreatedTime).end(),"twitter"===this.data.social.source?this.container.find(".social-profile").show().find(".social-profile-image-primary").attr("href",profileLink).end().find(".social-icon").attr("class","social-icon").addClass(d).attr("href","https://twitter.com").end():this.settings.displayUsername||this.container.find(".social-profile").hide(),"direct"===this.data.social.source?this.container.find(".amp-source").html(this.data.social.source+" upload"):this.container.find(".amp-source").html("via "+this.data.social.source),this.settings.data.length<=1&&this.container.find(".amp-navigation").hide()},d.prototype.updateProductValues=function(){if(this.products&&this.products.length>0){var a=this.container.find(".amp-products");for(var b=0;b<this.products.length;b++){var c=this.products[b];"string"==typeof c?a.append('<div class="amp-product-url"><button data-url="'+c+'">Buy Now</button></div>'):"[object Array]"!==Object.prototype.toString.call(c)&&"error"!==c.status&&a.append('<div class="amp-product"><div class="amp-product-thumb"><img src="'+c.thumbnail+'" /></div><div class="amp-product-details"><p>'+c.name+"</p><p>"+c.price+'</p></div><button id="product-'+c.sku+'" onclick="window.location.href=\''+c.url+"'\">Buy Now</button></div>")}}},d.prototype.buildHTML=function(){var a=this,b=this.container=$('<div class="amp-modal-detail amp-modal-grey-out"><div class="amp-row"><div class="amp-cell amp-full-size"><div class="amp-content"><div class="amp-navigation prev"><div class="noselect caret-left"></div></div><div class="amp-close amp-close-prod-modal"></div><div class="amp-left-section"><div class="amp-main-image-container"><img class="amp-main-image" /></div><div class="amp-insta-report">Report this image</div></div><div class="amp-right-section"><div class="amp-products"></div><div class="social-details"><div class="social-profile"><div class="social-profile-image"><a class="social-profile-image-primary" target="_blank"></a></div><a href="" class="social-profile-name" target="_blank"><div class="social-display-name"></div><div class="social-handle"></div><div class="amp-source"></div></a><a class="social-icon" target="_blank"></a></div><div class="social-text"></div><div class="social-footer"><span class="social-profile-created"><a href="" target="_blank"></a></span><div class="social-intents"></div></div></div></div><div class="amp-navigation next"><div class="noselect caret-right"></div></div></div></div></div>');b.on("touchstart mousedown",$.proxy(this.hide,this)),b.find(".amp-close-prod-modal").on("touchstart mousedown",$.proxy(this.hide,this)),b.find(".amp-content").on("touchstart mousedown",function(a){a.stopPropagation()}),b.find(".amp-navigation.next").on("touchstart mousedown",$.proxy(this.next,this)),b.find(".amp-navigation.prev").on("touchstart mousedown",$.proxy(this.prev,this)),$("body").append(b),b.on("click touchstart mousedown",".amp-product button",function(b){var c=$(b.currentTarget);window.ecommBridge&&window.ecommBridge.capability&&window.ecommBridge.capability.quickView?(window.ecommBridge.interaction.quickview(a.getSku(b),a.data),amp.stats.event(c,a.namespace,"productQuickView",{index:a.selected,ugcdata:a.data,sku:a.getSku(b)})):window.ecommBridge&&window.ecommBridge.capability&&window.ecommBridge.capability.url&&window.ecommBridge.site.getUrl({type:"product",parameter:a.getSku(b)},function(b,d){amp.stats.event(c,a.namespace,"productDisplayPage",{index:a.selected,ugcdata:a.data,url:d}),setTimeout(function(){window.location.href=d},50)})}),b.on("click touchstart mousedown",".amp-product-url button",function(b){var c="productDisplayPage",d=$(this).attr("data-url");amp.stats.event($(b.currentTarget),a.namespace,c,{index:a.selected,ugcdata:a.data,url:d}),setTimeout(function(){window.location.href=d},50)}),b.find(".amp-insta-report").on("mousedown touchstart",$.proxy(function(b){return b.preventDefault(),a.settings.reportModal.show(),!1},this))};d.prototype.getSku=function(a){var b=a.currentTarget.id,c="product-";return b.substring(b.indexOf(c)+c.length)},d.prototype.resizeModal=function(){var a=$(window).height();$(".amp-modal-detail").find(".amp-content").css("max-height",a-40+"px")},amp.ImageModal=d}();