startit/MVC/skjemaer.html

109 lines
3.1 KiB
HTML
Raw Normal View History

2024-08-29 10:33:18 +02:00
<!DOCTYPE html>
<html lang="en">
2024-08-30 10:34:25 +02:00
2024-08-29 10:33:18 +02:00
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2024-08-30 10:34:25 +02:00
<title>Document</title>
2024-08-29 10:33:18 +02:00
</head>
2024-08-30 10:34:25 +02:00
2024-08-29 10:33:18 +02:00
<body>
<div id="app">
2024-08-30 10:34:25 +02:00
2024-08-29 10:33:18 +02:00
</div>
<script>
2024-08-30 10:34:25 +02:00
// Model
let aName;
let number;
let fontFamily;
let fontSize;
let isDarkMode = false;
2024-08-29 10:33:18 +02:00
// view
updateView()
2024-08-30 10:34:25 +02:00
function updateView() {
// let extraWord = '';
// if (number < 10){
// extraWord = 'ikke';
// } else {
// extraWord = '';
// }
document.getElementById('app').innerHTML = /*HTML*/ `
<p>Hei ${aName ?? 'på deg!'}</p>
Navn:<br>
<input
type="text"
oninput="aName=this.value"
value="${aName ?? ''}"/>
Tall:<br>
<input
type="range"
min="1"
max="100"
step="1"
oninput="number=this.valueAsNumber"
value ="${number ?? ''}">${number ?? ''}
<br>
<input
type="checkbox"
oninput="isDarkMode=this.checked"
${isDarkMode ? 'checked' : ''}
>
Dark Mode:
<br>
<button onclick="selectFont('helvetica')">Font A</button>
<button onclick="selectFont('courier')">Font B</button>
<br>
<button
onclick="register()">Registrer</button><br>
<b>Font-størrelse</b><br>
Normal
<input
type="radio"
name="fontSize"
oninput="fontSize='100%'"
${fontSize == '100%' ? 'checked' : ''}
/><br>
50%
<input
type="radio"
name="fontSize"
oninput="fontSize='50%'"
${fontSize == '50%' ? 'checked' : ''}
/> <br>
200%
<input
type="radio"
name="fontSize"
oninput="fontSize='200%'"
${fontSize == '200%' ? 'checked' : ''}
><br>
2024-08-29 10:33:18 +02:00
`;
2024-08-30 10:34:25 +02:00
let bodyStyle = document.body.style;
bodyStyle.fontFamily = fontFamily ?? serif;
if (isDarkMode){
bodyStyle.background = 'black';
bodyStyle.color = 'white';
} else {
bodyStyle.background = 'white';
bodyStyle.color = 'black';
2024-08-29 10:33:18 +02:00
};
2024-08-30 10:34:25 +02:00
bodyStyle.fontSize = fontSize;
}
// Controller
function register() {
updateView();
}
function selectFont(newFontFamily){
fontFamily = newFontFamily;
updateView()
2024-08-29 10:33:18 +02:00
}
</script>
</body>
2024-08-30 10:34:25 +02:00
2024-08-29 10:33:18 +02:00
</html>