| 1 |
jQuery(document).ready(function ($) { |
| 2 |
var active_xhr_request = null; |
| 3 |
|
| 4 |
$('.f12-cf7-templateloader').on('change', function(){ |
| 5 |
let value = $(this).val(); |
| 6 |
|
| 7 |
if (active_xhr_request != null) { |
| 8 |
active_xhr_request.abort(); |
| 9 |
} |
| 10 |
|
| 11 |
// add overlay to textarea while loading the new template |
| 12 |
if($('#templateloader-overlay').length <= 0) { |
| 13 |
$('textarea[name="_fusion[doubleoptin][body]"]').parent().css('position', 'relative'); |
| 14 |
$('textarea[name="_fusion[doubleoptin][body]"]').parent().append('<div id="templateloader-overlay" style="border-radius:5px; position:absolute; background-color:rgba(255,255,255,0.9); left:0; top:0; right:0; bottom:0;"><div style="position:absolute; top:45%; width:100%; text-align:center;">' + templateloader.label_placeholder + '</div></div>'); |
| 15 |
} |
| 16 |
|
| 17 |
if (value) { |
| 18 |
$(this).parent().parent().parent().find('.active').removeClass('active'); |
| 19 |
$(this).parent().addClass('active'); |
| 20 |
|
| 21 |
active_xhr_request = $.ajax({ |
| 22 |
url: templateloader.ajax_url, |
| 23 |
type: 'post', |
| 24 |
data: { |
| 25 |
action: 'f12_doi_templateloader', |
| 26 |
nonce: templateloader.nonce, |
| 27 |
template: value |
| 28 |
}, |
| 29 |
success(data) { |
| 30 |
var data = JSON.parse(data); |
| 31 |
if (data.status == 200) { |
| 32 |
if ($('textarea[name="_fusion[doubleoptin][body]"]').length > 0) { |
| 33 |
$('textarea[name="_fusion[doubleoptin][body]"]').val(data.content); |
| 34 |
|
| 35 |
// set a little delay to have a smooth gradient |
| 36 |
setTimeout(function () { |
| 37 |
$('#templateloader-overlay').fadeOut().remove(); |
| 38 |
}, 1000); |
| 39 |
|
| 40 |
active_xhr_request = null; |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
}) |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
|
| 49 |
$('.f12-cf7-templateloader-preview').on('click', function () { |
| 50 |
let value = $(this).attr('data-template'); |
| 51 |
|
| 52 |
if (active_xhr_request != null) { |
| 53 |
active_xhr_request.abort(); |
| 54 |
} |
| 55 |
|
| 56 |
// add overlay to textarea while loading the new template |
| 57 |
if($('#templateloader-overlay').length <= 0) { |
| 58 |
$('#doubleoptin-body').parent().css('position', 'relative'); |
| 59 |
$('#doubleoptin-body').parent().append('<div id="templateloader-overlay" style="border-radius:5px; position:absolute; background-color:rgba(255,255,255,0.9); left:0; top:0; right:0; bottom:0;"><div style="position:absolute; top:45%; width:100%; text-align:center;">' + templateloader.label_placeholder + '</div></div>'); |
| 60 |
} |
| 61 |
|
| 62 |
if (value) { |
| 63 |
$(this).parent().parent().parent().find('.active').removeClass('active'); |
| 64 |
$(this).parent().addClass('active'); |
| 65 |
|
| 66 |
active_xhr_request = $.ajax({ |
| 67 |
url: templateloader.ajax_url, |
| 68 |
type: 'post', |
| 69 |
data: { |
| 70 |
action: 'f12_doi_templateloader', |
| 71 |
nonce: templateloader.nonce, |
| 72 |
template: value |
| 73 |
}, |
| 74 |
success(data) { |
| 75 |
var data = JSON.parse(data); |
| 76 |
if (data.status == 200) { |
| 77 |
if ($('#doubleoptin-body').length > 0) { |
| 78 |
$('#doubleoptin-body').val(data.content); |
| 79 |
$('.f12-cf7-templateloader').val(value); |
| 80 |
$('.f12-cf7-templateloader').change(); |
| 81 |
|
| 82 |
// set a little delay to have a smooth gradient |
| 83 |
setTimeout(function(){ |
| 84 |
$('#templateloader-overlay').fadeOut().remove(); |
| 85 |
},1000); |
| 86 |
|
| 87 |
active_xhr_request = null; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
}) |
| 92 |
} |
| 93 |
}); |
| 94 |
}); |