summaryrefslogtreecommitdiff
blob: 1cfe3962e8fae2282705808de3eb8342ae52d132 (plain)
1
2
3
/* 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"),o=n('<iframe class="jp-jetpack-connect__iframe" />'),a=n("#jetpack-connection-cards, .jp-connect-full__dismiss-paragraph");e.on("click",function(n){n.preventDefault(),a.length&&a.fadeOut(600),i.selectAndStartConnectionFlow()});var i={isRegistering:!1,isPaidPlan:!1,selectAndStartConnectionFlow:function(){var e=n("#jetpack-connection-cards");e.length&&e.fadeOut(600),i.isRegistering||("original"===jpConnect.forceVariation?i.handleOriginalFlow():"in_place"===jpConnect.forceVariation?i.handleConnectInPlaceFlow():i.startConnectionFlow())},startConnectionFlow:function(){n.ajax({url:"https://public-api.wordpress.com/wpcom/v2/abtest/jetpack_connect_in_place_v3",type:"GET",error:i.handleConnectionError,data:jpConnect.identity,xhrFields:{withCredentials:!0},crossDomain:!0,success:function(n){n&&"in_place"===n.variation?i.handleConnectInPlaceFlow():i.handleOriginalFlow()}})},handleOriginalFlow:function(){window.location=e.attr("href")},handleConnectInPlaceFlow:function(){if(e.hasClass("jp-banner__alt-connect-button"))window.location=jpConnect.connectInPlaceUrl;else{i.isRegistering=!0,t.hide(),e.hide(),i.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:i.handleConnectionError,success:i.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"),o=n("<div>").addClass("jp-spinner__outer").appendTo(t);n("<div>").addClass("jp-spinner__inner").appendTo(o),e.after(t)},handleConnectionSuccess:function(e){i.fetchPlanType(),window.addEventListener("message",i.receiveData),o.attr("src",e.authorizeUrl),o.on("load",function(){o.show(),n(".jp-connect-full__button-container").hide()}),o.hide(),n(".jp-connect-full__button-container").after(o)},fetchPlanType:function(){n.ajax({url:jpConnect.apiBaseUrl+"/site",type:"GET",data:{_wpnonce:jpConnect.apiSiteDataNonce},success:function(n){var e=JSON.parse(n.data);i.isPaidPlan=!e.plan.is_free}})},receiveData:function(n){n.origin===jpConnect.jetpackApiDomain&&n.source===o.get(0).contentWindow&&"close"===n.data&&(window.removeEventListener("message",this.receiveData),i.handleAuthorizationComplete())},handleAuthorizationComplete:function(){i.isRegistering=!1,i.isPaidPlan?window.location.assign(jpConnect.dashboardUrl):window.location.assign(jpConnect.plansPromptUrl),window.location.reload(!0)},handleConnectionError:function(n){i.isRegistering=!1,i.handleOriginalFlow()}};"setup"===location.hash.replace(/#\//,"")&&(a.length&&a.hide(),i.selectAndStartConnectionFlow())});