aboutsummaryrefslogtreecommitdiff
path: root/src/main.ts
diff options
context:
space:
mode:
authorJoris2020-02-13 18:54:18 +0100
committerJoris2020-02-15 10:59:25 +0100
commit7a01b001ccc4a7bda3da92486903540e3f9754fd (patch)
treefbe269faa319fd7f21049612f8a62c0c169f369e /src/main.ts
parent8328c11ac6706e3adf9b09877c02897132b8927a (diff)
downloadcooking-7a01b001ccc4a7bda3da92486903540e3f9754fd.tar.gz
cooking-7a01b001ccc4a7bda3da92486903540e3f9754fd.tar.bz2
cooking-7a01b001ccc4a7bda3da92486903540e3f9754fd.zip
Set up bucklescript
Diffstat (limited to 'src/main.ts')
-rw-r--r--src/main.ts71
1 files changed, 0 insertions, 71 deletions
diff --git a/src/main.ts b/src/main.ts
deleted file mode 100644
index 184d26d..0000000
--- a/src/main.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import * as number from './number'
-import * as dom from './dom'
-
-/* Set up inputs for the ingredients */
-
-const itemEntries =
- dom.nodeListToArray(document.querySelectorAll('.g-Recipe__Content ul > li'))
- .map(itemNode => ({ name: 'li', node: itemNode }))
-
-const h1 = document.querySelector<HTMLElement>('.g-Recipe__Content h1')
-
-if (h1 !== null) {
- itemEntries.push({ name: 'h1', node: h1 })
-}
-
-const inputs = setupInputs(itemEntries)
-
-inputs.map(input => {
- input.node.oninput = e => {
- if (e.target !==null) {
- const parsed = number.parse((e.target as HTMLInputElement).value)
-
- if (parsed !== undefined) {
- const factor = parsed.number / input.number
- inputs.map(input2 => {
- if (input.node !== input2.node) {
- input2.node.value = number.prettyPrint(input2.number * factor)
- }
- })
- }
- }
- }
-})
-
-interface InputTag {
- name: string;
- node: HTMLElement;
-}
-
-interface InputResult {
- number: number,
- node: HTMLInputElement
-}
-
-function setupInputs(tags: InputTag[]): InputResult[] {
- const res: InputResult[] = []
-
- tags.forEach(tag => {
- const parsed = number.parseInsideText(tag.node.innerText)
-
- if (parsed !== undefined) {
- const numberNode = number.node(tag.name, parsed)
- dom.replace(tag.node, numberNode.node)
- res.push({
- number: parsed.number,
- node: numberNode.numberInput
- })
- }
- })
-
- return res
-}
-
-/* Set up done marks for steps */
-
-dom.nodeListToArray(document.querySelectorAll('.g-Recipe__Content ol > li')).forEach(todo => {
- todo.onclick = e => {
- dom.toggleClassName(todo, 'g-Recipe__Completed')
- e.stopPropagation()
- }
-})