Files
Last update 2 months 4 days
by
Arnaud-Apu-Fanovard
share-button.js.téléchargementvar shareEvent=!1,pageType="unknown",strResources=null,shareLinkData=null;$(document).ready(function(){pageType=$("#share-refine-button").length>0?"refine":$("#share-pdp-button").length>0?"pdp":"unknown",strResources=pageType==="refine"?refineStrResources:pageType==="pdp"?pdpStrResources:null,InitializeSharePopover()});function InitializeSharePopover(){var n,o,t="",e=!1,s=".popover-custom";pageType==="refine"?t="#share-refine-button":pageType==="pdp"&&(t="#share-pdp-button"),pageType!=="unknown"&&(o=$("#share-refine-pdp-modal").html(),n="#custom-popover-overlay",$('[data-toggle="customPopover"]').popover({trigger:"manual",template:'<div class="popover popover-custom"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'}).off("click").on("click",function(){if($(this).attr("data-content",o),e)setTimeout(function(){$(n).fadeOut()},0),$(this).popover("hide"),e=!1;else{$(this).popover("show");var t=$(this).data("verify-user");openSharePopover(t),e=!0,setTimeout(function(){$(n).fadeIn()},0),$(s).find('button, [href], a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])').first().focus()}positionPopover($(this),pageType)}),SetShareButtonText(),$(window).on("resize",function(){SetShareButtonText(),$('[data-toggle="customPopover"]').each(function(){$(this).data("bs.popover").tip().hasClass("in")&&positionPopover($(this),pageType)})}),$(n).off("click").on("click",function(n){n.stopPropagation(),CloseSharePopover("Click Outside",t),e=!1}),$('[data-toggle="customPopover"]').on("hidden.bs.popover",function(){e=!1,$(n).fadeOut(),$(".popover-custom").is(":visible")&&$(t).focus()}),$(document).on("keydown",s,function(n){if(e){n.stopPropagation();var o,i,a,r=9,c=27;n.which===r&&(o=$(s).find('button, [href], a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),i=o.first(),a=o.last(),n.shiftKey?document.activeElement===i[0]&&(n.preventDefault(),a.focus()):document.activeElement===a[0]&&(n.preventDefault(),i.focus())),n.which===c&&CloseSharePopover("Close ESC",t)}}))}function positionPopover(e,t){var n=e.data("bs.popover").tip(),s=e.offset(),o=e.outerHeight(),i=n.outerWidth(),a=t==="refine"?-100:91;n.css({top:s.top+o+"px",left:s.left+e.outerWidth()/2-i/2+a+"px",display:"block"})}function openSharePopover(e){ResetSelectedText();var n=$(".popover-custom"),t=n.find("#share-refine-pdp-modal-copy-text");window.isShareModelGa4Enabled&&window.dataLayer.push({event:"share_modal_opened"}),ga("send","event","Share Modal","Opened","Opened"),$(" .popover-content #share-refine-pdp-modal-copy-text").val()==""&&(shareLinkData===null||shareLinkData===""?($(".popover-content .share-refine-pdp-modal-copy-button").html('<i class="fa fa-spinner fa-spin fa-md"></i>'),$.ajax({type:"GET",url:"/Search/GetSearchRefineShareLink",data:{url:window.location.href,id:e},success:function(e){e.length==0?HandleShareRefineError(!1):(HandleShareRefineError(!0),t.val(e),$(".share-refine-pdp-modal-copy-button").html(strResources.copy),shareLinkData=e),ResetSelectedText()},error:function(){HandleShareRefineError(!1)}})):t.val(shareLinkData))}function CloseSharePopover(e,t){$(".popover-custom").popover("hide"),$(t).focus();var n="Closed Without Share";shareEvent&&(n="Closed After Share"),$(".popover-content .share-refine-pdp-modal-button").hasClass("share-hide")&&(n="Closed After Error"),ga("send","event","Share Modal",n,e),ResetSelectedText(),shareEvent=!1}function HandleShareRefineError(e){e?($(".popover-content #share-refine-pdp-modal-error-message").addClass("share-hide"),$(".popover-content .share-refine-pdp-modal-button").removeClass("share-hide"),$(".popover-content .share-refine-pdp-modal-copy-text").removeClass("share-hide")):($(".popover-content #share-refine-pdp-modal-error-message").removeClass("share-hide"),$(".popover-content .share-refine-pdp-modal-button").addClass("share-hide"),$(".popover-content .share-refine-pdp-modal-copy-text").addClass("share-hide"),ga("send","event","Share Modal","Error","The link could not be generated at this time. Please try again."))}function CopyShareLink(){if($(" .popover-content #share-refine-pdp-modal-copy-button").length>0){shareEvent=!0;var e,t=$(".popover-content #share-refine-pdp-modal-copy-text");t.select(),document.execCommand("copy"),e=$(".popover-content #share-refine-pdp-modal-copy-button"),e.removeClass("btn-primary"),e.addClass("btn-buy"),e.html(strResources.Copied+' <i class="fa fa-check-circle fa-md"></i>'),e.focus(),ga("send","social","link","share",$(".popover-content #share-refine-pdp-modal-copy-text").val()),ga("send","event","Share Modal","Shared","Copy Button")}}function ResetSelectedText(){window.getSelection?window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges():document.getSelection()&&document.getSelection().empty&&document.getSelection().empty()}function SetShareButtonText(){$(".share-refine-pdp-button").length>0&&($(window).width()<=767?($(".share-refine-pdp-button").html('<i class="fa fa-share-alt fa-lg" aria-hidden="true"></i>'),$(".share-refine-pdp-button").attr("aria-label",strResources.shareText)):($(".share-refine-pdp-button").html('<i class="fa fa-share-alt fa-lg" aria-hidden="true"></i> '+strResources.shareText),$(".share-refine-pdp-button").removeAttr("aria-label"))),pageType==="pdp"&&($("#share-pdp-button").html('<i class="fa fa-share-alt fa-lg" aria-hidden="true"></i> '+strResources.shareText),$("#share-pdp-button").removeAttr("aria-label"))}