Skip to content

Commit

Permalink
added set-prop as a new transfromation
Browse files Browse the repository at this point in the history
  • Loading branch information
ckirkendall committed Jul 29, 2012
1 parent 5be2ee9 commit 89f4feb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
12 changes: 9 additions & 3 deletions project/cljs-src/enfocus/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,20 @@
[& values]
(let [pairs (partition 2 values)]
(domina-chain
#(doseq [[name value] pairs] (domina/set-attr! % name value)))))

#(doseq [[name value] pairs] (domina/set-attr! % name value)))))

(defn en-remove-attr
"Dissocs attributes on the selected element."
[& values]
(domina-chain #(doseq [name values] (domina/remove-attr! % name))))



(defn en-set-prop [& forms]
(chainable-standard
(fn [node]
(let [h (mapcat (fn [[n v]](list (name n) v)) (partition 2 forms))]
(dom/setProperties node (apply js-obj h))))))


(defn- has-class
"returns true if the element has a given class"
Expand Down
2 changes: 2 additions & 0 deletions project/cljs-src/enfocus/enlive/syntax.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@

(defn but [& sel]
(str "not(" (convert sel) ")"))


3 changes: 2 additions & 1 deletion project/cljs-src/enfocus/example.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
["#mv-tst"] (em/move 300 305 500
(em/move 0 0 500))))
["#test-from"] (em/listen :click test-from)
["#test-get-text"] (em/listen :click test-get-text))
["#test-get-text"] (em/listen :click test-get-text)
["#cb1"] (em/set-prop :checked true))

;(em/defaction test-suite [])

Expand Down
3 changes: 2 additions & 1 deletion project/cljs-src/enfocus/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@
(defmacro set-attr [& forms]
`(enfocus.core/en-set-attr ~@forms))


(defmacro remove-attr [& forms]
`(enfocus.core/en-remove-attr ~@forms))

(defmacro set-prop [& forms]
`(enfocus.core/en-set-prop ~@forms))

(defmacro add-class [& forms]
`(enfocus.core/en-add-class ~@forms))
Expand Down
6 changes: 3 additions & 3 deletions sample/resources/public/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
<form id="from-form">
<input id="ftest1" name="test1" value="Testing1"/><br>
<input id="ftest2" name="test2" value="Testing2"/><br>
one<input name="test3" type="checkbox" value="one">
two<input name="test3" type="checkbox" value="two">
three<input name="test3" type="checkbox" value="thee"><br>
one<input id="cb1" name="test3" type="checkbox" value="one">
two<input id="cb2" name="test3" type="checkbox" value="two">
three<input id="cb3" name="test3" type="checkbox" value="thee"><br>
<select name="test4" multiple="multiple">
<option value="ten">ten</option>
<option value="twenty">twenty</option>
Expand Down

0 comments on commit 89f4feb

Please sign in to comment.