Skip to content

Commit

Permalink
[accountant] internal refactoring
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
venantius committed Nov 15, 2015
1 parent 1eee43d commit 500b66f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
24 changes: 12 additions & 12 deletions src/accountant/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))))))
Expand Down

0 comments on commit 500b66f

Please sign in to comment.