| 1 |
jQuery(document).ready(function($) { |
| 2 |
|
| 3 |
function disableBtn(el, exceptEl = '', isTrue = false) { |
| 4 |
if (exceptEl !== "") { |
| 5 |
jQuery(el).not(exceptEl).each((index, item) => { |
| 6 |
jQuery(item).prop('disabled', isTrue); |
| 7 |
}) |
| 8 |
} else { |
| 9 |
jQuery(el).each((index, item) => { |
| 10 |
jQuery(item).prop('disabled', isTrue); |
| 11 |
}) |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
$('.emailkit-edit-button').on('click', function(e) { |
| 16 |
e.preventDefault(); |
| 17 |
let _self = this; |
| 18 |
|
| 19 |
disableBtn('.emailkit-woocom-btn', _self, true); |
| 20 |
|
| 21 |
var builderUrl = $(this).attr('href'); |
| 22 |
|
| 23 |
if (builderUrl.trim() !=='') { |
| 24 |
window.open(builderUrl, '_blank'); |
| 25 |
disableBtn('.emailkit-woocom-btn', "", false); |
| 26 |
return false; |
| 27 |
} |
| 28 |
|
| 29 |
jQuery(this).addClass('emailkit-slider-loader'); |
| 30 |
|
| 31 |
var editorTemplateUrl = $(this).data('editor-template-url'); |
| 32 |
var emailType = $(this).data('emailkit-email-type'); |
| 33 |
var templateType = $(this).data('emailkit-template-type'); |
| 34 |
var templateTitle = $(this).data('emailkit-template-title'); |
| 35 |
var templateStatus = 'active'; |
| 36 |
|
| 37 |
// Make an AJAX request to the REST API endpoint |
| 38 |
$.ajax({ |
| 39 |
url: woocommerce.rest_url + 'template-data', |
| 40 |
method: 'POST', |
| 41 |
headers: { |
| 42 |
'X-WP-Nonce': woocommerce.rest_nonce, |
| 43 |
}, |
| 44 |
data: { |
| 45 |
'emailkit-editor-template': editorTemplateUrl, |
| 46 |
'emailkit_email_type': emailType, |
| 47 |
'emailkit_template_type': templateType, |
| 48 |
'emailkit_template_title': templateTitle, |
| 49 |
'emailkit_template_status': templateStatus |
| 50 |
}, |
| 51 |
success: function(response) { |
| 52 |
window.open(response.data.builder_url, '_blank'); |
| 53 |
disableBtn('.emailkit-woocom-btn', "", false); |
| 54 |
jQuery(_self).removeClass('emailkit-slider-loader'); |
| 55 |
}, |
| 56 |
error: function(error) { |
| 57 |
console.error(error); |
| 58 |
disableBtn('.emailkit-woocom-btn', "", false); |
| 59 |
jQuery(_self).removeClass('emailkit-slider-loader'); |
| 60 |
} |
| 61 |
}); |
| 62 |
|
| 63 |
|
| 64 |
}); |
| 65 |
}); |