From 183efca5c0cfd064f06b34a92b6cd9be3e0d75bf Mon Sep 17 00:00:00 2001 From: itsMontoya Date: Fri, 16 Dec 2016 15:04:20 -0800 Subject: [PATCH 1/4] Implementing window.history --- dom.go | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/dom.go b/dom.go index 97f98a4..ccc3771 100644 --- a/dom.go +++ b/dom.go @@ -113,6 +113,7 @@ import ( "time" "github.com/gopherjs/gopherjs/js" + "honnef.co/go/js/console" ) // toString returns the string representation of o. If o is nil or @@ -1043,8 +1044,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 { @@ -2851,3 +2851,35 @@ func (css *CSSStyleDeclaration) Length() int { type Text struct { *BasicNode } + +type history struct { + *js.Object +} + +func (h *history) Length() int { + return h.Get("state") +} + +func (h *history) State() interface{} { + return h.Get("state") +} + +func (h *history) Back() { + h.Object.Call("forward") +} + +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) +} From 17e0171dec74ee1d64583d357b124cdc0229bef3 Mon Sep 17 00:00:00 2001 From: itsMontoya Date: Fri, 16 Dec 2016 15:11:34 -0800 Subject: [PATCH 2/4] Removed reference to 'console' package, as it's no longer being used. Fixed return value type for history.Length --- dom.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dom.go b/dom.go index ccc3771..aae05e9 100644 --- a/dom.go +++ b/dom.go @@ -113,7 +113,6 @@ import ( "time" "github.com/gopherjs/gopherjs/js" - "honnef.co/go/js/console" ) // toString returns the string representation of o. If o is nil or @@ -2857,7 +2856,7 @@ type history struct { } func (h *history) Length() int { - return h.Get("state") + return h.Get("state").Int() } func (h *history) State() interface{} { From fc1d809ce3f265f601b4e30e9d564eacecfd0f19 Mon Sep 17 00:00:00 2001 From: itsmontoya Date: Sun, 18 Dec 2016 22:33:51 -0800 Subject: [PATCH 3/4] Removing non-needed reference to h.Object --- dom.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dom.go b/dom.go index aae05e9..11dae4e 100644 --- a/dom.go +++ b/dom.go @@ -2864,21 +2864,21 @@ func (h *history) State() interface{} { } func (h *history) Back() { - h.Object.Call("forward") + h.Call("forward") } func (h *history) Forward() { - h.Object.Call("forward") + h.Call("forward") } func (h *history) Go(offset int) { - h.Object.Call("go", offset) + h.Call("go", offset) } func (h *history) PushState(state interface{}, title string, url string) { - h.Object.Call("pushState", state, title, url) + h.Call("pushState", state, title, url) } func (h *history) ReplaceState(state interface{}, title string, url string) { - h.Object.Call("replaceState", state, title, url) + h.Call("replaceState", state, title, url) } From b3f3f2e76e91cef9af62e824eb81731aa3d2c26a Mon Sep 17 00:00:00 2001 From: itsMontoya Date: Mon, 23 Jan 2017 11:28:30 -0800 Subject: [PATCH 4/4] Fixed h.Get references, copy/paste bug --- dom.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.go b/dom.go index 11dae4e..9d9f335 100644 --- a/dom.go +++ b/dom.go @@ -2856,7 +2856,7 @@ type history struct { } func (h *history) Length() int { - return h.Get("state").Int() + return h.Get("length").Int() } func (h *history) State() interface{} { @@ -2864,7 +2864,7 @@ func (h *history) State() interface{} { } func (h *history) Back() { - h.Call("forward") + h.Call("back") } func (h *history) Forward() {