Skip to content

Commit

Permalink
Use HTML 5 History when supported. Fixes #32.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brenton Ashworth committed Jan 6, 2012
1 parent 0c81165 commit b8882f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/app/cljs/one/sample/controller.cljs
Expand Up @@ -29,7 +29,8 @@
(reset! state {:state :init}))

(defmethod action :form [_]
(swap! state assoc :state :form))
(when-not (#{:form :init} (:state @state))
(swap! state assoc :state :form)))

(defn host
"Get the name of the host which served this script."
Expand Down
7 changes: 5 additions & 2 deletions src/lib/cljs/one/browser/history.cljs
Expand Up @@ -3,7 +3,8 @@

one.browser.history
(:require [clojure.browser.event :as event]
[goog.History :as history]))
[goog.History :as history]
[goog.history.Html5History :as history5]))

(extend-type goog.History

Expand All @@ -28,7 +29,9 @@
Any changes to the location hash will call the passed callback
function."
[callback]
(let [h (goog.History.)]
(let [h (if (history5/isSupported)
(goog.history.Html5History.)
(goog.History.))]
(do (event/listen h "navigate"
(fn [e]
(callback {:token (keyword (.token e))
Expand Down

0 comments on commit b8882f3

Please sign in to comment.