Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 934df802a5
Fetching contributors…

Cannot retrieve contributors at this time

49 lines (41 sloc) 1.658 kb
(ns ^{:doc "Supports working with [Google Closure's history management object][gch].
(:require [clojure.browser.event :as event]
[goog.History :as history]
[goog.history.Html5History :as history5]))
(extend-type goog.History
(event-types [this]
(into {}
(fn [[k v]]
[(keyword (. k (toLowerCase)))
(js->clj goog.history.EventType)))))
(defn history
"Create a new history object in user visible mode. This allows users
to, for example, hit the browser's back button without leaving the
current page. The current history state is shown in the browser
address bar as a document location fragment (the portion of the URL
after the '#'). These addresses can be bookmarked, copied and pasted
into another browser, and modified directly by the user like any
other URL.
Any changes to the location hash will call the passed callback
(let [h (if (history5/isSupported)
(do (event/listen h "navigate"
(fn [e]
(callback {:token (keyword (.-token e))
:type (.-type e)
:navigation? (.-isNavigation e)})))
(.setEnabled h true)
(defn set-token
"Sets the `history` state. The URL fragment will be set to the
provided token."
[history token]
(.setToken history (name token)))
Jump to Line
Something went wrong with that request. Please try again.