PluginProbe
Maps Plugin using Google Maps for WordPress – WP Google Map / trunk
Maps Plugin using Google Maps for WordPress – WP Google Map vtrunk
1.9.7 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 All 96 releases
gmap-embed / admin / assets / js / setup_wizard.js

setup_wizard.js in Maps Plugin using Google Maps for WordPress – WP Google Map trunk, at admin/assets/js/setup_wizard.js

208 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 "use strict";
3
4 /**
5 * Setup wizard tabs
6 */
7 function wpgmapRenderTab(wgm_step = 0) {
8 var wgm_contents = document.getElementsByClassName("wgm_setup_content"),
9 wgm_prev = document.getElementById("wgm_prev"),
10 wgm_nextElement = document.getElementById("wgm_next"),
11 wgm_saveElement = document.getElementById("wgm_save");
12
13 if (wgm_contents.length < 1) {
14 return;
15 }
16
17 wgm_contents[wgm_step].style.display = "block";
18 wgm_prev.style.display = wgm_step === 0 ? "none" : "inline";
19 wgm_nextElement.style.display = "inline";
20 wgm_saveElement.style.display = "none";
21 if (wgm_step === wgm_contents.length - 1) {
22 wgm_saveElement.style.display = "inline";
23 wgm_nextElement.style.display = "none";
24 }
25 var wgm_container = document.getElementsByClassName(
26 "wgm_setup_wizard_steps"
27 );
28 wgm_container[0].setAttribute("data-step", wgm_step);
29 }
30
31 wpgmapRenderTab(0);
32
33 /**
34 * Generating preview of final step
35 *
36 * @param api_key
37 * @param language_full_name
38 * @param regional_area_full_name
39 */
40 function wgp_generateFinalResponse(
41 api_key,
42 language_full_name,
43 regional_area_full_name
44 ) {
45 // Escape output to prevent XSS
46 $(".wgm_apikey").html("<p>" + $("<div>").text(api_key).html() + "</p>");
47 $(".wgm_language").html(
48 "<p>" + $("<div>").text(language_full_name).html() + "</p>"
49 );
50 $(".wgm_region").html(
51 "<p>" + $("<div>").text(regional_area_full_name).html() + "</p>"
52 );
53 }
54
55 /**
56 * Next | Previous button click actions
57 */
58 $(document).on("click", "#wgm_next,#wgm_skip,#wgm_prev", function (e) {
59 var wgm_container = document.getElementsByClassName(
60 "wgm_setup_wizard_steps"
61 ),
62 wgm_StepNumber = parseInt(wgm_container[0].getAttribute("data-step")),
63 wgm_contents = document.getElementsByClassName("wgm_setup_content");
64 var wgm_api_key = $("#wgm_key").val(),
65 wgm_language = $("#wgm_gmap_lng").val(),
66 wgm_language_full_name = $("#wgm_gmap_lng option:selected").text(),
67 wgm_regional_area = $("#wgm_region").val(),
68 wgm_regional_area_full_name = $("#wgm_region option:selected")
69 .text()
70 .toUpperCase();
71
72 if (e.target.id === "wgm_next" || e.target.id === "wgm_skip") {
73 if (wgm_StepNumber == 0) {
74 // Getting API key stage
75 if (wgm_api_key === "") {
76 Swal.fire({
77 icon: "warning",
78 title: wgm_l.setup_wizard.setup_validation_msg.apikey,
79 html:
80 "<a href='//www.youtube.com/watch?v=1G2VksP-uX0' target='_blank' style='text-decoration: none;'><i class='dashicons dashicons-youtube'></i> See video tutorial</a>" +
81 "&nbsp;&nbsp;&nbsp;<a href='https://wpgooglemap.com/documentation/wp-google-map-quick-installation?utm_source=gmap-embed&utm_medium=wordpress-plugin&utm_campaign=documentation&utm_content=setup-wizard-quick-install-link' target='_blank' style='text-decoration: none;' ><i class='fas fa-external-link-alt'></i> See help manual</a>",
82 });
83 return false;
84 }
85 } else if (wgm_StepNumber == 1) {
86 // Regional area stage
87 if (wgm_language === "") {
88 Swal.fire({
89 title: wgm_l.setup_wizard.setup_validation_msg.language,
90 icon: "warning",
91 });
92 return false;
93 }
94 if (wgm_regional_area === "") {
95 Swal.fire({
96 title: wgm_l.setup_wizard.setup_validation_msg.regionalarea,
97 icon: "warning",
98 });
99 return false;
100 }
101 }
102 wgp_generateFinalResponse(
103 wgm_api_key,
104 wgm_language_full_name,
105 wgm_regional_area_full_name
106 );
107 }
108 wgm_contents[wgm_StepNumber].style.display = "none";
109 wgm_StepNumber =
110 e.target.id === "wgm_prev" ? wgm_StepNumber - 1 : wgm_StepNumber + 1;
111 if (wgm_StepNumber >= wgm_contents.length) {
112 return false;
113 }
114 wpgmapRenderTab(wgm_StepNumber);
115 });
116
117 /**
118 * Save setup wizard information
119 */
120 $(document).on("click", "#wgm_save", function (e) {
121 Swal.showLoading();
122 var wgm_api_key = document.getElementById("wgm_key").value,
123 wgm_language = document.getElementById("wgm_gmap_lng").value,
124 wgm_regional_area = document.getElementById("wgm_region").value;
125 var data = {
126 action: "wpgmapembed_save_setup_wizard",
127 wgm_api_key: wgm_api_key,
128 wgm_language: wgm_language,
129 wgm_regional_area: wgm_regional_area,
130 _wpnonce: wgm_l.nonces.wpgmapembed_save_setup_wizard,
131 };
132 $.post(ajaxurl, data, function (response) {
133 try {
134 if (typeof response === "string") response = JSON.parse(response);
135 } catch (err) {
136 Swal.hideLoading();
137 console.error("WGM: Invalid setup response", err);
138 Swal.fire({
139 icon: "error",
140 title: "Unexpected server response",
141 text: "Please try again or contact support.",
142 });
143 return;
144 }
145
146 Swal.hideLoading();
147 if (response.responseCode === 101) {
148 Swal.fire({
149 icon: "error",
150 title: wgm_l.setup_wizard.setup_validation_msg.apikey,
151 });
152 return false;
153 }
154 if (response.responseCode === 102) {
155 Swal.fire({
156 icon: "error",
157 title: wgm_l.setup_wizard.setup_validation_msg.language,
158 });
159 return false;
160 }
161 if (response.responseCode === 103) {
162 Swal.fire({
163 icon: "error",
164 title: wgm_l.setup_wizard.setup_validation_msg.regionalarea,
165 });
166 return false;
167 }
168 if (response.responseCode === 200) {
169 Swal.fire({
170 icon: "success",
171 title: wgm_l.setup_wizard.setup_validation_msg.success,
172 confirmButtonText: "Let's Get Started",
173 showCloseButton: true,
174 }).then((result) => {
175 window.location.replace(
176 wgm_l.site_url.concat("/wp-admin/admin.php?page=wpgmapembed")
177 );
178 });
179 } else {
180 Swal.fire({
181 icon: "error",
182 title: wgm_l.setup_wizard.setup_validation_msg.failed_to_finish,
183 text: response.message || "",
184 });
185 return false;
186 }
187 }).fail(function (xhr, status, error) {
188 Swal.hideLoading();
189 Swal.fire({
190 icon: "error",
191 title: "Connection Error",
192 text: "Failed to communicate with the server: " + error,
193 });
194 });
195 });
196 /**
197 * What we collect modal
198 */
199 $(document).on("click", "#wgm_wwc_notice", function (e) {
200 e.preventDefault();
201 Swal.fire({
202 icon: "info",
203 title: wgm_l.setup_wizard.wgm_wwc_msg.title,
204 text: wgm_l.setup_wizard.wgm_wwc_msg.desc,
205 });
206 });
207 })(jQuery);
208