Altes Köln

Widget:GOV-Test: Unterschied zwischen den Versionen

Aus Altes Köln
Wechseln zu:Navigation, Suche
(Überschriften der derzeit 4 Optionen)
Keine Bearbeitungszusammenfassung
 
(72 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
<h1>Laden der GOV-Seite mit Javascript (fetch)</h1>
<!--Test-Widget von Christopher zum Austesten des GOV-Aufrufes (eigentlich für das GenWiki)-->
<div id="external-content"></div>
<div id="widget-container"></div>
 
<script>
<script>
  fetch('https://gov.genealogy.net/item/show/HOHAUSJO30MX')
    (function () {
    .then(response => response.text())
        const fetchURL = "https://gov.genealogy.net/item/wikihtml/<!--{$GOVID|escape:'url'}-->";
    .then(data => {
        const baseURL = "https://gov.genealogy.net";
      document.getElementById('external-content').innerHTML = data;
 
    })
        fetch(fetchURL)
    .catch(error => {
            .then(response => {
      console.error('Error loading external content:', error);
                if (!response.ok) {
    });
                    throw new Error(`HTTP-Fehler! Status: ${response.status}`);
</script>
                }
                return response.text();
            })
            .then(html => {
                const widgetContainer = document.getElementById('widget-container');
 
                // Shadow DOM erstellen
                const shadow = widgetContainer.attachShadow({ mode: 'open' });
 
                // Stile für das Widget im Shadow DOM hinzufügen
                const style = document.createElement('style');
                style.textContent = `
                    :host {
                        all: initial;
                        display: block;
                        max-width: 1200px;
                        margin: 20px auto;
                        padding: 0;
                        border: none;
                        background-color: #fff;
                        overflow: auto;
                        font-family: Arial, sans-serif;
                        font-size: 16px;
                    }
                    table {
                        width: 100%;
                        table-layout: auto;
                        border-collapse: collapse;
                        margin: 10px 0;
                        border: 1px solid #ccc;
                    }
                    th, td {
                        border: 1px solid #ddd;
                        padding: 10px;
                        text-align: left;
                        word-wrap: break-word;
                    }
                    th {
                        background-color: #f2f2f2;
                    }
                    td:first-child {
                        width: 1%;
                        white-space: nowrap;
                    }
                    ul {
                        padding-left: 20px;
                        margin: 10px 0;
                    }
                    object {
                        max-width: 100%;
                        height: 400px; /* Feste Höhe */
                        display: block;
                        margin: 0;
                    }
                    .map-container {
                        text-align: left;
                    }
                    a {
                        color: #007BFF;
                        text-decoration: none;
                    }
                    a:hover {
                        text-decoration: underline;
                    }
                `;
 
                // Geladenen HTML-Inhalt einfügen
                const content = document.createElement('div');
                content.innerHTML = html;
 
                // 1) Passe width und height in <object> an
                const objects = content.querySelectorAll('object[data^="https://www.genealogy.net/viewer-js/"]');
                objects.forEach(obj => {
                    obj.setAttribute('width', '400'); // Setze Breite auf 400
                    obj.setAttribute('height', '400'); // Setze Höhe auf 400
                });
 
                // 2) Passe <a> und <img> für den relationshipGraph an
                const imageLinks = content.querySelectorAll('a[href*="relationshipGraph"]');
                imageLinks.forEach(link => {
                    // Passe das <a>-Tag an die Base-URL an
                    const originalHref = link.getAttribute('href');
                    link.setAttribute('href', baseURL + originalHref);


<h1>Einfaches HTML (nur Hyberlink auf GOV)</h1>
                    // Passe das <img>-Tag im <a>-Tag an
<!--Test-Widget von Christopher zum Austesten des GOV-Aufrufes (eigentlich für das GenWiki)-->
                    const img = link.querySelector('img');
<p>Hello <b>World</b></p>
                    if (img) {
<p>Die GOV-Daten <a href="https://gov.genealogy.net/item/show/HOHAUSJO30MX">finden Sie hier</a>.</p>
                        const originalSrc = img.getAttribute('src');
                        img.setAttribute('src', baseURL + originalSrc + "?full-size=1"); // Absoluten Pfad setzen
                        img.setAttribute('width', '80%'); // Breite auf 80% setzen
                    }
                });


<h1>Aufruf von GOV mit Object</h1>
                // 3) Füge Base-URL zu allen relativen <a> hinzu
                const allLinks = content.querySelectorAll('a[href^="/"]');
                allLinks.forEach(link => {
                    const originalHref = link.getAttribute('href');
                    link.setAttribute('href', baseURL + originalHref);
                });


<object data="https://gov.genealogy.net/item/show/HOHAUSJO30MX" width="600" height="400"></object>
                // 4) Füge Base-URL zu allen relativen <img> hinzu
                const allImages = content.querySelectorAll('img[src^="/"]');
                allImages.forEach(img => {
                    const originalSrc = img.getAttribute('src');
                    img.setAttribute('src', baseURL + originalSrc);
                });


<h1>Aufruf von GOV mit Iframe</h1>
                // Stile und Inhalte in das Shadow DOM einfügen
<iframe src="https://gov.genealogy.net/item/show/HOHAUSJO30MX" width="1000" height="800"></iframe>
                shadow.appendChild(style);
                shadow.appendChild(content);
            })
            .catch(error => {
                console.error('Fehler beim Laden:', error);
                const widgetContainer = document.getElementById('widget-container');
                widgetContainer.textContent = "Fehler: Inhalte konnten nicht geladen werden.";
            });
    })();
</script>

Aktuelle Version vom 22. Januar 2025, 18:18 Uhr

<script>

   (function () {
       const fetchURL = "https://gov.genealogy.net/item/wikihtml/";
       const baseURL = "https://gov.genealogy.net";
       fetch(fetchURL)
           .then(response => {
               if (!response.ok) {
                   throw new Error(`HTTP-Fehler! Status: ${response.status}`);
               }
               return response.text();
           })
           .then(html => {
               const widgetContainer = document.getElementById('widget-container');
               // Shadow DOM erstellen
               const shadow = widgetContainer.attachShadow({ mode: 'open' });
               // Stile für das Widget im Shadow DOM hinzufügen
               const style = document.createElement('style');
               style.textContent = `
                   :host {
                       all: initial;
                       display: block;
                       max-width: 1200px;
                       margin: 20px auto;
                       padding: 0;
                       border: none;
                       background-color: #fff;
                       overflow: auto;
                       font-family: Arial, sans-serif;
                       font-size: 16px;
                   }
                   table {
                       width: 100%;
                       table-layout: auto;
                       border-collapse: collapse;
                       margin: 10px 0;
                       border: 1px solid #ccc;
                   }
                   th, td {
                       border: 1px solid #ddd;
                       padding: 10px;
                       text-align: left;
                       word-wrap: break-word;
                   }
                   th {
                       background-color: #f2f2f2;
                   }
                   td:first-child {
                       width: 1%;
                       white-space: nowrap;
                   }
                   ul {
                       padding-left: 20px;
                       margin: 10px 0;
                   }
                   object {
                       max-width: 100%;
                       height: 400px; /* Feste Höhe */
                       display: block;
                       margin: 0;
                   }
                   .map-container {
                       text-align: left;
                   }
                   a {
                       color: #007BFF;
                       text-decoration: none;
                   }
                   a:hover {
                       text-decoration: underline;
                   }
               `;
               // Geladenen HTML-Inhalt einfügen
               const content = document.createElement('div');
               content.innerHTML = html;
               // 1) Passe width und height in <object> an
               const objects = content.querySelectorAll('object[data^="https://www.genealogy.net/viewer-js/"]');
               objects.forEach(obj => {
                   obj.setAttribute('width', '400'); // Setze Breite auf 400
                   obj.setAttribute('height', '400'); // Setze Höhe auf 400
               });
               // 2) Passe <a> und <img> für den relationshipGraph an
               const imageLinks = content.querySelectorAll('a[href*="relationshipGraph"]');
               imageLinks.forEach(link => {
                   // Passe das <a>-Tag an die Base-URL an
                   const originalHref = link.getAttribute('href');
                   link.setAttribute('href', baseURL + originalHref);
                   // Passe das <img>-Tag im <a>-Tag an
                   const img = link.querySelector('img');
                   if (img) {
                       const originalSrc = img.getAttribute('src');
                       img.setAttribute('src', baseURL + originalSrc + "?full-size=1"); // Absoluten Pfad setzen
                       img.setAttribute('width', '80%'); // Breite auf 80% setzen
                   }
               });
               // 3) Füge Base-URL zu allen relativen <a> hinzu
               const allLinks = content.querySelectorAll('a[href^="/"]');
               allLinks.forEach(link => {
                   const originalHref = link.getAttribute('href');
                   link.setAttribute('href', baseURL + originalHref);
               });
               // 4) Füge Base-URL zu allen relativen <img> hinzu
               const allImages = content.querySelectorAll('img[src^="/"]');
               allImages.forEach(img => {
                   const originalSrc = img.getAttribute('src');
                   img.setAttribute('src', baseURL + originalSrc);
               });
               // Stile und Inhalte in das Shadow DOM einfügen
               shadow.appendChild(style);
               shadow.appendChild(content);
           })
           .catch(error => {
               console.error('Fehler beim Laden:', error);
               const widgetContainer = document.getElementById('widget-container');
               widgetContainer.textContent = "Fehler: Inhalte konnten nicht geladen werden.";
           });
   })();

</script>

Cookies helfen uns bei der Bereitstellung von Altes Köln. Durch die Nutzung von Altes Köln erklärst du dich damit einverstanden, dass wir Cookies speichern.