File: /home/perditaeyz/www/wp-content/plugins/jetpack/_inc/build/connect-button.min.js
/* Do not modify this file directly. It is compiled from other files. */
/* global jpConnect */
jQuery(document).ready(function(n){var e=n(".jp-connect-button, .jp-banner__alt-connect-button").eq(0),t=n(".jp-connect-full__tos-blurb"),a=n('<iframe class="jp-jetpack-connect__iframe" />'),o=n("#jetpack-connection-cards, .jp-connect-full__dismiss-paragraph, .jp-connect-full__testimonial"),i=n("#jp-authenticate-no_user_test_mode"),c="";i.hide(),e.on("click",function(e){if(e.preventDefault(),"undefined"==typeof URLSearchParams)c="";else{var t=new URLSearchParams(n(this).prop("search"));c=t&&t.get("from")}o.length&&o.fadeOut(600),r.selectAndStartConnectionFlow()});var r={isRegistering:!1,isPaidPlan:!1,selectAndStartConnectionFlow:function(){var e=n("#jetpack-connection-cards, .jp-connect-full__testimonial");e.length&&e.fadeOut(600),r.isRegistering||("original"===jpConnect.forceVariation?r.handleOriginalFlow():r.handleConnectInPlaceFlow())},handleOriginalFlow:function(){window.location=e.attr("href")},handleConnectInPlaceFlow:function(){if(e.hasClass("jp-banner__alt-connect-button")){var a=c&&"&from="+c||"";window.location=jpConnect.connectInPlaceUrl+a}else{r.isRegistering=!0,t.hide(),e.hide(),r.triggerLoadingState();var o=jpConnect.apiBaseUrl+"/connection/register";window.Initial_State&&window.Initial_State.calypsoEnv&&(o=o+"?"+n.param({calypso_env:window.Initial_State.calypsoEnv})),n.ajax({url:o,type:"POST",data:{registration_nonce:jpConnect.registrationNonce,_wpnonce:jpConnect.apiNonce},error:r.handleConnectionError,success:r.handleConnectionSuccess})}},triggerLoadingState:function(){var e=n("<span>").addClass("jp-connect-full__button-container-loading").text(jpConnect.buttonTextRegistering).appendTo(".jp-connect-full__button-container"),t=n("<div>").addClass("jp-spinner"),a=n("<div>").addClass("jp-spinner__outer").appendTo(t);n("<div>").addClass("jp-spinner__inner").appendTo(a),e.after(t)},handleConnectionSuccess:function(e){window.addEventListener("message",r.receiveData),a.attr("src",e.authorizeUrl+"&from="+c),a.on("load",function(){a.show(),n(".jp-connect-full__button-container").hide(),i.show()}),a.hide(),n(".jp-connect-full__button-container").after(a);var t=document.createElement("link");t.rel="preload",t.as="script",t.href=jpConnect.preFetchScript,document.head.appendChild(t)},fetchPlanType:function(){return n.ajax({url:jpConnect.apiBaseUrl+"/site",type:"GET",data:{_wpnonce:jpConnect.apiSiteDataNonce},success:function(n){var e=JSON.parse(n.data);r.isPaidPlan=e.options.is_pending_plan||!e.plan.is_free}})},receiveData:function(n){if(n.origin===jpConnect.jetpackApiDomain&&n.source===a.get(0).contentWindow)switch(n.data){case"close":window.removeEventListener("message",this.receiveData),r.handleAuthorizationComplete();break;case"wpcom_nocookie":a.hide(),r.handleConnectionError()}},handleAuthorizationComplete:function(){r.isRegistering=!1,
// Fetch plan type late to make sure any stored license keys have been
// attached to the site during the connection.
r.fetchPlanType().always(function(){if(r.isPaidPlan){var n=document.createElement("a");n.href=jpConnect.dashboardUrl;var e=window.location.pathname===n.pathname&&window.location.hash.length&&n.hash.length;window.location.assign(jpConnect.dashboardUrl),e&&window.location.reload(!0)}else window.location.assign(jpConnect.plansPromptUrl)})},handleConnectionError:function(n){r.isRegistering=!1,r.handleOriginalFlow()}},l=location.hash.replace(/(#\/setup).*/,"setup");c=location.hash.split("&from=")[1],"setup"===l&&(o.length&&o.hide(),r.selectAndStartConnectionFlow())});