First commit of homework assistant. Only contains vocabulary base functionality
This commit is contained in:
31
javascript/homeworkElement.js
Normal file
31
javascript/homeworkElement.js
Normal file
@@ -0,0 +1,31 @@
|
||||
class HomeworkElement extends HTMLElement {
|
||||
|
||||
static updateTexts(container) {
|
||||
let textElements = container.querySelectorAll(".text")
|
||||
console.log(textElements)
|
||||
textElements.forEach((item, index) => {
|
||||
let itemId = item.getAttribute("id")
|
||||
let itemText = HomeworkSession.texts[itemId]
|
||||
HomeworkElement.applyText(itemText, item, null)
|
||||
})
|
||||
}
|
||||
|
||||
static applyText(sourceText, targetElement, fallback = '') {
|
||||
if(sourceText.length > 0) {
|
||||
targetElement.innerHTML = sourceText
|
||||
targetElement.innerHTML = targetElement.textContent.trim()
|
||||
} else if(fallback == '') {
|
||||
console.warn('Missing text in: ', sourceText)
|
||||
} else {
|
||||
targetElement.innerHTML = fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const HomeworkTypes = Object.freeze({
|
||||
VOCABULARY_ENGLISH: "'English vocabulary'",
|
||||
VOCABULARY_FRENCH: "'French vocabulary'",
|
||||
VOCABULARY_GERMAN: "'German vocabulary'",
|
||||
VOCABULARY_SPANISH: "'Spanish vocabulary'",
|
||||
MATH: "'Math'"
|
||||
})
|
||||
Reference in New Issue
Block a user