Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing window.history #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions dom.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,7 @@ func (w *window) Top() Window {
}

func (w *window) History() History {
// FIXME implement
return nil
return &history{w.Get("history")}
}

func (w *window) Navigator() Navigator {
Expand Down Expand Up @@ -2851,3 +2850,35 @@ func (css *CSSStyleDeclaration) Length() int {
type Text struct {
*BasicNode
}

type history struct {
*js.Object
}

func (h *history) Length() int {
return h.Get("state").Int()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to write h.Get("length").Int() here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch. I'll fix

}

func (h *history) State() interface{} {
return h.Get("state")
}

func (h *history) Back() {
h.Object.Call("forward")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style suggestion. For consistency with above h.Get and the rest of the package, you can skip skip .Object since it's an embedded struct, just do h.Call("forward").

Here, and in 4 places below.

}

func (h *history) Forward() {
h.Object.Call("forward")
}

func (h *history) Go(offset int) {
h.Object.Call("go", offset)
}

func (h *history) PushState(state interface{}, title string, url string) {
h.Object.Call("pushState", state, title, url)
}

func (h *history) ReplaceState(state interface{}, title string, url string) {
h.Object.Call("replaceState", state, title, url)
}