diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d56269..b9ae60b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +0.1.5 + * Internal refactoring + * Extended browser event gating for meta key, alt key, ctrl key, shift key, etc. + 0.1.4 * Modify `navigate!` to not suppress browser events when the user tries to open a new tab diff --git a/README.md b/README.md index 91d96ee..a9e3f6b 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ browsers will be left behind. Just add the following to your `project.clj`: ```clojure -:dependencies [venantius/accountant "0.1.4"] +:dependencies [venantius/accountant "0.1.5"] ``` ## Usage diff --git a/project.clj b/project.clj index 2c93412..1c473a8 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject venantius/accountant "0.1.4" +(defproject venantius/accountant "0.1.5" :description "Navigation for Single-Page Applications Made Easy." :url "http://github.com/venantius/accountant" :license {:name "Eclipse Public License" diff --git a/src/accountant/core.cljs b/src/accountant/core.cljs index b568815..d32490c 100644 --- a/src/accountant/core.cljs +++ b/src/accountant/core.cljs @@ -29,11 +29,10 @@ "Given a DOM element that may or may not be a link, traverse up the DOM tree to see if any of its parents are links. If so, return the href content." [e] - ((fn [e] - (if-let [href (.-href e)] - href - (when-let [parent (.-parentNode e)] - (recur parent)))) (.-target e))) + (if-let [href (.-href e)] + href + (when-let [parent (.-parentNode e)] + (recur parent)))) (defn- prevent-reload-on-known-path "Create a click handler that blocks page reloads for known routes in @@ -43,15 +42,16 @@ js/document "click" (fn [e] - (let [button (.-button e) - meta-key (.metaKey e) - alt-key (.altKey e) - ctrl-key (.ctrlKey e) - shift-key (.shiftKey e) + (let [target (.-target e) + button (.-button e) + meta-key (.-metaKey e) + alt-key (.-altKey e) + ctrl-key (.-ctrlKey e) + shift-key (.-shiftKey e) any-key (or meta-key alt-key ctrl-key shift-key) - href (find-href e) + href (find-href target) path (.getPath (.parse Uri href)) - title (.-title (.-target e))] + title (.-title target)] (when (and (not any-key) (= button 0) (secretary/locate-route path)) (. history (setToken path title)) (.preventDefault e))))))