document.addEventListener('DOMContentLoaded', function() { var publishButton = document.getElementById('publish'); var confirmed = false; // Status variable to prevent multiple confirmations if (publishButton !== null) { publishButton.addEventListener('click', function(event) { if (confirmed) return; var postFormat = document.querySelector('input[name="post_format"]:checked').value; //var body_content =document.getElementById('content').value; if (tinymce.activeEditor != null) { var body_content = tinymce.activeEditor.getContent(); //check tincyMCE body }else{ var body_content =document.getElementById('content').value; } //var pattern = /\bcaption\b/i; // Pattern to match the word "caption" (case-insensitive) var pattern = /\[caption/g; // Matches all occurrences of "[caption" //alert(body_content); //alert(postFormat); if (postFormat === '0') { confirmationMessage = 'Are you confirm?you choose "news" format?'; } else if (postFormat === 'gallery') { if (!body_content.match(pattern)) { alert("Please select the appropriate story format, as no images have been included in the body content for the chosen Gallery format."); event.preventDefault(); // Prevent default form submission return false; } confirmationMessage = 'Are you confirm?you choose "gallery" format?'; }else if (postFormat === 'quote') { if (!body_content.match(pattern)) { alert("Please select the appropriate story format, as no images have been included in the body content for the chosen Gallery format."); event.preventDefault(); // Prevent default form submission return false; } confirmationMessage = 'Are you confirm?you choose "photo story" format?'; } else if (postFormat === 'video') { confirmationMessage = 'are you confirm?you choose "video" format?'; } else if (postFormat === 'link') { confirmationMessage = 'Are you confirm?you link "link" format?'; }else if (postFormat === 'audio') { confirmationMessage = 'Are you confirm?you link "audio" format?'; }else if (postFormat === 'aside') { confirmationMessage = 'Are you confirm?you link "blog" format?'; } else { confirmationMessage = 'Are you confirm?you choose "blog" format?'; } if (confirm(confirmationMessage)) { // Proceed with publishing confirmed = true; } else { event.preventDefault(); // Prevent default form submission } }); } });
admin Asked question 6 days ago