PluginProbe
Insert PHP Code Snippet / 1.4.2
Insert PHP Code Snippet v1.4.2
1.4.7 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
insert-php-code-snippet / admin / snippet-js.php

snippet-js.php in Insert PHP Code Snippet 1.4.2, at admin/snippet-js.php

77 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <script type="text/javascript">
2 $ = jQuery;
3 $(document).ready(() => {
4 const XYZ_IPS_INSERTION_LOCATION = <?php echo json_encode(XYZ_IPS_INSERTION_LOCATION); ?>;
5 const XYZ_IPS_INSERTION_METHOD = <?php echo json_encode(XYZ_IPS_INSERTION_METHOD); ?>;
6 const XYZ_IPS_INSERTION_LOCATION_TYPE = <?php echo json_encode(XYZ_IPS_INSERTION_LOCATION_TYPE); ?>;
7 let xyz_ips_snippetType = $('#xyz_ips_snippetType').val();
8 let xyz_ips_insertionMethod = $('#xyz_ips_insertionMethod').val();
9
10 /* General functions starts */
11 const toggleListItemVisibility = (locationKey, showHide) => {
12 const listItem = $(`#xyz_ips_uniq_list li[data-value="${XYZ_IPS_INSERTION_LOCATION[locationKey]}"]`);
13 listItem.css('display', showHide === 'show' ? 'block' : 'none');
14 };
15
16 const getInsertionLocationText = (xyz_ips_insertionLocation) => {
17 xyz_ips_insertion_location_txt =
18 (xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['ADMIN_RUN_ON_HEADER']) ? 'Admin - Run On Header' :
19 (xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['ADMIN_RUN_ON_FOOTER']) ? 'Admin - Run On Footer' :
20 (xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['FRONTEND_RUN_ON_HEADER']) ? 'Front End - Run On Header' :
21 (xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['FRONTEND_RUN_ON_FOOTER']) ? 'Front End - Run On Footer' :null;
22
23 const targetElement = $('#xyz_ips_insertion-location-txt');
24
25 if (targetElement.length > 0 && xyz_ips_insertion_location_txt) {
26 $('#xyz_ips_insertion-location-txt').text(xyz_ips_insertion_location_txt);
27 }
28 };
29 /* General functions ends */
30
31
32 if (xyz_ips_insertionMethod != XYZ_IPS_INSERTION_METHOD['AUTOMATIC']) {
33 $('#xyz_ips_insertionLocationTR').hide();
34 } else {
35 $('#xyz_ips_insertionLocationTR').show();
36 }
37
38 $('#xyz_ips_insertionMethod').change((e) => {
39 let xyz_ips_insertionMethod = $(e.target).val();
40
41 if (xyz_ips_insertionMethod == XYZ_IPS_INSERTION_METHOD['AUTOMATIC']) {
42 $('#xyz_ips_insertionLocationTR').show();
43
44
45 } else {
46 $('#xyz_ips_insertionLocationTR').hide();
47
48 }
49 });
50
51 let xyz_ips_insertionLocation = $('#xyz_ips_insertionLocation').val();
52 let xyz_ips_insertion_location_txt = 'Select Insertion Location';
53 if (xyz_ips_insertionLocation > 0) {
54 getInsertionLocationText(xyz_ips_insertionLocation);
55 }
56
57
58 const listItems = document.querySelectorAll('.xyz_ips_li_option');
59 listItems.forEach(item => {
60 item.addEventListener('click', () => {
61 listItems.forEach(li => li.classList.remove('selected'));
62 item.classList.add('selected');
63 const selectedValue = item.getAttribute('data-value');
64 $('#xyz_ips_insertionLocation').val(selectedValue);
65 getInsertionLocationText(selectedValue);
66
67
68 });
69 });
70 $('#xyz_ips_uniq_list').hide();
71 $('.xyz_ips_insertionLocationDiv').on('click', () => {
72 $('#xyz_ips_uniq_list').toggle();
73 });
74 });
75
76 </script>
77