Nachricht für neue Nutzer.
Nachricht für engagierte Nutzer.
Widget:KnowHowComputer: Unterschied zwischen den Versionen
Aus ZUM-Unterrichten
KKeine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
<script type="text/ | <includeonly><script type="text/JavaScript"> | ||
(function () { | (function () { | ||
| Zeile 6: | Zeile 6: | ||
// Define the KnowHowComputer Web Component | // Define the KnowHowComputer Web Component | ||
class KnowHowComputerElement extends HTMLElement { | class KnowHowComputerElement extends HTMLElement { | ||
static observedAttributes = ['no-help']; | |||
constructor() { | constructor() { | ||
| Zeile 33: | Zeile 16: | ||
display: block; | display: block; | ||
font-size: calc(15px + 0.390625vw); | font-size: calc(15px + 0.390625vw); | ||
} | |||
.no-help .khc-help { | |||
display: none; | |||
} | } | ||
:host > div { | :host > div { | ||
display: grid; | display: grid; | ||
gap: | gap: 1rem; | ||
grid-template-areas: | grid-template-areas: | ||
"title title" | "title title" | ||
"nav | "nav nav " | ||
"main side "; | "main side "; | ||
grid-template-rows: min-content min-content; | |||
> h1:first-child { | > h1:first-child { | ||
| Zeile 67: | Zeile 55: | ||
display: flex; | display: flex; | ||
flex-direction: column; | flex-direction: column; | ||
fieldset { | |||
display: flex; | |||
flex-direction: column; | |||
gap:0.5rem; | |||
} | |||
} | } | ||
| Zeile 82: | Zeile 76: | ||
} | } | ||
@media (max-width: | @media (max-width: 600px) { | ||
:host > div { | :host > div { | ||
display: flex; | display: flex; | ||
flex-direction: column; | flex-direction: column; | ||
grid-template-areas: | grid-template-areas: "title" "nav" "main" "side"; | ||
} | |||
nav { | |||
flex-direction: column; | |||
} | } | ||
} | } | ||
| Zeile 116: | Zeile 112: | ||
aria-describedby="descr-speicheranzeigefeld"> | aria-describedby="descr-speicheranzeigefeld"> | ||
</textarea> | </textarea> | ||
<fieldset id="memory-selector"> | |||
<legend>Speicherkonfiguration laden:</legend> | |||
</fieldset> | |||
</main> | </main> | ||
<aside> | <aside class="khc-help"> | ||
<details open> | <details open> | ||
<summary><span is="h2">Bedeutung der KHC Befehle</span></summary> | <summary><span is="h2">Bedeutung der KHC Befehle</span></summary> | ||
| Zeile 222: | Zeile 218: | ||
refreshMemoryConfigurations() { | refreshMemoryConfigurations() { | ||
this.memoryConfigurations = [ | this.memoryConfigurations = [ | ||
...this.parseMemoryElements() | ...this.parseMemoryElements() | ||
]; | ]; | ||
this.refreshMemorySelector(this.memoryConfigurations); | this.refreshMemorySelector(this.memoryConfigurations); | ||
} | |||
refreshHelp() { | |||
this.shadowRoot.querySelector(':host > div') | |||
.classList | |||
.toggle('no-help', this.hasAttribute('no-help')); | |||
} | |||
attributeChangedCallback (name, oldValue, newValue) { | |||
this.refreshHelp() | |||
} | } | ||
| Zeile 238: | Zeile 243: | ||
}); | }); | ||
this.observer.observe(this, {childList: true}); | this.observer.observe(this, {childList: true}); | ||
// Add event listener for memory selector | // Add event listener for memory selector | ||
const memorySelector = this.shadowRoot.getElementById('memory-selector'); | const memorySelector = this.shadowRoot.getElementById('memory-selector'); | ||
memorySelector.addEventListener(' | memorySelector.addEventListener('click', (e) => { | ||
const selectedValue = | const selectedValue = e.target.value; | ||
// Load program from khc-memory elements | // Load program from khc-memory elements | ||
const index = parseInt(selectedValue); | const index = parseInt(selectedValue); | ||
| Zeile 248: | Zeile 254: | ||
this.loadMemoryConfiguration(this.memoryConfigurations[index]); | this.loadMemoryConfiguration(this.memoryConfigurations[index]); | ||
} | } | ||
e.preventDefault(); | |||
}); | }); | ||
this.refreshMemoryConfigurations(); | |||
this.refreshHelp(); | |||
} | } | ||
| Zeile 290: | Zeile 297: | ||
refreshMemorySelector(memoryConfigurations) { | refreshMemorySelector(memoryConfigurations) { | ||
const memorySelector = this.shadowRoot.getElementById('memory-selector'); | const memorySelector = this.shadowRoot.getElementById('memory-selector'); | ||
memorySelector.querySelectorAll('button').forEach(button => memorySelector.removeChild(button)); | |||
// Add options for each memory configuration | // Add options for each memory configuration | ||
memoryConfigurations.forEach((config, index) => { | memoryConfigurations.forEach((config, index) => { | ||
const | const button = document.createElement('button'); | ||
button.value = (index).toString(); | |||
button.textContent = config.name; | |||
memorySelector.appendChild( | button.type = 'button'; | ||
memorySelector.appendChild(button); | |||
}); | }); | ||
} | } | ||
| Zeile 719: | Zeile 725: | ||
customElements.define('khc-memory', KhcMemoryElement, {extends: 'pre'}); | customElements.define('khc-memory', KhcMemoryElement, {extends: 'pre'}); | ||
} | } | ||
<know-how-computer></know-how-computer> | |||
// Initialize when the DOM is loaded | |||
document.addEventListener('DOMContentLoaded', function () { | |||
// For MediaWiki gadget, this would be the initialization code | |||
// No need to do anything here as the custom element will initialize itself when added to the DOM | |||
}); | |||
})(); | |||
</script> | |||
<know-how-computer <!-- {$noHelp|validate:boolean ? 'no-help' : ''} --> > | |||
<!-- {if $param1|default:false} --> | |||
<khc-memory><!-- {$param1|escape"htmlall} --></khc-memory> | |||
<!-- {/if} --> | |||
</know-how-computer> | |||
</includeonly> | |||
