Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added keys-down, which allows listening to multiple keys in one call

  • Loading branch information...
commit b7a1d720e51f0b8c7080bf99be30c6cd2db52b95 1 parent 46c2066
@zk authored
Showing with 23 additions and 2 deletions.
  1. +23 −2 src/cljs/nsfw/dom.cljs
View
25 src/cljs/nsfw/dom.cljs
@@ -179,8 +179,12 @@
els)
(defn handler [evt]
- (fn [els f]
- (listen els (name evt) f)))
+ (fn
+ ([els f]
+ (listen els (name evt) f))
+ ([els sel f]
+ (listen (dom/$ els sel) (name evt) f)
+ els)))
(def click (handler :click))
(def dblclick (handler :dblclick))
@@ -269,6 +273,23 @@
(f e el)))))
els)
+(defn keys-down [root & args]
+ (let [sel (when (-> args count odd?)
+ (first args))
+ args (if (-> args count odd?)
+ (rest args)
+ args)
+ pairs (partition 2 args)
+ els (if sel ($ root sel) root)]
+ (when (> (count els) 0)
+ (doseq [[target-key f] pairs]
+ (keydown
+ els
+ (fn [{:keys [key-code] :as e}]
+ (when (= key-code target-key)
+ (f e els))))))
+ root))
+
(defn scroll-end [els f]
(doseq [el (ensure-coll els)]
(let [timer (atom -1)]
Please sign in to comment.
Something went wrong with that request. Please try again.