Add localstorage support
This commit is contained in:
parent
615e20c34a
commit
e5357c54dc
|
@ -6,6 +6,7 @@ dependencies:
|
||||||
go get -u github.com/gopherjs/gopherjs
|
go get -u github.com/gopherjs/gopherjs
|
||||||
go get -u github.com/bep/debounce
|
go get -u github.com/bep/debounce
|
||||||
go get -u github.com/gopherjs/jquery
|
go get -u github.com/gopherjs/jquery
|
||||||
|
go get -u go get github.com/go-humble/locstor
|
||||||
go get -u gitlab.com/chrissexton/togoist
|
go get -u gitlab.com/chrissexton/togoist
|
||||||
|
|
||||||
togoist: togoist.go web.go dependencies
|
togoist: togoist.go web.go dependencies
|
||||||
|
|
15
web/web.go
15
web/web.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bep/debounce"
|
"github.com/bep/debounce"
|
||||||
|
"github.com/go-humble/locstor"
|
||||||
"github.com/gopherjs/jquery"
|
"github.com/gopherjs/jquery"
|
||||||
"gitlab.com/chrissexton/togoist"
|
"gitlab.com/chrissexton/togoist"
|
||||||
)
|
)
|
||||||
|
@ -25,13 +26,25 @@ func handleChange() {
|
||||||
jQuery("#output").SetText(err.Error())
|
jQuery("#output").SetText(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
locstor.SetItem("tmpl", tmpl)
|
||||||
|
locstor.SetItem("input", input)
|
||||||
jQuery("#output").SetText(out)
|
jQuery("#output").SetText(out)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getLocalStorage() {
|
||||||
|
if tmpl, err := locstor.GetItem("tmpl"); err == nil {
|
||||||
|
jQuery("#tmpl").SetText(tmpl)
|
||||||
|
}
|
||||||
|
if input, err := locstor.GetItem("input"); err == nil {
|
||||||
|
jQuery("#input").SetText(input)
|
||||||
|
}
|
||||||
|
handleChange()
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
debounced, _ := debounce.New(time.Second)
|
debounced, _ := debounce.New(time.Second)
|
||||||
jQuery("#tmpl").On(jquery.KEYUP, func() { debounced(handleChange) })
|
jQuery("#tmpl").On(jquery.KEYUP, func() { debounced(handleChange) })
|
||||||
jQuery("#input").On(jquery.KEYUP, func() { debounced(handleChange) })
|
jQuery("#input").On(jquery.KEYUP, func() { debounced(handleChange) })
|
||||||
handleChange()
|
getLocalStorage()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue