-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
33 lines (27 loc) · 1.07 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
import {htmlToElement, Observable} from "./framework.js";
let mainInput = document.querySelector("input");
const nInputs = new Observable(mainInput.valueAsNumber);
const message = new Observable("Binded data");
function inputElement() {
let element = htmlToElement(`<article>
<input name="msg" type="text" style="max-width: 17cm; width: 100%" >
<br><br>
</article>`);
let input = element.querySelector('input');
input.value = message.value;
input.oninput = () => {message.value = input.value};
input.onmouseenter = () => input.focus();
message.subscribe(input, () => input.value = message.value);
return element;
}
function inputsElement() {
let element = htmlToElement(`<section id="inputs"></section>`);
for (let i = 0; i < nInputs.value; i++)
element.appendChild(inputElement());
nInputs.subscribe(element, () => element.replaceWith(inputsElement()));
return element;
}
mainInput.oninput = () => {nInputs.value = mainInput.valueAsNumber};
mainInput.onmouseenter = () => mainInput.select();
document.getElementById("inputs").replaceWith(inputsElement());