PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 149
Lasso Lite – Affiliate Link Manager & Product Displays v149
158 157 155 156 154 153 152 151 150 149 148 trunk 0.9.9 104 105 106 107 108 109 110 111 112 113 114 115 All 57 releases
simple-urls / admin / assets / js / support.js

support.js in Lasso Lite – Affiliate Link Manager & Product Displays 149, at admin/assets/js/support.js

228 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function () {
2 setTimeout(function () {
3 jQuery("#fake-intercom-bubble-chat").css("opacity", 1);
4 jQuery("#support-launcher").css("opacity", 1);
5 }, 2000);
6
7 jQuery(document)
8 .on("click", "#enable-support-wrapper .dismiss", function () {
9 jQuery("#enable-support").modal("hide");
10 lasso_lite_helper.set_local_storage(
11 "lasso_lite_should_open_support_modal",
12 0
13 );
14 })
15 .on("change", "#enable-support-wrapper #share_diagnostics", save_support)
16 .on("click", "#btn-connect-for-free", save_support)
17 .on("click", "#fake-intercom-bubble-chat", function () {
18 jQuery("#enable-support").modal("show");
19 })
20 .on("click", "#support-launcher", support_launcher)
21 .on("click", "#flow-confirm-button", customer_flow_confirm)
22 .on(
23 "click",
24 "#customer-flow-confirm .no-thanks-button",
25 customer_flow_no_thanks
26 )
27 .on("click", "#customer-flow .support-option", intercom_support)
28 .on("click", "#connect-to-lasso", function (event) {
29 event.stopPropagation();
30 jQuery("#enable-support").modal("show");
31 })
32 .ready(function () {
33 update_support();
34 });
35
36 function save_support(e) {
37 let btn_save = jQuery("#btn-connect-for-free");
38 let originalLabel = btn_save.text().trim();
39 let js_error = jQuery("#enable-support-wrapper .js-error");
40 let email_input = jQuery("#enable-support-wrapper #email");
41 let triggered_by_button = e && jQuery(e.target).is("#btn-connect-for-free");
42 let email =
43 email_input && email_input.length > 0
44 ? email_input.val().trim()
45 : "";
46 let is_subscribe = jQuery("#enable-support-wrapper #subscribe").prop(
47 "checked"
48 );
49 let share_diagnostics = 1;
50 let triggered_by_email =
51 e && jQuery(e.target).is("#enable-support-wrapper #email");
52
53 let is_onboarding = "surl-onboarding" === lasso_lite_helper.get_page_name();
54 let should_advance = is_onboarding && !triggered_by_email;
55 jQuery
56 .ajax({
57 url: lassoLiteOptionsData.ajax_url,
58 type: "post",
59 data: {
60 action: "lasso_lite_save_support",
61 nonce: lassoLiteOptionsData.optionsNonce,
62 email: email,
63 is_subscribe: is_subscribe,
64 share_diagnostics: share_diagnostics,
65 },
66 beforeSend: function () {
67 jQuery("#enable-support-wrapper #email").removeClass(
68 "invalid-field"
69 );
70 js_error.css("display", "none");
71 // Show loading when proceeding via button click or onboarding flow
72 if (should_advance || triggered_by_button) {
73 lasso_lite_helper.add_loading_button(btn_save);
74 }
75 },
76 })
77 .done(function (res) {
78 lasso_lite_helper.add_loading_button(
79 btn_save,
80 originalLabel,
81 false
82 );
83 let data = res.data;
84 if (data.success) {
85 jQuery("#enable-support").modal("hide");
86
87 // Auto open customization display helper after enabling support
88 if (
89 "undefined" !==
90 typeof window.need_more_customization_flag
91 ) {
92 lasso_lite_helper.set_local_storage(
93 "lasso_lite_open_need_more_customization",
94 1
95 );
96 }
97
98 // Go to next step if we are in Welcome page
99 if (should_advance) {
100 go_to_next_step_action(btn_save);
101 } else if (!triggered_by_email) {
102 // Reuse global bootstrap from footer
103 try {
104 if (res && res.data && res.data.intercom && typeof window.lassoInitIntercom === "function") {
105 var p = res.data.intercom;
106 var intercomParams = {
107 app_id: p.app_id,
108 name: p.name,
109 email: p.email,
110 lasso_version: parseInt(p.lasso_version),
111 classic_editor: !!p.classic_editor,
112 wp_admin_url: p.wp_admin_url,
113 lasso_lite_user: !!p.lasso_lite_user,
114 intercom_user_jwt: p.intercom_user_jwt
115 };
116 window.lassoInitIntercom(intercomParams, { show: true });
117 jQuery("#support-launcher").hide();
118 jQuery("#fake-intercom-bubble-chat").hide();
119 } else if (typeof window.Intercom === "function") {
120 window.Intercom("show");
121 jQuery("#support-launcher").hide();
122 jQuery("#fake-intercom-bubble-chat").hide();
123 }
124 } catch (e) {}
125 }
126 } else {
127 if (should_advance) {
128 // Don't block onboarding when email is invalid/blank
129 go_to_next_step_action(btn_save);
130 } else {
131 jQuery("#enable-support-wrapper #email").addClass(
132 "invalid-field"
133 );
134 js_error.text(data.msg);
135 js_error.css("display", "block");
136 }
137 }
138 });
139 }
140
141 function update_support() {
142 jQuery('input[name="enable_support"]').change(
143 lasso_lite_helper.debounce(
144 function (e) {
145 let enable_support = jQuery(
146 'input[name="enable_support"]'
147 ).prop("checked");
148 jQuery.ajax({
149 url: lassoLiteOptionsData.ajax_url,
150 type: "post",
151 data: {
152 action: "lasso_lite_update_support",
153 nonce: lassoLiteOptionsData.optionsNonce,
154 enable_support: enable_support,
155 },
156 });
157 },
158 1000,
159 null,
160 true
161 )
162 );
163 }
164
165 function support_launcher() {
166 jQuery('#enable-support').modal('show');
167 }
168
169 function customer_flow_confirm() {
170 let $customer_flow_confirm_btn = jQuery("#flow-confirm-button");
171 let customer_flow_confirm = 1;
172
173 jQuery
174 .ajax({
175 url: lassoLiteOptionsData.ajax_url,
176 type: "post",
177 data: {
178 action: "lasso_lite_update_customer_flow_enabled",
179 nonce: lassoLiteOptionsData.optionsNonce,
180 customer_flow_enabled: customer_flow_confirm,
181 },
182 beforeSend: function () {
183 $customer_flow_confirm_btn.html(
184 lasso_lite_helper.get_loading_image_small()
185 );
186 },
187 })
188 .done(function (res) {
189 if (res.success) {
190 jQuery("#customer-flow").data(
191 "customer-flow-enabled",
192 customer_flow_confirm
193 );
194 jQuery("#customer-flow-confirm").modal("hide");
195 Intercom("show");
196 }
197 });
198 }
199
200 function customer_flow_no_thanks() {
201 let $el_support_launcher = jQuery("#support-launcher");
202
203 jQuery("#support-launcher .icon-default").css({
204 transform: "rotate(0deg) scale(1)",
205 opacity: "1",
206 });
207 jQuery("#support-launcher .icon-close").css({
208 transform: "rotate(-180deg) scale(.5)",
209 opacity: "0",
210 });
211 jQuery(".support-wrap").css({ opacity: 0, height: "0" });
212 $el_support_launcher.data("active", false);
213 }
214
215 function intercom_support() {
216 let customer_flow_enabled = jQuery("#customer-flow").data(
217 "customer-flow-enabled"
218 );
219
220 if (!customer_flow_enabled) {
221 jQuery("#customer-flow-confirm").modal("show");
222 } else {
223 Intercom("show");
224 jQuery(".support-wrap").css({ opacity: 0, height: "0" });
225 }
226 }
227 });
228