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