Skip to content

Instantly share code, notes, and snippets.

@gf3
Created October 1, 2013 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gf3/5df04fc4ed3a8bc4f84a to your computer and use it in GitHub Desktop.
Save gf3/5df04fc4ed3a8bc4f84a to your computer and use it in GitHub Desktop.
;; History
(def *h* (atom nil))
(defn start-history!
"HTML5 History API FTW!"
[uri-path]
(compare-and-set! *h* nil (new goog.history.Html5History))
(.setUseFragment @*h* false)
(.setPathPrefix @*h* "")
(.setEnabled @*h* true)
(events/listen @*h*
event-type/NAVIGATE
(fn [e]
(secretary/dispatch! (scm-js.common/get-current-path)))))
(defn ^:export navigate
"Navigate to a path including a page title"
[token title]
(. @*h* (setToken token title)))
(defn start-click-listener!
"Intercept clicks and prevent default if we have a matching route"
[]
(delegate ($ js/document) "a" :click (fn [e]
(this-as me
(when (secretary/any-matches? me.pathname)
(.preventDefault e)
(navigate me.pathname (or e.currentTarget.title "SCM Module")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment