1jQuery(document).ready(function ($) { 2 // Update the button image with the license image 3 var button = $("#cc-post-republisher-modal-button-open"); 4 var licenseImage = modalSettings.licenseImage; 5 button.find('img').attr('src', licenseImage); 6 7 // Populate and open modal on button click 8 $(document).on('click', '#cc-post-republisher-modal-button-open', function () { 9 var postId = modalSettings.postID; 10 var postType = modalSettings.postType; 11 12 // Ensure postId is valid before making the AJAX request 13 if (postId) { 14 // Set the REST URL based on the post type (must be pluralized for posts and pages) 15 if (postType === 'post') { 16 postType = 'posts'; 17 } else if (postType === 'page') { 18 postType = 'pages'; 19 } 20 var postUrl = modalSettings.root + 'wp/v2/' + postType + '/' + postId; 21 22 // AJAX request to get content 23 $.ajax({ 24 url: postUrl, 25 method: 'GET', 26 beforeSend: function (xhr) { 27 xhr.setRequestHeader('X-WP-Nonce', modalSettings.nonce); 28 }, 29 success: function (response) { 30 var modal = $('#cc-post-republisher-modal'); 31 var container = $('#cc-post-republisher-modal-container'); 32 33 if (modal.length) { 34 var licenseContent = modalSettings.licenseContent; 35 var termsContent = modalSettings.termsContent; 36 37 var content = '<button id="cc-post-republisher-modal-button-close">×</button>'; 38 content += termsContent; 39 content += licenseContent; 40 content += '<div id="cc-post-republisher-post-content">'; 41 content += '<textarea><h1>' + response.title.rendered + '</h1>\n\n' + response.content.rendered + '</textarea>'; 42 content += '</div>'; 43 44 modal.html(content); 45 container.css('display', 'block'); 46 } else { 47 console.error('Modal element not found'); 48 } 49 }, 50 error: function (error) { 51 console.error('AJAX error:', error); 52 } 53 }); 54 } else { 55 console.error('Post ID is not valid.'); 56 } 57 }); 58 59 $(document).on('click', '#cc-post-republisher-modal-button-close', function () { 60 $('#cc-post-republisher-modal-container').css('display', 'none'); 61 }); 62 63 // Close modal if clicking outside the modal 64 $(document).on('click', '#cc-post-republisher-modal-container', function (e) { 65 if ($(e.target).is('#cc-post-republisher-modal-container')) { 66 $(this).css('display', 'none'); 67 } 68 }); 69 70 // Close modal if pressing the escape key 71 $(document).on('keydown', function (e) { 72 if (e.key === "Escape") { 73 $('#cc-post-republisher-modal-container').css('display', 'none'); 74 } 75 }); 76});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.