PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / trunk
Brevo – Email, SMS, Web Push, Chat, and more. vtrunk
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 07ce647460eedd481f6c.png 5 months ago 7121da981b3a8f7cc599.png 5 months ago 78b609c78c1dd3312c78.webp 5 months ago admin.js 10 months ago chosen.jquery.min.js 9 years ago index.php 11 years ago mailin-front.js 1 year ago post-editor.bundle.js 2 months ago push.bundle.js 2 months ago select2.full.min.js 1 year ago
admin.js
1476 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 contentNode = document.getElementById('deactivate_push_content');
821 var content = contentNode ? contentNode.textContent : '';
822 if (confirm(content)) {
823 var data = {
824 action: 'sib_push_set_push_activated',
825 activated: 'false',
826 nonce: ajax_sib_object.ajax_nonce
827 };
828 $jQ.post(ajax_sib_object.ajax_url, data, function(response) {
829 window.location.reload();
830 });
831 }
832
833 });
834 // validate MA
835 $jQ('#validate_ma_btn').on('click',function(){
836 var option_val = $jQ('input[name=activate_ma]:checked').val();
837 var data = {
838 action:'sib_validate_ma',
839 option_val: option_val,
840 security: ajax_sib_object.ajax_nonce
841 };
842 var uninstall = false;
843 var uninstallMsg = $jQ('#sib-ma-unistall').val();
844 if(option_val != 'yes'){
845 uninstall = confirm(uninstallMsg);
846 }
847 if(option_val == 'yes' || uninstall) {
848 $jQ(this).find('.sib-spin').show();
849 $jQ('.sib-ma-alert').hide();
850 $jQ(this).attr('disabled', 'true');
851 $jQ.post(ajax_sib_object.ajax_url, data, function (respond) {
852 $jQ('.sib-spin').hide();
853 $jQ('#validate_ma_btn').removeAttr('disabled');
854 if (respond == 'yes') {
855 $jQ('.sib-ma-active').show();
856 } else if(respond == 'no') {
857 $jQ('.sib-ma-inactive').show();
858 } else if(respond == 'disabled'){
859 $jQ('.sib-ma-disabled').show();
860 $jQ('#activate_ma_radio_no').prop('checked', true);
861 }
862 setTimeout(function(){
863 if(respond != 'disabled')
864 window.location.reload();
865 },2000);
866
867 });
868 }
869 });
870
871 // send activate email button
872 $jQ('#send_email_btn').on('click',function(){
873 var activate_email = $jQ('#activate_email');
874 var email = activate_email.val();
875 if(email == '' || isValidEmailAddress(email) != true) {
876 activate_email.removeClass('has-success').addClass('error');
877 $jQ('#failure-alert').show();
878 return false;
879 }
880 $jQ(this).attr('disabled', 'true');
881
882 var data = {
883 action:'sib_send_email',
884 email:email,
885 security: ajax_sib_object.ajax_nonce
886 };
887
888 $jQ('.sib_alert').hide();
889 activate_email.removeClass('error');
890 $jQ(this).find('.sib-spin').show();
891 $jQ.post(ajax_sib_object.ajax_url, data,function(respond) {
892 $jQ('.sib-spin').hide();
893 $jQ('#send_email_btn').removeAttr('disabled');
894 if(respond != 'success') {
895 $jQ('#activate_email').removeClass('has-success').addClass('error');
896 $jQ('#failure-alert').show();
897 } else {
898 $jQ('#success-alert').show();
899 }
900 });
901 });
902
903 ////////////////////////////////
904 /* manage forms */
905 ////////////////////////////////
906
907 $jQ('#sib-field-content').hide();
908
909 // check confirm email
910 var is_send_confirm_email = $jQ("input[name=is_confirm_email]:checked").val();
911
912 if(is_send_confirm_email == '1') {
913 $jQ('#sib_confirm_template_area').show();
914 $jQ('#sib_confirm_sender_area').show();
915 } else {
916 $jQ('#sib_confirm_template_area').hide();
917 $jQ('#sib_confirm_sender_area').hide();
918 }
919
920 // check double optin
921 var is_double_optin = $jQ("input[name=is_double_optin]:checked").val();
922
923 if(is_double_optin == '1') {
924 $jQ('#is_confirm_email_no').prop("checked", true);
925 $jQ('#sib_confirm_template_area').hide();
926 $jQ('#sib_confirm_sender_area').hide();
927 $jQ('#sib_double_sender_area').show();
928 $jQ('#sib_doubleoptin_template_area').show();
929
930 } else {
931 $jQ('#sib_double_sender_area').hide();
932 $jQ('#sib_double_redirect_area').hide();
933 $jQ('#sib_doubleoptin_template_area').hide();
934 $jQ('#sib_final_confirm_template_area').hide();
935 }
936
937 if ($jQ('#sib_setting_signup_body').find('#sib_select_list_area').length > 0 ) {
938 set_select_list();
939 $jQ('#sib_select_list').chosen({width:"100%"});
940 }
941
942 // For multi lists subscription
943 if ( $jQ('#sib_setting_form_body').find('#sib_sel_multi_list_area').length > 0 ) {
944 var data = {
945 frmid : $jQ('input[name=sib_form_id]').val(),
946 action : 'sib_get_lists',
947 security: ajax_sib_object.ajax_nonce
948 };
949 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
950 var select_html = '';
951 $jQ.each(respond.lists, function(index, value) {
952 if(value['name'] == 'Temp - DOUBLE OPTIN') return true;
953 select_html += '<option value="' + value['id'] + '" data-list="' + value['name'] + '">' + value['name'] + '</option>';
954 });
955 $jQ('#sib_select_multi_list').html(select_html).trigger("chosen:updated");
956 $jQ('#sib_select_multi_list').chosen({width:"100%"});
957 });
958 }
959
960 $jQ('#sib_select_multi_list').on('change', function(){
961 if ( $jQ(this).val() != null )
962 {
963 $jQ('#sib_multi_list_field').show();
964 generate_multi_list_html();
965 }
966 else {
967 $jQ('#sib_multi_list_field').hide();
968 }
969 });
970
971 $jQ('#sib_multi_field_label').on('change', function () {
972 generate_multi_list_html();
973 });
974
975 $jQ('#sib_multi_field_required').on('change', function () {
976 generate_multi_list_html();
977 });
978 // keep change of fields
979 $jQ('.sib_field_changes').on('change',function() {
980 change_field_attr();
981 });
982
983 // click confirm email
984 $jQ("input[name=is_confirm_email]").on('click',function() {
985 var confirm_email = $jQ(this).val();
986 var is_activated_smtp = parseInt($jQ("#is_smtp_activated").val());
987
988 if(confirm_email == '1') {
989 $jQ('#sib_doubleoptin_template_id').val('-1');
990 $jQ('#sib_confirm_template_id').val('-1');
991 $jQ('#is_double_optin_no').prop("checked", true);
992 $jQ('#sib_double_sender_area').hide();
993 $jQ('#sib_double_redirect_area').hide();
994 $jQ('#sib_confirm_template_area').show();
995 $jQ('#sib_confirm_sender_area').show();
996 $jQ('#sib_doubleoptin_template_area').hide();
997 $jQ('#sib_final_confirm_template_area').hide();
998 $jQ('#sib_form_alert_message').hide();
999 if (is_activated_smtp == 0) {
1000 $jQ('#sib_form_alert_message').show();
1001 $jQ('#sib_disclaim_smtp').show();
1002 $jQ('#sib_disclaim_do_template').hide();
1003 $jQ('#sib_disclaim_confirm_template').hide();
1004 }
1005 } else {
1006 $jQ('#sib_confirm_template_area').hide();
1007 $jQ('#sib_confirm_sender_area').hide();
1008 $jQ('#sib_form_alert_message').hide();
1009 }
1010 });
1011
1012 // click double optin
1013 $jQ('input[name=is_double_optin]').on('click', function() {
1014 var double_optin = $jQ(this).val();
1015 var is_activated_smtp = parseInt($jQ("#is_smtp_activated").val());
1016 if(double_optin == '1') {
1017 $jQ('#sib_template_id').val('-1');
1018 $jQ('#is_confirm_email_no').prop("checked", true);
1019 $jQ('#sib_confirm_template_area').hide();
1020 $jQ('#sib_confirm_sender_area').hide();
1021 $jQ('#sib_double_sender_area').show();
1022 $jQ('#sib_double_redirect_area').show();
1023 $jQ('#sib_doubleoptin_template_area').show();
1024 $jQ('#sib_final_confirm_template_area').show();
1025 if (is_activated_smtp == 0) {
1026 $jQ('#sib_form_alert_message').show();
1027 $jQ('#sib_disclaim_smtp').show();
1028 $jQ('#sib_disclaim_do_template').hide();
1029 $jQ('#sib_disclaim_confirm_template').hide();
1030 }
1031 } else {
1032 $jQ('#sib_double_sender_area').hide();
1033 $jQ('#sib_double_redirect_area').hide();
1034 $jQ('#sib_doubleoptin_template_area').hide();
1035 $jQ('#sib_form_alert_message').hide();
1036 $jQ('#sib_final_confirm_template_area').hide();
1037 }
1038 });
1039
1040 // click redirect url
1041 $jQ('#is_redirect_url_click_yes').on('click', function () {
1042 $jQ('#sib_subscrition_redirect_area').show();
1043 });
1044 $jQ('#is_redirect_url_click_no').on('click', function () {
1045 $jQ('#sib_subscrition_redirect_area').hide();
1046 });
1047
1048 //// refresh iframe to preview form
1049 $jQ('#sib-preview-form-refresh').on('click',function(){
1050 // ajax to update form html
1051 update_preview();
1052 });
1053
1054 //// display popup when delete form
1055 $jQ('.sib-form-delete').on('click', function(e) {
1056 return confirm('Are you sure you want to delete this form?');
1057 });
1058
1059 //// custom or theme's css
1060 $jQ('input[name=sib_css_type]').on('change',function() {
1061 $jQ('#sibcssmarkup').toggle();
1062 update_preview();
1063 });
1064
1065 // remove all transients
1066 $jQ(window).focus(function() {
1067
1068 var data = {
1069 action: 'sib_remove_cache',
1070 security: ajax_sib_object.ajax_nonce
1071 };
1072 $jQ.post(ajax_sib_object.ajax_url, data,function(respond) {
1073
1074 if(respond == 'success') {
1075 //
1076 }
1077 });
1078 });
1079
1080 /* sync wordpress users to sendinblue contact list */
1081 // sync popup
1082 $jQ('#sib-sync-btn').on('click', function() {
1083 var syncModal = $jQ('.sib-sync-modal');
1084 syncModal.modal();
1085 $jQ('#sync-failure').hide();
1086
1087 // add to multilist field
1088 var list = $jQ('#sib_select_list');
1089 list[0].selectedIndex = 0;
1090 list.chosen({width:"100%"});
1091
1092 syncModal.on('hidden.bs.modal', function () {
1093 //window.location.reload();
1094 });
1095 });
1096
1097 var attrFieldLine = $jQ('.sync-attr-line').html();
1098 var appenderLine = $jQ('.sync-attr-plus-col').html();
1099 // sync add attr line filed
1100 $jQ('.modal-body').on('click', '.sync-attr-plus', function(){
1101 $jQ(this).css('visibility', 'hidden');
1102 $jQ(this).addClass('pb-2');
1103 $jQ('.sync-attr-plus-col').append(appenderLine);
1104 $jQ('.sync-attr-line').append(attrFieldLine);
1105 $jQ('.sync-attr-dismiss').show();
1106 });
1107 // sync dismiss attr line filed
1108 $jQ('.modal-body').on('click', '.sync-attr-dismiss', function(){
1109 $jQ(this).closest('.sync-attr').remove();
1110 var attrCount = $jQ('.sync-attr').length;
1111 if(attrCount == 1) {
1112 $jQ('.sync-attr-dismiss').hide();
1113 }
1114 $jQ(`.sync-attr-plus-col .sync-attr-plus:nth-child(${attrCount - 1})`).css('visibility', 'show');
1115 $jQ(`.sync-attr-plus-col .sync-attr-plus:nth-child(${attrCount})`).remove();
1116 });
1117
1118 // set attribute matching
1119 $jQ('.modal-body').on('change', 'select', function () {
1120 if($jQ(this).attr("class") == 'sync-wp-attr'){
1121 $jQ(this).closest('.sync-attr').find('.sync-match').val($jQ(this).val());
1122 }else{
1123 $jQ(this).closest('.sync-attr').find('.sync-match').attr('name',$jQ(this).val());
1124 }
1125 });
1126
1127 // sync users to sendinblue
1128 $jQ('#sib_sync_users_btn').on('click', function(){
1129
1130 $jQ(this).attr('disabled', 'true');
1131 var postData = $jQ('#sib-sync-form').serializeObject();
1132 $jQ(this).closest('form').find('input[type=hidden]').each(function (index, value) {
1133 var attrName = $jQ(this).attr('name');
1134 if($jQ('input[name='+attrName+']').length > 1){
1135 // the attribute is duplicated !
1136 postData['errAttr'] = attrName;
1137 }
1138 });
1139
1140 var data = {
1141 action:'sib_sync_users',
1142 data: postData,
1143 security: ajax_sib_object.ajax_nonce
1144 };
1145
1146 $jQ('.sib_alert').hide();
1147 $jQ(this).find('.sib-spin').show();
1148 $jQ.post(ajax_sib_object.ajax_url, data,function(respond) {
1149 $jQ('.sib-spin').hide();
1150 $jQ('#sib_sync_users_btn').removeAttr('disabled');
1151 let messageBox = '';
1152 if(respond.code != 'success') {
1153 messageBox = 'sync-failure';
1154 $jQ('#sync-failure').show().html(respond.message);
1155 } else {
1156 // success to sync wp users
1157 location.reload();
1158 $jQ('.sib-sync-modal').modal('toggle');
1159 $jQ('#sib-message-body').html(respond.message);
1160 $jQ('#sib-message-box').show();
1161 }
1162 });
1163
1164 });
1165 $jQ('.sib-add-captcha').on('click', function(){
1166 var add_captcha = $jQ(this).val();
1167 var selectCaptchaType = $jQ('.sib-captcha-select').val();
1168 if(add_captcha == '1')
1169 {
1170 $jQ('.sib-captcha-select').show('slow');
1171
1172 if (selectCaptchaType == 2) {
1173 $jQ('.sib-captcha-key').show('slow');
1174 } else if (selectCaptchaType == 3) {
1175 $jQ('.sib-captcha-key-turnstile').show('slow');
1176 }
1177 }
1178 else
1179 {
1180 $jQ('.sib-captcha-select').hide('slow');
1181 $jQ('.sib-captcha-key').hide('slow');
1182 $jQ('.sib-captcha-key-turnstile').hide('slow');
1183 }
1184 });
1185
1186 //Captcha select
1187 $jQ('.sib-captcha-select').on('change', function(){
1188 var add_captcha = $jQ(this).val();
1189 if(add_captcha == '1')
1190 {
1191 $jQ('.sib-captcha-key-turnstile').hide('slow');
1192 $jQ('.sib-captcha-key').hide('slow');
1193 }
1194 else if(add_captcha == '2')
1195 {
1196 $jQ('.sib-captcha-key-turnstile').hide('slow');
1197 $jQ('.sib-captcha-key').show('slow');
1198 }
1199 else if (add_captcha == '3')
1200 {
1201 $jQ('.sib-captcha-key').hide('slow');
1202 $jQ('.sib-captcha-key-turnstile').show('slow');
1203 }
1204 });
1205
1206 $jQ('.popover-help-form').popover({
1207 });
1208 $jQ('.sib-spin').hide();
1209 $jQ('body').on('click', function(e) {
1210 if(!$jQ(e.target).hasClass('popover-help-form')) {
1211 $jQ('.popover-help-form').popover('hide');
1212 }
1213 });
1214
1215 $jQ('.sib-add-terms').on('click', function(){
1216 var add_terms = $jQ(this).val();
1217 if(add_terms == '1')
1218 {
1219 $jQ('.sib-terms-url').show('slow');
1220 }
1221 else
1222 {
1223 $jQ('.sib-terms-url').hide('slow');
1224 }
1225 });
1226
1227 $jQ('.sib-add-to-form').on('click', function(){
1228 var btn_id = $jQ(this).attr('id');
1229 var field_html = '';
1230
1231 var formMarkup = $jQ("#sibformmarkup");
1232 var cursorPosition = get_cursor_position(formMarkup[0]);
1233 var html = formMarkup.val();
1234 var replacedHTML = "";
1235
1236 if(btn_id == 'sib_add_to_form_btn')
1237 {
1238 let textToslice = $jQ("#sib_field_html").val();
1239 var position = textToslice.search("sib_SMS_prefix");
1240 let firstpart = position + 22;
1241
1242 let lastPoint = firstpart + 7;
1243 let sliceValue = textToslice.slice(firstpart, lastPoint);
1244 var code = sliceValue.substring(sliceValue.indexOf("+") + 1, sliceValue.lastIndexOf('"'));
1245
1246 var flagInicial = CountryList[code];
1247 if (typeof flagInicial !== "undefined") {
1248 var flagICo = jQuery('#getDomain').val() + flagInicial.toLowerCase() + ".png";
1249
1250 field_html = textToslice.replace('class="sib-cflags"', `class="sib-cflags" style=background-image:url(${flagICo})`);
1251 } else {
1252 field_html = textToslice;
1253 }
1254 }
1255 else if(btn_id == 'sib_multi_lists_add_form_btn')
1256 {
1257 field_html = $jQ('#sib_multi_field_html').val();
1258 $jQ('#sib_multi_list_field').hide();
1259 }
1260 else if(btn_id == 'sib_add_captcha_btn')
1261 {
1262 var site_key = $jQ('#sib_captcha_site').val();
1263 var secret_key = $jQ('#sib_captcha_secret').val();
1264 var gCaptcha_type = $jQ('input[name=sib_recaptcha_type]:checked').val();
1265
1266 if(gCaptcha_type == '0')
1267 {
1268 $jQ('.cf-turnstile').remove();
1269 field_html = '<div id="sib_captcha"></div>';
1270 }
1271
1272 if(site_key == '')
1273 {
1274 $jQ('#sib_form_captcha .alert-danger').html('You should input <strong>Site Key</strong>').show(300);
1275 return false;
1276 }
1277 else if(secret_key == '')
1278 {
1279 $jQ('#sib_form_captcha .alert-danger').html('You should input <strong>Secrete Key</strong>').show(300);
1280 return false;
1281 }
1282 }
1283 else if(btn_id == 'sib_add_captcha_btn_turnstile')
1284 {
1285 var site_key = $jQ('#sib_captcha_site_turnstile').val();
1286 var secret_key = $jQ('#sib_captcha_secret_turnstile').val();
1287 var secret_key = $jQ('#sib_captcha_secret_turnstile').val();
1288 var cCaptchaStyle = $jQ('input[name=turnstile_captcha_theme]:checked').val();
1289
1290 var if_site_key_exists = $jQ('#cf-turnstile').val();
1291
1292 if ((if_site_key_exists == '') || (if_site_key_exists != site_key)) {
1293 field_html = '<div id="' + "cf-turnstile-"+site_key + '"' + ' class="cf-turnstile" data-error-callback="errorCallbackForTurnstileErrors" data-sitekey="'+site_key+'" data-theme="'+cCaptchaStyle+'"></div>';
1294 } else {
1295 replacedHTML = html;
1296 }
1297
1298 if(site_key == '')
1299 {
1300 $jQ('#sib_form_captcha .alert-danger').html('You should input <strong>Site Key</strong>').show(300);
1301 return false;
1302 }
1303 else if(secret_key == '')
1304 {
1305 $jQ('#sib_form_captcha .alert-danger').html('You should input <strong>Secrete Key</strong>').show(300);
1306 return false;
1307 }
1308 }
1309 else if(btn_id == 'sib_add_termsUrl_btn')
1310 {
1311 var terms_url = $jQ('#sib_terms_url').val();
1312 field_html = '<input type="checkbox" name="terms" required="required">I accept the <a href="' + terms_url + '">terms and conditions</a> ';
1313 if(terms_url == '')
1314 {
1315 $jQ('#sib_form_terms .alert-danger').html('You should input <strong>Terms URL</strong>').show(300);
1316 return false;
1317 }
1318 }
1319 else if(btn_id == 'sib_add_compliance_note')
1320 {
1321 var compliance_note = $jQ('#sib_gdpr_text').val();
1322 field_html = '<p>' + compliance_note + '</p>';
1323 }
1324
1325 replacedHTML = html.replace(/<div id="cf-turnstile.*?>(.*?)<\/div>/, '$1');
1326
1327 if(replacedHTML.charCodeAt(cursorPosition) == 10 || replacedHTML.charCodeAt(cursorPosition) == 13){ // 10 is value of new line
1328 field_html = "\n" + field_html;
1329 }else{
1330 field_html = field_html + "\n";
1331 }
1332
1333 var formData = [replacedHTML.slice(0, cursorPosition), field_html, replacedHTML.slice(cursorPosition)].join('');
1334
1335 formMarkup.val(formData);
1336
1337 // hide field edit after add the field to form
1338 $jQ('#sib-field-content').hide();
1339 $jQ("#sib_sel_attribute").val('-1');
1340
1341 /*/ refresh iframe form /*/
1342 // ajax to update form html
1343 update_preview();
1344 // set cursor position at top
1345 setSelectionRange(formMarkup[0], 0, 0);
1346 return false;
1347 });
1348
1349 var redirect = '';
1350 $jQ('.sib-form-redirect').on('click', function(e){
1351 e.preventDefault();
1352 redirect = $jQ(this).attr('href');
1353 $jQ('#sib_modal').modal();
1354 });
1355
1356 $jQ('#sib_form_lang').on('change', function(){
1357 $jQ('#sib_modal').modal();
1358 });
1359
1360 $jQ('#sib_modal_cancel').on('click', function(){
1361 $jQ('#sib_modal').modal('hide');
1362 $jQ('#sib_form_lang').val("");
1363 });
1364 $jQ('#sib_modal_ok').on('click', function(){
1365 var url = (redirect != '')? redirect :$jQ('#sib_form_lang').val();
1366 window.location.href = url;
1367 });
1368
1369 // duplicate content from origin form in translation
1370 $jQ('.sib-duplicate-btn').on('click', function(){
1371 $jQ('.sib-spin').show();
1372 var pid = $jQ('input[name="pid"]').val();
1373 var data = {
1374 action: 'sib_copy_origin_form',
1375 pid: pid,
1376 security: ajax_sib_object.ajax_nonce
1377 };
1378 $jQ.post(ajax_sib_object.ajax_url, data, function(respond) {
1379 $jQ('.sib-spin').hide();
1380 $jQ('#sibformmarkup').val(respond);
1381 });
1382
1383 });
1384
1385 $jQ('.sib-add-compliant-note').on('click', function () {
1386 var add_notes = $jQ(this).val();
1387 if(add_notes == '1')
1388 {
1389 $jQ('.sib-gdpr-block-area').show('slow');
1390 $jQ('.sib-gdpr-block-btn').show('slow');
1391 }
1392 else
1393 {
1394 $jQ('.sib-gdpr-block-area').hide('slow');
1395 $jQ('.sib-gdpr-block-btn').hide('slow');
1396 }
1397 });
1398 $jQ('#set_gdpr_default').on('click', function () {
1399 $jQ('#sib_gdpr_text').val(ajax_sib_object.compliance_note);
1400 })
1401
1402 if($jQ("#sib-statistics-date").length) {
1403 $jQ("#sib-statistics-date").datepicker({
1404 dateFormat: 'yy-mm-dd',
1405 numberOfMonths: 1,
1406 onSelect: function( selectedDate ) {
1407 if(!$jQ(this).data().datepicker.first){
1408 $jQ(this).data().datepicker.inline = true
1409 $jQ(this).data().datepicker.first = selectedDate;
1410 }else{
1411 if(selectedDate > $jQ(this).data().datepicker.first){
1412 $jQ(this).val($jQ(this).data().datepicker.first+" - "+selectedDate);
1413 }else{
1414 $jQ(this).val(selectedDate+" - "+$jQ(this).data().datepicker.first);
1415 }
1416 $jQ(this).data().datepicker.inline = false;
1417 }
1418 },
1419 onClose:function(){
1420 delete $jQ(this).data().datepicker.first;
1421 $jQ(this).data().datepicker.inline = false;
1422 }
1423 })
1424 }
1425 $jQ('#sib-statistics-form').on('submit', function (data) {
1426 $jQ("#apply-date-range").attr("disabled", true);
1427 $jQ('.sib-spinner').addClass('is-active');
1428 return true;
1429 });
1430
1431 $jQ('#sibformmarkup').on('change', function ($data) {
1432 var formHtml = $jQ('#sibformmarkup').val();
1433 formHtml = updateHtmlWithFlag(formHtml);
1434 $jQ('#sibformmarkup').val(formHtml);
1435 });
1436 });
1437
1438 // get serialized data form sync users form
1439 $jQ.fn.serializeObject = function()
1440 {
1441 var o = {};
1442 var a = this.serializeArray();
1443 $jQ.each(a, function() {
1444 if (o[this.name] !== undefined) {
1445 if (!o[this.name].push) {
1446 o[this.name] = [o[this.name]];
1447 }
1448 o[this.name].push(this.value || '');
1449 } else {
1450 o[this.name] = this.value || '';
1451 }
1452 });
1453 return o;
1454 };
1455
1456 function updateHtmlWithFlag(htmlString) {
1457 var customEle = document.createElement( 'section' );
1458 customEle.innerHTML = htmlString;
1459 var codeEle = customEle.querySelector("[name='sib_SMS_prefix']");
1460 if(codeEle === null) {
1461 return htmlString;
1462 }
1463 let dialCode = codeEle.value;
1464 dialCode = dialCode.replace('+','');
1465 var flagInicial = CountryList[dialCode];
1466 if (typeof flagInicial !== "undefined") {
1467 let flagICo = jQuery('#getDomain').val()+flagInicial.toLowerCase()+".png";
1468 customEle.querySelector("[class='sib-cflags']").removeAttribute("style");
1469 customEle.querySelector("[class='sib-cflags']").setAttribute("style","background-image:url("+flagICo+")");
1470 }
1471 var HtString = customEle.innerHTML;
1472 HtString = HtString.replace('</p><div class="sib-sms-field','<div class="sib-sms-field');
1473 HtString = HtString.replace('<p></p>','</p>');
1474 return HtString;
1475 }
1476