(function($) { $(document).ready(function() { // Event-Listener für das Öffnen des Modals $(document).on('click', '#openModal', function() { $('#modal').removeClass('hidden'); // Auslesen der bestehenden Beschriftung const captionFields = [ $('#attachment-details-two-column-caption'), $('#attachment-details-caption'), $('#attachment_caption') ]; let currentCaption = ''; for (const field of captionFields) { if (field.length && field.val()) { currentCaption = field.val(); break; } } // Extrahieren der Werte aus der bestehenden Beschriftung und ins Formular einfügen const imageTitle = currentCaption.match(/([^<]*)<\/a>/); const imageSourceUrl = currentCaption.match(/[^<]*<\/a>/); const imageAuthor = currentCaption.match(/von: ([^<]*)<\/a>/); const authorImageUrl = currentCaption.match(/von: [^<]*<\/a>/); const imageLicense = currentCaption.match(/Lizenz\/Rechte: ([^<]*)<\/a>/); const licenseUrl = currentCaption.match(/Lizenz\/Rechte: [^<]*<\/a>/); // Füllen der Formularfelder mit den extrahierten Werten $('#imageTitle').val(imageTitle ? imageTitle[1] : ''); $('#imageSourceUrl').val(imageSourceUrl ? imageSourceUrl[1] : ''); $('#imageAuthor').val(imageAuthor ? imageAuthor[1] : ''); $('#authorImageUrl').val(authorImageUrl ? authorImageUrl[1] : ''); $('#imageLicense').val(imageLicense ? imageLicense[1] : ''); $('#licenseUrl').val(licenseUrl ? licenseUrl[1] : ''); }); // Event-Listener für das Schließen des Modals $(document).on('click', '#closeModal', function() { $('#modal').addClass('hidden'); }); // Event-Listener für das Speichern der Daten und das Einfügen in das Beschriftungsfeld $('#metaDataForm').on('submit', function(event) { event.preventDefault(); // Sammeln der Werte aus den Formularfeldern const imageTitle = $('#imageTitle').val(); const imageSourceUrl = $('#imageSourceUrl').val(); const imageAuthor = $('#imageAuthor').val(); const authorImageUrl = $('#authorImageUrl').val(); const imageLicense = $('#imageLicense').val(); const licenseUrl = $('#licenseUrl').val(); // Erstellen des neuen HTML-Snippets für die Bildbeschriftung let newCaption = `${imageTitle} |`; if (imageAuthor) { newCaption += ` von: ${imageAuthor} |`; } newCaption += ` Lizenz/Rechte: ${imageLicense}`; // Einfügen des neuen HTML-Snippets in das passende Beschriftungsfeld const captionFields = [ $('#attachment-details-two-column-caption'), $('#attachment-details-caption'), $('#attachment_caption') ]; for (const field of captionFields) { if (field.length) { field.val(newCaption); break; } } // Schließen des Modals $('#modal').addClass('hidden'); }); }); })(jQuery);