From 500b66fde2816d42c82f901d3734731e75542faa Mon Sep 17 00:00:00 2001 From: Ursa Americanus Kermodei Date: Sat, 14 Nov 2015 18:32:52 -0800 Subject: [PATCH] [accountant] internal refactoring Refactoring `find-href` to not use an anonymous function. Also, cleans up meta-key, alt-key, etc to be called properly at attributes, not functions. --- CHANGELOG.md | 4 ++++ README.md | 2 +- project.clj | 2 +- src/accountant/core.cljs | 24 ++++++++++++------------ 4 files changed, 18 insertions(+), 14 deletions(-) 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))))))