-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.nim
52 lines (42 loc) · 1.26 KB
/
button.nim
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import karax / [karax, karaxdsl,vdom, vstyles,kbase]
import dom
import math
import jsffi, tables
from sugar import `=>`
import mdcRippleFoundation
proc login(e:Event, n: VNode) =
echo n.dom.nodeName
proc loginButton():VNode =
buildHtml button(class="mdc-button mdc-button--raised", onmousedown = ripple, onblur = blurHandler, onfocus = focusHandler, onclick = login):
span(class = "mdc-button__label"):text "LOG IN"
type
State = ref object
originalTitle: cstring
url: Location
proc copyLocation(loc: Location): Location =
Location(
hash: loc.hash,
host: loc.host,
hostname: loc.hostname,
href: loc.href,
pathname: loc.pathname,
port: loc.port,
protocol: loc.protocol,
search: loc.search
)
proc newState(): State =
State(
originalTitle: document.title,
url: copyLocation(window.location),
)
var state = newState()
proc createDom(): VNode =
buildHtml tdiv(class = "login"):
loginButton()
proc onPopState(event: Event) =
document.title = state.originalTitle
if state.url.href != window.location.href:
state = newState()
state.url = copyLocation(window.location)
window.onpopstate = onpopstate
setRenderer createDom