| 1 |
<script type="text/javascript"> |
| 2 |
$ = jQuery; |
| 3 |
$(document).ready(() => { |
| 4 |
const XYZ_IHS_INSERTION_LOCATION = <?php echo json_encode(XYZ_IHS_INSERTION_LOCATION); ?>; |
| 5 |
const XYZ_IHS_INSERTION_METHOD = <?php echo json_encode(XYZ_IHS_INSERTION_METHOD); ?>; |
| 6 |
const XYZ_IHS_INSERTION_LOCATION_TYPE = <?php echo json_encode(XYZ_IHS_INSERTION_LOCATION_TYPE); ?>; |
| 7 |
let xyz_ihs_snippetType = $('#xyz_ihs_snippetType').val(); |
| 8 |
let xyz_ihs_insertionMethod = $('#xyz_ihs_insertionMethod').val(); |
| 9 |
|
| 10 |
/* General functions starts */ |
| 11 |
const toggleListItemVisibility = (locationKey, showHide) => { |
| 12 |
const listItem = $(`#xyz_ihs_uniq_list li[data-value="${XYZ_IHS_INSERTION_LOCATION[locationKey]}"]`); |
| 13 |
listItem.css('display', showHide === 'show' ? 'block' : 'none'); |
| 14 |
}; |
| 15 |
|
| 16 |
const getInsertionLocationTextIHS = (xyz_ihs_insertionLocation) => { |
| 17 |
|
| 18 |
|
| 19 |
XYZ_IHS_INSERTION_LOCATION_txt = |
| 20 |
(xyz_ihs_insertionLocation == XYZ_IHS_INSERTION_LOCATION['ADMIN_RUN_ON_HEADER']) ? 'Admin - Run On Header' : |
| 21 |
(xyz_ihs_insertionLocation == XYZ_IHS_INSERTION_LOCATION['ADMIN_RUN_ON_FOOTER']) ? 'Admin - Run On Footer' : |
| 22 |
(xyz_ihs_insertionLocation == XYZ_IHS_INSERTION_LOCATION['FRONTEND_RUN_ON_HEADER']) ? 'Front End - Run On Header' : |
| 23 |
(xyz_ihs_insertionLocation == XYZ_IHS_INSERTION_LOCATION['FRONTEND_RUN_ON_FOOTER']) ? 'Front End - Run On Footer' :null; |
| 24 |
|
| 25 |
const targetElement = $('#xyz_ihs_insertion-location-txt'); |
| 26 |
|
| 27 |
if (targetElement.length > 0 && XYZ_IHS_INSERTION_LOCATION_txt) { |
| 28 |
$('#xyz_ihs_insertion-location-txt').text(XYZ_IHS_INSERTION_LOCATION_txt); |
| 29 |
} |
| 30 |
}; |
| 31 |
/* General functions ends */ |
| 32 |
|
| 33 |
|
| 34 |
if (xyz_ihs_insertionMethod != XYZ_IHS_INSERTION_METHOD['AUTOMATIC']) { |
| 35 |
$('#xyz_ihs_insertionLocationTR').hide(); |
| 36 |
} else { |
| 37 |
$('#xyz_ihs_insertionLocationTR').show(); |
| 38 |
} |
| 39 |
|
| 40 |
$('#xyz_ihs_insertionMethod').change((e) => { |
| 41 |
let xyz_ihs_insertionMethod = $(e.target).val(); |
| 42 |
|
| 43 |
if (xyz_ihs_insertionMethod == XYZ_IHS_INSERTION_METHOD['AUTOMATIC']) { |
| 44 |
$('#xyz_ihs_insertionLocationTR').show(); |
| 45 |
|
| 46 |
|
| 47 |
} else { |
| 48 |
$('#xyz_ihs_insertionLocationTR').hide(); |
| 49 |
|
| 50 |
} |
| 51 |
}); |
| 52 |
|
| 53 |
let xyz_ihs_insertionLocation = $('#xyz_ihs_insertionLocation').val(); |
| 54 |
let XYZ_IHS_INSERTION_LOCATION_txt = 'Select Insertion Location'; |
| 55 |
if (xyz_ihs_insertionLocation > 0) { |
| 56 |
getInsertionLocationTextIHS(xyz_ihs_insertionLocation); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
const listItems = document.querySelectorAll('.xyz_ihs_li_option'); |
| 61 |
listItems.forEach(item => { |
| 62 |
item.addEventListener('click', () => { |
| 63 |
|
| 64 |
|
| 65 |
listItems.forEach(li => li.classList.remove('selected')); |
| 66 |
item.classList.add('selected'); |
| 67 |
const selectedValue = item.getAttribute('data-value'); |
| 68 |
$('#xyz_ihs_insertionLocation').val(selectedValue); |
| 69 |
getInsertionLocationTextIHS(selectedValue); |
| 70 |
|
| 71 |
|
| 72 |
}); |
| 73 |
}); |
| 74 |
$('#xyz_ihs_uniq_list').hide(); |
| 75 |
$('.xyz_ihs_insertionLocationDiv').on('click', () => { |
| 76 |
$('#xyz_ihs_uniq_list').toggle(); |
| 77 |
}); |
| 78 |
}); |
| 79 |
|
| 80 |
</script> |
| 81 |
|