Permalink
Browse files

added the ability to bind events to a partial function itself

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
1 parent 53a86eb commit 845073a5256beaf3a7e48c6536b1d5244e3ce4d0 @ibdknox committed Aug 22, 2011
Showing with 20 additions and 16 deletions.
  1. +8 −7 src/pinot/events.cljs
  2. +8 −5 src/pinot/html.cljs
  3. +3 −3 src/pinot/macros.clj
  4. +1 −1 src/pinot/util/js.cljs
View
@@ -1,6 +1,7 @@
(ns pinot.events
(:require [goog.events :as events]
[pinot.util.clj :as pclj]
+ [pinot.util.js :as pjs]
[pinot.html :as html]
[clojure.string :as string]))
@@ -14,19 +15,19 @@
;;TODO: this is ugly.
(defn ->target [elem]
(cond
- (fn? elem) {:group-id (:pinot-group (meta elem))}
- (html/attr elem :pinot-id) {:elem elem :pinot-id (html/attr elem :pinot-id)}
+ (fn? elem) {:pinotGroup (html/attr (first (elem)) :pinotGroup)}
+ (html/attr elem :pinotId) {:elem elem :pinotId (html/attr elem :pinotId)}
:else {:elem elem }))
-(defn match? [{:keys [elem group-id pinot-id]} init-target]
+(defn match? [{:keys [elem pinotGroup pinotId]} init-target]
(loop [target init-target]
- (let [target-group (html/attr target :group-id)
- target-pinot (html/attr target :pinot-id)]
+ (let [target-group (html/attr target :pinotGroup)
+ target-pinot (html/attr target :pinotId)]
(when (not= target (html/parent (get-body)))
(if (or
(and elem (= elem target))
- (and group-id (= group-id target-group))
- (and pinot-id (= pinot-id target-pinot)))
+ (and pinotGroup (= pinotGroup target-group))
+ (and pinotId (= pinotId target-pinot)))
target
(recur (html/parent target)))))))
View
@@ -22,9 +22,12 @@
(defn attr [elem attrs]
(if-not (map? attrs)
- (aget elem (name attrs))
- (doseq [el (pclj/->coll elem)]
- (dom/setProperties el (pjs/map->js attrs)))))
+ (. elem (getAttribute (name attrs)))
+ (do
+ (doseq [el (pclj/->coll elem)
+ [k v] attrs]
+ (. el (setAttribute (name k) v)))
+ elem)))
(defn val [elem & [v]]
(let [elem (if (seq elem)
@@ -40,6 +43,7 @@
(declare elem-factory)
(def elem-id (atom 0))
+(def group-id (atom 0))
(defn as-content [parent content]
(doseq[c content]
@@ -84,7 +88,7 @@
(defn elem-factory [tag-def]
(let [[tag attrs content] (normalize-element tag-def)
elem (dom/createElement tag (pjs/map->js attrs))]
- (attr elem {:pinot-id (swap! elem-id inc)})
+ (attr elem {:pinotId (swap! elem-id inc)})
(as-content elem content)
elem))
@@ -103,7 +107,6 @@
(defn dom-clone [elem]
(let [neue (. elem (cloneNode true))]
- (attr neue {:pinot-id (.pinotId elem)})
neue))
;;TODO: for a collection of elements it appends the same DOM
@@ -2,13 +2,13 @@
(defmacro defpartial
[name params & body]
- `(let [group# (swap! inc pinot.html/group-counter)]
- (defn ^{:pinot-group group#}
+ `(let [group# (swap! pinot.html/group-id inc)]
+ (defn ^{:pinotGroup group#}
~name ~params
(pinot.html/attr
(pinot.html/html
~@body)
- {:pinot-group group#}))))
+ {:pinotGroup group#}))))
(defmacro defelem
"Defines a function that will return a tag vector. If the first argument
@@ -7,4 +7,4 @@
out))
(defn log [text]
- (. (js* "console") (log text)))
+ (. js/console (log text)))

0 comments on commit 845073a

Please sign in to comment.