PluginProbe ʕ •ᴥ•ʔ
Rich Showcase for Google Reviews / 6.4
Rich Showcase for Google Reviews v6.4
6.9.8 6.9.7 6.9.6 trunk 1.4 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.5 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.7 1.6.8 1.6.9 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.4 2.4.1 2.4.2 2.5 2.5.1 2.6 2.6.1 2.6.2 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.6.1 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.8.1 4.8.2 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.7.1 5.8 5.9 5.9.1 5.9.2 5.9.3 5.9.7 6.0 6.1 6.2 6.3 6.4 6.4.1 6.5 6.6 6.6.1 6.6.2 6.7 6.8 6.8.1 6.8.2 6.9 6.9.1 6.9.2 6.9.3 6.9.4 6.9.4.1 6.9.4.2 6.9.4.3 6.9.4.4 6.9.5
widget-google-reviews / assets / src / js / admin-builder.js
widget-google-reviews / assets / src / js Last commit date
admin-apexcharts.js 3 years ago admin-builder.js 10 months ago admin-main.js 1 year ago public-main.js 1 year ago
admin-builder.js
1479 lines
1 const GRW_AUTOSAVE_KEYUP_TIMEOUT = 1500;
2 var GRW_AUTOSAVE_TIMEOUT = null;
3
4 const GRW_LANGS = [
5 ['ar', 'Arabic'],
6 ['bg', 'Bulgarian'],
7 ['bn', 'Bengali'],
8 ['ca', 'Catalan'],
9 ['cs', 'Czech'],
10 ['da', 'Danish'],
11 ['de', 'German'],
12 ['el', 'Greek'],
13 ['en', 'English'],
14 ['es', 'Spanish'],
15 ['eu', 'Basque'],
16 ['eu', 'Basque'],
17 ['fa', 'Farsi'],
18 ['fi', 'Finnish'],
19 ['fil', 'Filipino'],
20 ['fr', 'French'],
21 ['gl', 'Galician'],
22 ['gu', 'Gujarati'],
23 ['hi', 'Hindi'],
24 ['hr', 'Croatian'],
25 ['hu', 'Hungarian'],
26 ['id', 'Indonesian'],
27 ['it', 'Italian'],
28 ['iw', 'Hebrew'],
29 ['ja', 'Japanese'],
30 ['kn', 'Kannada'],
31 ['ko', 'Korean'],
32 ['lt', 'Lithuanian'],
33 ['lv', 'Latvian'],
34 ['ml', 'Malayalam'],
35 ['mr', 'Marathi'],
36 ['nl', 'Dutch'],
37 ['no', 'Norwegian'],
38 ['pl', 'Polish'],
39 ['pt', 'Portuguese'],
40 ['pt-BR', 'Portuguese (Brazil)'],
41 ['pt-PT', 'Portuguese (Portugal)'],
42 ['ro', 'Romanian'],
43 ['ru', 'Russian'],
44 ['sk', 'Slovak'],
45 ['sl', 'Slovenian'],
46 ['sr', 'Serbian'],
47 ['sv', 'Swedish'],
48 ['ta', 'Tamil'],
49 ['te', 'Telugu'],
50 ['th', 'Thai'],
51 ['tl', 'Tagalog'],
52 ['tr', 'Turkish'],
53 ['uk', 'Ukrainian'],
54 ['vi', 'Vietnamese'],
55 ['zh', 'Chinese (Simplified)'],
56 ['zh-Hant', 'Chinese (Traditional)']
57 ];
58
59 const GRW_HTML_CONTENT =
60
61 '<div class="grw-builder-platforms grw-builder-inside">' +
62
63 '<div class="grw-builder-connect grw-connect-google">Connect Google</div>' +
64 '<div id="grw-connect-wizard" title="Google reviews" style="display:none;">{{wizard}}</div>' +
65 '<div class="grw-connections"></div>' +
66 '</div>' +
67
68 '<div class="grw-connect-options">' +
69
70 '<div class="grw-builder-inside">' +
71
72 '<div class="grw-builder-option">' +
73 'Layout' +
74 '<select id="view_mode" name="view_mode">' +
75 '<option value="slider" selected="selected">Slider</option>' +
76 '<option value="grid">Grid</option>' +
77 '<option value="list">List</option>' +
78 '<option value="rating">Rating</option>' +
79 '</select>' +
80 '</div>' +
81
82 '</div>' +
83
84 /* Common Options */
85 '<div class="grw-builder-top grw-toggle">Common Options</div>' +
86 '<div class="grw-builder-inside" style="display:none">' +
87 '<div class="grw-builder-option">' +
88 'Pagination' +
89 '<input type="text" name="pagination" value="">' +
90 '</div>' +
91 '<div class="grw-builder-option">' +
92 'Maximum characters before \'read more\' link' +
93 '<input type="text" name="text_size" value="">' +
94 '</div>' +
95 '<div class="grw-builder-option">' +
96 '<label>' +
97 '<input type="checkbox" name="header_center" value="">' +
98 'Show rating by center' +
99 '</label>' +
100 '</div>' +
101 '<div class="grw-builder-option">' +
102 '<label>' +
103 '<input type="checkbox" name="header_hide_photo" value="">' +
104 'Hide business photo' +
105 '</label>' +
106 '</div>' +
107 '<div class="grw-builder-option">' +
108 '<label>' +
109 '<input type="checkbox" name="header_hide_name" value="">' +
110 'Hide business name' +
111 '</label>' +
112 '</div>' +
113 '<div class="grw-builder-option">' +
114 '<label>' +
115 '<input type="checkbox" name="hide_based_on" value="">' +
116 'Hide \'Based on ... reviews\'' +
117 '</label>' +
118 '</div>' +
119 '<div class="grw-builder-option">' +
120 '<label>' +
121 '<input type="checkbox" name="hide_writereview" value="">' +
122 'Hide \'review us on G\' button' +
123 '</label>' +
124 '</div>' +
125 '<div class="grw-builder-option">' +
126 '<label>' +
127 '<input type="checkbox" name="short_last_name" value="">' +
128 'Short last name (GDPR)' +
129 '</label>' +
130 '<span class="grw-quest grw-quest-top grw-toggle" title="Click to help">?</span>' +
131 '<div class="grw-quest-help" style="display:none;">Show only first name and first letter of last name</div>' +
132 '</div>' +
133 '<div class="grw-builder-option">' +
134 '<label>' +
135 '<input type="checkbox" name="min_letter" value="">' +
136 'Hide reviews without text' +
137 '</label>' +
138 '</div>' +
139 '<div class="grw-builder-option">' +
140 '<label>' +
141 '<input type="checkbox" name="media" value="" checked>' +
142 'Show review images' +
143 '</label>' +
144 '</div>' +
145 '<div class="grw-builder-option">' +
146 '<label>' +
147 '<input type="checkbox" name="reply" value="" checked>' +
148 'Show owner responses' +
149 '</label>' +
150 '</div>' +
151 '<div class="grw-builder-option">' +
152 '<label>' +
153 '<input type="checkbox" name="header_hide_social" value="">' +
154 'Hide rating header, leave only reviews' +
155 '</label>' +
156 '</div>' +
157 '<div class="grw-builder-option">' +
158 '<label>' +
159 '<input type="checkbox" name="hide_reviews" value="">' +
160 'Hide reviews, leave only rating header' +
161 '</label>' +
162 '</div>' +
163 '</div>' +
164
165 /* Slider Options */
166 '<div class="grw-builder-top grw-toggle">Slider Options</div>' +
167 '<div class="grw-builder-inside" style="display:none">' +
168 '<div class="grw-builder-option">' +
169 'Speed in second' +
170 '<input type="text" name="slider_speed" value="" placeholder="Default: 3">' +
171 '</div>' +
172 '<div class="grw-builder-option">' +
173 'Text height' +
174 '<input type="text" name="slider_text_height" value="" placeholder="Default: 100px">' +
175 '</div>' +
176 '<div class="grw-builder-option">' +
177 '<label>' +
178 '<input type="checkbox" name="slider_autoplay" value="" checked>' +
179 'Auto-play' +
180 '</label>' +
181 '</div>' +
182 '<div class="grw-builder-option">' +
183 '<label>' +
184 '<input type="checkbox" name="slider_mousestop" value="" checked>' +
185 'Stop auto play on mouse over' +
186 '</label>' +
187 '</div>' +
188 '<div class="grw-builder-option">' +
189 '<label>' +
190 '<input type="checkbox" name="slider_hide_prevnext" value="">' +
191 'Hide prev & next buttons' +
192 '</label>' +
193 '</div>' +
194 '<div class="grw-builder-option">' +
195 '<label>' +
196 '<input type="checkbox" name="slider_hide_dots" value="">' +
197 'Hide dots' +
198 '</label>' +
199 '</div>' +
200 '</div>' +
201
202 /* Breakpoints */
203 '<div class="grw-builder-top grw-toggle">Column Options</div>' +
204 '<div class="grw-builder-inside" style="display:none">' +
205 '<div class="grw-builder-option">' +
206 '<input type="hidden" name="slider_breakpoints">' +
207 '<label>' +
208 'How many columns to show (for Slider & Grid)' +
209 '</label>' +
210 '<div class="grw-slider-br">' +
211 '<label>' +
212 '<select>' +
213 '<option value="off">Disable</option>' +
214 '<option value="3000">Large Desktop & TV</option>' +
215 '<option value="1200">Desktop</option>' +
216 '<option value="1024">Laptop</option>' +
217 '<option value="768">Table</option>' +
218 '<option value="480">Mobile</option>' +
219 '<option value="">Custom</option>' +
220 '</select>' +
221 '</label>' +
222 '<label>' +
223 '<input type="range" name="" value="3" min="1" max="12" step="1" oninput="this.nextSibling.innerHTML=this.value"/><span></span>' +
224 '</label>' +
225 '<span class="grw-quest" title="Click to add new breakpoints">+</span>' +
226 '</div>' +
227 '</div>' +
228 '</div>' +
229
230 /* Style Options */
231 '<div class="grw-builder-top grw-toggle">Style Options</div>' +
232 '<div class="grw-builder-inside" style="display:none">' +
233 '<div class="grw-builder-option">' +
234 '<input type="color" name="--star-color" value="#fb8e28" data-val="#fb8e28" data-defval="#fb8e28"/>' +
235 '<input type="text" value="#fb8e28"/>' +
236 'Stars color' +
237 '</div>' +
238 '<div class="grw-builder-option">' +
239 '<input type="color" name="--head-name-color" value="#333333" data-val="#333333" data-defval="#333333"/>' +
240 '<input type="text" value="#333333"/>' +
241 'Business name color' +
242 '</div>' +
243 '<div class="grw-builder-option">' +
244 '<input type="color" name="--head-based-color" value="#555555" data-val="#555555" data-defval="#555555"/>' +
245 '<input type="text" value="#555555"/>' +
246 'Based on color' +
247 '</div>' +
248 '<div class="grw-builder-option">' +
249 '<input type="color" name="--powered-color" value="#777777" data-val="#777777" data-defval="#777777"/>' +
250 '<input type="text" value="#777777"/>' +
251 'Powered color' +
252 '</div>' +
253 '<div class="grw-builder-option">' +
254 '<input type="color" name="--btn-color" value="#1f67e7" data-val="#1f67e7" data-defval="#1f67e7"/>' +
255 '<input type="text" value="#1f67e7"/>' +
256 'Button color' +
257 '</div>' +
258 '<div class="grw-builder-option">' +
259 '<input type="color" name="--rev-color" value="#fafafa" data-val="#fafafa" data-defval="#fafafa"/>' +
260 '<input type="text" value="#fafafa"/>' +
261 'Reviews color' +
262 '</div>' +
263 '<div class="grw-builder-option">' +
264 '<input type="color" name="--name-color" value="#154fc1" data-val="#154fc1" data-defval="#154fc1"/>' +
265 '<input type="text" value="#154fc1"/>' +
266 'Review author name color' +
267 '</div>' +
268 '<div class="grw-builder-option">' +
269 '<input type="color" name="--text-color" value="#222222" data-val="#222222" data-defval="#222222"/>' +
270 '<input type="text" value="#222222"/>' +
271 'Reviews text color' +
272 '</div>' +
273 '<div class="grw-builder-option">' +
274 '<a href="javascript:void(0)" onclick="stylereset(this.parentNode.parentNode);grw_serialize_connections()">' +
275 'Reset to default style' +
276 '</a>' +
277 '</div>' +
278 '<div class="grw-builder-option">' +
279 '<label>' +
280 '<input type="checkbox" name="dark_theme">' +
281 'Dark background' +
282 '</label>' +
283 '</div>' +
284 '<div class="grw-builder-option">' +
285 '<label>' +
286 '<input type="checkbox" name="hide_backgnd" value="">' +
287 'Hide reviews background' +
288 '</label>' +
289 '</div>' +
290 '<div class="grw-builder-option">' +
291 '<label>' +
292 '<input type="checkbox" name="show_round" value="">' +
293 'Round reviews borders' +
294 '</label>' +
295 '</div>' +
296 '<div class="grw-builder-option">' +
297 '<label>' +
298 '<input type="checkbox" name="show_shadow" value="">' +
299 'Show reviews shadow' +
300 '</label>' +
301 '</div>' +
302 '<div class="grw-builder-option">' +
303 '<label>' +
304 '<input type="checkbox" name="centered" value="">' +
305 'Place by center (only if max-width is set)' +
306 '</label>' +
307 '</div>' +
308 '<div class="grw-builder-option">' +
309 'Container max-width' +
310 '<input type="text" name="max_width" value="" placeholder="for instance: 300px">' +
311 '<small>Be careful: this will make reviews unresponsive</small>' +
312 '</div>' +
313 '<div class="grw-builder-option">' +
314 'Container max-height' +
315 '<input type="text" name="max_height" value="" placeholder="for instance: 500px">' +
316 '</div>' +
317 '<input id="style_vars" name="style_vars" type="hidden"/>' +
318 '</div>' +
319
320 /* Advance Options */
321 '<div class="grw-builder-top grw-toggle">Advance Options</div>' +
322 '<div class="grw-builder-inside" style="display:none">' +
323 '<div class="grw-builder-option">' +
324 '<label>' +
325 '<input type="checkbox" name="lazy_load_img" checked>' +
326 'Lazy load images' +
327 '</label>' +
328 '</div>' +
329 '<div class="grw-builder-option">' +
330 '<label>' +
331 '<input type="checkbox" name="google_def_rev_link">' +
332 'Use default Google reviews link' +
333 '</label>' +
334 '<span class="grw-quest grw-quest-top grw-toggle" title="Click to help">?</span>' +
335 '<div class="grw-quest-help" style="display:none;">If the direct link to all reviews <b>https://search.google.com/local/reviews?placeid=&lt;PLACE_ID&gt;</b> does not work with your Google place (leads to 404), please use this option to use the default reviews link to Google map.</div>' +
336 '</div>' +
337 '<div class="grw-builder-option">' +
338 '<label>' +
339 '<input type="checkbox" name="open_link" checked>' +
340 'Open links in new Window' +
341 '</label>' +
342 '</div>' +
343 '<div class="grw-builder-option">' +
344 '<label>' +
345 '<input type="checkbox" name="nofollow_link" checked>' +
346 'Use no follow links' +
347 '</label>' +
348 '</div>' +
349 '<div class="grw-builder-option">' +
350 '<label>' +
351 '<input type="checkbox" name="aria_label">' +
352 'Enable ARIA label for screen readers' +
353 '</label>' +
354 '</div>' +
355 '<div class="grw-builder-option">' +
356 'Reviewer avatar size' +
357 '<select name="reviewer_avatar_size">' +
358 '<option value="56" selected="selected">Small: 56px</option>' +
359 '<option value="128">Medium: 128px</option>' +
360 '<option value="256">Large: 256px</option>' +
361 '</select>' +
362 '</div>' +
363 '<div class="grw-builder-option">' +
364 'Cache data' +
365 '<select name="cache">' +
366 '<option value="1">1 Hour</option>' +
367 '<option value="3">3 Hours</option>' +
368 '<option value="6">6 Hours</option>' +
369 '<option value="12" selected="selected">12 Hours</option>' +
370 '<option value="24">1 Day</option>' +
371 '<option value="48">2 Days</option>' +
372 '<option value="168">1 Week</option>' +
373 '<option value="">Disable (NOT recommended)</option>' +
374 '</select>' +
375 '</div>' +
376 '<div class="grw-builder-option">' +
377 'Reviews limit' +
378 '<input type="text" name="reviews_limit" value="">' +
379 '</div>' +
380 '</div>' +
381
382 '</div>';
383
384 const GRW_WIZARD =
385 '<iframe id="gpidc" src="https://app.richplugins.com/gpidc?authcode={{authcode}}&lang={{lang}}" style="width:100%;height:400px"></iframe>' +
386 '<small class="grw-connect-error"></small>';
387
388 const GRW_WIZARD2 =
389 '<div style="width:100%;height:400px">' +
390 '<h3>Connection Wizard</h3>' +
391 '<p>Please start typing your business name or address in the search field below.<br>Alternatively, you can paste your Google Place ID if you know it.</p>' +
392 '<div style="position:relative">' +
393 '<input id="grw_place_autocomplete" type="text" placeholder="Start typing here your business place address and name" autofocus/>' +
394 '<svg id="grw_place_spin_svg" style="display:none" viewBox="0 0 16 16"><path fill="#999999" d="M12.9 3.1c1.3 1.2 2.1 3 2.1 4.9 0 3.9-3.1 7-7 7s-7-3.1-7-7c0-1.9 0.8-3.7 2.1-4.9l-0.8-0.8c-1.4 1.5-2.3 3.5-2.3 5.7 0 4.4 3.6 8 8 8s8-3.6 8-8c0-2.2-0.9-4.2-2.3-5.7l-0.8 0.8z"/></svg>' +
395 '<ul id="grw_place_list" role="listbox"></ul>' +
396 '</div>' +
397 '<div id="grw_place" style="display:none;margin-top:12px">' +
398 '<div class="wp-google-place" style="display:flex;align-items:center;gap:16px;flex-wrap:wrap">' +
399 '<div class="wp-google-left">' +
400 '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="g business img" width="50" height="50" title="g business img" style="border-radius:50%">' +
401 '</div>' +
402 '<div class="wp-google-right">' +
403 '<b class="wp-google-name"></b>' +
404 '<div style="display:flex;align-items:center;gap:2px">' +
405 '<span class="wp-google-rating"></span>' +
406 '<svg width="17" height="17" viewBox="0 0 1792 1792"><path d="M1728 647q0 22-26 48l-363 354 86 500q1 7 1 20 0 21-10.5 35.5t-30.5 14.5q-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z" fill="#fb8e28"></path></svg>' +
407 '<svg width="17" height="17" viewBox="0 0 1792 1792"><path d="M1728 647q0 22-26 48l-363 354 86 500q1 7 1 20 0 21-10.5 35.5t-30.5 14.5q-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z" fill="#fb8e28"></path></svg>' +
408 '<svg width="17" height="17" viewBox="0 0 1792 1792"><path d="M1728 647q0 22-26 48l-363 354 86 500q1 7 1 20 0 21-10.5 35.5t-30.5 14.5q-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z" fill="#fb8e28"></path></svg>' +
409 '<svg width="17" height="17" viewBox="0 0 1792 1792"><path d="M1728 647q0 22-26 48l-363 354 86 500q1 7 1 20 0 21-10.5 35.5t-30.5 14.5q-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z" fill="#fb8e28"></path></svg>' +
410 '<svg width="17" height="17" viewBox="0 0 1792 1792"><path d="M1728 647q0 22-26 48l-363 354 86 500q1 7 1 20 0 21-10.5 35.5t-30.5 14.5q-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z" fill="#fb8e28"></path></svg>' +
411 '</div>' +
412 '<small class="wp-google-powered">Based on <span class="wp-google-based"></span> reviews</small>' +
413 '</div>' +
414 '<select id="grw_place_lang"></select>' +
415 '<button id="grw_place_btn">Connect</button>' +
416 '</div>' +
417 '</div>' +
418 '<p id="grw_place_error" class="grw-connect-error"></p>' +
419 '</div>';
420
421 function grw_stylechange2(target) {
422 let rp = document.getElementsByClassName('wp-gr')[0];
423
424 if (target.type == 'range' || target.type == 'color') {
425 let val = target.value + (target.getAttribute('data-postfix') || '');
426 target.setAttribute('data-val', val);
427 rp.style.setProperty(target.name, val);
428
429 // if color input put color to the next text input
430 if (target.type == 'color') {
431 target.nextSibling.value = val;
432 }
433 } else if (target.type == 'checkbox' || target.type == 'radio') {
434 let vars = target.getAttribute('data-vars');
435 if (vars) {
436 let arr = vars.split(';');
437 for (let i = 0; i < arr.length; i++) {
438 let pair = arr[i].split(':');
439 if (pair.length > 1) {
440 if (target.checked) {
441 let val = pair[1].trim();
442 rp.style.setProperty(pair[0].trim(), pair[1].trim());
443 } else {
444 rp.style.removeProperty(pair[0].trim());
445 }
446 }
447 }
448 }
449 if (target.checked) {
450 rp.style.setProperty(target.name, target.getAttribute('data-on'));
451 } else if (target.getAttribute('data-off')) {
452 rp.style.setProperty(target.name, target.getAttribute('data-off'));
453 } else {
454 rp.style.removeProperty(target.name);
455 }
456 }
457
458 let style = rp.getAttribute('style'),
459 cssvars = style.match(/(--[a-z]+(-[a-z]+)*:\s*[#0-9a-z]+\s*;)+/g);
460
461 if (cssvars && cssvars.length) {
462 window.style_vars.value = cssvars.join('');
463 }
464 }
465
466 function stylereset(parentEl, style_var) {
467 let rp = document.getElementsByClassName('wp-gr')[0];
468 if (rp) {
469 let inputs = (parentEl ? parentEl : document).querySelectorAll('input[name^="--"]');
470
471 for (let i = 0; i < inputs.length; i++) {
472 let defval = inputs[i].getAttribute('data-defval'),
473 pf = inputs[i].getAttribute('data-postfix') || '',
474 val = inputs[i].value + pf;
475
476 inputs[i].value = defval;
477 inputs[i].setAttribute('data-val', defval + pf);
478
479 // if color input put color to the next text input
480 if (inputs[i].type == 'color') {
481 inputs[i].nextSibling.value = defval + pf;
482 } else if (inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
483 let vars = inputs[i].getAttribute('data-vars');
484 if (vars) {
485 let arr = vars.split(';');
486 for (let i = 0; i < arr.length; i++) {
487 let pair = arr[i].split(':');
488 rp.style.removeProperty(pair[0].trim());
489 }
490 }
491 inputs[i].checked = inputs[i].getAttribute('data-checked') == '1';
492 }
493 rp.style.removeProperty(inputs[i].name);
494 }
495 window.style_vars.value = rp.getAttribute('style');
496 }
497 }
498
499 function grw_builder_init($, data) {
500
501 var el = document.querySelector(data.el);
502 if (!el) return;
503
504 el.innerHTML = GRW_HTML_CONTENT.replace('{{wizard}}',
505 data.key ? GRW_WIZARD2 : GRW_WIZARD.replace('{{authcode}}', data.authcode).replace('{{lang}}', GRW_VARS.lang));
506
507 var $connect_wizard_el = $('#grw-connect-wizard');
508
509 if (data.conns && data.conns.connections && data.conns.connections.length) {
510 grw_deserialize_connections($, el, data);
511 } else {
512 $('.grw-connect-google').hide();
513 $connect_wizard_el.dialog({
514 modal: false,
515 width: '50%',
516 maxWidth: '600px',
517 closeOnEscape: false,
518 open: function() { $(".ui-dialog-titlebar-close").hide() }
519 });
520 }
521
522 // GPIDC
523 window.onmessage = function(e) {
524 if (e.origin !== 'https://app.richplugins.com') return;
525 if (e.data) {
526 let gdata = e.data;
527 switch (gdata.action) {
528 case 'get_place':
529 $.post(ajaxurl, {
530 pid : gdata.pid,
531 token : gdata.token,
532 action : 'grw_get_place',
533 grw_nonce : jQuery('#grw_nonce').val()
534 }, function(res) {
535 if (res.status == 'success') {
536 res.result.place_id = gdata.pid;
537 window.gpidc.contentWindow.postMessage({data: res, action: 'set_place'}, '*');
538 } else {
539 grw_connect_error($, grw_get_error(res));
540 }
541 });
542 break;
543 case 'connect':
544 grw_connect_ajax($, el, gdata, data.authcode, 1);
545 break;
546 }
547 }
548 };
549
550 // Init slider breakpoints
551 grw_sbs_init();
552
553 $('.grw-connect-options input[type="text"],.grw-connect-options textarea').keyup(function() {
554 clearTimeout(GRW_AUTOSAVE_TIMEOUT);
555 GRW_AUTOSAVE_TIMEOUT = setTimeout(grw_serialize_connections, GRW_AUTOSAVE_KEYUP_TIMEOUT);
556 });
557 $('.grw-connect-options input[type="checkbox"],.grw-connect-options select').change(function() {
558 grw_serialize_connections();
559 });
560 $('.grw-connect-options input[name^="--"]').on('input', function() {
561 grw_stylechange2(this);
562 clearTimeout(GRW_AUTOSAVE_TIMEOUT);
563 GRW_AUTOSAVE_TIMEOUT = setTimeout(grw_serialize_connections, GRW_AUTOSAVE_KEYUP_TIMEOUT);
564 });
565 $('.grw-connect-options input[type="color"][name^="--"] + input[type="text"]').keyup(function() {
566 if (this.value.indexOf('#') == 0 && this.value.length == 7) {
567 this.previousElementSibling.value = this.value;
568 this.previousElementSibling.dispatchEvent(new Event('input'));
569 }
570 });
571
572 $('.grw-toggle', el).unbind('click').click(function () {
573 $(this).toggleClass('toggled');
574 $(this).next().slideToggle();
575 });
576
577 $('.grw-builder-connect.grw-connect-google').click(function () {
578 $connect_wizard_el.dialog({modal: true, width: '50%', maxWidth: '600px'});
579 });
580
581 if ($('.grw-connections').sortable) {
582 $('.grw-connections').sortable({
583 stop: function(event, ui) {
584 grw_serialize_connections();
585 }
586 });
587 $('.grw-connections').disableSelection();
588 }
589
590 $('.wp-review-hide').click(function() {
591 grw_review_hide($(this));
592 return false;
593 });
594
595 $('#grw_save').click(function() {
596 grw_serialize_connections();
597 return false;
598 });
599
600 window.addEventListener('beforeunload', function(e) {
601 if (!GRW_AUTOSAVE_TIMEOUT) return undefined;
602
603 var msg = 'It looks like you have been editing something. If you leave before saving, your changes will be lost.';
604 (e || window.event).returnValue = msg;
605 return msg;
606 });
607
608 if (data.key) {
609 let lang, opts = '<option value="" selected="selected">Choose language if needed</option>';
610 for (var i = 0; i < GRW_LANGS.length; i++) {
611 opts += '<option value="' + GRW_LANGS[i][0] + '"' + (lang == GRW_LANGS[i][0] ? ' selected="selected"' : '') + '>' + GRW_LANGS[i][1] + '</option>';
612 }
613 window.grw_place_lang.innerHTML = opts;
614 window.grw_place_autocomplete.focus();
615 window.grw_place_autocomplete.addEventListener('keyup', grw_input_keyup);
616 }
617 }
618
619 function grw_input_keyup(e) {
620 clearTimeout(window.keyupTimeout);
621
622 if (e.keyCode === 13) return;
623
624 let val = this.value.trim();
625 if (val && /^(\s+|\S+)+$/giu.test(val)) {
626 grw_place_spin(1);
627 if (/^ChIJ\S+$/giu.test(val)) {
628 grw_get_place(val);
629 } else {
630 keyupTimeout = setTimeout(grw_on_keyup, 1000, e, this.value.trim());
631 }
632 } else {
633 grw_place_spin();
634 }
635 }
636
637 function grw_on_keyup(e, val) {
638 if (val && val != window.grw_keyup_val) {
639 grw_keyup_val = val;
640 e.preventDefault();
641
642 jQuery.post(ajaxurl, {
643 input: val,
644 action: 'grw_place_autocomplete',
645 grw_nonce: jQuery('#grw_nonce').val()
646 }, function(res) {
647 grw_place_spin();
648 window.grw_place_list.innerHTML = '';
649 if (res && res.error_message) {
650 window.grw_place_error.innerHTML = res.error_message;
651 return;
652 }
653
654 for (let i = 0; i < res.predictions.length; i++) {
655 (function(pred) {
656 let a = document.createElement('a');
657 a.href = '#';
658 a.className = 'dropdown-item';
659 a.role = 'option';
660 a.innerHTML = '<div class="location-name">' + pred.structured_formatting.main_text + '</div>';
661 if (pred.structured_formatting.secondary_text) {
662 a.innerHTML += '<small class="location-address">' + pred.structured_formatting.secondary_text + '</small>';
663 }
664 a.onclick = function(e) {
665 e.preventDefault();
666 grw_get_place(pred.place_id);
667 grw_place_spin(1);
668 };
669
670 let li = document.createElement('li');
671 li.appendChild(a);
672 window.grw_place_list.appendChild(li);
673 })(res.predictions[i]);
674 }
675 window.grw_place_list.style.display = 'block';
676 });
677 } else {
678 grw_place_spin();
679 }
680 }
681
682 function grw_get_place(pid) {
683 jQuery.post(ajaxurl, {
684 pid : pid,
685 action : 'grw_get_place',
686 grw_nonce : jQuery('#grw_nonce').val()
687 }, function(res) {
688 grw_place_spin();
689 window.grw_place_list.innerHTML = '';
690 const err = grw_get_error(res);
691 if (err) {
692 window.grw_place_error.innerHTML = err;
693 return;
694 }
695 grw_set_place(pid, res.result);
696 });
697 }
698
699 function grw_get_error(res) {
700 return res?.result?.error_message?.message || res?.result?.error_message || null;
701 }
702
703 function grw_set_place(pid, place) {
704 let img = window.grw_place.getElementsByTagName('img')[0],
705 name = window.grw_place.getElementsByClassName('wp-google-name')[0],
706 rating = window.grw_place.getElementsByClassName('wp-google-rating')[0],
707 based = window.grw_place.getElementsByClassName('wp-google-based')[0];
708
709 img.src = place.photo || place.icon;
710 name.innerHTML = place.name;
711 rating.innerHTML = place.rating;
712 based.innerHTML = place.user_ratings_total;
713
714 window.grw_place_list.style.display = 'none';
715 window.grw_place.style.display = 'block';
716
717 window.grw_place_btn.onclick = function(e) {
718 e.preventDefault();
719
720 let btn = e.target;
721 btn.disabled = true;
722
723 const params = {
724 id: pid,
725 lang: window.grw_place_lang.value
726 };
727 grw_connect_ajax(jQuery, document, params, null, 1, function() {
728 btn.disabled = false;
729 grw_place_spin();
730 grw_wizard_close();
731 });
732 grw_place_spin(1);
733 }
734 }
735
736 function grw_place_spin(s) {
737 window.grw_place_spin_svg.style.display = s ? 'block' : 'none';
738 }
739
740 function grw_feed_save_ajax() {
741 if (!window.grw_title.value) {
742 window.grw_title.focus();
743 return false;
744 }
745
746 window.grw_save.innerText = 'Auto save, wait';
747 window.grw_save.disabled = true;
748
749 jQuery.post(ajaxurl, {
750
751 post_id : window.grw_post_id.value,
752 title : window.grw_title.value,
753 content : document.getElementById('grw-builder-connection').value,
754 action : 'grw_feed_save_ajax',
755 grw_nonce : jQuery('#grw_nonce').val()
756
757 }, function(res) {
758
759 rpi.Utils.clear();
760
761 var wpgr = document.querySelectorAll('.wp-gr');
762 for (var i = 0; i < wpgr.length; i++) {
763 wpgr[i].parentNode.removeChild(wpgr[i]);
764 }
765
766 window.grw_collection_preview.innerHTML = res;
767
768 jQuery('.wp-review-hide').unbind('click').click(function() {
769 grw_review_hide(jQuery(this));
770 return false;
771 });
772
773 if (!window.grw_post_id.value) {
774 var post_id = document.querySelector('.wp-gr').getAttribute('data-id');
775 window.grw_post_id.value = post_id;
776 window.location.href = GRW_VARS.builderUrl + '&grw_feed_id=' + post_id + '&grw_feed_new=1';
777 } else {
778 var $rateus = jQuery('#grw-rate_us');
779 if ($rateus.length && !$rateus.hasClass('grw-flash-visible') && !window['grw_rateus']) {
780 $rateus.addClass('grw-flash-visible');
781 }
782 }
783
784 window.grw_save.innerText = 'Save & Update';
785 window.grw_save.disabled = false;
786 GRW_AUTOSAVE_TIMEOUT = null;
787 });
788 }
789
790 function grw_review_hide($this) {
791
792 jQuery.post(ajaxurl, {
793
794 id : $this.attr('data-id'),
795 feed_id : jQuery('input[name="grw_feed[post_id]"]').val(),
796 grw_wpnonce : jQuery('#grw_nonce').val(),
797 action : 'grw_hide_review'
798
799 }, function(res) {
800 var parent = $this.parent().parent();
801 if (res.hide) {
802 $this.text('show review');
803 parent.addClass('wp-review-hidden');
804 } else {
805 $this.text('hide review');
806 parent.removeClass('wp-review-hidden');
807 }
808 }, 'json');
809 }
810
811 function grw_connect_ajax($, el, params, authcode, attempt, cb) {
812
813 var platform = 'google',
814 connect_btn = el.querySelector('.grw-connect-btn'),
815 local_img = params.local_img !== undefined ? params.local_img : true;
816
817 window.grw_save.innerText = 'Auto save, wait';
818 window.grw_save.disabled = true;
819
820 const args = {
821 id : decodeURIComponent(params.id),
822 lang : params.lang,
823 local_img : local_img,
824 token : params.token,
825 feed_id : $('input[name="grw_feed[post_id]"]').val(),
826 grw_wpnonce : $('#grw_nonce').val(),
827 action : 'grw_connect_google',
828 v : new Date().getTime()
829 };
830 if (params.props && params.props.map_url) {
831 args.map_url = params.props.map_url;
832 }
833
834 $.post(ajaxurl, args, function(res) {
835
836 console.log('grw_connect_debug:', res);
837
838 if (res.status == 'success') {
839
840 let error_els = document.querySelectorAll('.grw-connect-error');
841 for (let i = 0; i < error_els.length; i++) {
842 error_els[i].innerHTML = '';
843 }
844
845 grw_wizard_close();
846
847 let props = {
848 default_photo : res.result.photo
849 };
850 if (res.result.map_url) {
851 props.map_url = res.result.map_url;
852 }
853
854 let connection_params = {
855 id : res.result.id,
856 lang : params.lang,
857 name : res.result.name,
858 photo : res.result.photo,
859 refresh : true,
860 local_img : local_img,
861 platform : platform,
862 props : props
863 };
864
865 grw_connection_add($, el, connection_params);
866 grw_serialize_connections();
867
868 } else {
869 grw_connect_error($, grw_get_error(res), function() {
870 if (attempt > 1) return;
871 if (window.gpidc) {
872 grw_popup('https://app.richplugins.com/gpaw/botcheck?authcode=' + authcode, 640, 480, function() {
873 window.gpidc.contentWindow.postMessage({params: params, action: 'connect'}, '*');
874 });
875 }
876 });
877 }
878
879 cb && cb(res);
880
881 }, 'json');
882 }
883
884 function grw_wizard_close() {
885 try {
886 jQuery('#grw-connect-wizard').dialog('close');
887 } catch (e) {}
888 }
889
890 function grw_connect_error($, error_message, cb) {
891
892 let error_els = document.querySelectorAll('.grw-connect-error');
893 for (let i = 0; i < error_els.length; i++) {
894 error_els[i].innerHTML = '';
895 }
896
897 switch (error_message) {
898
899 case 'usage_limit':
900 $('#dialog').dialog({width: '50%', maxWidth: '600px'});
901 break;
902
903 case 'bot_check':
904 cb && cb();
905 break;
906
907 default:
908 for (let i = 0; i < error_els.length; i++) {
909 error_els[i].innerHTML = '<b>Error</b>: ' + error_message;
910 }
911 }
912
913 window.grw_save.innerText = 'Save & Update';
914 window.grw_save.disabled = false;
915 }
916
917 function grw_connection_add($, el, conn, checked, append) {
918
919 var connected_id = grw_connection_id(conn),
920 connected_el = $('#' + connected_id);
921
922 if (!connected_el.length) {
923 connected_el = $('<div class="grw-connection"></div>')[0];
924 connected_el.id = connected_id;
925 if (conn.lang != undefined) {
926 connected_el.setAttribute('data-lang', conn.lang);
927 }
928 connected_el.setAttribute('data-platform', conn.platform);
929 connected_el.innerHTML = grw_connection_render(conn, checked);
930
931 var connections_el = $('.grw-connections')[0];
932 if (append) {
933 connections_el.appendChild(connected_el);
934 } else {
935 connections_el.prepend(connected_el);
936 }
937
938 jQuery('.grw-toggle', connected_el).unbind('click').click(function () {
939 jQuery(this).toggleClass('toggled');
940 jQuery(this).next().slideToggle();
941 });
942
943 var file_frame;
944 jQuery('.grw-connect-photo-change', connected_el).on('click', function(e) {
945 e.preventDefault();
946 grw_upload_photo(connected_el, file_frame, function() {
947 grw_serialize_connections();
948 });
949 return false;
950 });
951
952 jQuery('.grw-connect-photo-default', connected_el).on('click', function(e) {
953 grw_change_photo(connected_el, conn.props.default_photo);
954 grw_serialize_connections();
955 return false;
956 });
957
958 $('input[type="text"]', connected_el).keyup(function() {
959 clearTimeout(GRW_AUTOSAVE_TIMEOUT);
960 GRW_AUTOSAVE_TIMEOUT = setTimeout(grw_serialize_connections, GRW_AUTOSAVE_KEYUP_TIMEOUT);
961 });
962
963 $('input[type="checkbox"]', connected_el).click(function() {
964 grw_serialize_connections();
965 });
966
967 $('select.grw-connect-lang', connected_el).change(function() {
968 conn.lang = this.value;
969 connected_el.id = grw_connection_id(conn);
970 connected_el.setAttribute('data-lang', this.value);
971 grw_reconnect($, el, conn);
972 return false;
973 });
974
975 $('input[name="local_img"]', connected_el).unbind('click').click(function() {
976 conn.local_img = this.checked;
977 grw_reconnect($, el, conn);
978 });
979
980 $('.grw-connect-reconnect', connected_el).click(function() {
981 grw_reconnect($, el, conn);
982 return false;
983 });
984
985 $('.grw-connect-delete', connected_el).click(function() {
986 if (confirm('Are you sure to delete this business?')) {
987 $(connected_el).remove();
988 grw_serialize_connections();
989 }
990 return false;
991 });
992 }
993 }
994
995 function grw_reconnect($, el, conn) {
996 window.grw_save.disabled = true;
997 window.grw_save.innerText = 'Updating...';
998 if (window.gpidc) {
999 window.gpidc.contentWindow.postMessage({params: conn, action: 'connect'}, '*');
1000 } else {
1001 grw_connect_ajax($, el, conn, null, 1);
1002 }
1003 }
1004
1005 function grw_connection_id(conn) {
1006 var id = 'grw-' + conn.platform + '-' + conn.id.replace(/\//g, '');
1007 if (conn.lang != null) {
1008 id += conn.lang;
1009 }
1010 return id;
1011 }
1012
1013 function grw_connection_render(conn, checked) {
1014 var name = conn.name;
1015 if (conn.lang) {
1016 name += ' (' + conn.lang + ')';
1017 }
1018
1019 conn.photo = conn.photo || 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
1020
1021 var option = document.createElement('option');
1022 if (conn.platform == 'google' && conn.props && conn.props.place_id) {
1023 option.value = conn.props.place_id;
1024 } else {
1025 option.value = conn.id;
1026 }
1027 option.text = grw_capitalize(conn.platform) + ': ' + conn.name;
1028
1029 return '' +
1030 '<div class="grw-toggle grw-builder-connect grw-connect-business">' +
1031 '<input type="checkbox" class="grw-connect-select" onclick="event.stopPropagation();" ' + (checked?'checked':'') + ' /> ' +
1032 name + (conn.address ? ' (' + conn.address + ')' : '') +
1033 '</div>' +
1034 '<div style="display:none">' +
1035 (function(props) {
1036 var result = '';
1037 for (prop in props) {
1038 if (prop != 'platform' && Object.prototype.hasOwnProperty.call(props, prop)) {
1039 result += '<input type="hidden" name="' + prop + '" value="' + props[prop] + '" class="grw-connect-prop" readonly />';
1040 }
1041 }
1042 return result;
1043 })(conn.props) +
1044 '<input type="hidden" name="id" value="' + conn.id + '" readonly />' +
1045 (conn.address ? '<input type="hidden" name="address" value="' + conn.address + '" readonly />' : '') +
1046 (conn.access_token ? '<input type="hidden" name="access_token" value="' + conn.access_token + '" readonly />' : '') +
1047 '<div class="grw-builder-option">' +
1048 '<img src="' + conn.photo + '" alt="' + conn.name + '" class="grw-connect-photo">' +
1049 '<a href="#" class="grw-connect-photo-change">Change</a>' +
1050 '<a href="#" class="grw-connect-photo-default">Default</a>' +
1051 '<input type="hidden" name="photo" class="grw-connect-photo-hidden" value="' + conn.photo + '" tabindex="2"/>' +
1052 '</div>' +
1053 '<div class="grw-builder-option">' +
1054 '<input type="text" name="name" value="' + conn.name + '" />' +
1055 '</div>' +
1056 (conn.website != undefined ?
1057 '<div class="grw-builder-option">' +
1058 '<input type="text" name="website" value="' + conn.website + '" />' +
1059 '</div>'
1060 : '' ) +
1061 (conn.lang != undefined ?
1062 '<div class="grw-builder-option">' +
1063 //'<input type="text" name="lang" value="' + conn.lang + '" placeholder="Default language (English)" />' +
1064 grw_lang('Show all connected languages', conn.lang) +
1065 '</div>'
1066 : '' ) +
1067 (conn.review_count != undefined ?
1068 '<div class="grw-builder-option">' +
1069 '<input type="text" name="review_count" value="' + conn.review_count + '" placeholder="Total number of reviews" />' +
1070 '<span class="grw-quest grw-toggle" title="Click to help">?</span>' +
1071 '<div class="grw-quest-help">Google return only 5 most helpful reviews and does not return information about total number of reviews and you can type here it manually.</div>' +
1072 '</div>'
1073 : '' ) +
1074 (conn.refresh != undefined ?
1075 '<div class="grw-builder-option">' +
1076 '<label>' +
1077 '<input type="checkbox" name="refresh" ' + (conn.refresh ? 'checked' : '') + '> Include in auto-update<br>' +
1078 '<small>Works only with your own Google API key</small>' +
1079 '</label>' +
1080 /*'<span class="grw-quest grw-quest-top grw-toggle" title="Click to help">?</span>' +
1081 '<div class="grw-quest-help">' +
1082 (conn.platform == 'google' ? 'The plugin uses the Google Places API to get your reviews. <b>The API only returns the 5 most helpful reviews (it\'s a limitation of Google, not the plugin)</b>. This option calls the Places API once in 24 hours (to keep the plugin\'s free and avoid a Google Billing) to check for a new reviews and if there are, adds to the plugin. Thus slowly building up a database of reviews.<br><br>Also if you see the new reviews on Google map, but after some time it\'s not added to the plugin, it means that Google does not include these reviews to the API and the plugin can\'t get this.<br><br>If you need to show <b>all reviews</b>, please use <a href="https://richplugins.com/business-reviews-bundle-wordpress-plugin?promo=GRGROW23" target="_blank">Business plugin</a> which uses a Google My Business API without API key and billing.' : '') +
1083 (conn.platform == 'yelp' ? 'The plugin uses the Yelp API to get your reviews. <b>The API only returns the 3 most helpful reviews without sorting possibility.</b> When Yelp changes the 3 most helpful the plugin will automatically add the new one to your database. Thus slowly building up a database of reviews.' : '') +
1084 '</div>' +*/
1085 '</div>'
1086 : '' ) +
1087 '<div class="grw-builder-option">' +
1088 '<label>' +
1089 '<input type="checkbox" name="local_img" ' + (conn.local_img ? 'checked' : '') + '>' +
1090 'Save images locally (GDPR)' +
1091 '</label>' +
1092 '</div>' +
1093 '<div class="grw-builder-option">' +
1094 '<button class="grw-connect-reconnect">Update reviews</button>' +
1095 '</div>' +
1096 '<div class="grw-builder-option">' +
1097 '<button class="grw-connect-delete">Delete connection</button>' +
1098 '</div>' +
1099 '<div class="grw-builder-option">' +
1100 '<small class="grw-connect-error"></small>' +
1101 '</div>' +
1102 '</div>';
1103 }
1104
1105 function grw_serialize_connections() {
1106
1107 var connections = [],
1108 connections_el = document.querySelectorAll('.grw-connection');
1109
1110 for (var i in connections_el) {
1111 if (Object.prototype.hasOwnProperty.call(connections_el, i)) {
1112
1113 var select_el = connections_el[i].querySelector('.grw-connect-select');
1114 if (select_el && !grw_is_hidden(select_el) && !select_el.checked) {
1115 continue;
1116 }
1117
1118 var connection = {},
1119 lang = connections_el[i].getAttribute('data-lang'),
1120 platform = connections_el[i].getAttribute('data-platform'),
1121 inputs = connections_el[i].querySelectorAll('input');
1122
1123 //connections[platform] = connections[platform] || [];
1124
1125 if (lang != undefined) {
1126 connection.lang = lang;
1127 }
1128
1129 for (var j in inputs) {
1130 if (Object.prototype.hasOwnProperty.call(inputs, j)) {
1131 var input = inputs[j],
1132 name = input.getAttribute('name');
1133
1134 if (!name) continue;
1135
1136 if (input.className == 'grw-connect-prop') {
1137 connection.props = connection.props || {};
1138 connection.props[name] = input.value;
1139 } else {
1140 connection[name] = (input.type == 'checkbox' ? input.checked : input.value);
1141 }
1142 }
1143 }
1144 connection.platform = platform;
1145 connections.push(connection);
1146 }
1147 }
1148
1149 var options = {},
1150 options_el = document.querySelector('.grw-connect-options').querySelectorAll('input[name],select,textarea');
1151
1152 for (var o in options_el) {
1153 if (Object.prototype.hasOwnProperty.call(options_el, o)) {
1154 var input = options_el[o],
1155 name = input.getAttribute('name');
1156
1157 if (input.type == 'checkbox') {
1158 options[name] = input.checked;
1159 } else if (input.value != undefined) {
1160 options[name] = (
1161 input.type == 'textarea' ||
1162 name == 'word_filter' ||
1163 name == 'word_exclude' ?
1164 encodeURIComponent(input.value) : input.value
1165 );
1166 }
1167 }
1168 }
1169
1170 document.getElementById('grw-builder-connection').value = JSON.stringify({connections: connections, options: options});
1171
1172 if (connections.length) {
1173 var first = connections[0],
1174 title = window.grw_title.value;
1175
1176 if (!title) {
1177 window.grw_title.value = first.name;
1178 }
1179 grw_feed_save_ajax();
1180 } else {
1181 /*var connect_google_el = document.querySelector('.grw-connect-google-inside'),
1182 google_pid_el = document.querySelector('.grw-connect-id');
1183
1184 connect_google_el.style = '';
1185 google_pid_el.focus();*/
1186 }
1187 }
1188
1189 function grw_deserialize_connections($, el, data) {
1190 var connections = data.conns,
1191 options = connections.options;
1192
1193 if (Array.isArray(connections.connections)) {
1194 connections = connections.connections;
1195 } else {
1196 var temp_conns = [];
1197 if (Array.isArray(connections.google)) {
1198 for (var c = 0; c < connections.google.length; c++) {
1199 connections.google[c].platform = 'google';
1200 }
1201 temp_conns = temp_conns.concat(connections.google);
1202 }
1203 if (Array.isArray(connections.facebook)) {
1204 for (var c = 0; c < connections.facebook.length; c++) {
1205 connections.facebook[c].platform = 'facebook';
1206 }
1207 temp_conns = temp_conns.concat(connections.facebook);
1208 }
1209 if (Array.isArray(connections.yelp)) {
1210 for (var c = 0; c < connections.yelp.length; c++) {
1211 connections.yelp[c].platform = 'yelp';
1212 }
1213 temp_conns = temp_conns.concat(connections.yelp);
1214 }
1215 connections = temp_conns;
1216 }
1217
1218 let $bp = el.querySelector('.grw-builder-platforms');
1219 for (var i = 0; i < connections.length; i++) {
1220 grw_connection_add($, $bp, connections[i], true, true);
1221 }
1222
1223 for (var opt in options) {
1224 if (Object.prototype.hasOwnProperty.call(options, opt) && opt) {
1225 var control = el.querySelector('input[name="' + opt + '"],select[name="' + opt + '"],textarea[name="' + opt + '"]');
1226 if (control) {
1227 var name = control.getAttribute('name');
1228 if (typeof(options[opt]) === 'boolean') {
1229 control.checked = options[opt];
1230 } else {
1231 control.value = (
1232 control.type == 'textarea' ||
1233 name == 'word_filter' ||
1234 name == 'word_exclude' ?
1235 decodeURIComponent(options[opt]) : options[opt]
1236 );
1237 if (opt.indexOf('_photo') > -1 && control.value) {
1238 control.parentNode.querySelector('img').src = control.value;
1239 }
1240 if (opt == 'style_vars') {
1241 rplg_sv_parse(el, control.value);
1242 }
1243 if (opt == 'slider_breakpoints') {
1244 grw_sbs_parse(control.value);
1245 }
1246 }
1247 }
1248 }
1249 }
1250 }
1251
1252 function rplg_sv_parse(el, val) {
1253 if (val) {
1254 let sv = val.split(';');
1255 for (let i = 0; i < sv.length; i++) {
1256 if (sv[i]) {
1257 let svp = sv[i].split(':'),
1258 svcs = el.querySelectorAll('input[name="' + svp[0].trim() + '"]');
1259 for (let j = 0; j < svcs.length; j++) {
1260 let svc = svcs[j];
1261 if (svc.type == 'checkbox') {
1262 let off = svc.getAttribute('data-off'),
1263 on = svc.getAttribute('data-on');
1264 svc.checked = svp[1].trim() != off ? (svp[1].trim() == on) : false;
1265 } else {
1266 let da = svc.getAttribute('data-postfix');
1267 svc.setAttribute('data-val', svp[1].trim());
1268 svc.value = svp[1].trim().replace(da, '');
1269
1270 // if color input put color to the next text input
1271 if (svc.type == 'color') {
1272 svc.nextSibling.value = svp[1].trim();
1273 }
1274 }
1275 }
1276 }
1277 }
1278 } else {
1279 stylereset();
1280 }
1281 }
1282
1283 function grw_upload_photo(el, file_frame, cb) {
1284 if (file_frame) {
1285 file_frame.open();
1286 return;
1287 }
1288
1289 file_frame = wp.media.frames.file_frame = wp.media({
1290 title: jQuery(this).data('uploader_title'),
1291 button: {text: jQuery(this).data('uploader_button_text')},
1292 multiple: false
1293 });
1294
1295 file_frame.on('select', function() {
1296 var attachment = file_frame.state().get('selection').first().toJSON();
1297 grw_change_photo(el, attachment.url);
1298 cb && cb(attachment.url);
1299 });
1300 file_frame.open();
1301 }
1302
1303 function grw_change_photo(el, photo_url) {
1304 var place_photo_hidden = jQuery('.grw-connect-photo-hidden', el),
1305 place_photo_img = jQuery('.grw-connect-photo', el);
1306
1307 place_photo_hidden.val(photo_url);
1308 place_photo_img.attr('src', photo_url);
1309 place_photo_img.show();
1310
1311 grw_serialize_connections();
1312 }
1313
1314 function grw_popup(url, width, height, cb) {
1315 var top = top || (screen.height/2)-(height/2),
1316 left = left || (screen.width/2)-(width/2),
1317 win = window.open(url, '', 'location=1,status=1,resizable=yes,width='+width+',height='+height+',top='+top+',left='+left);
1318 function check() {
1319 if (!win || win.closed != false) {
1320 cb();
1321 } else {
1322 setTimeout(check, 100);
1323 }
1324 }
1325 setTimeout(check, 100);
1326 }
1327
1328 function grw_randstr(len) {
1329 var result = '',
1330 chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
1331 charsLen = chars.length;
1332 for ( var i = 0; i < len; i++ ) {
1333 result += chars.charAt(Math.floor(Math.random() * charsLen));
1334 }
1335 return result;
1336 }
1337
1338 function grw_is_hidden(el) {
1339 return el.offsetParent === null;
1340 }
1341
1342 function grw_capitalize(str) {
1343 return str.charAt(0).toUpperCase() + str.slice(1);
1344 }
1345
1346 function grw_lang(defname, lang) {
1347 var html = '';
1348 for (var i = 0; i < GRW_LANGS.length; i++) {
1349 html += '<option value="' + GRW_LANGS[i][0] + '"' + (lang == GRW_LANGS[i][0] ? ' selected="selected"' : '') + '>' + GRW_LANGS[i][1] + '</option>';
1350 }
1351 return '<select class="grw-connect-lang" name="lang">' +
1352 '<option value=""' + (lang ? '' : ' selected="selected"') + '>' + defname + '</option>' +
1353 html +
1354 '</select>';
1355 }
1356
1357 /******************************** Breakpoints copy & paste ********************************/
1358 function grw_sbs_init() {
1359 var select = document.querySelector('.grw-slider-br select'),
1360 range = document.querySelector('.grw-slider-br input[type="range"]'),
1361 span = document.querySelector('.grw-slider-br .grw-quest');
1362
1363 select.addEventListener('change', grw_sbs_keyup);
1364 range.addEventListener('input', grw_sbs_keyup);
1365
1366 span.onclick = function() {
1367 grw_sbs_clone(document.querySelector('.grw-slider-br:last-child'));
1368 grw_sbs_keyup();
1369 };
1370 }
1371
1372 function grw_sbs_parse(sbs) {
1373 var brs,
1374 select = document.querySelector('.grw-slider-br select'),
1375 range = document.querySelector('.grw-slider-br input[type="range"]'),
1376 span = document.querySelector('.grw-slider-br input[type="range"] + span');
1377
1378 if (sbs && (brs = sbs.split(',')).length) {
1379 var br_first = brs.shift(),
1380 br_vals = br_first.split(':');
1381 select.value = br_vals[0].replace('px', '').trim();
1382 range.value = parseInt(br_vals[1]);
1383 span.innerHTML = br_vals[1];
1384
1385 while (brs.length) {
1386 grw_sbs_clone(document.querySelector('.grw-slider-br:last-child'), brs.shift().split(':'));
1387 }
1388 }
1389 }
1390
1391 function grw_sbs_clone(br, vals) {
1392 let clone = br.cloneNode(true),
1393 prevSelect = br.querySelector('select'),
1394 quest = clone.querySelector('.grw-quest'),
1395 select = clone.querySelector('select'),
1396 input = clone.querySelector('input[type="text"]')
1397 range = clone.querySelector('input[type="range"]'),
1398 span = clone.querySelector('input[type="range"] + span');
1399
1400 clearTimeout(window.grw_sbt);
1401
1402 if (select.options.length > prevSelect.selectedIndex + 1) {
1403 select.selectedIndex = prevSelect.selectedIndex + 1;
1404 }
1405 if (select.selectedIndex == 0) {
1406 select.selectedIndex = 1;
1407 }
1408
1409 quest.innerHTML = '-';
1410 br.parentNode.appendChild(clone);
1411
1412 if (vals) {
1413 select.value = vals[0];
1414 if (!select.value) {
1415 select.value = '';
1416 if (!input) {
1417 input = document.createElement('input');
1418 input.type = 'text';
1419 select.after(input);
1420 }
1421 input.value = vals[0];
1422 input.addEventListener('keyup', grw_sbs_keyup);
1423 } else if (input) {
1424 input.parentNode.removeChild(input);
1425 }
1426 range.value = vals[1];
1427 span.innerHTML = vals[1];
1428 }
1429
1430 select.addEventListener('change', grw_sbs_keyup);
1431 range.addEventListener('input', grw_sbs_keyup);
1432
1433 quest.onclick = function() {
1434 clone.parentNode.removeChild(clone);
1435 grw_sbs_keyup();
1436 };
1437 }
1438
1439 function grw_sbs_keyup() {
1440 clearTimeout(window.grw_sbt);
1441 let vals = [], brs = document.querySelectorAll('.grw-slider-br');
1442 for (let i = 0; i < brs.length; i++) {
1443 let select = brs[i].querySelector('select'),
1444 input = brs[i].querySelector('input[type="text"]'),
1445 range = brs[i].querySelector('input[type="range"]');
1446 //inputs = brs[i].querySelectorAll('input,select');
1447
1448 if (select.value == 'off') {
1449 rpi.Utils.rm(input);
1450 continue;
1451 } else if ((select.value || (input && input.value)) && range.value) {
1452 let reslt;
1453 if (select.value) {
1454 reslt = select.value;
1455 rpi.Utils.rm(input);
1456 } else {
1457 reslt = input.value;
1458 }
1459 vals.push([reslt, range.value].join(':'));
1460 } else if (!input) {
1461 let custom = document.createElement('input');
1462 custom.type = 'text';
1463 custom.addEventListener('keyup', grw_sbs_keyup);
1464 select.after(custom);
1465 custom.focus();
1466 }
1467 }
1468 const bp = vals.join(',');
1469 rpi.Instances[0].setBreakpoints(bp);
1470 grw_sbs_set(bp);
1471 }
1472
1473 function grw_sbs_set(val) {
1474 let input = document.querySelector('input[name="slider_breakpoints"]');
1475 if (input.value != val) {
1476 input.value = val;
1477 window.grw_sbt = setTimeout(grw_serialize_connections, 3000);
1478 }
1479 }