Widget:GOV-Test: Unterschied zwischen den Versionen
Aus Altes Köln
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
<!--Test-Widget von Christopher zum Austesten des GOV-Aufrufes (eigentlich für das GenWiki)--> | <!--Test-Widget von Christopher zum Austesten des GOV-Aufrufes (eigentlich für das GenWiki)--> | ||
<h1>Ajax-Variante mit wiki</h1> | <h1>Ajax-Variante mit wiki</h1> | ||
<div id="widget-container"> | <div id="widget-container"></div> | ||
</div> | |||
<script> | <script> | ||
(function() { | (function () { | ||
const | const fetchURL = "https://gov.genealogy.net/item/wikihtml/SCHERGJO54EJ"; | ||
fetch( | fetch(fetchURL) | ||
.then(response => { | .then(response => { | ||
if (!response.ok) { | if (!response.ok) { | ||
Zeile 20: | Zeile 15: | ||
}) | }) | ||
.then(html => { | .then(html => { | ||
const widgetContainer = document.getElementById('widget-container'); | |||
// | // Shadow DOM erstellen | ||
const | const shadow = widgetContainer.attachShadow({ mode: 'open' }); | ||
// | // Stile für das Widget im Shadow DOM hinzufügen | ||
const | const style = document.createElement('style'); | ||
style.textContent = ` | |||
:host { | |||
all: initial; /* Verhindert globale Stile */ | |||
display: block; | |||
max-width: 800px; | |||
margin: 20px auto; | |||
padding: 10px; | |||
border: 1px solid #ccc; | |||
background-color: #f9f9f9; | |||
overflow: auto; | |||
} | |||
table { | |||
width: 100%; | |||
table-layout: fixed; /* Verhindert Überdehnung von Tabellenzellen */ | |||
border-collapse: collapse; | |||
margin: 10px 0; | |||
} | |||
// Geladenen Inhalt | th, td { | ||
const | border: 1px solid #ddd; | ||
padding: 8px; | |||
text-align: left; | |||
word-wrap: break-word; /* Zeilenumbruch für lange Wörter */ | |||
} | |||
th { | |||
background-color: #f2f2f2; | |||
} | |||
ul { | |||
padding-left: 20px; | |||
} | |||
object { | |||
max-width: 100%; | |||
height: auto; | |||
display: block; | |||
margin: 10px auto; | |||
} | |||
a { | |||
color: #007BFF; /* Linkfarbe */ | |||
text-decoration: none; | |||
} | |||
a:hover { | |||
text-decoration: underline; | |||
} | |||
`; | |||
// Geladenen HTML-Inhalt einfügen | |||
const content = document.createElement('div'); | |||
content.innerHTML = html; | |||
// Stile und Inhalte in das Shadow DOM einfügen | |||
shadow.appendChild(style); | |||
shadow.appendChild(content); | |||
}) | }) | ||
.catch(error => { | .catch(error => { | ||
console.error('Fehler beim Laden | console.error('Fehler beim Laden:', error); | ||
const widgetContainer = document.getElementById('widget-container'); | |||
const | widgetContainer.textContent = "Fehler: Inhalte konnten nicht geladen werden."; | ||
}); | }); | ||
})(); | })(); | ||
</script> | </script> | ||
<h1>Variante: Einfacher iframe mit <!--{$CallType|escape:'url'}--></h1> | <h1>Variante: Einfacher iframe mit <!--{$CallType|escape:'url'}--></h1> |
Version vom 21. Januar 2025, 14:15 Uhr
Ajax-Variante mit wiki
<script>
(function () { const fetchURL = "https://gov.genealogy.net/item/wikihtml/SCHERGJO54EJ";
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; /* Verhindert globale Stile */ display: block; max-width: 800px; margin: 20px auto; padding: 10px; border: 1px solid #ccc; background-color: #f9f9f9; overflow: auto; }
table { width: 100%; table-layout: fixed; /* Verhindert Überdehnung von Tabellenzellen */ border-collapse: collapse; margin: 10px 0; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; word-wrap: break-word; /* Zeilenumbruch für lange Wörter */ }
th { background-color: #f2f2f2; }
ul { padding-left: 20px; }
object { max-width: 100%; height: auto; display: block; margin: 10px auto; }
a { color: #007BFF; /* Linkfarbe */ text-decoration: none; }
a:hover { text-decoration: underline; } `;
// Geladenen HTML-Inhalt einfügen const content = document.createElement('div'); content.innerHTML = html;
// 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>
Variante: Einfacher iframe mit
Variante: responsiv mit
<style>
body { margin: 0; padding: 0; font-family: Arial, sans-serif; }
.iframe-container { width: 100%; /* Container hat immer die volle Breite des Viewports */ position: relative; /* Wichtig für absolute Positionierung */ padding-top: 56.25%; /* Seitenverhältnis 16:9 */ }
iframe { position: absolute; top: 0; left: 0; width: 100vw; /* Breite des Viewports */ height: calc(100vw * 0.5625); /* Höhe proportional zur Breite (16:9) */ transform-origin: top left; /* Skalierung startet oben links */ }
/* Media Queries für kleinere Bildschirme */ @media (max-width: 768px) { iframe { transform: scale(0.9); /* Skaliere den iframe-Inhalt */ } }
@media (max-width: 480px) { iframe { transform: scale(0.8); /* Weitere Skalierung für kleine Geräte */ } } </style>