PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.2.0
Brevo – Email, SMS, Web Push, Chat, and more. v3.2.0
2.9.13 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.1.29 3.1.3 3.1.30 3.1.31 3.1.32 3.1.33 3.1.34 3.1.35 3.1.36 3.1.37 3.1.38 3.1.39 3.1.4 3.1.40 3.1.41 3.1.42 3.1.43 3.1.44 3.1.45 3.1.46 3.1.47 3.1.48 3.1.49 3.1.5 3.1.50 3.1.51 3.1.52 3.1.53 3.1.54 3.1.55 3.1.56 3.1.57 3.1.58 3.1.59 3.1.6 3.1.60 3.1.61 3.1.62 3.1.63 3.1.64 3.1.65 3.1.66 3.1.67 3.1.68 3.1.69 3.1.7 3.1.70 3.1.71 3.1.72 3.1.73 3.1.74 3.1.75 3.1.76 3.1.77 3.1.78 3.1.79 3.1.8 3.1.80 3.1.81 3.1.82 3.1.83 3.1.84 3.1.85 3.1.86 3.1.87 3.1.88 3.1.89 3.1.9 3.1.90 3.1.91 3.1.92 3.1.93 3.1.94 3.1.95 3.1.96 3.1.97 3.1.98 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 trunk 1.0 1.5 2.0.8 2.9.10 2.9.11 2.9.12
mailin / js / admin.js
mailin / js Last commit date
bootstrap 4 years ago admin.js 1 year ago chosen.jquery.min.js 9 years ago index.php 11 years ago mailin-front.js 1 year ago post-editor.bundle.js 1 year ago push.bundle.js 1 year ago select2.full.min.js 1 year ago
admin.js
1472 lines
1 var $jQ = jQuery.noConflict();
2 var ajax_sib_object;
3 var CountryList = {
4 213: "DZ",
5 376: "AD",
6 54: "AR",
7 971: "AE",
8 43: "AT",
9 61: "AU",
10 387: "BA",
11 880: "BD",
12 32: "BE",
13 359: "BG",
14 973: "BH",
15 590: "BL",
16 55: "BR",
17 1: "CA",
18 41: "CH",
19 56: "CL",
20 86: "CN",
21 57: "CO",
22 420: "CZ",
23 49: "DE",
24 45: "DK",
25 593: "EC",
26 372: "EE",
27 20: "EG",
28 34: "ES",
29 358: "FI",
30 33: "FR",
31 44: "GB",
32 995: "GE",
33 30: "GR",
34 852: "HK",
35 385: "HR",
36 509: "HT",
37 36: "HU",
38 62: "ID",
39 353: "IE",
40 972: "IL",
41 91: "IN",
42 98: "IR",
43 39: "IT",
44 1876: "JM",
45 962: "JO",
46 81: "JP",
47 269: "KM",
48 961: "LB",
49 94: "LK",
50 370: "LT",
51 352: "LU",
52 371: "LV",
53 212: "MA",
54 261: "MG",
55 356: "MT",
56 230: "MU",
57 52: "MX",
58 60: "MY",
59 687: "NC",
60 234: "NG",
61 505: "NI",
62 31: "NL",
63 47: "NO",
64 977: "NP",
65 64: "NZ",
66 507: "PA",
67 51: "PE",
68 689: "PF",
69 675: "PG",
70 63: "PH",
71 92: "PK",
72 48: "PL",
73 508: "PM",
74 1787: "PR",
75 351: "PT",
76 595: "PY",
77 974: "QA",
78 40: "RO",
79 7: "RU",
80 46: "SE",
81 65: "SG",
82 386: "SI",
83 421: "SK",
84 66: "TH",
85 216: "TN",
86 90: "TR",
87 886: "TW",
88 380: "UA",
89 256: "UG",
90 1: "US",
91 598: "UY",
92 58: "VE",
93 84: "VN",
94 681: "WF",
95 262: "YT",
96 27: "ZA",
97 };
98 $jQ(document).ready(function(){
99
100 var bodyHeight = $jQ(document).height();
101 var adminmenu_height = $jQ('#adminmenuwrap').height();
102 if(bodyHeight > adminmenu_height){
103 $jQ("#datamain").height(bodyHeight);
104 }
105 else
106 {
107 $jQ("#datamain").height(adminmenu_height);
108 }
109
110
111 var normal_attributes = [];
112
113 var category_attributes = [];
114
115 var multiple_choice_attributes = [];
116
117 function isValidEmailAddress(emailAddress) {
118
119 var pattern = new RegExp(/^[#&*\/=?^{!}~'_a-z0-9-\+]+([#&*\/=?^{!}~'_a-z0-9-\+]+)*(\.[#&*\/=?^{!}~'_a-z0-9-\+]+)*[.]?@[_a-z0-9-]+(\.[_a-z0-9-]+)*(\.[a-z0-9]{2,10})$/);
120 return pattern.test(emailAddress);
121 }
122
123 function change_field_attr(){
124 var attr_val = $jQ('#sib_sel_attribute').val();
125 var attr_type, attr_name, attr_text;
126 if (attr_val == 'email' || attr_val == 'submit') {
127 // get all info of attr
128 var hidden_attr = $jQ('#sib_hidden_' + attr_val);
129 attr_type = hidden_attr.attr('data-type');
130 attr_name = hidden_attr.attr('data-name');
131 attr_text = hidden_attr.attr('data-text');
132 }
133 else {
134 $jQ.each(normal_attributes, function(index, value) {
135 if (value['name'] == attr_val) {
136 attr_type = value['type'];
137 attr_name = value['name'];
138 attr_text = attr_name;
139 }
140 });
141
142 $jQ.each(category_attributes, function(index, value) {
143 if (value['name'] == attr_val) {
144 attr_type = value['type'];
145 attr_name = value['name'];
146 attr_text = attr_name;
147 }
148 });
149
150 $jQ.each(multiple_choice_attributes, function(index, value) {
151 if (value['name'] == attr_val) {
152 attr_type = value['type'];
153 attr_name = value['name'];
154 attr_text = attr_name;
155 }
156 });
157 }
158
159 // generate attribute html
160 generate_attribute_html(attr_type, attr_name, attr_text);
161 }
162
163 function change_attribute_tag(attr_type, attr_name, attr_text){
164 $jQ('#sib_field_label').attr('value', attr_text);
165 $jQ('#sib_field_placeholder').attr('value', '');
166 $jQ('#sib_field_initial').attr('value', '');
167 $jQ('#sib_field_button_text').attr('value', attr_text);
168 $jQ('.sib-attr-other').hide();
169 $jQ('.sib-attr-normal').hide();
170 $jQ('.sib-attr-category').hide();
171 $jQ('.sib-attr-multiple-choice').hide();
172 $jQ('#sib_field_required').removeAttr('checked');
173 var dateformat = $jQ('.sib-dateformat').val();
174 switch(attr_type)
175 {
176 case 'email':
177 $jQ('#sib_field_required').attr('checked', 'true');
178 dateformat = '';
179 case 'date':
180 $jQ('#sib_field_placeholder').val(dateformat);
181 case 'text':
182 case 'float':
183 $jQ('.sib-attr-normal').show();
184 if(attr_name == 'SMS'){
185 $jQ('#sib_field_initial_area').hide();
186 }
187 break;
188 case 'boolean':
189 $jQ('.sib-attr-normal').show();
190 break;
191 case 'category':
192 $jQ('.sib-attr-category').show();
193 break;
194 case 'multiple-choice':
195 $jQ('.sib-attr-multiple-choice').show();
196 break;
197 case 'submit':
198 $jQ('.sib-attr-other').show();
199 break;
200 }
201 }
202
203 // generate attribute html
204 function generate_attribute_html(attr_type, attr_name, attr_text){
205 var field_label = $jQ('#sib_field_label').val();
206 var field_placeholder = $jQ('#sib_field_placeholder').val();
207 var field_initial = $jQ('#sib_field_initial').val();
208 var field_buttontext = $jQ('#sib_field_button_text').val();
209 //var field_wrap = $jQ('#sib_field_wrap').is(':checked');
210 var field_required = $jQ('#sib_field_required').is(':checked');
211 if(field_required == true) field_label += '*';
212 var field_type = $jQ('input[name=sib_field_type]:checked').val();
213 var dateformat = $jQ('.sib-dateformat').val();
214 var field_html = '';
215
216 if(attr_type != 'submit') {
217 field_html += '<p class="sib-' + attr_name + '-area"> \n';
218 }
219 else {
220 field_html += '<p> \n';
221 }
222
223 if ((field_label != '') && (attr_type == 'category')) {
224 if (field_type == 'select') {
225 field_html += ' <label class="sib-' + attr_name + '-area">' + field_label + '</label> \n';
226 }
227 else {
228 field_html += ' <div style="display:block;"><label class="sib-' + attr_name + '-area">' + field_label + '</label></div> \n';
229 }
230 }
231 else if ((field_label != '') && (attr_type == 'multiple-choice')) {
232 field_html += ' <label class="sib-' + attr_name + '-area">' + field_label + '</label> \n';
233 }
234 else if((field_label != '') && (attr_type != 'submit')) {
235 field_html += ' <label class="sib-' + attr_name + '-area">' + field_label + '</label> \n';
236 }
237
238 switch (attr_type)
239 {
240 case 'email':
241 field_html += ' <input type="email" class="sib-' + attr_name + '-area" name="' + attr_name + '" ';
242 field_html += 'placeholder="' + field_placeholder + '" ';
243 field_html += 'value="' + field_initial + '" ';
244 if(field_required == true) {
245 field_html += 'required="required" ';
246 }
247 field_html += '> \n';
248 break;
249 case 'date':
250 field_html += ' <input type="text" class="sib-' + attr_name + '-area sib-date" name="' + attr_name + '" placeholder="' + dateformat + '" data-format="' + dateformat + '">';
251 break;
252 case 'boolean':
253 field_html += ' <input type="hidden" name="' + attr_name + '" value="0"><input type="checkbox" value="1" class="sib-' + attr_name + '-area" name="' + attr_name + '" ';
254 if(field_placeholder != '') {
255 field_html += 'placeholder="' + field_placeholder + '" ';
256 }
257 if(field_required == true) {
258 field_html += 'required="required" ';
259 }
260 field_html += '> \n';
261 break;
262 case 'text':
263 if ( attr_name == "SMS" ) {
264 field_html += '<div class="sib-sms-field"><div class="sib-country-block">' +
265 '<div class="sib-toggle sib-country-flg"><div class="sib-cflags"></div> ' +
266 '<div class="sib-icon-arrow"></div></div> '+
267 '</div>' + '<ul class="sib-country-list" style="display: none;"></ul>' +
268 '<input type="hidden" name="sib_SMS_prefix" value="+33"><input type="text" name="SMS" class="sib-sms" value="+33" ';
269 if(field_placeholder != '') {
270 field_html += 'placeholder="' + field_placeholder + '" ';
271 }
272 if(field_required == true) {
273 field_html += 'required="required" ';
274 }
275 field_html += '></div>\n';
276 }
277 else {
278 field_html += ' <input type="text" class="sib-' + attr_name + '-area" name="' + attr_name + '" ';
279 if(field_placeholder != '') {
280 field_html += 'placeholder="' + field_placeholder + '" ';
281 }
282 if(field_initial != '') {
283 field_html += 'value="' + field_initial + '" ';
284 }
285 if(field_required == true) {
286 field_html += 'required="required" ';
287 }
288 field_html += '> \n';
289 }
290 break;
291 case 'float':
292 field_html += ' <input type="text" class="sib-' + attr_name + '-area" name="' + attr_name + '" ';
293 if(field_placeholder != '') {
294 field_html += 'placeholder="' + field_placeholder + '" ';
295 }
296 if(field_initial != '') {
297 field_html += 'value="' + field_initial + '" ';
298 }
299 if(field_required == true) {
300 field_html += 'required="required" ';
301 }
302 field_html += 'pattern="[0-9]+([\\.|,][0-9]+)?" > \n';
303 break;
304 case 'submit':
305 field_html += ' <input type="submit" class="sib-default-btn" name="' + attr_name + '" ';
306 field_html += 'value="' + field_buttontext + '" ';
307 field_html += '> \n';
308 break;
309 case 'category':
310 var enumeration = [];
311 $jQ.each(category_attributes, function(index, value) {
312 if (value['name'] == attr_name) {
313 enumeration = value['enumeration'];
314 }
315 });
316
317 if (field_type == 'select') {
318 field_html += ' <select class="sib-' + attr_name + '-area" name="' + attr_name + '" ';
319 if (field_required == true) {
320 field_html += 'required="required" ';
321 }
322 field_html += '> \n';
323 }
324 $jQ.each(enumeration, function(index, value) {
325 if (field_type == 'select') {
326 field_html += ' <option value="' + value['value'] + '">' + value['label'] + '</option> \n';
327 }
328 else {
329 field_html += ' <div style="display:block;"><input type="radio" class="sib-' + attr_name + '-area" name="' + attr_name + '" value="' + value['value'] + '" ';
330 if (field_required == true) {
331 field_html += 'required="required" ';
332 }
333 field_html += '>' + value['label'] + '</div> \n';
334 }
335 });
336 if (field_type == 'select') {
337 field_html += ' </select> \n';
338 }
339 break;
340 case 'multiple-choice':
341 var choices = [];
342 $jQ.each(multiple_choice_attributes, function(index, value) {
343 if (value['name'] == attr_name) {
344 choices = value['multiCategoryOptions'];
345 }
346 });
347 if (field_type == 'select') {
348 field_html += ' <select class="sib-' + attr_name + '-area" name="' + attr_name + '[]" multiple="true" ';
349 if (field_required == true) {
350 field_html += 'required="required" ';
351 }
352 field_html += '> \n';
353 }
354 $jQ.each(choices, function(index, value) {
355 if (field_type == 'select') {
356 field_html += ' <option value="' + value + '">' + value + '</option> \n';
357 } else {
358 field_html += ' <div style="display:block;"><input type="checkbox" class="sib-' + attr_name + '-area" name="' + attr_name + '[]" value="' + value + '" ';
359 if (field_required == true) {
360 field_html += 'required="required" ';
361 }
362 field_html += '>' + value + '</div> \n';
363 }
364
365 });
366 if (field_type == 'select') {
367 field_html += ' </select> \n';
368 }
369 break;
370 }
371
372 field_html += '</p>';
373 $jQ('#sib_field_html').html(field_html);
374 }
375
376 function set_select_list() {
377 var selected_list_id = $jQ('#sib_selected_list_id').val();
378
379 var data = {
380 frmid : $jQ('input[name=sib_form_id]').val(),
381 action : 'sib_get_lists',
382 security: ajax_sib_object.ajax_nonce
383 };
384 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
385 var select_html = '';
386 var selected = respond.selected;
387
388 $jQ.each(respond.lists, function(index, value) {
389 if(value['name'] == 'Temp - DOUBLE OPTIN') return true;
390 if ( selected.indexOf(value['id'].toString()) != '-1' ) {
391 select_html += '<option value="' + value['id'] + '" selected>' + value['name'] + '</option>';
392 }
393 else {
394 select_html += '<option value="' + value['id'] + '">' + value['name'] + '</option>';
395 }
396 });
397 $jQ('#sib_select_list').html(select_html).trigger("chosen:updated");
398
399 set_select_attributes();
400
401 });
402 }
403
404 function set_select_template() {
405 var selected_template_id = $jQ('#sib_selected_template_id').val();
406 var selected_do_template_id = $jQ('#sib_selected_do_template_id').val();
407 var selected_confirm_template_id = $jQ('#sib_selected_confirm_template_id').val();
408 var default_template_name = $jQ('#sib_default_template_name').val();
409 var data = {
410 action : 'sib_get_templates',
411 security: ajax_sib_object.ajax_nonce
412 };
413 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
414 var select_html = '<select id="sib_template_id" class="col-md-11" name="template_id">';
415 if (selected_template_id == '-1') {
416 select_html += '<option value="-1" selected>' + default_template_name + '</option>';
417 }
418 else {
419 select_html += '<option value="-1">' + default_template_name + '</option>';
420 }
421 $jQ.each(respond.templates, function(index, value) {
422 if (value['id'] == selected_template_id) {
423 select_html += '<option value="' + value['id'] + '" selected>' + value['name'] + '</option>';
424 }
425 else if (!value['is_dopt']) {
426 select_html += '<option value="' + value['id'] + '">' + value['name'] + '</option>';
427 }
428 });
429 select_html += '</select>';
430 $jQ('#sib_template_id_area').html(select_html);
431
432 // For double optin.
433 select_html = '<select class="col-md-11" name="doubleoptin_template_id" id="sib_doubleoptin_template_id">';
434 if (selected_do_template_id == '-1') {
435 select_html += '<option value="-1" selected>' + default_template_name + '</option>';
436 }
437 else {
438 select_html += '<option value="-1">' + default_template_name + '</option>';
439 }
440 $jQ.each(respond.templates, function(index, value) {
441 if (value['id'] == selected_do_template_id) {
442 select_html += '<option is_shortcode="' + value['is_dopt'] + '" value="' + value['id'] + '" selected>' + value['name'] + '</option>';
443 }
444 else if (value['is_dopt']) {
445 select_html += '<option is_shortcode="' + value['is_dopt'] + '" value="' + value['id'] + '">' + value['name'] + '</option>';
446 }
447 });
448 select_html += '</select>';
449 $jQ('#sib_doubleoptin_template_id_area').html(select_html);
450
451 // For final confirmation emait template
452 select_html = '<select id="sib_confirm_template_id" class="col-md-11" name="confirm_template_id">';
453 if (selected_confirm_template_id == '-1') {
454 select_html += '<option value="-1" selected>' + default_template_name + '</option>';
455 }
456 else {
457 select_html += '<option value="-1">' + default_template_name + '</option>';
458 }
459
460 $jQ.each(respond.templates, function(index, value) {
461 if (value['id'] == selected_confirm_template_id) {
462 select_html += '<option is_shortcode="' + value['is_dopt'] + '" value="' + value['id'] + '" selected>' + value['name'] + '</option>';
463 }
464 else if (!value['is_dopt']) {
465 select_html += '<option is_shortcode="' + value['is_dopt'] + '" value="' + value['id'] + '">' + value['name'] + '</option>';
466 }
467 });
468 select_html += '</select>';
469 $jQ('#sib_final_confirm_template_id_area').html(select_html);
470
471 // double optin template id
472 $jQ('#sib_doubleoptin_template_id').on('change', function() {
473 var shortcode_exist = $jQ(this).find(':selected').attr('is_shortcode');
474 if (shortcode_exist == 0 && $jQ(this).val() != -1) {
475 $jQ('#sib_form_alert_message').show();
476 $jQ('#sib_disclaim_smtp').hide();
477 $jQ('#sib_disclaim_confirm_template').hide();
478 $jQ('#sib_disclaim_do_template').show();
479 $jQ(this).val('-1');
480 }
481 else {
482 $jQ('#sib_form_alert_message').hide();
483 }
484 });
485
486 // Final confirm template id
487 $jQ('#sib_confirm_template_id').on('change', function() {
488 var shortcode_exist = $jQ(this).find(':selected').attr('is_shortcode');
489 if (shortcode_exist == 1 && $jQ(this).val() != -1) {
490 $jQ('#sib_form_alert_message').show();
491 $jQ('#sib_disclaim_smtp').hide();
492 $jQ('#sib_disclaim_confirm_template').show();
493 $jQ('#sib_disclaim_do_template').hide();
494 $jQ(this).val('-1');
495 }
496 else {
497 $jQ('#sib_form_alert_message').hide();
498 }
499 });
500
501 $jQ('#sib_setting_signup_spin').addClass('hide');
502
503 });
504 }
505
506 function set_select_attributes() {
507 var data = {
508 action : 'sib_get_attributes',
509 security: ajax_sib_object.ajax_nonce
510 };
511
512 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
513
514 var iframWidth = $jQ('.form-field').width() - 48;
515 $jQ('#sib-preview-form').width(iframWidth);
516
517 normal_attributes = respond.attrs.attributes.normal_attributes;
518 category_attributes = respond.attrs.attributes.category_attributes;
519 multiple_choice_attributes = respond.attrs.attributes.multiple_choice_attributes;
520 var attr_email_name = $jQ('#sib_hidden_email').attr('data-text');
521 var message_1 = $jQ('#sib_hidden_message_1').val();
522 var message_2 = $jQ('#sib_hidden_message_2').val();
523 var message_3 = $jQ('#sib_hidden_message_3').val();
524 var message_multichoice = $jQ('#sib_hidden_message_multichoice').val();
525 var message_4 = $jQ('#sib_hidden_message_4').val();
526 var message_5 = $jQ('#sib_hidden_message_5').val();
527 var select_html = '<select class="col-md-12" id="sib_sel_attribute">' +
528 '<option value="-1" disabled selected>' + message_1 + '</option>' +
529 '<optgroup label="' + message_2 + '">';
530 select_html += '<option value="email">' + attr_email_name + '*</option>';
531 $jQ.each(normal_attributes, function(index, value) {
532 select_html += '<option value="' + value['name'] + '">' + value['name'] + '</option>';
533 });
534 select_html += '</optgroup>';
535 select_html += '<optgroup label="' + message_3 + '">';
536 $jQ.each(category_attributes, function(index, value) {
537 if(value['name'] == 'DOUBLE_OPT-IN') return;
538 select_html += '<option value="' + value['name'] + '">' + value['name'] + '</option>';
539 });
540 select_html += '</optgroup>';
541 select_html += '<optgroup label="' + message_multichoice + '">';
542 $jQ.each(multiple_choice_attributes, function(index, value) {
543 select_html += '<option value="' + value['name'] + '">' + value['name'] + '</option>';
544 });
545 select_html += '</optgroup>';
546 select_html += '<optgroup label="' + message_4 + '">';
547 select_html += '<option value="submit">' + message_5 + '</option>';
548 select_html += '</optgroup>';
549 select_html += '</select>';
550
551 $jQ('#sib_sel_attribute_area').html(select_html);
552 $jQ('#sib_sel_attribute').on('change', function() {
553 //
554 $jQ('#sib-field-content').show();
555
556 var attr_val = $jQ(this).val();
557 var attr_type, attr_name, attr_text;
558 if (attr_val == 'email' || attr_val == 'submit') {
559 // get all info of attr
560 var hidden_attr = $jQ('#sib_hidden_' + attr_val);
561 attr_type = hidden_attr.attr('data-type');
562 attr_name = hidden_attr.attr('data-name');
563 attr_text = hidden_attr.attr('data-text');
564 }
565 else {
566 $jQ.each(normal_attributes, function(index, value) {
567 if (value['name'] == attr_val) {
568 attr_type = value['type'];
569 attr_name = value['name'];
570 attr_text = attr_name;
571 }
572 });
573
574 $jQ.each(category_attributes, function(index, value) {
575 if (value['name'] == attr_val) {
576 attr_type = value['type'];
577 attr_name = value['name'];
578 attr_text = attr_name;
579 }
580 });
581
582 $jQ.each(multiple_choice_attributes, function(index, value) {
583 if (value['name'] == attr_val) {
584 attr_type = value['type'];
585 attr_name = value['name'];
586 attr_text = attr_name;
587 }
588 });
589 }
590 // change attribute tags
591 change_attribute_tag(attr_type, attr_name, attr_text);
592
593 // generate attribute html
594 generate_attribute_html(attr_type, attr_name, attr_text);
595 });
596 $jQ('#sib_setting_form_spin').addClass('hide');
597 set_select_template();
598 });
599 }
600
601 function update_preview(){
602
603 var selectCaptchaType = $jQ('.sib-captcha-select').val();
604 var frmid = $jQ('#sib_form_id').val();
605 var formHtml = $jQ('#sibformmarkup').val();
606 var formCss = $jQ('#sibcssmarkup').val();
607 var isDepend = $jQ('input[name=sib_css_type]:checked').val();
608 if (selectCaptchaType == 3) {
609 var cCaptcha = $jQ('input[name=sib_add_captcha]:checked').val();
610 var cCaptchaSite = $jQ('#sib_captcha_site_turnstile').val();
611 var data = {
612 action:'sib_update_form_html',
613 security: ajax_sib_object.ajax_nonce,
614 frmid: frmid,
615 frmData: formHtml,
616 frmCss: formCss,
617 isDepend: isDepend,
618 selectCaptchaType: selectCaptchaType,
619 gCaptcha: cCaptcha,
620 cCaptchaSite: cCaptchaSite
621 };
622 } else if (selectCaptchaType != 3) {
623 var gCaptcha = $jQ('input[name=sib_add_captcha]:checked').val();
624 var gCaptchaType = $jQ('input[name=sib_recaptcha_type]:checked').val();
625 var gCaptchaSite = $jQ('#sib_captcha_site').val();
626 var data = {
627 action:'sib_update_form_html',
628 security: ajax_sib_object.ajax_nonce,
629 frmid: frmid,
630 frmData: formHtml,
631 frmCss: formCss,
632 isDepend: isDepend,
633 gCaptcha: gCaptcha,
634 gCaptchaType: gCaptchaType,
635 gCaptchaSite: gCaptchaSite,
636 selectCaptchaType: selectCaptchaType,
637 };
638 }
639 $jQ.post(ajax_sib_object.ajax_url, data,function() {
640 var preview_form = $jQ('#sib-preview-form');
641 preview_form.attr('src', preview_form.attr('src') + '&action=update');
642 });
643
644 }
645 // get cursor posistion of text area
646 function get_cursor_position(node) {
647 //node.focus();
648 /* without node.focus() IE will returns -1 when focus is not on node */
649 if(node.selectionStart) return node.selectionStart;
650 else if(!document.selection) return 0;
651 var c = "\001";
652 var sel = document.selection.createRange();
653 var dul = sel.duplicate();
654 dul.moveToElementText(node);
655 sel.text = c;
656 var len = (dul.text.indexOf(c));
657 sel.moveStart('character',-1);
658 sel.text = "";
659 return len;
660 }
661 // set cursor position at top of text area
662 function setSelectionRange(input, selectionStart, selectionEnd) {
663 if (input.setSelectionRange) {
664 input.focus();
665 input.setSelectionRange(selectionStart, selectionEnd);
666 } else if (input.createTextRange) {
667 var range = input.createTextRange();
668 range.collapse(true);
669 range.moveEnd('character', selectionEnd);
670 range.moveStart('character', selectionStart);
671 range.select();
672 }
673 }
674
675 // generate html for multi subscription lists
676 function generate_multi_list_html() {
677 var field_label = $jQ('#sib_multi_field_label').val();
678 var field_html = '<p class="sib-multi-lists-area">\n';
679 var list_id = '';
680 var list_name = '';
681 var required = false;
682 var required_label = '';
683 var required_attr = '';
684 if ( $jQ('#sib_multi_field_required').is(":checked"))
685 {
686 required = true;
687 required_label = '*';
688 required_attr = 'required';
689 }
690 if ( field_label != '' )
691 {
692 field_html += '<label>' + field_label + required_label + '</label>\n';
693 }
694
695 field_html += '<div class="sib-multi-lists" data-require="' + required_attr + '">\n';
696 var selected_lists = $jQ('#sib_select_multi_list').find('option:selected', this);
697 selected_lists.each(function(){
698 list_id = $jQ(this).val();
699 list_name = $jQ(this).data('list');
700 field_html += '<div style="block"><input type="checkbox" class="sib-interesting-lists" value="' + list_id + '" name="listIDs[]">' + list_name + '</div>\n';
701 });
702 field_html += '</div></p>';
703 $jQ('#sib_multi_field_html').html(field_html);
704 }
705 /////////////////////////////////
706 /* home settings */
707 /////////////////////////////////
708
709 // var elements
710 var sib_access_key = $jQ('#sib_access_key');
711 var sib_validate_btn = $jQ('#sib_validate_btn');
712
713 // validate button click process in welcome page
714 sib_validate_btn.on('click', function(){
715
716 var access_key = sib_access_key.val();
717
718 // check validation
719 var error_flag = 0;
720 if(access_key == '') {
721 sib_access_key.addClass('error');
722 error_flag =1;
723 }
724
725 if(error_flag != 0) {
726 return false;
727 }
728
729 // ajax process for validate
730 var data = {
731 action:'sib_validate_process',
732 access_key: access_key,
733 security: ajax_sib_object.ajax_nonce
734 };
735
736 $jQ('.sib_alert').hide();
737 $jQ('.sib-spin').show();
738 sib_access_key.removeClass('error');
739 $jQ(this).attr('disabled', 'true');
740
741 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
742 $jQ('.sib-spin').hide();
743 sib_validate_btn.removeAttr('disabled');
744 if(respond == 'success') {
745 $jQ('#success-alert').show();
746 /*var cur_url = $jQ('#cur_refer_url').val();
747 window.location.href = cur_url;*/
748 window.location.reload();
749 }
750 else if (respond == 'curl_no_installed') {
751 sib_access_key.addClass('error');
752 $jQ('#failure-alert').html($jQ('#curl_no_exist_error').val()).show();
753 }
754 else if (respond == 'curl_error') {
755 sib_access_key.addClass('error');
756 $jQ('#failure-alert').html($jQ('#curl_error').val()).show();
757 }
758 else {
759 sib_access_key.addClass('error');
760 $jQ('#failure-alert').html(respond).show();
761 }
762 });
763 });
764
765 sib_access_key.on('keypress', function(){
766 $jQ(this).removeClass('error');
767 });
768
769 // Transactional emails
770 $jQ('input[name=activate_email]').on('click', function(){
771 var option_val = $jQ(this).val();
772 var data = {
773 action: 'sib_activate_email_change',
774 option_val: option_val,
775 security: ajax_sib_object.ajax_nonce
776 };
777 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
778 if(respond == 'yes')
779 $jQ('#email_send_field').show();
780 else
781 $jQ('#email_send_field').hide();
782 });
783
784 return true;
785 });
786
787 // change sender detail
788 $jQ('#sender_list').on('change',function(){
789 var data = {
790 action: 'sib_sender_change',
791 sender: $jQ(this).val(),
792 security: ajax_sib_object.ajax_nonce
793 };
794 $jQ.post(ajax_sib_object.ajax_url, data, function() {
795 $jQ(this).blur();
796 });
797
798 return true;
799 });
800 $jQ('#activate_push_btn').on('click', function() {
801 var $btn = this;
802 var deactivate = function() {
803 $jQ('#sib-push-activation-message').show();
804 $jQ($btn).find('.sib-spin').show();
805 $jQ($btn).attr('disabled', 'disabled');
806 };
807 deactivate();
808 var data = {
809 action: 'sib_push_set_push_activated',
810 activated: 'true',
811 nonce: ajax_sib_object.ajax_nonce
812 };
813 $jQ.post(ajax_sib_object.ajax_url, data, function(response) {
814 window.location.reload();
815 });
816 });
817 $jQ(document).on('click', '#deactivate_push_btn', function(event) {
818 event.preventDefault();
819 event.stopPropagation();
820 var data = {
821 action: 'sib_push_set_push_activated',
822 activated: 'false',
823 nonce: ajax_sib_object.ajax_nonce
824 };
825 $jQ.post(ajax_sib_object.ajax_url, data, function(response) {
826 window.location.reload();
827 });
828
829 });
830 // validate MA
831 $jQ('#validate_ma_btn').on('click',function(){
832 var option_val = $jQ('input[name=activate_ma]:checked').val();
833 var data = {
834 action:'sib_validate_ma',
835 option_val: option_val,
836 security: ajax_sib_object.ajax_nonce
837 };
838 var uninstall = false;
839 var uninstallMsg = $jQ('#sib-ma-unistall').val();
840 if(option_val != 'yes'){
841 uninstall = confirm(uninstallMsg);
842 }
843 if(option_val == 'yes' || uninstall) {
844 $jQ(this).find('.sib-spin').show();
845 $jQ('.sib-ma-alert').hide();
846 $jQ(this).attr('disabled', 'true');
847 $jQ.post(ajax_sib_object.ajax_url, data, function (respond) {
848 $jQ('.sib-spin').hide();
849 $jQ('#validate_ma_btn').removeAttr('disabled');
850 if (respond == 'yes') {
851 $jQ('.sib-ma-active').show();
852 } else if(respond == 'no') {
853 $jQ('.sib-ma-inactive').show();
854 } else if(respond == 'disabled'){
855 $jQ('.sib-ma-disabled').show();
856 $jQ('#activate_ma_radio_no').prop('checked', true);
857 }
858 setTimeout(function(){
859 if(respond != 'disabled')
860 window.location.reload();
861 },2000);
862
863 });
864 }
865 });
866
867 // send activate email button
868 $jQ('#send_email_btn').on('click',function(){
869 var activate_email = $jQ('#activate_email');
870 var email = activate_email.val();
871 if(email == '' || isValidEmailAddress(email) != true) {
872 activate_email.removeClass('has-success').addClass('error');
873 $jQ('#failure-alert').show();
874 return false;
875 }
876 $jQ(this).attr('disabled', 'true');
877
878 var data = {
879 action:'sib_send_email',
880 email:email,
881 security: ajax_sib_object.ajax_nonce
882 };
883
884 $jQ('.sib_alert').hide();
885 activate_email.removeClass('error');
886 $jQ(this).find('.sib-spin').show();
887 $jQ.post(ajax_sib_object.ajax_url, data,function(respond) {
888 $jQ('.sib-spin').hide();
889 $jQ('#send_email_btn').removeAttr('disabled');
890 if(respond != 'success') {
891 $jQ('#activate_email').removeClass('has-success').addClass('error');
892 $jQ('#failure-alert').show();
893 } else {
894 $jQ('#success-alert').show();
895 }
896 });
897 });
898
899 ////////////////////////////////
900 /* manage forms */
901 ////////////////////////////////
902
903 $jQ('#sib-field-content').hide();
904
905 // check confirm email
906 var is_send_confirm_email = $jQ("input[name=is_confirm_email]:checked").val();
907
908 if(is_send_confirm_email == '1') {
909 $jQ('#sib_confirm_template_area').show();
910 $jQ('#sib_confirm_sender_area').show();
911 } else {
912 $jQ('#sib_confirm_template_area').hide();
913 $jQ('#sib_confirm_sender_area').hide();
914 }
915
916 // check double optin
917 var is_double_optin = $jQ("input[name=is_double_optin]:checked").val();
918
919 if(is_double_optin == '1') {
920 $jQ('#is_confirm_email_no').prop("checked", true);
921 $jQ('#sib_confirm_template_area').hide();
922 $jQ('#sib_confirm_sender_area').hide();
923 $jQ('#sib_double_sender_area').show();
924 $jQ('#sib_doubleoptin_template_area').show();
925
926 } else {
927 $jQ('#sib_double_sender_area').hide();
928 $jQ('#sib_double_redirect_area').hide();
929 $jQ('#sib_doubleoptin_template_area').hide();
930 $jQ('#sib_final_confirm_template_area').hide();
931 }
932
933 if ($jQ('#sib_setting_signup_body').find('#sib_select_list_area').length > 0 ) {
934 set_select_list();
935 $jQ('#sib_select_list').chosen({width:"100%"});
936 }
937
938 // For multi lists subscription
939 if ( $jQ('#sib_setting_form_body').find('#sib_sel_multi_list_area').length > 0 ) {
940 var data = {
941 frmid : $jQ('input[name=sib_form_id]').val(),
942 action : 'sib_get_lists',
943 security: ajax_sib_object.ajax_nonce
944 };
945 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
946 var select_html = '';
947 $jQ.each(respond.lists, function(index, value) {
948 if(value['name'] == 'Temp - DOUBLE OPTIN') return true;
949 select_html += '<option value="' + value['id'] + '" data-list="' + value['name'] + '">' + value['name'] + '</option>';
950 });
951 $jQ('#sib_select_multi_list').html(select_html).trigger("chosen:updated");
952 $jQ('#sib_select_multi_list').chosen({width:"100%"});
953 });
954 }
955
956 $jQ('#sib_select_multi_list').on('change', function(){
957 if ( $jQ(this).val() != null )
958 {
959 $jQ('#sib_multi_list_field').show();
960 generate_multi_list_html();
961 }
962 else {
963 $jQ('#sib_multi_list_field').hide();
964 }
965 });
966
967 $jQ('#sib_multi_field_label').on('change', function () {
968 generate_multi_list_html();
969 });
970
971 $jQ('#sib_multi_field_required').on('change', function () {
972 generate_multi_list_html();
973 });
974 // keep change of fields
975 $jQ('.sib_field_changes').on('change',function() {
976 change_field_attr();
977 });
978
979 // click confirm email
980 $jQ("input[name=is_confirm_email]").on('click',function() {
981 var confirm_email = $jQ(this).val();
982 var is_activated_smtp = parseInt($jQ("#is_smtp_activated").val());
983
984 if(confirm_email == '1') {
985 $jQ('#sib_doubleoptin_template_id').val('-1');
986 $jQ('#sib_confirm_template_id').val('-1');
987 $jQ('#is_double_optin_no').prop("checked", true);
988 $jQ('#sib_double_sender_area').hide();
989 $jQ('#sib_double_redirect_area').hide();
990 $jQ('#sib_confirm_template_area').show();
991 $jQ('#sib_confirm_sender_area').show();
992 $jQ('#sib_doubleoptin_template_area').hide();
993 $jQ('#sib_final_confirm_template_area').hide();
994 $jQ('#sib_form_alert_message').hide();
995 if (is_activated_smtp == 0) {
996 $jQ('#sib_form_alert_message').show();
997 $jQ('#sib_disclaim_smtp').show();
998 $jQ('#sib_disclaim_do_template').hide();
999 $jQ('#sib_disclaim_confirm_template').hide();
1000 }
1001 } else {
1002 $jQ('#sib_confirm_template_area').hide();
1003 $jQ('#sib_confirm_sender_area').hide();
1004 $jQ('#sib_form_alert_message').hide();
1005 }
1006 });
1007
1008 // click double optin
1009 $jQ('input[name=is_double_optin]').on('click', function() {
1010 var double_optin = $jQ(this).val();
1011 var is_activated_smtp = parseInt($jQ("#is_smtp_activated").val());
1012 if(double_optin == '1') {
1013 $jQ('#sib_template_id').val('-1');
1014 $jQ('#is_confirm_email_no').prop("checked", true);
1015 $jQ('#sib_confirm_template_area').hide();
1016 $jQ('#sib_confirm_sender_area').hide();
1017 $jQ('#sib_double_sender_area').show();
1018 $jQ('#sib_double_redirect_area').show();
1019 $jQ('#sib_doubleoptin_template_area').show();
1020 $jQ('#sib_final_confirm_template_area').show();
1021 if (is_activated_smtp == 0) {
1022 $jQ('#sib_form_alert_message').show();
1023 $jQ('#sib_disclaim_smtp').show();
1024 $jQ('#sib_disclaim_do_template').hide();
1025 $jQ('#sib_disclaim_confirm_template').hide();
1026 }
1027 } else {
1028 $jQ('#sib_double_sender_area').hide();
1029 $jQ('#sib_double_redirect_area').hide();
1030 $jQ('#sib_doubleoptin_template_area').hide();
1031 $jQ('#sib_form_alert_message').hide();
1032 $jQ('#sib_final_confirm_template_area').hide();
1033 }
1034 });
1035
1036 // click redirect url
1037 $jQ('#is_redirect_url_click_yes').on('click', function () {
1038 $jQ('#sib_subscrition_redirect_area').show();
1039 });
1040 $jQ('#is_redirect_url_click_no').on('click', function () {
1041 $jQ('#sib_subscrition_redirect_area').hide();
1042 });
1043
1044 //// refresh iframe to preview form
1045 $jQ('#sib-preview-form-refresh').on('click',function(){
1046 // ajax to update form html
1047 update_preview();
1048 });
1049
1050 //// display popup when delete form
1051 $jQ('.sib-form-delete').on('click', function(e) {
1052 return confirm('Are you sure you want to delete this form?');
1053 });
1054
1055 //// custom or theme's css
1056 $jQ('input[name=sib_css_type]').on('change',function() {
1057 $jQ('#sibcssmarkup').toggle();
1058 update_preview();
1059 });
1060
1061 // remove all transients
1062 $jQ(window).focus(function() {
1063
1064 var data = {
1065 action: 'sib_remove_cache',
1066 security: ajax_sib_object.ajax_nonce
1067 };
1068 $jQ.post(ajax_sib_object.ajax_url, data,function(respond) {
1069
1070 if(respond == 'success') {
1071 //
1072 }
1073 });
1074 });
1075
1076 /* sync wordpress users to sendinblue contact list */
1077 // sync popup
1078 $jQ('#sib-sync-btn').on('click', function() {
1079 var syncModal = $jQ('.sib-sync-modal');
1080 syncModal.modal();
1081 $jQ('#sync-failure').hide();
1082
1083 // add to multilist field
1084 var list = $jQ('#sib_select_list');
1085 list[0].selectedIndex = 0;
1086 list.chosen({width:"100%"});
1087
1088 syncModal.on('hidden.bs.modal', function () {
1089 //window.location.reload();
1090 });
1091 });
1092
1093 var attrFieldLine = $jQ('.sync-attr-line').html();
1094 var appenderLine = $jQ('.sync-attr-plus-col').html();
1095 // sync add attr line filed
1096 $jQ('.modal-body').on('click', '.sync-attr-plus', function(){
1097 $jQ(this).css('visibility', 'hidden');
1098 $jQ(this).addClass('pb-2');
1099 $jQ('.sync-attr-plus-col').append(appenderLine);
1100 $jQ('.sync-attr-line').append(attrFieldLine);
1101 $jQ('.sync-attr-dismiss').show();
1102 });
1103 // sync dismiss attr line filed
1104 $jQ('.modal-body').on('click', '.sync-attr-dismiss', function(){
1105 $jQ(this).closest('.sync-attr').remove();
1106 var attrCount = $jQ('.sync-attr').length;
1107 if(attrCount == 1) {
1108 $jQ('.sync-attr-dismiss').hide();
1109 }
1110 $jQ(`.sync-attr-plus-col .sync-attr-plus:nth-child(${attrCount - 1})`).css('visibility', 'show');
1111 $jQ(`.sync-attr-plus-col .sync-attr-plus:nth-child(${attrCount})`).remove();
1112 });
1113
1114 // set attribute matching
1115 $jQ('.modal-body').on('change', 'select', function () {
1116 if($jQ(this).attr("class") == 'sync-wp-attr'){
1117 $jQ(this).closest('.sync-attr').find('.sync-match').val($jQ(this).val());
1118 }else{
1119 $jQ(this).closest('.sync-attr').find('.sync-match').attr('name',$jQ(this).val());
1120 }
1121 });
1122
1123 // sync users to sendinblue
1124 $jQ('#sib_sync_users_btn').on('click', function(){
1125
1126 $jQ(this).attr('disabled', 'true');
1127 var postData = $jQ('#sib-sync-form').serializeObject();
1128 $jQ(this).closest('form').find('input[type=hidden]').each(function (index, value) {
1129 var attrName = $jQ(this).attr('name');
1130 if($jQ('input[name='+attrName+']').length > 1){
1131 // the attribute is duplicated !
1132 postData['errAttr'] = attrName;
1133 }
1134 });
1135
1136 var data = {
1137 action:'sib_sync_users',
1138 data: postData,
1139 security: ajax_sib_object.ajax_nonce
1140 };
1141
1142 $jQ('.sib_alert').hide();
1143 $jQ(this).find('.sib-spin').show();
1144 $jQ.post(ajax_sib_object.ajax_url, data,function(respond) {
1145 $jQ('.sib-spin').hide();
1146 $jQ('#sib_sync_users_btn').removeAttr('disabled');
1147 let messageBox = '';
1148 if(respond.code != 'success') {
1149 messageBox = 'sync-failure';
1150 $jQ('#sync-failure').show().html(respond.message);
1151 } else {
1152 // success to sync wp users
1153 location.reload();
1154 $jQ('.sib-sync-modal').modal('toggle');
1155 $jQ('#sib-message-body').html(respond.message);
1156 $jQ('#sib-message-box').show();
1157 }
1158 });
1159
1160 });
1161 $jQ('.sib-add-captcha').on('click', function(){
1162 var add_captcha = $jQ(this).val();
1163 var selectCaptchaType = $jQ('.sib-captcha-select').val();
1164 if(add_captcha == '1')
1165 {
1166 $jQ('.sib-captcha-select').show('slow');
1167
1168 if (selectCaptchaType == 2) {
1169 $jQ('.sib-captcha-key').show('slow');
1170 } else if (selectCaptchaType == 3) {
1171 $jQ('.sib-captcha-key-turnstile').show('slow');
1172 }
1173 }
1174 else
1175 {
1176 $jQ('.sib-captcha-select').hide('slow');
1177 $jQ('.sib-captcha-key').hide('slow');
1178 $jQ('.sib-captcha-key-turnstile').hide('slow');
1179 }
1180 });
1181
1182 //Captcha select
1183 $jQ('.sib-captcha-select').on('change', function(){
1184 var add_captcha = $jQ(this).val();
1185 if(add_captcha == '1')
1186 {
1187 $jQ('.sib-captcha-key-turnstile').hide('slow');
1188 $jQ('.sib-captcha-key').hide('slow');
1189 }
1190 else if(add_captcha == '2')
1191 {
1192 $jQ('.sib-captcha-key-turnstile').hide('slow');
1193 $jQ('.sib-captcha-key').show('slow');
1194 }
1195 else if (add_captcha == '3')
1196 {
1197 $jQ('.sib-captcha-key').hide('slow');
1198 $jQ('.sib-captcha-key-turnstile').show('slow');
1199 }
1200 });
1201
1202 $jQ('.popover-help-form').popover({
1203 });
1204 $jQ('.sib-spin').hide();
1205 $jQ('body').on('click', function(e) {
1206 if(!$jQ(e.target).hasClass('popover-help-form')) {
1207 $jQ('.popover-help-form').popover('hide');
1208 }
1209 });
1210
1211 $jQ('.sib-add-terms').on('click', function(){
1212 var add_terms = $jQ(this).val();
1213 if(add_terms == '1')
1214 {
1215 $jQ('.sib-terms-url').show('slow');
1216 }
1217 else
1218 {
1219 $jQ('.sib-terms-url').hide('slow');
1220 }
1221 });
1222
1223 $jQ('.sib-add-to-form').on('click', function(){
1224 var btn_id = $jQ(this).attr('id');
1225 var field_html = '';
1226
1227 var formMarkup = $jQ("#sibformmarkup");
1228 var cursorPosition = get_cursor_position(formMarkup[0]);
1229 var html = formMarkup.val();
1230 var replacedHTML = "";
1231
1232 if(btn_id == 'sib_add_to_form_btn')
1233 {
1234 let textToslice = $jQ("#sib_field_html").val();
1235 var position = textToslice.search("sib_SMS_prefix");
1236 let firstpart = position + 22;
1237
1238 let lastPoint = firstpart + 7;
1239 let sliceValue = textToslice.slice(firstpart, lastPoint);
1240 var code = sliceValue.substring(sliceValue.indexOf("+") + 1, sliceValue.lastIndexOf('"'));
1241
1242 var flagInicial = CountryList[code];
1243 if (typeof flagInicial !== "undefined") {
1244 var flagICo = jQuery('#getDomain').val() + flagInicial.toLowerCase() + ".png";
1245
1246 field_html = textToslice.replace('class="sib-cflags"', `class="sib-cflags" style=background-image:url(${flagICo})`);
1247 } else {
1248 field_html = textToslice;
1249 }
1250 }
1251 else if(btn_id == 'sib_multi_lists_add_form_btn')
1252 {
1253 field_html = $jQ('#sib_multi_field_html').val();
1254 $jQ('#sib_multi_list_field').hide();
1255 }
1256 else if(btn_id == 'sib_add_captcha_btn')
1257 {
1258 var site_key = $jQ('#sib_captcha_site').val();
1259 var secret_key = $jQ('#sib_captcha_secret').val();
1260 var gCaptcha_type = $jQ('input[name=sib_recaptcha_type]:checked').val();
1261
1262 if(gCaptcha_type == '0')
1263 {
1264 $jQ('.cf-turnstile').remove();
1265 field_html = '<div id="sib_captcha"></div>';
1266 }
1267
1268 if(site_key == '')
1269 {
1270 $jQ('#sib_form_captcha .alert-danger').html('You should input <strong>Site Key</strong>').show(300);
1271 return false;
1272 }
1273 else if(secret_key == '')
1274 {
1275 $jQ('#sib_form_captcha .alert-danger').html('You should input <strong>Secrete Key</strong>').show(300);
1276 return false;
1277 }
1278 }
1279 else if(btn_id == 'sib_add_captcha_btn_turnstile')
1280 {
1281 var site_key = $jQ('#sib_captcha_site_turnstile').val();
1282 var secret_key = $jQ('#sib_captcha_secret_turnstile').val();
1283 var secret_key = $jQ('#sib_captcha_secret_turnstile').val();
1284 var cCaptchaStyle = $jQ('input[name=turnstile_captcha_theme]:checked').val();
1285
1286 var if_site_key_exists = $jQ('#cf-turnstile').val();
1287
1288 if ((if_site_key_exists == '') || (if_site_key_exists != site_key)) {
1289 field_html = '<div id="' + "cf-turnstile-"+site_key + '"' + ' class="cf-turnstile" data-error-callback="errorCallbackForTurnstileErrors" data-sitekey="'+site_key+'" data-theme="'+cCaptchaStyle+'"></div>';
1290 } else {
1291 replacedHTML = html;
1292 }
1293
1294 if(site_key == '')
1295 {
1296 $jQ('#sib_form_captcha .alert-danger').html('You should input <strong>Site Key</strong>').show(300);
1297 return false;
1298 }
1299 else if(secret_key == '')
1300 {
1301 $jQ('#sib_form_captcha .alert-danger').html('You should input <strong>Secrete Key</strong>').show(300);
1302 return false;
1303 }
1304 }
1305 else if(btn_id == 'sib_add_termsUrl_btn')
1306 {
1307 var terms_url = $jQ('#sib_terms_url').val();
1308 field_html = '<input type="checkbox" name="terms" required="required">I accept the <a href="' + terms_url + '">terms and conditions</a> ';
1309 if(terms_url == '')
1310 {
1311 $jQ('#sib_form_terms .alert-danger').html('You should input <strong>Terms URL</strong>').show(300);
1312 return false;
1313 }
1314 }
1315 else if(btn_id == 'sib_add_compliance_note')
1316 {
1317 var compliance_note = $jQ('#sib_gdpr_text').val();
1318 field_html = '<p>' + compliance_note + '</p>';
1319 }
1320
1321 replacedHTML = html.replace(/<div id="cf-turnstile.*?>(.*?)<\/div>/, '$1');
1322
1323 if(replacedHTML.charCodeAt(cursorPosition) == 10 || replacedHTML.charCodeAt(cursorPosition) == 13){ // 10 is value of new line
1324 field_html = "\n" + field_html;
1325 }else{
1326 field_html = field_html + "\n";
1327 }
1328
1329 var formData = [replacedHTML.slice(0, cursorPosition), field_html, replacedHTML.slice(cursorPosition)].join('');
1330
1331 formMarkup.val(formData);
1332
1333 // hide field edit after add the field to form
1334 $jQ('#sib-field-content').hide();
1335 $jQ("#sib_sel_attribute").val('-1');
1336
1337 /*/ refresh iframe form /*/
1338 // ajax to update form html
1339 update_preview();
1340 // set cursor position at top
1341 setSelectionRange(formMarkup[0], 0, 0);
1342 return false;
1343 });
1344
1345 var redirect = '';
1346 $jQ('.sib-form-redirect').on('click', function(e){
1347 e.preventDefault();
1348 redirect = $jQ(this).attr('href');
1349 $jQ('#sib_modal').modal();
1350 });
1351
1352 $jQ('#sib_form_lang').on('change', function(){
1353 $jQ('#sib_modal').modal();
1354 });
1355
1356 $jQ('#sib_modal_cancel').on('click', function(){
1357 $jQ('#sib_modal').modal('hide');
1358 $jQ('#sib_form_lang').val("");
1359 });
1360 $jQ('#sib_modal_ok').on('click', function(){
1361 var url = (redirect != '')? redirect :$jQ('#sib_form_lang').val();
1362 window.location.href = url;
1363 });
1364
1365 // duplicate content from origin form in translation
1366 $jQ('.sib-duplicate-btn').on('click', function(){
1367 $jQ('.sib-spin').show();
1368 var pid = $jQ('input[name="pid"]').val();
1369 var data = {
1370 action: 'sib_copy_origin_form',
1371 pid: pid,
1372 security: ajax_sib_object.ajax_nonce
1373 };
1374 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
1375 $jQ('.sib-spin').hide();
1376 $jQ('#sibformmarkup').val(respond);
1377 });
1378
1379 });
1380
1381 $jQ('.sib-add-compliant-note').on('click', function () {
1382 var add_notes = $jQ(this).val();
1383 if(add_notes == '1')
1384 {
1385 $jQ('.sib-gdpr-block-area').show('slow');
1386 $jQ('.sib-gdpr-block-btn').show('slow');
1387 }
1388 else
1389 {
1390 $jQ('.sib-gdpr-block-area').hide('slow');
1391 $jQ('.sib-gdpr-block-btn').hide('slow');
1392 }
1393 });
1394 $jQ('#set_gdpr_default').on('click', function () {
1395 $jQ('#sib_gdpr_text').val(ajax_sib_object.compliance_note);
1396 })
1397
1398 if($jQ("#sib-statistics-date").length) {
1399 $jQ("#sib-statistics-date").datepicker({
1400 dateFormat: 'yy-mm-dd',
1401 numberOfMonths: 1,
1402 onSelect: function( selectedDate ) {
1403 if(!$jQ(this).data().datepicker.first){
1404 $jQ(this).data().datepicker.inline = true
1405 $jQ(this).data().datepicker.first = selectedDate;
1406 }else{
1407 if(selectedDate > $jQ(this).data().datepicker.first){
1408 $jQ(this).val($jQ(this).data().datepicker.first+" - "+selectedDate);
1409 }else{
1410 $jQ(this).val(selectedDate+" - "+$jQ(this).data().datepicker.first);
1411 }
1412 $jQ(this).data().datepicker.inline = false;
1413 }
1414 },
1415 onClose:function(){
1416 delete $jQ(this).data().datepicker.first;
1417 $jQ(this).data().datepicker.inline = false;
1418 }
1419 })
1420 }
1421 $jQ('#sib-statistics-form').on('submit', function (data) {
1422 $jQ("#apply-date-range").attr("disabled", true);
1423 $jQ('.sib-spinner').addClass('is-active');
1424 return true;
1425 });
1426
1427 $jQ('#sibformmarkup').on('change', function ($data) {
1428 var formHtml = $jQ('#sibformmarkup').val();
1429 formHtml = updateHtmlWithFlag(formHtml);
1430 $jQ('#sibformmarkup').val(formHtml);
1431 });
1432 });
1433
1434 // get serialized data form sync users form
1435 $jQ.fn.serializeObject = function()
1436 {
1437 var o = {};
1438 var a = this.serializeArray();
1439 $jQ.each(a, function() {
1440 if (o[this.name] !== undefined) {
1441 if (!o[this.name].push) {
1442 o[this.name] = [o[this.name]];
1443 }
1444 o[this.name].push(this.value || '');
1445 } else {
1446 o[this.name] = this.value || '';
1447 }
1448 });
1449 return o;
1450 };
1451
1452 function updateHtmlWithFlag(htmlString) {
1453 var customEle = document.createElement( 'section' );
1454 customEle.innerHTML = htmlString;
1455 var codeEle = customEle.querySelector("[name='sib_SMS_prefix']");
1456 if(codeEle === null) {
1457 return htmlString;
1458 }
1459 let dialCode = codeEle.value;
1460 dialCode = dialCode.replace('+','');
1461 var flagInicial = CountryList[dialCode];
1462 if (typeof flagInicial !== "undefined") {
1463 let flagICo = jQuery('#getDomain').val()+flagInicial.toLowerCase()+".png";
1464 customEle.querySelector("[class='sib-cflags']").removeAttribute("style");
1465 customEle.querySelector("[class='sib-cflags']").setAttribute("style","background-image:url("+flagICo+")");
1466 }
1467 var HtString = customEle.innerHTML;
1468 HtString = HtString.replace('</p><div class="sib-sms-field','<div class="sib-sms-field');
1469 HtString = HtString.replace('<p></p>','</p>');
1470 return HtString;
1471 }
1472