renamed key to 'index'; all virtual components have a 'key' attribute
This commit is contained in:
parent
5838271f8b
commit
91d7ba25ea
5 changed files with 37 additions and 41 deletions
|
|
@ -15,7 +15,7 @@ proc `width=`(n: Node, w: int) {.importcpp: "#.width = #".}
|
|||
proc mplayer*(id, resource: cstring): VNode {.compact.} =
|
||||
proc handler(ev: Event; n: VNode) =
|
||||
let myVideo = document.getElementById(id)
|
||||
case n.key
|
||||
case n.index
|
||||
of Play:
|
||||
if myVideo.paused:
|
||||
myVideo.play()
|
||||
|
|
@ -27,13 +27,13 @@ proc mplayer*(id, resource: cstring): VNode {.compact.} =
|
|||
else: discard
|
||||
|
||||
result = buildHtml(tdiv):
|
||||
button(onclick=handler, key=Play):
|
||||
button(onclick=handler, index=Play):
|
||||
text "Play/Pause"
|
||||
button(onclick=handler, key=Big):
|
||||
button(onclick=handler, index=Big):
|
||||
text "Big"
|
||||
button(onclick=handler, key=Small):
|
||||
button(onclick=handler, index=Small):
|
||||
text "Small"
|
||||
button(onclick=handler, key=Normal):
|
||||
button(onclick=handler, index=Normal):
|
||||
text "Normal"
|
||||
br()
|
||||
br()
|
||||
|
|
|
|||
|
|
@ -45,19 +45,19 @@ proc onTodoEnter(ev: Event; n: VNode) =
|
|||
n.value = ""
|
||||
|
||||
proc removeHandler(ev: Event; n: VNode) =
|
||||
updateEntry(n.key, cstring(nil), false)
|
||||
updateEntry(n.index, cstring(nil), false)
|
||||
|
||||
proc editHandler(ev: Event; n: VNode) =
|
||||
selectedEntry = n.key
|
||||
selectedEntry = n.index
|
||||
|
||||
proc focusLost(ev: Event; n: VNode) = selectedEntry = -1
|
||||
|
||||
proc editEntry(ev: Event; n: VNode) =
|
||||
setEntryContent(n.key, n.value)
|
||||
setEntryContent(n.index, n.value)
|
||||
selectedEntry = -1
|
||||
|
||||
proc toggleEntry(ev: Event; n: VNode) =
|
||||
let id = n.key
|
||||
let id = n.index
|
||||
markAsCompleted(id, not isCompleted(id))
|
||||
|
||||
proc onAllDone(ev: Event; n: VNode) =
|
||||
|
|
@ -83,12 +83,12 @@ proc createEntry(id: int; d: cstring; completed, selected: bool): VNode {.compac
|
|||
if not selected:
|
||||
tdiv(class = "view"):
|
||||
input(class = "toggle", `type` = "checkbox", checked = toChecked(completed),
|
||||
onclick=toggleEntry, key=id)
|
||||
label(onDblClick=editHandler, key=id):
|
||||
onclick=toggleEntry, index=id)
|
||||
label(onDblClick=editHandler, index=id):
|
||||
text d
|
||||
button(class = "destroy", key=id, onclick=removeHandler)
|
||||
button(class = "destroy", index=id, onclick=removeHandler)
|
||||
else:
|
||||
input(class = "edit", name = "title", key=id,
|
||||
input(class = "edit", name = "title", index=id,
|
||||
onblur = focusLost,
|
||||
onkeyupenter = editEntry, value = d, setFocus=true)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue