Permalink
Browse files

fix event targets not being closed over correctly

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
1 parent 0b23c63 commit 502205c278c302ecdedbe65ae464003f75d61d0a @ibdknox committed Sep 28, 2011
Showing with 19 additions and 16 deletions.
  1. +19 −14 src/pinot/events.cljs
  2. +0 −2 src/pinot/html/tags.cljs
View
@@ -21,29 +21,34 @@
(defn match? [{:keys [elem pinotGroup pinotId]} init-target]
(loop [target init-target]
- (let [target-group (dom/attr target :pinotGroup)
- target-pinot (dom/attr target :pinotId)]
- (when (not= target (dom/parent (get-body)))
- (if (or
- (and elem (= elem target))
- (and pinotGroup (= pinotGroup target-group))
- (and pinotId (= pinotId target-pinot)))
- target
- (recur (dom/parent target)))))))
+ (when target
+ (let [target-group (dom/attr target :pinotGroup)
+ target-pinot (dom/attr target :pinotId)]
+ (when (not= target (dom/parent (get-body)))
+ (if (or
+ (and elem (= elem target))
+ (and pinotGroup (= pinotGroup target-group))
+ (and pinotId (= pinotId target-pinot)))
+ target
+ (recur (dom/parent target))))))))
+
+(defn make-listener [func parsed]
+ (fn [e]
+ (let [target (.target e)]
+ (if-let [match (match? parsed target)]
+ (func match e)
+ true))))
(defn on [elem event func]
(let [ev-name (string/upper-case (name event))
event (aget events/EventType ev-name)
body-elem (get-body)]
(doseq [el (pclj/->coll elem)]
(let [parsed (->target el)]
+ (pjs/log parsed)
(events/listen body-elem
event
- (fn [e]
- (let [target (.target e)]
- (if-let [match (match? parsed target)]
- (func match e)
- true))))))
+ (make-listener func parsed))))
elem))
(defn prevent [e]
View
@@ -1,8 +1,6 @@
(ns pinot.html.tags
(:require-macros [pinot.macros :as pm]))
-;;TODO: this needs to handle extra attributes
-
;; From Weavejester's Hiccup: https://github.com/weavejester/hiccup/blob/master/src/hiccup/core.clj#L284
(defn add-optional-attrs
"Add an optional attribute argument to a function that returns a vector tag."

0 comments on commit 502205c

Please sign in to comment.